Registry / messaging / altamoon-robust-websocket

altamoon-robust-websocket

JSON →
library1.0.3jsnpmunverified

A robust, reconnecting WebSocket client for the browser that wraps the standard WebSocket API with automatic reconnection, online/offline awareness, and configurable reconnect strategies. Version 1.0.3 is the current stable release, last updated in 2020. It differentiates from alternatives like reconnecting-websocket by providing native error-code awareness (skipping reconnection on HTTP 400/500 equivalent codes), online/offline detection to avoid battery drain, and a functional composition approach for custom reconnect logic via the shouldReconnect callback. Includes TypeScript type definitions and supports a function-based URL for dynamic endpoint selection. No known security issues.

npm install altamoon-robust-websocket
INSTALL
IMPORT
SIG · ALTAMOON-ROBUST-WE
A
altamoon-robust-websocket
messagingjavascriptv1.0.3
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.

RobustWebSocket
import RobustWebSocket from 'robust-websocket'
import { RobustWebSocket } from 'robust-websocket'
Default export only. Named export does not exist.
RobustWebSocket
const RobustWebSocket = require('robust-websocket')
const { RobustWebSocket } = require('robust-websocket')
CommonJS require uses default export directly.
RobustWebSocket
import type RobustWebSocket from 'robust-websocket'
import { type RobustWebSocket } from 'robust-websocket'
TypeScript type import uses default syntax; the package ships types.

Shows creating a RobustWebSocket with custom reconnect strategy and event listeners.

import RobustWebSocket from 'robust-websocket'; const ws = new RobustWebSocket('ws://echo.websocket.org', null, { timeout: 4000, shouldReconnect: (event, ws) => { if (event.code === 1008 || event.code === 1011) return; return [0, 3000, 10000][ws.attempts]; }, automaticOpen: true, ignoreConnectivityEvents: false }); ws.addEventListener('open', () => { console.log('Connected'); ws.send('Hello!'); }); ws.addEventListener('message', (event) => { console.log('Received:', event.data); }); ws.addEventListener('close', (event) => { console.log('Closed with code', event.code); });
Debug
Known issues
breakingConstructor signature changed: third parameter is now an options object, not a string.
fix
Update to new constructor: new RobustWebSocket(url, protocols, options) where options is an object.
affects: <1.0.0
deprecatedThe open() method is no longer needed; automaticOpen option controls connection.
fix
Set automaticOpen: true or call open() only when needed.
affects: >=1.0.0
gotchaClose codes 1008 and 1011 are not reconnected by default; may surprise users expecting automatic reconnect.
fix
Override shouldReconnect to include these codes if desired.
affects: >=0.0.0
gotchaURL can be a function, not just a string; docs show signature: URL(ws) => string.
fix
Use a function if dynamic URLs are needed, e.g., (ws) => ws.reconnects > 0 ? ... : ...
affects: >=1.0.0
gotchaAttempts property resets after successful connection; reconnects count total reconnections.
fix
Use ws.reconnects for persistent count; ws.attempts resets per successful connection.
affects: >=0.0.0
Errors
Common errors & fixes
Uncaught TypeError: RobustWebSocket is not a constructor
Using named import instead of default import.
fix
Use default import: import RobustWebSocket from 'robust-websocket'
Module not found: Can't resolve 'robust-websocket'
Package not installed or missing from package.json.
fix
Run: npm install robust-websocket
TypeError: ws.addEventListener is not a function
Using RobustWebSocket without 'new' keyword.
fix
Instantiate with: new RobustWebSocket(url)
WebSocket connection to 'ws://...' failed: The connection to ws://... was interrupted while the page was loading.
Page is unloading; RobustWebSocket cannot prevent this.
fix
Ignore this if it happens during navigation; it's expected behavior.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
30
OpenAI (training)
1
Resources
altamoon-robust-websocket — npm install altamoon-robust-websocket · libregistry