WebSocket Streaming
Live equipment status, alarms, events and messages.
Connect
The socket is at /ws on the gateway (not under /api/v1). Authenticate during the upgrade with an X-API-Key header, an Authorization: Bearer header, or, from a browser, a token query parameter. Browser origins must be on the gateway’s websocket.allowed_origins list.
const ws = new WebSocket(`ws://gateway:8080/ws?token=${accessToken}`);
ws.onopen = () => {
ws.send(JSON.stringify({
type: "subscribe",
payload: { topics: ["equipment", "alarms", "events"] }
}));
};
ws.onmessage = (e) => {
const { type, timestamp, payload } = JSON.parse(e.data);
};Topics
Messages arrive only for topics you subscribe to: equipment, alarms, events, messages. unsubscribe takes the same payload.
Subscribe with equipment_id in the payload to receive one tool’s traffic; messages that name no tool, such as the heartbeat, still arrive.
Message types
| Type | Payload fields |
|---|---|
equipment_status, equipment_connected, equipment_disconnected | equipment_id, name, status, communication_state, control_state |
alarm_raised, alarm_cleared, alarm_acknowledged | alarm_id, equipment_id, alarm_code, alarm_text, severity, is_set, timestamp |
collection_event | event_id, equipment_id, ceid, event_name, reports, timestamp |
secs_message, secs_response | message_id, equipment_id, stream, function, w_bit, direction, timestamp |
heartbeat | server_time, every 30 seconds |
GraphQL subscriptions
GraphQL subscriptions at /api/v1/graphql/ws deliver equipment status, alarms, events and messages live, scoped to your tenant.