Registry / messaging / websocket-perfect

websocket-perfect

JSON →
library1.1.3jsnpmunverified

An RxJS-based WebSocket wrapper for JavaScript/TypeScript that supports automatic reconnection and business subscription caching. At version 1.1.3, it provides observable-based WebSocket communication with hooks (beforeSend/afterSend), interceptors for message transformation, and configurable buffer/cache settings to resubscribe after reconnect. Key differentiators: integrates with RxJS 6+, allows per-message cache control via bufferWhen or _flush property, and offers simple send/close API. Stable release, low update cadence.

npm install websocket-perfect
INSTALL
IMPORT
SIG · WEBSOCKET-PERFECT
W
websocket-perfect
messagingjavascriptv1.1.3
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.

default
import Ws from 'websocket-perfect'
const Ws = require('websocket-perfect')
Package uses default export as class. Requires a default import in ES modules.
Ws
import Ws from 'websocket-perfect'
import { Ws } from 'websocket-perfect'
Named import Ws is invalid; the default export is the constructor.
Observable
import { Observable } from 'rxjs'
import { Observable } from 'websocket-perfect'
Observable is from rxjs package, not re-exported by websocket-perfect.

Shows creation of a WebSocket connection with buffering enabled, sending a message, and handling response via RxJS subscription.

import Ws from 'websocket-perfect'; const ws = new Ws({ url: 'wss://echo.websocket.org', buffer: true, debug: true }); ws.send({ subscribe: 'apple' }).subscribe(([e, data]) => { console.log('Received:', data); }); // Close after 5 seconds setTimeout(() => ws.close(), 5000);
Debug
Known issues
gotchaWebSocket URL must be valid and the server must be reachable; otherwise send() observable will error silently.
fix
Ensure ws:// or wss:// URL is correct and the server is running.
affects: >=1.0.0
breakingDefault import changed from previous versions: use `import Ws from 'websocket-perfect'` instead of other patterns.
fix
Update to default import as shown in quickstart.
affects: >=1.1.0
deprecatedbuffer config may be deprecated in future versions; prefer bufferWhen for per-message control.
fix
Use bufferWhen function to individually decide caching.
affects: >=1.1.0
gotchasend() returns an Observable; forgetting to call subscribe() will not execute the WebSocket send.
fix
Always call .subscribe() on the returned observable to trigger the send.
affects: >=1.0.0
gotchaThe `_flush` property on message overrides buffer settings; if incorrectly used, messages may not be cached as expected.
fix
Use `_flush: true` only when you want the message to always be cached (lowest priority).
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'websocket-perfect'
Package is not installed or import path is incorrect.
fix
Run `npm install websocket-perfect` and use correct default import.
WebSocket is not defined
Running in a non-browser environment without a WebSocket polyfill.
fix
Use a WebSocket polyfill like ws package in Node.js.
this.send is not a function
Instance method called incorrectly - ws.send() called without a proper instance.
fix
Ensure ws is an instance of Ws: const ws = new Ws({...}); then ws.send().
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
rxjsrequiredRequired for WebSocket observable subscriptions and operators.
Agent activity
21 hits · last 30 days
node
19
OpenAI (training)
1
Resources
websocket-perfect — npm install websocket-perfect · libregistry