WebSocket heartbeat and auto-reconnection library for browser JavaScript. Version 1.1.3 is the latest stable release, with infrequent updates. Automatically sends ping messages to detect connection status and reconnects on failure. Differentiates from native WebSocket by handling network outages and server errors that would otherwise go undetected, using a heartbeat mechanism with configurable intervals and reconnection attempts.
npm install websocket-heartbeat-jsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a websocket heartbeat instance with custom options and event handlers for open, message, close, and reconnect.
Handle server close messages in onmessage: if (e.data === 'close') ws.close();
Always wait for onopen event before calling send().
Set pingMsg to match your server's expected ping format, e.g., {type: 'ping'} as JSON string.Manually define options interface or upgrade to v1.2.0+ (if available). In v1.1.3, use 'typeof WebsocketHeartbeatJsOptions' as a workaround.
Change to: import WebsocketHeartbeatJs from 'websocket-heartbeat-js'
Use const WebsocketHeartbeatJs = require('websocket-heartbeat-js').default or use import statement.Use wss:// for secure connections or ensure URL matches protocol (ws for HTTP, wss for HTTPS).
No dependency data recorded yet.