{"id":49776,"library":"wscl","title":"wscl","description":"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.","status":"active","version":"2.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/farwayer/wscl","tags":["javascript","websocket","websocket-client","socket","ws","wss","reconnect","typescript"],"install":[{"cmd":"npm install wscl","lang":"bash","label":"npm"},{"cmd":"yarn add wscl","lang":"bash","label":"yarn"},{"cmd":"pnpm add wscl","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package; cannot use require() in Node <12. May need --experimental-modules or Node version >=14.","wrong":"const Client = require('wscl').Client","symbol":"Client","correct":"import { Client } from 'wscl'"},{"note":"events is a named export, not default.","wrong":"import events from 'wscl'","symbol":"events","correct":"import { events } from 'wscl'"},{"note":"TypeScript type import for type-only usage.","symbol":"Client type","correct":"import type { Client } from 'wscl'"}],"quickstart":{"code":"import { Client, events } from 'wscl';\n\nconst wsc = new Client({\n  url: process.env.WS_URL ?? 'wss://echo.websocket.org',\n});\n\nwsc.on(events.Open, () => console.log('connected'));\nwsc.on(events.Message, (data) => console.log('received:', data));\nwsc.on(events.Close, (event) => console.log('closed:', event.code));\nwsc.on(events.Error, (err) => console.error(err));\n\n// Buffered send works before connect\nwsc.send('hello');\n\nawait wsc.connect();\nconsole.log('Connected:', wsc.connected);","lang":"typescript","description":"Creates a WebSocket client with auto-reconnect, sends a message before connection, then connects and logs events."},"warnings":[{"fix":"Change import from 'import Client from \"wscl\"' to 'import { Client } from \"wscl\"'.","message":"v2 removes default export; use named exports { Client, events } instead.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Pass url in constructor options.","message":"WebSocket URL must be passed to constructor; Client does not support URL argument in connect() separate from constructor.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Handle connection errors or use a timeout to detect failure.","message":"Calling send() before connect() buffers the message, but if connection never succeeds, the message is lost.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Move URL to constructor options.","message":"v1 had a 'connect(url)' method that accepted URL; v2 requires URL in constructor.","severity":"deprecated","affected_versions":">=1.0.0 <2.0.0"}],"env_vars":null,"search_vec":"'2.3.2':18 '635':5 'altern':22 'auto':10 'auto-reconnect':9 'backoff':13 'brot':7 'buffer':16 'byte':6 'callback':35 'client':48 'connect':41 'data':37 'direct':38 'event':40 'exponenti':12 'featur':30 'javascript':44 'like':23 'messag':15,34 'promis':43 'receiv':36 'reconnect':11,25,52 'reconnecting-websocket':24 'return':32,42 'ship':27 'smaller':20 'socket':49 'stabl':19 'tini':2 'type':29 'typescript':28,53 'unsubscrib':33 'version':17 'websocket':3,26,45,47 'websocket-cli':46 'wrapper':4 'ws':50 'wscl':1 'wss':51","created_at":"2026-06-07T17:03:32.771905+00:00","updated_at":"2026-06-07T17:03:32.771905+00:00","problems":[{"fix":"Ensure you have created a Client instance: const client = new Client({ url: '...' }); await client.connect();","cause":"Attempting to call connect on an instance that hasn't been initialized via 'new Client()' or using a stale reference.","error":"TypeError: client.connect is not a function"},{"fix":"Install via 'npm install wscl' and use 'import { Client } from 'wscl''.","cause":"Package not installed or import path incorrect (e.g., using default import when named import required).","error":"Module not found: Can't resolve 'wscl'"},{"fix":"Install 'ws' package and set global.WebSocket = require('ws') before importing wscl, or use a bundler.","cause":"wscl uses the browser WebSocket API, which is not available in Node.js without a polyfill.","error":"WebSocket is not defined (Node.js)"},{"fix":"Use 'import { events } from 'wscl'' and then access events.Open.","cause":"Using default import for events instead of named import.","error":"Uncaught TypeError: events.Open is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/farwayer/wscl#readme","github":"https://github.com/farwayer/wscl","docs":null,"changelog":null,"pypi":null,"npm":"wscl","openapi_spec":null,"status_page":null,"smithery":null,"categories":["communication"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}