Registry /
communication / light-websocket-client-ts
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-ts'
✗ const LightWebsocketClientImpl = require('light-websocket-client-ts')
ESM-only package; CommonJS require will not work. TypeScript types included.
LightWebsocketCLientNodeImpl
✓ import { LightWebsocketClientImpl } from 'light-websocket-client-ts'; import * as WebSocket from 'ws'; class LightWebsocketCLientNodeImpl extends LightWebsocketClientImpl { ... }
✗ const LightWebsocketCLientNodeImpl = require('light-websocket-client-ts').LightWebsocketCLientNodeImpl
Node.js implementation is not exported; you must create a subclass that overrides createWebsocket. The example uses a class named LightWebsocketCLientNodeImpl but that's user-defined.
LightWebsocketClientImpl (default export?)
✓ import { LightWebsocketClientImpl } from 'light-websocket-client-ts'
✗ import LightWebsocketClientImpl from 'light-websocket-client-ts'
The library does not have a default export; only named exports.
methods onInstance
✓ const client = new LightWebsocketClientImpl(url); client.onConnect(cb); client.onDisconnect(cb); client.onMessage(cb); client.connect(); client.disconnect();
✗ client.onconnect(cb)
Method names are camelCase; onConnect, onDisconnect, onMessage are methods, not properties. Callback registration is via method calls, not assignment.
Creates a WebSocket client, registers lifecycle callbacks, connects, sends a message, and demonstrates disconnect.
import { LightWebsocketClientImpl } from 'light-websocket-client-ts';
const client = new LightWebsocketClientImpl('ws://localhost:8080/ws');
client.onConnect(() => {
console.log('Connected');
});
client.onDisconnect((code?: number, reason?: string) => {
console.log('Disconnected', code, reason);
});
client.onMessage((message: string) => {
console.log('Received:', message);
});
client.connect();
// Send a message
client.send('Hello server');
// Disconnect (disables auto-reconnect)
// client.disconnect();
Errors
Common errors & fixes
TypeError: LightWebsocketClientImpl is not a constructor
Using CommonJS require or default import when only named export exists.
fixUse `import { LightWebsocketClientImpl } from 'light-websocket-client-ts'` Error: No 'ws' module found. Please install 'ws' for Node.js usage.
Trying to use the client in Node.js without installing the 'ws' package.
fixRun `npm install ws` and ensure it's available.
WebSocket connection to 'ws://...' failed: Unexpected response code: 101
The server side does not have the custom protocol implemented; standard WebSocket server returns 101 and connection appears to succeed but client will fail due to missing heartbeat.
fixDeploy the required `light-websocket-server` or ensure your server sends the correct protocol header.
Cannot read properties of undefined (reading 'on')
Creating a LightWebsocketClientImpl without calling `connect()` first before calling `onConnect` or other methods? Actually the methods can be called before connect; this error may occur if the internal socket is not initialized.
fixCall `client.connect()` after setting callbacks. Ensure you are not interacting before connect.
Audit
Dependencies
wsoptionalRequired for Node.js environments to create WebSocket instances