A minimal, dependency-free WebSocket wrapper that automatically reconnects when the connection is closed. Current stable version is 4.4.0, with frequent releases. It implements the standard WebSocket API (both Level0 and Level2 event models), supports custom WebSocket constructors (e.g., the 'ws' library in Node.js), URL providers (sync or async) for dynamic endpoints, connection timeout, exponential backoff with jitter, and message buffering until reconnection. It is designed for multi-platform use (browser, Service Workers, Node.js, React Native) and ships with TypeScript definitions. Unlike alternatives, it has zero dependencies and does not rely on any DOM or EventEmitter libraries.
npm install reconnecting-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage: create a ReconnectingWebSocket, listen for open/message/close events, send a message, and close the connection.
Use import or dynamic import: const { default: RWS } = await import('reconnecting-websocket')Use default import: import ReconnectingWebSocket from 'reconnecting-websocket'
Set 'startClosed: true' and call .reconnect() manually, or handle initial connection errors via 'error' event.
Monitor the buffer or set maxEnqueuedMessages to a safe value; implement your own backpressure if needed.
Run: npm install reconnecting-websocket
Add 'esModuleInterop': true in tsconfig.json or use import ReconnectingWebSocket = require('reconnecting-websocket')Use: import ReconnectingWebSocket from 'reconnecting-websocket' instead of require()
No dependency data recorded yet.