WebSocket Streaming
Real-time event streaming via WebSocket.
WebSocket Connection
const ws = new WebSocket("ws://localhost:8080/api/v1/ws");
ws.onopen = () => {
// Authenticate
ws.send(JSON.stringify({
type: "auth",
token: "your-jwt-token"
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log("Received:", data);
};Subscribing to Events
// Subscribe to all equipment events
ws.send(JSON.stringify({
type: "subscribe",
channel: "equipment.*"
}));
// Subscribe to specific equipment
ws.send(JSON.stringify({
type: "subscribe",
channel: "equipment.eq_123"
}));
// Subscribe to alarms only
ws.send(JSON.stringify({
type: "subscribe",
channel: "alarms.*"
}));Event Format
{
"type": "event",
"channel": "equipment.eq_123",
"event": "state_change",
"data": {
"equipment_id": "eq_123",
"previous_state": "IDLE",
"current_state": "EXECUTING",
"timestamp": "2025-12-07T10:30:00Z"
}
}