Registry / messaging / reconnectingwebsocket

reconnectingwebsocket

JSON →
library1.0.0jsnpmunverified

A small JavaScript library that decorates the WebSocket API to provide automatic reconnection when the connection is dropped. Current stable version is 1.0.0, released in 2016 with no further updates. It is API compatible with the standard WebSocket, meaning you can replace `new WebSocket('ws://...')` with `new ReconnectingWebSocket('ws://...')` with minimal code changes. Key differentiators include configurable reconnect interval, exponential backoff, and automatic retry until success.

npm install reconnectingwebsocket
INSTALL
IMPORT
SIG · RECONNECTINGWEBSOC
R
reconnectingwebsocket
messagingjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ReconnectingWebSocket
import ReconnectingWebSocket from 'reconnectingwebsocket';
const ReconnectingWebSocket = require('reconnectingwebsocket');
The package uses CommonJS module.exports, so import default works. If using require, note it returns the constructor function directly.

Shows how to import and instantiate ReconnectingWebSocket with all options, handling the basic WebSocket events.

import ReconnectingWebSocket from 'reconnectingwebsocket'; const url = 'wss://example.com/socket'; const protocols = []; const options = { debug: true, reconnectInterval: 1000, maxReconnectInterval: 30000, reconnectDecay: 1.5, timeoutInterval: 2000, maxReconnectAttempts: null }; const ws = new ReconnectingWebSocket(url, protocols, options); ws.onopen = () => console.log('Connected'); ws.onmessage = (event) => console.log('Message:', event.data); ws.onclose = () => console.log('Disconnected'); ws.onerror = (error) => console.error('Error:', error);
Debug
Known issues
gotchaReconnectingWebSocket does not inherit from EventTarget, so you cannot use addEventListener. Only onopen, onmessage, onclose, onerror properties work.
fix
Use property callbacks instead of addEventListener.
affects: >=1.0.0
gotchaThe send() method is not automatically queued when disconnected. Calling send() while not connected will silently fail or throw an error.
fix
Check ws.readyState before sending, or implement a manual queue.
affects: >=1.0.0
gotchaReconnectingWebSocket does not support the WebSocket binaryType property. It defaults to 'blob' and cannot be changed to 'arraybuffer'.
fix
If you need binary data as ArrayBuffer, use the native WebSocket or a different library.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught ReferenceError: WebSocket is not defined
Using ReconnectingWebSocket in a non-browser environment (e.g., Node.js) without a WebSocket implementation.
fix
Install a WebSocket polyfill like 'ws' and set global.WebSocket before importing ReconnectingWebSocket.
TypeError: ReconnectingWebSocket is not a constructor
Incorrect import or require statement; the default export is the constructor.
fix
Use `const ReconnectingWebSocket = require('reconnectingwebsocket');` or `import ReconnectingWebSocket from 'reconnectingwebsocket';`
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
25
OpenAI (training)
1
Resources
reconnectingwebsocket — npm install reconnectingwebsocket · libregistry