WebSocket Connection¶
Connect to wss://realtime.steamdeals.example/v1. Use a short-lived OAuth access token or a Realtime-scoped API key in the Authorization header. Browsers that cannot set headers may send an OAuth token as the first auth message; never place credentials in a URL.
const socket = new WebSocket("wss://realtime.steamdeals.example/v1");
socket.onopen = () => socket.send(JSON.stringify({
type: "auth", token: accessToken
}));
socket.onmessage = ({data}) => console.log(JSON.parse(data));
After auth.ok, send a subscribe message with one or more channels. Every event has an increasing channel-local sequence and global event_id.
{"type":"subscribe","request_id":"sub_01J4RB8Y","channels":["deal.US","price.game_01J2M4T5K7HADES2.US"]}
The gateway sends a ping every 25 seconds; respond with { "type": "pong", "timestamp": "..." } within 10 seconds. It closes idle or unauthenticated connections with WebSocket close code 4001.
Reconnection¶
Reconnect with exponential backoff plus jitter, capped at 30 seconds. Keep the most recent event_id per channel and include it in resume when reconnecting. The resume window is 10 minutes; after resume.unavailable, refetch REST state before resubscribing.