Registry / messaging / jsonrpc-client-websocket

jsonrpc-client-websocket

JSON →
library1.5.5jsnpmunverified

A simple JSON RPC 2.0 client over WebSocket. Version 1.5.5 released under MIT license. Provides a lightweight, typed, promise-based client for bidirectional JSON-RPC communication over WebSocket with support for both positional and named parameters, request timeouts, and automatic error handling. Ships TypeScript declarations. Differentiated by its minimal API footprint, built-in callback for unexpected errors, and support for defining methods that can be called remotely. Suitable for Node.js and browser environments.

npm install jsonrpc-client-websocket
INSTALL
IMPORT
SIG · JSONRPC-CLIENT-WEB
J
jsonrpc-client-websocket
messagingjavascriptv1.5.5
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.

JsonRpcWebsocket
import { JsonRpcWebsocket } from 'jsonrpc-client-websocket'
const JsonRpcWebsocket = require('jsonrpc-client-websocket')
ESM package; named export only; requires TypeScript or ES module import.
JsonRpcError
import { JsonRpcError } from 'jsonrpc-client-websocket'
TypeScript type for error handling; available as value export, not needed for JS.
default export
import { JsonRpcWebsocket } from 'jsonrpc-client-websocket'
import JsonRpcWebsocket from 'jsonrpc-client-websocket'
No default export; always use named import.

Shows how to create a WebSocket connection, open it, call an RPC method with positional parameters, handle errors, and close the connection.

import { JsonRpcWebsocket } from 'jsonrpc-client-websocket'; const wsUrl = process.env.WS_URL ?? 'ws://localhost:8080'; const timeoutMs = 5000; const ws = new JsonRpcWebsocket(wsUrl, timeoutMs, (error) => { console.error('WebSocket error:', error); }); async function main() { await ws.open(); console.log('Connected'); // Call a method try { const result = await ws.call('sum', [1, 2]); console.log('sum result:', result); } catch (err) { console.error('RPC call failed:', err); } await ws.close(); } main();
Debug
Known issues
gotchaNamed parameters depend on function parameter names; minification/obfuscation may break them.
fix
Use positional parameters or register methods with a single params object to avoid name mangling.
affects: >=0.0.0
gotchaThe error callback may be called for multiple types of errors (unmatched responses, connection errors, etc.). Not all errors are catchable in the call() promise.
fix
Provide a robust error handling function for the callback parameter that logs or handles unexpected errors.
affects: >=0.0.0
gotchaRequests can timeout if no response is received within the configured timeout; the default is 2000ms.
fix
Increase timeout if calling slow RPC methods or set to 0 for no timeout (not recommended).
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: JsonRpcWebsocket is not a constructor
Using default import instead of named import.
fix
Use `import { JsonRpcWebsocket } from 'jsonrpc-client-websocket'`
Module not found: Error: Can't resolve 'jsonrpc-client-websocket'
Package not installed or import path incorrect.
fix
Run `npm install jsonrpc-client-websocket` and ensure import path is correct.
Upgrade
Version history
1.5.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
jsonrpc-client-websocket — npm install jsonrpc-client-websocket · libregistry