Heartbeats and Reconnection
WebSocket is a long-lived connection, but network devices, proxies, and service maintenance can interrupt it. Clients must implement heartbeats, disconnect detection, and reconnection.
Heartbeats
Use both:
- WebSocket protocol Ping/Pong to detect network connectivity.
session.pingto confirm application-level message handling.
session.ping reply:
json
{
"type": "reply",
"requestId": "req_ping_001",
"code": "SUCCESS",
"message": "OK.",
"data": {}
}Follow Rate Limits and Retries for heartbeat frequency. Do not use device-state queries as heartbeats.
Reconnection Flow
- Detect a closed connection or heartbeat timeout.
- Apply exponential backoff with jitter.
- Use a valid access token to create a new WebSocket ticket.
- Establish a new connection.
- Send one
device.state.getfor each business-critical device. - Resume event processing.
Each ticket is single-use and cannot be reused for reconnection.
Event Continuity
WebSocket does not replay events missed while disconnected. Applications should:
- Persist important events promptly.
- Use
stateUpdatedAtto prevent older state from replacing newer state. - Query critical devices after reconnecting instead of refreshing every device in the account.
