Registry / messaging / forever-websocket

forever-websocket

JSON →
library1.0.1jsnpmunverified

A reconnecting WebSocket client that is isomorphic (works in browser and Node.js). Version 1.0.1 provides a WebSocket API-compatible wrapper with automatic reconnection, configurable backoff strategies (Fibonacci, exponential), pings to keep connections alive, and timeouts for idle connections. Unlike similar libraries like reconnecting-websocket, it exposes all standard WebSocket properties and methods directly, making it a drop-in replacement. The package is stable with no recent releases, suitable for applications needing persistent WebSocket connections with minimal overhead.

npm install forever-websocket
INSTALL
IMPORT
SIG · FOREVER-WEBSOCKET
F
forever-websocket
messagingjavascriptv1.0.1
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.

ForeverWebSocket
import { ForeverWebSocket } from 'forever-websocket'
import ForeverWebSocket from 'forever-websocket'
The package exports a named export, not a default export. CommonJS users should use const { ForeverWebSocket } = require('forever-websocket').
ForeverWebSocket
const { ForeverWebSocket } = require('forever-websocket')
const ForeverWebSocket = require('forever-websocket')
CommonJS require returns an object with the ForeverWebSocket property. Using it directly as a constructor will fail.
export default
import { ForeverWebSocket } from 'forever-websocket'
import ForeverWebSocket from 'forever-websocket'
There is no default export. All usage must be through the named export.

Creates a ForeverWebSocket instance with reconnection, timeout, and ping options.

import { ForeverWebSocket } from 'forever-websocket'; const ws = new ForeverWebSocket('wss://echo.websocket.org', [], { reconnect: { strategy: 'fibonacci', initialDelay: 100, maxDelay: 10000 }, timeout: 30000, ping: { interval: 5000, data: 'ping' } }); ws.onopen = () => { ws.send('Hello!'); }; ws.onmessage = (event) => { console.log('Received:', event.data); }; ws.onclose = (event) => { console.log('Connection closed:', event.code, event.reason); };
Debug
Known issues
gotchaThe library does not export a default export; using import ForeverWebSocket from 'forever-websocket' will result in undefined.
fix
Use import { ForeverWebSocket } from 'forever-websocket' or const { ForeverWebSocket } = require('forever-websocket').
affects: >=1.0.0
gotchaWhen running in Node.js, the 'ws' package must be installed separately; it is a peer dependency.
fix
Install 'ws' as a dependency: npm install ws.
affects: >=1.0.0
gotchaThe 'options.reconnect.randomizeDelay' is a number between 0 and 1, not a boolean. Setting it to true may cause unexpected behavior.
fix
Set randomizeDelay to a number like 0.5 for 50% randomization.
affects: >=1.0.0
gotchaThe 'options.ping.pingFrame' defaults to false; setting to true sends a WebSocket ping frame instead of a regular message. Not all servers support ping frames.
fix
Leave pingFrame as false unless you know the server supports RFC 6455 ping frames.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: ForeverWebSocket is not a constructor
Using require('forever-websocket') directly instead of destructuring.
fix
Use const { ForeverWebSocket } = require('forever-websocket');
Module not found: Error: Can't resolve 'ws'
Missing the 'ws' package in Node.js environment.
fix
Install ws: npm install ws
ws is not defined (browser)
Running in browser without bundler shim or accidentally importing Node.js version.
fix
Ensure your bundler uses the browser build of forever-websocket; the package is isomorphic and should auto-detect.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
wsrequiredUsed in Node.js environments as the underlying WebSocket implementation
Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
forever-websocket — npm install forever-websocket · libregistry