Registry / messaging / rpc-websocket

rpc-websocket

JSON →
library0.7.6jsnpmunverified

RPC WebSocket is a wrapper for standard WebSocket that adds support for message types, RPC calls, and before/after send/receive event hooks. Version 0.7.6 is the latest release; the package has not seen updates since 2016 and is in maintenance mode with known issues. It provides a lightweight alternative to Socket.io for simple RPC over WebSocket, lacking built-in reconnection or authentication. Works in both Node.js and browser environments. Note: The package is not actively maintained and may have compatibility issues with modern WebSocket APIs and module systems.

npm install rpc-websocket
INSTALL
IMPORT
SIG · RPC-WEBSOCKET
R
rpc-websocket
messagingjavascriptv0.7.6
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 RpcWebSocket from 'rpc-websocket'
const RpcWebSocket = require('rpc-websocket')
Package is ESM-only with a default export. CommonJS require will not work unless using a bundler that supports ESM interop.
RpcWebSocket
import RpcWebSocket from 'rpc-websocket'
import { RpcWebSocket } from 'rpc-websocket'
The package does not export a named export RpcWebSocket; only a default export.
type imports
import type { RpcWebSocketType } from 'rpc-websocket'
TypeScript users should import types from the package if available. However, the package does not ship TypeScript declarations; users may need to create their own.

Demonstrates creating an RPC WebSocket connection to a test server, calling an RPC method, and using message types for send/receive.

import RpcWebSocket from 'rpc-websocket'; const ws = new RpcWebSocket('wss://echo.websocket.org'); ws.on('open', () => { console.log('Connected'); ws.rpc('greeting', { name: 'World' }, (err, response) => { if (err) console.error('RPC error:', err); else console.log('RPC response:', response); }); }); ws.on('error', (err) => console.error('WebSocket error:', err)); ws.on('close', () => console.log('Disconnected')); // Enable message types ws.send('chat', { text: 'Hello' }); ws.on('chat', (data) => console.log('Received chat:', data));
Debug
Known issues
deprecatedPackage has not been updated since 2016; potential security vulnerabilities in underlying WebSocket implementation.
fix
Consider migrating to a maintained alternative like Socket.io or ws with custom RPC layer.
affects: >=0.0.0
gotchaWs.prototype.close is not a function on some Node.js versions?
fix
Ensure you are using a compatible WebSocket implementation (e.g., the 'ws' package in Node.js). Check your Node.js version.
affects: >=0.7.0
breakingEvent listener for 'error' may not fire?
fix
Attach error listener directly on underlying WebSocket instance via ws.ws.on('error', ...) for reliable error handling.
affects: >=0.0.0
gotchaMessage types may trigger multiple listeners?
fix
The package does not deduplicate listeners; each call to ws.on(type, cb) adds a new listener. Use removeListener if needed.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'rpc-websocket'
Package not installed or CommonJS require used with ESM-only package.
fix
npm install rpc-websocket and use ES module import syntax.
TypeError: ws.rpc is not a function
Attempting to use rpc method before WebSocket connection is open.
fix
Wrap rpc calls inside the 'open' event callback.
Uncaught Error: Invalid UTF-8
Sending non-UTF-8 data over WebSocket.
fix
Ensure payload is UTF-8 encoded string; binary data is not natively supported.
Upgrade
Version history
0.7.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
rpc-websocket — npm install rpc-websocket · libregistry