Lightweight heartbeat/ping-pong library for WebSocket connections, compatible with both server-side (ws library) and browser-side WebSocket. Version 1.3.0 provides a simple API to detect dead connections and maintain active WebSocket sessions. Differentiates from manual ping/pong implementations by handling intervals, timeouts, and automatic cleanup. No native WebSocket ping frames required, works with any message format. Low dependency footprint.
npm install ws-heartbeatNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows client and server setup: client sends ping, server responds with pong, both have timeout handling.
Use browser native WebSocket constructor (window.WebSocket) and not the 'ws' library when targeting browser.
Call setWsHeartbeat immediately after creating the WebSocketServer, before adding event listeners or starting the server.
Ensure the first argument of setWsHeartbeat on the client side is a string (e.g., JSON.stringify).
Update imports to use 'ws-heartbeat/client' or 'ws-heartbeat/server' as shown in documentation.
Import from 'ws-heartbeat/client' (browser) or 'ws-heartbeat/server' (Node).
Ensure client uses browser WebSocket (or wrappers) and server uses ws.WebSocket from 'ws' package.
Use correct import: import { setWsHeartbeat } from 'ws-heartbeat/client' (client) or 'ws-heartbeat/server' (server).