Registry / communication / wscl
library2.3.2jsnpmunverified

Tiny WebSocket wrapper (~635 bytes brotlied) with auto-reconnect (exponential backoff) and message buffering. Version 2.3.2, stable. Smaller than alternatives like reconnecting-websocket. Ships TypeScript types. Features: on() returns unsubscribe, message callback receives data directly (not event), connect() returns Promise.

npm install wscl
INSTALL
IMPORT
SIG · WSCL
W
wscl
communicationjavascriptv2.3.2
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.

Client
import { Client } from 'wscl'
const Client = require('wscl').Client
ESM-only package; cannot use require() in Node <12. May need --experimental-modules or Node version >=14.
events
import { events } from 'wscl'
import events from 'wscl'
events is a named export, not default.
Client type
import type { Client } from 'wscl'
TypeScript type import for type-only usage.

Creates a WebSocket client with auto-reconnect, sends a message before connection, then connects and logs events.

import { Client, events } from 'wscl'; const wsc = new Client({ url: process.env.WS_URL ?? 'wss://echo.websocket.org', }); wsc.on(events.Open, () => console.log('connected')); wsc.on(events.Message, (data) => console.log('received:', data)); wsc.on(events.Close, (event) => console.log('closed:', event.code)); wsc.on(events.Error, (err) => console.error(err)); // Buffered send works before connect wsc.send('hello'); await wsc.connect(); console.log('Connected:', wsc.connected);
Debug
Known issues
breakingv2 removes default export; use named exports { Client, events } instead.
fix
Change import from 'import Client from "wscl"' to 'import { Client } from "wscl"'.
affects: >=2.0.0
gotchaWebSocket URL must be passed to constructor; Client does not support URL argument in connect() separate from constructor.
fix
Pass url in constructor options.
affects: >=1.0.0
gotchaCalling send() before connect() buffers the message, but if connection never succeeds, the message is lost.
fix
Handle connection errors or use a timeout to detect failure.
affects: >=1.0.0
deprecatedv1 had a 'connect(url)' method that accepted URL; v2 requires URL in constructor.
fix
Move URL to constructor options.
affects: >=1.0.0 <2.0.0
Errors
Common errors & fixes
TypeError: client.connect is not a function
Attempting to call connect on an instance that hasn't been initialized via 'new Client()' or using a stale reference.
fix
Ensure you have created a Client instance: const client = new Client({ url: '...' }); await client.connect();
Module not found: Can't resolve 'wscl'
Package not installed or import path incorrect (e.g., using default import when named import required).
fix
Install via 'npm install wscl' and use 'import { Client } from 'wscl''.
WebSocket is not defined (Node.js)
wscl uses the browser WebSocket API, which is not available in Node.js without a polyfill.
fix
Install 'ws' package and set global.WebSocket = require('ws') before importing wscl, or use a bundler.
Uncaught TypeError: events.Open is undefined
Using default import for events instead of named import.
fix
Use 'import { events } from 'wscl'' and then access events.Open.
Upgrade
Version history
2.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
34
OpenAI (training)
1
Resources
packagewscl
wscl — npm install wscl · libregistry