A robust, reconnecting WebSocket client for the browser that wraps the standard WebSocket class with the same interface but adds automatic reconnection. It is error-code aware (avoids reconnecting on 1008/1011 by default) and respects browser online/offline events to prevent unnecessary reconnection attempts. Version 1.0.0 is stable; well-tested with cross-browser coverage. Key differentiators vs alternatives: includes test suite, offline awareness, and functional composition for custom reconnect strategies.
npm install robust-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a RobustWebSocket instance, listens for open/message/close events, sends a message, and logs output.
Always use 'new RobustWebSocket(url)' or 'new RobustWebSocket(url, protocols, options)'
Check event.type before accessing event.code: if (event.type === 'online') { /* handle online */ } else { /* handle CloseEvent */ }Use shouldReconnect to return undefined or non-number after max attempts.
Use ws.attempts in shouldReconnect for attempt index; use ws.reconnects for total reconnects.
const RobustWebSocket = require('robust-websocket'); const ws = new RobustWebSocket(url);Run 'npm install robust-websocket' and ensure import is 'robust-websocket' (not 'robust-websocket/index').
if (event.type === 'online') { return ... } else { return event.code ... }No dependency data recorded yet.