Registry / messaging / light-websocket-client

light-websocket-client

JSON →
library0.0.45jsnpmunverified

A lightweight TypeScript Websocket client with built-in keep-alive, auto-reconnect with exponential backoff, and application-level authentication. Designed to work with the `light-websocket-server`. Provides a custom protocol header for ping/pong keep-alive since browser WebSocket API cannot send raw ping frames. Suitable for both browser and Node.js environments when paired with the `ws` package on Node. Version 0.0.45, actively maintained.

npm install light-websocket-client
INSTALL
IMPORT
SIG · LIGHT-WEBSOCKET-CL
L
light-websocket-client
messagingjavascriptv0.0.45
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LightWebsocketClientImpl
import { LightWebsocketClientImpl } from 'light-websocket-client'
const LightWebsocketClientImpl = require('light-websocket-client')
Package exports ESM modules and TypeScript type definitions.
Options
import { Options } from 'light-websocket-client'
const Options = require('light-websocket-client').Options
Options is a named export, not default.
LightWebsocketNodeClient
import { LightWebsocketNodeClient } from 'light-websocket-client'
Node-specific client class ready to use with the ws library.

Shows how to create a WebSocket client with custom options, handle active/inactive events, subscribe to a topic, and connect.

import { LightWebsocketNodeClient, Options } from 'light-websocket-client'; const options = new Options(); options.idleTimeout = 50000; options.log = (message, param) => { console.log(message, param); }; const client = new LightWebsocketNodeClient( process.env.WS_URL ?? 'ws://localhost:8888/endpoint', process.env.APP_KEY ?? 'a3a45sfbc7e', process.env.TICKET ?? 'xxx', options ); client.onActive(() => { client.subscribe(['/topic/a']).then(() => { console.log('subscribe succeed'); }).catch(e => { console.error('subscribe error', e); client.disconnect(); }); }); client.onInactive(() => { console.log('onInactive'); }); client.onMessage((message) => { console.log('onMessage: ', message); }); client.connect();
Debug
Known issues
breakingWhen using in Node.js, you must install the 'ws' package separately and provide a custom implementation extending LightWebsocketClientImpl if not using LightWebsocketNodeClient.
fix
Install 'ws' and either use LightWebsocketNodeClient or subclass LightWebsocketClientImpl with the ws module.
affects: >=0.0.0
gotchaThe subscription method requires the server to support the topic pattern. Subscription may fail if topics are not properly formatted.
fix
Ensure topics start with '/' and are recognized by the server.
affects: >=0.0.0
gotchaAuto-reconnect is disabled when calling disconnect() explicitly. It will only re-enable on next connect() call.
fix
Use client.disconnect() carefully; if you want to temporarily disconnect and reconnect, consider using a flag to manage state.
affects: >=0.0.0
deprecatedThe package version 0.0.45 is below 1.0.0; APIs may change without major version bump.
fix
Pin to a specific version and test upgrades.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'ws'
The 'ws' package is not installed in the Node.js environment.
fix
Run 'npm install ws' or 'yarn add ws'.
TypeError: LightWebsocketNodeClient is not a constructor
Incorrect import: default import used instead of named import.
fix
Use import { LightWebsocketNodeClient } from 'light-websocket-client' (curly braces).
Error: connect ECONNREFUSED
The WebSocket server is not running or the URL is incorrect.
fix
Verify the server URL and ensure the server is running.
Upgrade
Version history
0.0.45latest on npm
Audit
Dependencies
wsoptionalRequired for Node.js environment to create WebSocket connections.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
light-websocket-client — npm install light-websocket-client · libregistry