A WebSocket client that automatically reconnects when the connection is closed. Stable version 4.4.1, actively maintained. Provides a WebSocket API compatible interface with Level0 and Level2 event models. Key differentiators: dependency-free, multi-platform (Web, ServiceWorkers, Node.js, React Native), configurable reconnect behavior, connection timeout handling, buffering of messages during disconnection, and support for dynamic server URLs via string, function, or async function.
npm install reconnectingNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a reconnecting WebSocket, sends a message on open, logs received data, and handles close/error events.
Use import syntax. If you need CJS, use v3.x or use dynamic import().
Check event.data type before processing. On Node.js, use ws package's 'blob' option to normalize.
If using startClosed, ensure to call rws.reconnect() when you want to connect.
Attach an error listener before or immediately after construction.
Ensure the provided WebSocket constructor matches the standard WebSocket API (e.g., the 'ws' package).
Change to import ReconnectingWebSocket from 'reconnecting-websocket'
Ensure the URL starts with 'ws://' or 'wss://' and is correctly formatted.
No dependency data recorded yet.