Registry / devops / jsonrpc-websocket-client

jsonrpc-websocket-client

JSON →
library0.7.2jsnpmunverified

A lightweight JavaScript client for JSON-RPC 2.0 over WebSocket, current version 0.7.2, with irregular release cadence. Offers simple API with connection management, event handling, and automatic notification support. Differentiates with minimal dependencies and straightforward usage, suitable for Node.js and browser environments. Supports ESM and CJS.

npm install jsonrpc-websocket-client
INSTALL
IMPORT
SIG · JSONRPC-WEBSOCKET-
J
jsonrpc-websocket-client
devopsjavascriptv0.7.2
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.

Client
import Client from 'jsonrpc-websocket-client'
const Client = require('jsonrpc-websocket-client')
Default export only; named exports for helpers
createBackoff
import { createBackoff } from 'jsonrpc-websocket-client'
import createBackoff from 'jsonrpc-websocket-client'
Named export for backoff utility; not default
Client (CommonJS)
const Client = require('jsonrpc-websocket-client').default
const Client = require('jsonrpc-websocket-client')
CommonJS requires .default due to ESM default export; applies to Node < 12

Creates a WebSocket JSON-RPC client, connects, calls a method with parameters, and disconnects.

import Client from 'jsonrpc-websocket-client'; async function main() { const client = new Client('ws://localhost:8080'); await client.open(); console.log('Connected:', client.status); // 'open' const result = await client.call('add', [1, 2]); console.log('Result:', result); await client.close(); } main().catch(console.error);
Debug
Known issues
gotchaWhen using CommonJS, require returns an object with .default property. Using require directly will not work.
fix
Use const Client = require('jsonrpc-websocket-client').default;
affects: >=0.6.0
gotchaThe client does not auto-reconnect by default; connection lost must be handled manually or with createBackoff.
fix
Listen for 'closed' event and call client.open() again, or use createBackoff().
affects: >=0.0.0
gotchaNotifications (methods without id) are not supported via client.call; use client.notify.
fix
For notifications, call client.notify(method, params) instead.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Client is not a constructor
Using CommonJS require without .default
fix
const Client = require('jsonrpc-websocket-client').default;
Error: WebSocket is not defined
Running in Node.js without 'ws' package installed
fix
npm install ws
UnhandledPromiseRejectionWarning: TypeError: client.call is not a function
Forgetting to await client.open() before calling call()
fix
Ensure await client.open() completes before making calls.
Upgrade
Version history
0.7.2latest on npm
Audit
Dependencies
wsoptionalWebSocket implementation for Node.js; not needed in browser
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
jsonrpc-websocket-client — npm install jsonrpc-websocket-client · libregistry