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() accepts a config object or URL string function. Unlike the SSE adapter, 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's 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
What incoming live frames need to look like
channel — since this is what the adapter uses to route the message to the right registration.One socket, not one per channel
Unlike SSE (one connection per channel) or Socket.IO (one connection, native event dispatch), the WebSocket adapter opens a single raw connection and multiplexes every registered channel over it using the SUBSCRIBE/UNSUBSCRIBE protocol above. Registering five channels still means one socket, not five.
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's 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 can't 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.