Registry / testing / reconnect-ws

reconnect-ws

JSON →
library0.1.0jsnpmunverified

A lightweight Node.js module that provides automatic reconnection for websocket-streams when the connection drops. Based on reconnect-core, it wraps websocket-stream to create a persistent stream that reconnects on failure. Version 0.1.0 is the latest release; the package has seen no updates since 2013 and should be considered in maintenance mode. It is a thin wrapper around websocket-stream and depends on both ws and websocket-stream. Compared to alternatives like reconnecting-websocket, it uses the stream API which may be preferable in streaming contexts but is less flexible for non-stream usage.

npm install reconnect-ws
INSTALL
IMPORT
SIG · RECONNECT-WS
R
reconnect-ws
testingjavascriptv0.1.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.

default export
var reconnect = require('reconnect-ws');
import reconnect from 'reconnect-ws';
This package uses CommonJS and does not support ESM imports. Use require().
Reconnect instance
var instance = require('reconnect-ws')(function(stream) { ... });
var instance = new require('reconnect-ws')(function(stream) { ... });
The default export is a factory function, not a constructor. Do not use new.
Reconnect events
reconnect(function(stream) { ... }).on('reconnect', function(n) { ... });
reconnect(function(stream) { ... }).on('reconnect', function(n) { ... }).connect(8080);
Events must be registered before calling .connect() to avoid missing early events.

Creates a WebSocket server and a client that automatically reconnects using reconnect-ws.

var WebSocketServer = require('ws').Server; var wss = new WebSocketServer({ port: 8080 }); wss.on('connection', function(ws) { ws.send('Hello'); }); var reconnect = require('reconnect-ws'); var r = reconnect(function(stream) { stream.on('data', function(data) { console.log('Received:', data.toString()); }); }); r.connect(8080);
Debug
Known issues
gotchaThe .connect() method accepts either a port number (for localhost) or an options object with host/port. Passing only a port number will connect to ws://localhost:<port>.
fix
Use reconnect({ host: 'example.com', port: 8080 }) for remote hosts.
affects: >=0.0.1
gotchaThe stream callback receives a duplex stream, but the stream is not open immediately. Listen for 'connect' event or wait for stream 'open' before sending data.
fix
Use .on('connect', function(stream) { ... }) to ensure connection is established.
affects: >=0.0.1
gotchaThis package depends on websocket-stream, which itself depends on ws. If you use a different WebSocket library (e.g., 'uws' or browser WebSocket), this package will not work.
fix
Ensure your environment uses Node.js with 'ws' installed.
affects: >=0.0.1
deprecatedThe package is no longer maintained. It uses old versions of dependencies which may have known vulnerabilities.
fix
Consider migrating to a maintained alternative like 'reconnecting-websocket' or implement a custom reconnection layer.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'websocket-stream'
websocket-stream is a required peer dependency not bundled with reconnect-ws.
fix
npm install websocket-stream ws
reconnect is not a function
Using ES6 import syntax (import reconnect from 'reconnect-ws') which is not supported.
fix
Use const reconnect = require('reconnect-ws');
TypeError: listener must be a function
Calling reconnect() without a callback function argument.
fix
reconnect(function(stream) { ... }); always provide a callback.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
websocket-streamrequiredProvides the underlying WebSocket stream that the reconnection logic wraps.
wsrequiredCore WebSocket library used by websocket-stream.
reconnect-corerequiredProvides the base reconnection logic and event interface.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
reconnect-ws — npm install reconnect-ws · libregistry