Typed WebSocket client for browsers and Node.js with automatic reconnection, heartbeat/keepalive, send buffer, and exponential backoff. The current stable version is 1.3.2. Release cadence is irregular. Key differentiators: full TypeScript generics for send/receive types, event-driven API (on/off), AbortSignal support, and pluggable encoding/decoding. Inspired by the Phoenix Framework Socket.
npm install typed-websocket-clientNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Create a typed WebSocket client with generic send/receive types, connect to a server, and handle messages.
Configure heartbeatReply detection: new WebSocketClient(url, { heartbeat: { replyPayload: 'pong' } })npm install ws
Use import { WebSocketClient } from 'typed-websocket-client'Use client.on('open', callback) or client.on('close', callback) to handle connection state.Call client.connect() before or after push; buffer will send when connected.
Provide wsConstructor: require('ws') in options.Install ws: npm install ws or provide custom constructor.
Use import { WebSocketClient } from 'typed-websocket-client'.Remove 'type' keyword: import { WebSocketClient } from 'typed-websocket-client'.Install @types/ws as dev dependency: npm install --save-dev @types/ws