Registry / messaging / websocket-rpc-client

websocket-rpc-client

JSON →
library0.2.0jsnpmunverified

A lightweight JavaScript library implementing JSON-RPC 2.0 over WebSockets, providing promise-based request/response handling and event subscription. Version 0.2.0 is the latest, with no clear release cadence. Designed for browser environments, it offers automatic reconnection with configurable timeout and retry count. Compared to alternatives like json-rpc-ws or isomorphic-wsrpc, this library provides a simple static API and built-in reconnect logic, but lacks TypeScript types and has no recent updates.

npm install websocket-rpc-client
INSTALL
IMPORT
SIG · WEBSOCKET-RPC-CLIE
W
websocket-rpc-client
messagingjavascriptv0.2.0
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-rpc-client'
const WS = require('websocket-rpc-client')
CommonJS require() works in Node but the library targets browsers; ESM import is recommended.
default (named alternative)
import * as WS from 'websocket-rpc-client'
Also valid for all symbols as namespace import.
start
import WS from 'websocket-rpc-client'; WS.start(params)
import { start } from 'websocket-rpc-client'
start is not a named export; it's a method on the default export.

Shows how to establish a WebSocket JSON-RPC connection, send a request, handle the response, and subscribe to events.

import WS from 'websocket-rpc-client'; WS.start({ url: 'ws://localhost:8080/ws', reconnectTimeout: 3000, reconnectCount: 5 }).then(() => { console.log('Connected'); WS.send('echo', { message: 'Hello' }).then(resp => { console.log('Response:', resp); }).catch(err => console.error('Send error:', err)); }).catch(err => console.error('Connection failed:', err)); WS.subscribe('onMessage', params => { console.log('Received:', params); });
Debug
Known issues
gotchaThe library expects to run in a browser environment; using it in Node.js requires a WebSocket polyfill (e.g., 'ws' package).
fix
Install 'ws' and assign it to global.WebSocket before importing the library.
affects: >=0.0.0
gotchaThe 'start' method must be called before any 'send' or 'subscribe' calls, or they may fail silently.
fix
Always ensure 'start' promise resolves before using other methods.
affects: >=0.0.0
gotchaThe library uses a static singleton connection; creating multiple instances is not supported.
fix
Only one WebSocket connection can be managed at a time; disconnect and reconnect as needed.
affects: >=0.0.0
deprecatedNo known deprecated APIs, but the library has not been updated since initial release.
fix
Consider evaluating alternatives for active maintenance.
affects: 0.2.0
Errors
Common errors & fixes
TypeError: WS.start is not a function
Imported named export instead of default export.
fix
Use import WS from 'websocket-rpc-client' (default import).
ReferenceError: WebSocket is not defined
Running in Node.js environment without global WebSocket.
fix
Install 'ws' package and set global.WebSocket = require('ws'); before importing the library.
Error: Not connected
Attempted to send or subscribe before the connection was established.
fix
Call send or subscribe only after the promise from WS.start() resolves.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
40 hits · last 30 days
node
32
OpenAI (training)
1
Resources
websocket-rpc-client — npm install websocket-rpc-client · libregistry