Registry / communication / reliable-websocket

reliable-websocket

JSON →
library0.1.0jsnpmunverified

A lightweight TypeScript-first WebSocket wrapper that provides automatic reconnection with exponential backoff and persistent offline message buffering via IndexedDB. Current stable version is 0.1.0, released as an early-stage package with limited API surface. Key differentiators include built-in offline support for medical and field applications, TypeScript type definitions bundled, and support for multiple message types (string, ArrayBuffer, Uint8Array, Blob). Unlike alternatives like reconnecting-websocket, this library persists messages in IndexedDB for later delivery when offline.

npm install reliable-websocket
INSTALL
IMPORT
SIG · RELIABLE-WEBSOCKET
R
reliable-websocket
communicationjavascriptv0.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.

ReliableWebSocket
import { ReliableWebSocket } from 'reliable-websocket'
import ReliableWebSocket from 'reliable-websocket'
Only named export exists; default export does not exist. Common mistake: trying default import.
ReliableWebSocketOptions
import { ReliableWebSocket, ReliableWebSocketOptions } from 'reliable-websocket'
const { ReliableWebSocketOptions } = require('reliable-websocket')
TypeScript type export, available only via named import; CJS require will not include types.
ReliableWebSocket
const { ReliableWebSocket } = require('reliable-websocket')
const ReliableWebSocket = require('reliable-websocket')
CJS destructured import is required; direct require gives an object with ReliableWebSocket property.

Shows minimal setup: create ReliableWebSocket instance with URL and callbacks, connect, send a message, and close the connection.

import { ReliableWebSocket } from 'reliable-websocket'; const socket = new ReliableWebSocket({ url: 'wss://example.com/socket', onMessage: (msg) => console.log('Received:', msg), onError: (err) => console.error('Error:', err), reconnectInterval: 3000, maxReconnectAttempts: 10 }); await socket.connect(); socket.send('hello world'); // Later socket.close();
Debug
Known issues
breakingLibrary uses ES modules (ESM) only; require() will fail if using older Node.js versions without 'type':'module' or .mjs extension.
fix
Set 'type':'module' in package.json or rename importing file to .mjs. Alternatively, use dynamic import() with CJS.
affects: >=0.1.0
deprecatedThe constructor option 'reconnectDelay' is deprecated; use 'reconnectInterval' instead.
fix
Replace 'reconnectDelay' with 'reconnectInterval' in options.
affects: >=0.1.0
gotchaIndexedDB buffering may silently drop messages if storage quota is exceeded; no explicit error is thrown.
fix
Monitor storage quota or use wrapper that handles quota errors. Alternative: set bufferSizeLimit option.
affects: >=0.1.0
gotchaInternet Explorer and older browsers (e.g., Safari < 10.1) do not support IndexedDB or WebSocket; library will throw on instantiation.
fix
Check for IndexedDB and WebSocket support before using, or apply a polyfill.
affects: >=0.1.0
breakingDefault reconnection behavior changed between versions: earlier alpha versions used a fixed interval; 0.1.0 switched to exponential backoff by default.
fix
If you relied on fixed interval, set 'reconnectInterval' and optionally set 'backoffMultiplier: 1'.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: ReliableWebSocket is not a constructor
Using default import instead of named import; e.g. import RWS from 'reliable-websocket'
fix
Use import { ReliableWebSocket } from 'reliable-websocket'
Error: Unable to open IndexedDB database
Browser does not support IndexedDB, or IndexedDB is disabled (e.g., private browsing in some browsers)
fix
Use a browser that supports IndexedDB, or disable offline buffering by passing options:{ useIndexedDB: false }
Uncaught (in promise) DOMException: The operation is insecure.
Page served over HTTP attempts to connect to a secure WebSocket (wss://) or vice versa
fix
Ensure your page protocol matches WebSocket protocol (http/wss or https/wss, or use same protocol)
ReferenceError: require is not defined
Trying to use require() in an ESM environment
fix
Use import syntax or switch to 'type':'module' in package.json and use dynamic import()
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
idbrequiredUsed for IndexedDB offline message buffering (peer dependency or bundled dependency)
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
reliable-websocket — npm install reliable-websocket · libregistry