A lightweight, standalone WebSocket client library for browsers written in TypeScript, offering optional auto-reconnect and message buffering. Current stable version is 2.3.0, with frequent updates. Key differentiators: zero dependencies, 2.5 kB min+gzip, uses native WebSocket API, provides a builder pattern for easy configuration, and supports both CommonJS and ES modules. It is well-tested with high coverage and includes comprehensive API documentation.
npm install websocket-tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a WebSocket with message buffering and auto-reconnect (1s delay), logs events, and echoes received messages.
Replace .withBuffer(true) with .withBuffer(new ArrayQueue()).
Replace ws.listen('open', cb) with ws.addEventListener(WebsocketEvent.open, cb).Use addEventListener or the on() method.
Use WebsocketEvent.open === 'open' or compare with the enum.
Use named import: import { WebsocketBuilder } from 'websocket-ts'Chain .withBuffer() before .build() on the builder.
Use buffering (ArrayQueue) to queue messages and send after connection.
Upgrade to v2.0.0+ or use string literals like 'open' instead of enum.