- Remove verbose console.log statements from WebSocket, map, and aircraft managers - Keep essential error messages and warnings for debugging - Consolidate app-new.js into app.js to eliminate confusing duplicate files - Update HTML reference to use clean app.js with incremented cache version - Significantly reduce console noise for better user experience 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
No EOL
1.7 KiB
JavaScript
54 lines
No EOL
1.7 KiB
JavaScript
// WebSocket communication module
|
|
export class WebSocketManager {
|
|
constructor(onMessage, onStatusChange) {
|
|
this.websocket = null;
|
|
this.onMessage = onMessage;
|
|
this.onStatusChange = onStatusChange;
|
|
}
|
|
|
|
async connect() {
|
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const wsUrl = `${protocol}//${window.location.host}/ws`;
|
|
|
|
try {
|
|
this.websocket = new WebSocket(wsUrl);
|
|
|
|
this.websocket.onopen = () => {
|
|
this.onStatusChange('connected');
|
|
};
|
|
|
|
this.websocket.onclose = () => {
|
|
this.onStatusChange('disconnected');
|
|
// Reconnect after 5 seconds
|
|
setTimeout(() => this.connect(), 5000);
|
|
};
|
|
|
|
this.websocket.onerror = (error) => {
|
|
console.error('WebSocket error:', error);
|
|
this.onStatusChange('disconnected');
|
|
};
|
|
|
|
this.websocket.onmessage = (event) => {
|
|
try {
|
|
const message = JSON.parse(event.data);
|
|
|
|
|
|
this.onMessage(message);
|
|
} catch (error) {
|
|
console.error('Failed to parse WebSocket message:', error);
|
|
}
|
|
};
|
|
|
|
} catch (error) {
|
|
console.error('WebSocket connection failed:', error);
|
|
this.onStatusChange('disconnected');
|
|
}
|
|
}
|
|
|
|
disconnect() {
|
|
if (this.websocket) {
|
|
this.websocket.close();
|
|
this.websocket = null;
|
|
}
|
|
}
|
|
} |