Registry / devops / reconnecting-websocket-fixclose

reconnecting-websocket-fixclose

JSON →
library1.0.0jsnpmunverified

A drop-in replacement for the WebSocket API that automatically reconnects when the connection is closed. Version 1.0.0 is the latest stable release, actively maintained on GitHub with full test coverage and TypeScript definitions. It is dependency-free, works in browsers, Node.js, ServiceWorkers, and React Native, and supports URL providers for dynamic server selection. Key differentiators: no external dependencies, fully configurable reconnection delays with exponential backoff, connection timeout handling, and debug mode. The package is a fork of reconnecting-websocket with a fix for close event handling.

npm install reconnecting-websocket-fixclose
INSTALL
IMPORT
SIG · RECONNECTING-WEBSO
R
reconnecting-websocket-fixclose
devopsjavascriptv1.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 'reconnecting-websocket-fixclose'
const ReconnectingWebSocket = require('reconnecting-websocket-fixclose')
Default export only; TypeScript types included. For CommonJS, use require('reconnecting-websocket-fixclose').default or set esModuleInterop.
Options
import { Options } from 'reconnecting-websocket-fixclose'
import { Options } from 'reconnecting-websocket-fixclose' (not available as named export in some versions; check package)
Options interface is exported for TypeScript usage. Not available as runtime value.

Shows basic usage: create a reconnecting WebSocket, listen for events, send/receive messages, and manually reconnect.

import ReconnectingWebSocket from 'reconnecting-websocket-fixclose'; const rws = new ReconnectingWebSocket('wss://echo.websocket.org', [], { maxRetries: 3, connectionTimeout: 5000, debug: false, }); rws.addEventListener('open', () => { console.log('connected'); rws.send('Hello, server!'); }); rws.addEventListener('message', (event) => { console.log('Received:', event.data); rws.close(); }); rws.addEventListener('close', () => { console.log('disconnected'); }); setTimeout(() => { rws.reconnect(); }, 2000);
Debug
Known issues
gotchaDefault export is ESM-only; using CommonJS require() returns an object with a default property unless esModuleInterop is enabled.
fix
Use import or enable esModuleInterop and use const RWS = require('reconnecting-websocket-fixclose').default;
affects: >=1.0.0
gotchaIf you pass a custom WebSocket constructor, ensure it follows the standard WebSocket API (e.g., 'ws' package). Mismatches cause runtime errors.
fix
Use compatible WebSocket implementations like 'ws' or globalThis.WebSocket.
affects: >=1.0.0
gotchaThe `reconnect()` method returns void; you cannot await reconnection. Use event listeners to detect reconnection.
fix
Add an 'open' event listener to know when reconnection succeeds.
affects: >=1.0.0
gotchaWhen using async URL provider, ensure the promise resolves quickly to avoid timeout issues. The connectionTimeout option applies per attempt.
fix
Resolve URL promise within a reasonable time (< connectionTimeout ms) to prevent unnecessary retries.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: rws.send is not a function
Trying to call send before connection is established or after close.
fix
Wait for 'open' event before sending. Check rws.readyState === WebSocket.OPEN.
Module not found: Can't resolve 'reconnecting-websocket-fixclose'
Package not installed or typo in package name.
fix
Run: npm install reconnecting-websocket-fixclose
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
reconnecting-websocket-fixclose — npm install reconnecting-websocket-fixclose · libregistry