@zedtech/zedkit-live
Receive WebSocket messages with reconnect and polling backup
Open a WebSocket on demand, reconnect with jittered exponential backoff, resolve the URL per attempt, and run a fallback source while it is down.
alpha
Usage
At a glance
- Who: Apps that want push updates and still work when the socket drops.
- What: Open a WebSocket on demand, reconnect with jittered exponential backoff, resolve the URL per attempt, and run a fallback source while it is down.
- Use when: Live lists and status pages behind a WebSocket endpoint.
- Avoid when: Guaranteed delivery; missed messages are not replayed, so make the fallback fetch current state.
- See also: Poll an endpoint as a live source
Install
pnpm add @zedtech/zedkit-liveLatest: 0.1.0 (via changesets).
Example
import { pollingSource, wsSource } from "@zedtech/zedkit-live";
const events = wsSource<{ type: string }>({
url: async () => `wss://example.com/live?token=${await getToken()}`,
fallback: pollingSource({ intervalMs: 10_000, poll: () => fetchLatest() }),
});
const stop = events.subscribe((event) => refresh(event));Wraps: (none)