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.
WebSocketBroadcaster
✓ import { WebSocketBroadcaster } from 'clhq-websocket-module'
✗ const WebSocketBroadcaster = require('clhq-websocket-module');
ESM-only package; CommonJS require() fails.
BroadcasterOptions
✓ import type { BroadcasterOptions } from 'clhq-websocket-module'
✗ import { BroadcasterOptions } from 'clhq-websocket-module'
Type-only import to avoid runtime errors in JavaScript.
default
✓ import Broadcaster from 'clhq-websocket-module'
✗ const Broadcaster = require('clhq-websocket-module').default
The default export is WebSocketBroadcaster.
Initializes a WebSocket broadcaster on port 8080, broadcasts a JSON event, and handles new connections.
import { WebSocketBroadcaster } from 'clhq-websocket-module';
import WebSocket from 'ws';
const broadcaster = new WebSocketBroadcaster({
port: 8080,
server: new WebSocket.Server({ port: 8080 }),
});
broadcaster.on('connection', (socket) => {
console.log('Client connected');
socket.send('Welcome!');
});
broadcaster.broadcast({ event: 'update', data: { message: 'Hello all' } });
Debug
Known issues
breakingWebSocketBroadcaster constructor removed 'ws' option; use 'server' option in v1.1.0-alpha.189fixPass WebSocket.Server instance via 'server' option instead of 'ws'.
affects: >=1.1.0-alpha.189
deprecatedMethod 'sendToAll' is deprecated; use 'broadcast' instead.fixReplace calls to 'sendToAll' with 'broadcast'.
affects: >=1.1.0-alpha.180
gotchaClient-to-server events not supported; only server-to-client broadcasting works.fixImplement custom client message handling if needed; this is a known limitation.
affects: <=1.1.0-alpha.189
gotchaTypeScript consumers must set 'esModuleInterop' to true or use default import correctly.fixAdd 'esModuleInterop': true in tsconfig.json or use 'import * as Broadcaster'.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'ws' or its corresponding type declarations.
Missing 'ws' dependency.
fixRun 'npm install ws' and 'npm install @types/ws' (if using TypeScript).
TypeError: WebSocketBroadcaster is not a constructor
Wrong import style (CommonJS require on an ESM-only package).
fixUse ES module import: 'import { WebSocketBroadcaster } from 'clhq-websocket-module' Upgrade
Version history
1.1.0-alpha.189latest on npm
Audit
Dependencies
wsrequiredCore WebSocket implementation