A lightweight TypeScript wrapper around the native browser WebSocket API, providing automatic reconnection and heartbeat detection out of the box. Version 1.1.4 is the latest stable release. It distinguishes itself by requiring zero configuration for basic usage — both reconnect and heartbeat are enabled by default — while still offering customizable options for timeouts, retry limits, and callbacks. Pure client-side library with no server-side dependencies. Ships TypeScript type definitions. Released at a moderate cadence (last update April 2024).
npm install websocket-frontNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows default connection with automatic reconnect and heartbeat, event handling, send, and close.
Set pingMsg: JSON.stringify({ messageType: '0', content: 'ping' }) or as per your backend.Either pass callbacks in options or use socket.on('event', handler) – not both for same event, as both will fire.Set reconnectTimeout: 3000 (3 seconds) in options.
Set isReconnect: false before closing, or call socket.close() and set socket = null.
Set pingTimeout: 30000 (30s) and pongTimeout: 5000 (5s).
Call send() only inside an 'open' event handler or after checking socket.readyState === WebSocket.OPEN.
Ensure close() is called after the connection is open (e.g., inside a setTimeout or after user action).
Use valid WebSocket URLs: ws:// or wss:// followed by host:port/path.
No dependency data recorded yet.