onopen and onmessage works in a demo; a stream you rely on also handles onerror, onclose, gaps, and a slow consumer.
What the server expects
Ping loop
Reconnect sequence
1
Stop the old socket's timers
Clear the ping interval and any pending reconnect timer attached to the closed socket.
2
Wait with capped backoff and jitter
Random jitter keeps many clients from reconnecting at the same moment. Stop after your retry budget and surface the failure instead of retrying forever.
3
Open a new socket
Authenticate the new connection the same way as the first, with the key kept on the server.
4
Restore subscriptions from tracked state
Recreate only the channel-symbol pairs your client recorded as active, and only after the new socket opens.
5
Rebuild unsafe state
For a local book, replay output, or alert state, load a fresh snapshot or replay checkpoint before trusting the output again.