Skip to main content

Signaling HTTP Socket.IO

The signaling HTTP Socket.IO has a server and a socket implementation.

The server is responsible for handling HTTP requests and WebSocket connections using Socket.IO. It allows clients to send events to specific devices and receive messages from those devices. The server uses Express for handling HTTP requests, Socket.IO for WebSocket communication, and CORS for enabling cross-origin resource sharing.

The server listens on a specified port and exposes two endpoints:

  • GET /{IG_PATH}: is a health check endpoint.
  • POST /{IG_PATH}/event: Receives events from clients and forwards them to the appropriate devices.

When a client connects to the server via WebSocket, it must provide a device name and a user token. The server authenticates the client and associates the WebSocket connection with the device and user. It maintains a mapping of device names to connected clients.

When an event is received via the POST /{IG_PATH}/event endpoint, the server checks the secret header to ensure the request is authorized. It then extracts the device name from the request body and looks up the connected clients for that device. It sends the event payload to each connected client.

The flow is that this application is receiving current events on the /{IG_PATH}/event endpoint from Twin Event Processor.

When a client disconnects from the server, the server removes the client from the mapping of connected clients.