Skip to main content

Websockets & Events

We use Websockets to enable Sub-second Latency for critical alerts.

Technical Architecture

The Websocket server is built on Socket.io and runs within the same Node.js process as the HTTP API.

// app/Services/Ws.ts
this.io = new Server(server.getNodeServer(), {
adapter: createAdapter(pubClient, subClient), // Redis Adapter
});
  • Redis Adapter: We use the @socket.io/redis-adapter. This is crucial because it allows specific API instances to broadcast messages to clients connected to other API instances (Horizontal Scaling ready).
  • HandShake: Occurs on the standard HTTP port (Upgrade request).
  • Routing: Defined in start/ws_routes.ts, separating event logic from connection management.

Channels & Events

cameras Channel

Used by the Dashboard to show live status lights (Green/Red).

EventPayloadTriggered By
status:update{ id: 1, status: 'online' }Camera Manager health check

alerts Channel

Used by the Top-Bar Notification Bell and Mobile App.

EventPayloadTriggered By
new:alert{ type: 'STRESSED', boxId: 12, severity: 'critical' }Redis Worker Analysis

stream Channel

Used for the "Live Preview" modal.

  • Sends Binary MJPEG blobs directly to the client.
  • Note: Heavy bandwidth usage. Only active when a client explicitly subscribes to a specific camera ID.