mirror of
https://github.com/seemueller-io/yachtpit.git
synced 2025-09-08 22:46:45 +00:00
WIP: Enable dynamic AIS stream handling based on user location and map focus.
- Prevent AIS stream from starting immediately; start upon user interaction. - Add `ais_stream_started` state for WebSocket management. - Extend `useRealAISProvider` with `userLocationLoaded` and `mapFocused` to control stream. - Update frontend components to handle geolocation and map focus. - Exclude test files from compilation Introduce WebSocket integration for AIS services - Added WebSocket-based `useRealAISProvider` React hook for real-time AIS vessel data. - Created various tests including unit, integration, and browser tests to validate WebSocket functionality. - Added `ws` dependency to enable WebSocket communication. - Implemented vessel data mapping and bounding box handling for dynamic updates.
This commit is contained in:
51
test_websocket.js
Normal file
51
test_websocket.js
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Simple WebSocket test client for AIS data
|
||||
const WebSocket = require('ws');
|
||||
|
||||
const ws = new WebSocket('ws://localhost:3000/ws');
|
||||
|
||||
ws.on('open', function open() {
|
||||
console.log('Connected to AIS WebSocket server');
|
||||
|
||||
// Send a test message
|
||||
ws.send('Hello from test client');
|
||||
});
|
||||
|
||||
ws.on('message', function message(data) {
|
||||
const message = data.toString();
|
||||
|
||||
if (message.startsWith('Connected to AIS stream')) {
|
||||
console.log('✓ Received connection confirmation:', message);
|
||||
} else if (message.startsWith('Echo:')) {
|
||||
console.log('✓ Received echo response:', message);
|
||||
} else {
|
||||
try {
|
||||
const aisData = JSON.parse(message);
|
||||
console.log('✓ Received AIS data:', {
|
||||
mmsi: aisData.mmsi,
|
||||
ship_name: aisData.ship_name,
|
||||
latitude: aisData.latitude,
|
||||
longitude: aisData.longitude,
|
||||
timestamp: aisData.timestamp
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('✓ Received message:', message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ws.on('error', function error(err) {
|
||||
console.error('WebSocket error:', err);
|
||||
});
|
||||
|
||||
ws.on('close', function close() {
|
||||
console.log('WebSocket connection closed');
|
||||
});
|
||||
|
||||
// Keep the script running for 30 seconds to receive some data
|
||||
setTimeout(() => {
|
||||
console.log('Closing connection after 30 seconds...');
|
||||
ws.close();
|
||||
process.exit(0);
|
||||
}, 30000);
|
Reference in New Issue
Block a user