Registry / messaging / vweb-websocket

vweb-websocket

JSON →
library1.0.32jsnpmunverified

A minimal WebSocket client library for browser and Node.js environments, version 1.0.32. Provides simple connection management, message sending/receiving, and automatic reconnection. Lightweight alternative to socket.io with no dependencies. Ships TypeScript definitions. Low release cadence with infrequent updates.

npm install vweb-websocket
INSTALL
IMPORT
SIG · VWEB-WEBSOCKET
V
vweb-websocket
messagingjavascriptv1.0.32
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.

WebSocketClient
import { WebSocketClient } from 'vweb-websocket'
const WebSocketClient = require('vweb-websocket')
ESM-only; CommonJS require not supported.
WebSocketEvent
import { WebSocketEvent } from 'vweb-websocket'
import WebSocketEvent from 'vweb-websocket'
Named export, not default.
ReconnectPolicy
import { ReconnectPolicy } from 'vweb-websocket'
TypeScript type export for configuring reconnection behavior.

Creates a WebSocket client, connects to an echo server, sends a message, and logs responses.

import { WebSocketClient } from 'vweb-websocket'; const client = new WebSocketClient('wss://echo.websocket.org', { reconnect: true, maxRetries: 5 }); client.on('open', () => { console.log('Connected'); client.send('Hello'); }); client.on('message', (data) => { console.log('Received:', data); }); client.on('close', (code, reason) => { console.log('Disconnected:', code, reason); }); client.connect();
Debug
Known issues
gotchaLibrary uses the global WebSocket object in browsers but requires `ws` package in Node.js if not natively supported (Node < 18). Not automatically installed.
fix
Install optional dependency: npm install ws
affects: >=1.0.0
breakingIn v1.0.20, the `connect()` method signature changed: `options` parameter was reordered.
fix
Update call to `client.connect(url, options)` -> `client.connect(options)`
affects: >=1.0.20
deprecatedThe `WebSocketClient.close()` method is deprecated in favor of `disconnect()` since v1.0.25.
fix
Replace `client.close()` with `client.disconnect()`
affects: >=1.0.25
gotchaReconnection is enabled by default; ensure you handle the `reconnect` option explicitly to avoid unexpected behavior.
fix
Set `{ reconnect: false }` in constructor options if not needed.
affects: >=1.0.0
gotchaTypeScript type exports might not be recognized if `moduleResolution` is set to 'node' in tsconfig; use 'node16' or 'bundler'.
fix
Set `moduleResolution` to 'node16' or 'bundler' in tsconfig.json.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: WebSocket is not defined
Node.js version < 18 does not have native WebSocket; need optional dependency.
fix
npm install ws
TypeError: client.connect is not a function
Using CommonJS require instead of ESM import.
fix
Switch to `import { WebSocketClient } from 'vweb-websocket'`
Module not found: Error: Can't resolve 'ws' in ...
Missing optional dependency 'ws' in Node.js environment.
fix
npm install ws
Upgrade
Version history
1.0.32latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
26
OpenAI (training)
1
Resources
vweb-websocket — npm install vweb-websocket · libregistry