A tiny (~6 KB minified), dependency-free WebSocket client with exponential-backoff reconnect, heartbeats, outgoing queue, and pluggable transports. Version 0.2.0 is the latest stable release (no major updates yet). Supports browsers, Node.js (with the 'ws' package), Deno, Bun, and edge runtimes. Key differentiators: zero runtime dependencies, full TypeScript types, dynamic URL provider for token refresh, and a first-class state machine with both hooks and typed event emitter API. Ideal for production WebSocket connections requiring resilience and minimal bundle size.
npm install tiny-resilient-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a ResilientWebSocketClient with a static URL, hooks for open/close events, and exponential-backoff reconnect policy, then initiates the connection.
Always pass a `webSocketFactory` that creates a WebSocket from the 'ws' package when running in Node.js.
Wrap the provider in try-catch and handle errors gracefully, or return a fallback URL.
Set `maxQueuedMessages` to a reasonable limit, or disable queueing with `queueOutgoingWhileDisconnected: false`.
Set a generous pong timeout, or handle application-level pings separately.
Pass a webSocketFactory option: webSocketFactory: (url, protocols) => new (require('ws'))(url, protocols, { headers: {...} })Use import { ResilientWebSocketClient } from 'resilient-websocket';Use the `onConnected` hook to send the first messages, or wait for the connect() promise to resolve and then check client.state === 'open' before sending.
Provide either a static `url` string or an async `urlProvider` function.