WebSocket
Point Flux at any backend that speaks raw WebSocket and it takes care of turning that connection into live store updates — a single multiplexed socket, reconnect handling, and catch-up after time offline all come for free once the adapter is wired in.
- A backend accepting WebSocket connections — any language or framework
- @tsworldtech/flux and @tsworldtech/flux_websocket installed
Create the adapter
createWebSocketAdapter() takes a config object with the socket url and a few optional settings. This connection is multiplexed — one raw socket carries every registered channel, distinguished by the SUBSCRIBE protocol described below rather than by separate connections.Register a store
channel and event are sent to your backend as part of a subscription message the moment this registration runs — there is no separate "connect" step to call yourself.The SUBSCRIBE / UNSUBSCRIBE protocol
SUBSCRIBED acknowledgment frame:Flux's client-side adapter waits for the { action: 'SUBSCRIBED', channel } frame before executing the authoritative SYNC_REQUEST catch-up handshake and updating the cache freshness clock. Omitting this acknowledgment will prevent automatic delta sync from executing upon reconnect.
Protocol envelopes: SYNC and RECONCILE
SYNC_REQUEST, even when nothing changed:What catch-up proves
SYNC_COMPLETE frame into an answer Flux can act on:Flux never invents an id or a timestamp. A catch-up row without them is counted as lost, the channel's catch-up reports failed, and Flux refetches instead of recording the channel as current. If you see repeated refetches after reconnects, check that your delta rows carry both.
What incoming live frames need to look like
channel at the top level — this is what the adapter uses to route the message to the right registration — plus the row's id and a server-clock timestamp.One socket, not one per channel
Like the SSE adapter, the WebSocket adapter opens a single raw connection and multiplexes every registered channel over it — here using the SUBSCRIBE/UNSUBSCRIBE protocol above. Registering five channels still means one socket, not five. (Socket.IO also holds one connection, using its own native event dispatch.)
Reconnects and catch-up are automatic
You never need to write reconnect logic yourself. If the connection drops, Flux reopens it automatically with backoff, re-sends SUBSCRIBE frames for every active channel, encodes eager sync anchors directly in the connection URL (?syncAnchors=...), and initiates authoritative SYNC_REQUEST / RECONCILE_REQUEST handshakes once re-subscribed.
Any backend that speaks WebSocket
Any backend able to accept a WebSocket upgrade and speak plain JSON frames works here — Node, Python, Go, Rails, whatever you already run. There is no required framework; the contract is just the SUBSCRIBE/UNSUBSCRIBE/SYNC frames going out and the channel-tagged event frames coming back.
Authentication
The browser's native WebSocket constructor cannot attach custom headers either, the same limitation EventSource has. A short-lived signed token appended to the connection URL as a query parameter, verified by your backend during the upgrade, is the common pattern here.
Building the server side of this contract from scratch? See getting_started/websocket for a full worked example. For what happens during reconnect specifically, see core_concepts/sync_anchors and core_concepts/activity_bus.