createWebSocketFeeds
Subscribe to topics whose messages carry a sequence number, and get each message once, in order, across reconnects. Duplicates are dropped, a gap asks the server for what's missing, and each new connection resumes from the last number received.
Available from both react-websocket and react-websocket/core. The guide is Numbered feeds.
Usage
Parameters
Returns
A WebSocketFeeds<In>, which is also a WebSocketTopics:
Pass it to useWebSocketTopic to hold topics from components, and to createWebSocketState in place of the client to reduce its messages.
Behavior
- Reconnects. Every new connection sends
subscribe(topic, last)for each held topic, before messages queued while disconnected, as topics do. - Releasing. A tick after the last holder releases a topic, it's unsubscribed and its number forgotten, so holding it again starts with
after: undefined. - What the server does. For
subscribewith anafter, send the messages numbered after it, then go on live. If it can't, because they're no longer kept, send a snapshot. Treat a subscribe for a topic the connection already has as a request to resend fromafter, or giveresumeits own message.