Registry / messaging / mole-rpc-transport-ws

mole-rpc-transport-ws

JSON →
library1.0.3jsnpmunverified

WebSocket transport layer for the Mole-RPC JSON-RPC 2.0 library. Current version 1.0.3, stable and feature-complete. Works in Node.js (>=10.0.0), browser, and Electron. Supports client-to-server, server-to-client, and bidirectional communication. Peer dependencies: mole-rpc 1.* and ws 8.*. Alternative transports exist for HTTP, TCP, etc.

npm install mole-rpc-transport-ws
INSTALL
IMPORT
SIG · MOLE-RPC-TRANSPORT
M
mole-rpc-transport-ws
messagingjavascriptv1.0.3
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 'mole-rpc'
import Client from 'mole-rpc'
Default export not available; named import required.
Server
import { Server } from 'mole-rpc'
WebSocketTransport
import { WebSocketTransport } from 'mole-rpc-transport-ws'
import WebSocketTransport from 'mole-rpc-transport-ws'
Named export only; default import does not exist.
WebSocketServer
import { WebSocketServer } from 'ws'
import WebSocket from 'ws'
WebSocketServer is used on server side for listening.

Basic setup of a Mole-RPC server and client over WebSocket, with a ping/pong example.

import { Client, Server } from 'mole-rpc'; import { WebSocketTransport } from 'mole-rpc-transport-ws'; import { WebSocketServer } from 'ws'; const WSS_PORT = 8080; // Server const server = new Server({ transport: new WebSocketTransport({ wss: new WebSocketServer({ port: WSS_PORT }) }) }); server.batch(() => { server.expose({ ping: () => 'pong' }); }); // Client const client = new Client({ transport: new WebSocketTransport({ url: `ws://localhost:${WSS_PORT}` }) }); (async () => { const result = await client.call('ping'); console.log(result); // 'pong' process.exit(); })();
Debug
Known issues
gotchaWebSocketTransport for server expects 'wss' (WebSocketServer instance), not URL.
fix
Pass { wss: new WebSocketServer({ port }) } instead of { url } for server transport.
affects: >=1.0.0
gotchaThe ws library version 8.x is required as peer dependency; using version 7.x may cause incompatibility.
fix
Install ws@8: npm install ws@8
affects: >=1.0.0
gotchaMole-RPC 1.* must be used; version 2.x is not compatible.
fix
Install mole-rpc@1: npm install mole-rpc@1
affects: >=1.0.0
gotchaBrowser usage requires bundler (Webpack, Rollup) for CommonJS modules.
fix
Use a bundler that can handle CommonJS modules (e.g., Webpack with node: false).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: transport.connect is not a function
Using WebSocketTransport with incorrect constructor arguments
fix
Ensure you pass 'url' for client or 'wss' for server, not WebSocket instance directly.
Error: Cannot find module 'ws'
Missing ws peer dependency
fix
Run 'npm install ws@8' in your project.
Error: This transport works in browser only if bundled.
Trying to use WebSocketTransport directly in browser without bundling
fix
Use Webpack/Rollup/Parcel to bundle the module.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
mole-rpcrequiredCore Mole-RPC library required to use this transport
wsrequiredWebSocket implementation used by the transport
Agent activity
6 hits · last 30 days
node
4
OpenAI (training)
2
Resources
mole-rpc-transport-ws — npm install mole-rpc-transport-ws · libregistry