Registry / messaging / w-websocket-client

w-websocket-client

JSON →
library1.0.29jsnpmunverified

A lightweight wrapper for WebSocket that works in both Node.js and browser environments. Current stable version is 1.0.29. It provides a simple constructor-based API with callbacks for open, close, message, and error events. In Node.js it depends on the 'ws' package, but in the browser it uses native WebSocket with no dependencies. Key differentiator: unified API across platforms with automatic fallback, and UMD distribution for direct browser script tags. Low download count but functional for simple WebSocket use cases.

npm install w-websocket-client
INSTALL
IMPORT
SIG · W-WEBSOCKET-CLIENT
W
w-websocket-client
messagingjavascriptv1.0.29
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.

WSC
import WSC from 'w-websocket-client/dist/w-websocket-client.umd.js'
import { WSC } from 'w-websocket-client'
The package does not expose a default export in the main entry; you must import the UMD file directly. Common mistake: importing from 'w-websocket-client' will result in undefined.
WSC
const WSC = require('w-websocket-client/dist/w-websocket-client.umd.js')
const WSC = require('w-websocket-client')
CommonJS require also must target the UMD file. The main entry is not configured for CJS.
WSC
const wsc = new WSC(opt)
const wsc = new ws(opt) or new WebSocket(opt)
The constructor expects an options object with url, token, and callbacks. Using native WebSocket directly will not work with this wrapper's API.

Creates a WebSocket client with an options object, connects to an echo server, sends a message, and logs received data.

import WSC from 'w-websocket-client/dist/w-websocket-client.umd.js'; const opt = { url: 'ws://echo.websocket.org', token: '*', open: () => { console.log('connected'); wsc.send('Hello'); }, message: (data) => { console.log('received:', data); }, error: (err) => { console.error('error:', err); }, close: () => { console.log('disconnected'); } }; const wsc = new WSC(opt);
Debug
Known issues
gotchaImport path must include '/dist/w-websocket-client.umd.js'. Importing from 'w-websocket-client' alone will not work.
fix
Use correct import path: 'w-websocket-client/dist/w-websocket-client.umd.js'
affects: >=0.0.0
gotchaIn browser, WSC is exposed as window['w-websocket-client'], not window.WSC.
fix
Use window['w-websocket-client'] to access the constructor.
affects: >=0.0.0
deprecatedThe token option is sent as part of the options object but its usage is not documented beyond being a placeholder.
fix
Set token to '*' unless the server requires authentication.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: WSC is not a constructor
Importing 'WSC' as a named export or using wrong path.
fix
Use correct import: import WSC from 'w-websocket-client/dist/w-websocket-client.umd.js'
Cannot find module 'w-websocket-client'
Using require('w-websocket-client') without specifying the UMD file.
fix
Use require('w-websocket-client/dist/w-websocket-client.umd.js')
Uncaught ReferenceError: WSC is not defined
In browser, using window.WSC instead of window['w-websocket-client'].
fix
Use window['w-websocket-client'] to access the constructor.
Upgrade
Version history
1.0.29latest on npm
Audit
Dependencies
wsrequiredWebSocket implementation in Node.js
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
w-websocket-client — npm install w-websocket-client · libregistry