WebSocket Management
Socket.IO-based real-time communication for dashboard clients and devices.
Components
EventsGateway (src/events/)
Core WebSocket gateway using Socket.IO:
- Room-based routing via
RoomManagerService:user:{userId}— User-specific eventsdevice:{deviceId}— Device-specific eventscommands:{deviceId}— Command channeltelemetry:{deviceId}— Telemetry streamrole:{roleName}— Role-based broadcasting
EventsService
Facade for WebSocket operations:
| Method | Description |
|---|---|
broadcastToUser(userId, event, data) | Send to specific user |
broadcastToRole(role, event, data) | Send to role group |
broadcast(event, data) | Send to all clients |
sendToDevice(deviceId, event, data) | Send to device room |
sendToTelemetryRoom(deviceId, event, data) | Send to telemetry subscribers |
sendCommandToDevice(deviceId, command) | Send via commands + device rooms |
WebSocket Management Service (src/websocket-management/)
Connection monitoring and statistics:
| Method | Description |
|---|---|
registerConnection(socketId, userId) | Track new connection |
unregisterConnection(socketId) | Remove connection |
updateActivity(socketId) | Touch last activity |
getConnectionStats(userId, role) | Connection statistics |
Activity threshold: 5 minutes for "active" status.
Authentication
WebSocket connections authenticated via JWT token on connect. After authentication, the client is joined to their user:{userId} room.
Client Usage
// Connect with auth
const socket = io('/events', {
auth: { token: 'jwt_token_here' }
});
// Listen for device updates
socket.on('device:status_changed', (data) => { ... });
socket.on('device:command_response', (data) => { ... });
Related Modules
ScreenStreamingModule— Separate WebSocket namespace for WebRTCCommandsModule— Command delivery via WebSocketTelemetryModule— Real-time telemetry streaming