Skip to main content

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 events
    • device:{deviceId} — Device-specific events
    • commands:{deviceId} — Command channel
    • telemetry:{deviceId} — Telemetry stream
    • role:{roleName} — Role-based broadcasting

EventsService

Facade for WebSocket operations:

MethodDescription
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:

MethodDescription
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) => { ... });
  • ScreenStreamingModule — Separate WebSocket namespace for WebRTC
  • CommandsModule — Command delivery via WebSocket
  • TelemetryModule — Real-time telemetry streaming