A lightweight TypeScript library for monitoring WebSocket connections using heartbeat pings. Version 1.2.0 is the latest stable release. It periodically sends ping frames and detects connection loss with configurable intervals, invoking a callback on timeout. Unlike manually implementing timers, it handles cleanup and disconnection scenarios. Designed for browser and Node.js environments with ESM and CJS support. No external dependencies. Suitable for real-time applications like chat, trading, or IoT.
npm install websocket-heartbeatsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a Heartbeat instance, starts it on WebSocket open, stops on close, and calls receive on pong messages.
Call heartbeat.stop() in the WebSocket onclose event handler.
Implement your own reconnection logic inside onTimeout callback.
Ensure your server sends 'pong' in response to the custom ping message, or use WebSocket built-in ping frames.
Change import to: import { Heartbeat } from 'websocket-heartbeats'Run 'npm install websocket-heartbeats' and ensure node_modules/websocket-heartbeats exists.
No dependency data recorded yet.