{"id":49731,"library":"websocket-perfect","title":"websocket-perfect","description":"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.","status":"active","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/weixiaoyi/websocket-perfect","tags":["javascript","websocket","rxjs","websocket-rxjs"],"install":[{"cmd":"npm install websocket-perfect","lang":"bash","label":"npm"},{"cmd":"yarn add websocket-perfect","lang":"bash","label":"yarn"},{"cmd":"pnpm add websocket-perfect","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for WebSocket observable subscriptions and operators.","package":"rxjs","optional":false}],"imports":[{"note":"Package uses default export as class. Requires a default import in ES modules.","wrong":"const Ws = require('websocket-perfect')","symbol":"default","correct":"import Ws from 'websocket-perfect'"},{"note":"Named import Ws is invalid; the default export is the constructor.","wrong":"import { Ws } from 'websocket-perfect'","symbol":"Ws","correct":"import Ws from 'websocket-perfect'"},{"note":"Observable is from rxjs package, not re-exported by websocket-perfect.","wrong":"import { Observable } from 'websocket-perfect'","symbol":"Observable","correct":"import { Observable } from 'rxjs'"}],"quickstart":{"code":"import Ws from 'websocket-perfect';\n\nconst ws = new Ws({\n  url: 'wss://echo.websocket.org',\n  buffer: true,\n  debug: true\n});\n\nws.send({ subscribe: 'apple' }).subscribe(([e, data]) => {\n  console.log('Received:', data);\n});\n\n// Close after 5 seconds\nsetTimeout(() => ws.close(), 5000);","lang":"typescript","description":"Shows creation of a WebSocket connection with buffering enabled, sending a message, and handling response via RxJS subscription."},"warnings":[{"fix":"Ensure ws:// or wss:// URL is correct and the server is running.","message":"WebSocket URL must be valid and the server must be reachable; otherwise send() observable will error silently.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to default import as shown in quickstart.","message":"Default import changed from previous versions: use `import Ws from 'websocket-perfect'` instead of other patterns.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Use bufferWhen function to individually decide caching.","message":"buffer config may be deprecated in future versions; prefer bufferWhen for per-message control.","severity":"deprecated","affected_versions":">=1.1.0"},{"fix":"Always call .subscribe() on the returned observable to trigger the send.","message":"send() returns an Observable; forgetting to call subscribe() will not execute the WebSocket send.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `_flush: true` only when you want the message to always be cached (lowest priority).","message":"The `_flush` property on message overrides buffer settings; if incorrectly used, messages may not be cached as expected.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.3':22 '6':50 'allow':51 'api':66 'automat':14 'base':7,27 'beforesend/aftersend':32 'buffer/cache':39 'bufferwhen':58 'busi':17 'cach':19,55 'cadenc':71 'communic':29 'configur':38 'control':56 'differenti':46 'flush':60 'hook':31 'integr':47 'interceptor':33 'javascript':72 'javascript/typescript':11 'key':45 'low':69 'messag':35,54 'observ':26 'observable-bas':25 'offer':63 'per':53 'per-messag':52 'perfect':3 'properti':61 'provid':24 'reconnect':15,44 'releas':68 'resubscrib':42 'rxjs':6,49,74,77 'rxjs-base':5 'send/close':65 'set':40 'simpl':64 'stabl':67 'subscript':18 'support':13 'transform':36 'updat':70 'version':21 'via':57 'websocket':2,8,28,73,76 'websocket-perfect':1 'websocket-rxj':75 'wrapper':9","created_at":"2026-06-07T17:03:19.235452+00:00","updated_at":"2026-06-07T17:03:19.235452+00:00","problems":[{"fix":"Run `npm install websocket-perfect` and use correct default import.","cause":"Package is not installed or import path is incorrect.","error":"Cannot find module 'websocket-perfect'"},{"fix":"Use a WebSocket polyfill like ws package in Node.js.","cause":"Running in a non-browser environment without a WebSocket polyfill.","error":"WebSocket is not defined"},{"fix":"Ensure ws is an instance of Ws: const ws = new Ws({...}); then ws.send().","cause":"Instance method called incorrectly - ws.send() called without a proper instance.","error":"this.send is not a function"}],"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/weixiaoyi/websocket-perfect#readme","github":"https://github.com/weixiaoyi/websocket-perfect","docs":null,"changelog":null,"pypi":null,"npm":"websocket-perfect","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"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}}