Fix aircraft markers not updating positions in real-time
Root cause: The merger was blocking position updates from the same source after the first position was established, designed for multi-source scenarios but preventing single-source position updates. Changes: - Refactor JavaScript into modular architecture (WebSocketManager, AircraftManager, MapManager, UIManager) - Add CPR coordinate validation to prevent invalid latitude/longitude values - Fix merger to allow position updates from same source for moving aircraft - Add comprehensive coordinate bounds checking in CPR decoder - Update HTML to use new modular JavaScript with cache busting - Add WebSocket debug logging to track data flow Technical details: - CPR decoder now validates coordinates within ±90° latitude, ±180° longitude - Merger allows updates when currentBest == sourceID (same source continuous updates) - JavaScript modules provide better separation of concerns and debugging - WebSocket properly transmits updated aircraft coordinates to frontend 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ddffe1428d
commit
1de3e092ae
13 changed files with 2222 additions and 33 deletions
70
assets/static/js/modules/websocket.js
Normal file
70
assets/static/js/modules/websocket.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// 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 = () => {
|
||||
console.log('WebSocket connected');
|
||||
this.onStatusChange('connected');
|
||||
};
|
||||
|
||||
this.websocket.onclose = () => {
|
||||
console.log('WebSocket disconnected');
|
||||
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);
|
||||
|
||||
// Debug: Log WebSocket messages to see what we're receiving
|
||||
if (message.data && message.data.aircraft) {
|
||||
const aircraftCount = Object.keys(message.data.aircraft).length;
|
||||
console.log(`📡 WebSocket: ${message.type} with ${aircraftCount} aircraft`);
|
||||
|
||||
// Log first few aircraft with coordinates
|
||||
let count = 0;
|
||||
for (const [icao, aircraft] of Object.entries(message.data.aircraft)) {
|
||||
if (count < 3 && aircraft.Latitude && aircraft.Longitude) {
|
||||
console.log(`📡 ${icao}: lat=${aircraft.Latitude}, lon=${aircraft.Longitude}`);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue