Registry / messaging / websocket-grpc

websocket-grpc

JSON →
library1.1.6jsnpmunverified

A lightweight JavaScript library that enables gRPC-style remote procedure calls over WebSocket connections. Version 1.1.6 provides a simple API to load protocol buffer descriptors and invoke RPC methods through WebSocket. It is designed for real-time communication in browser and Node.js environments where gRPC over HTTP/2 is not suitable. The library wraps WebSocket with gRPC-like request/response patterns, handling serialization via Protocol Buffers. It is actively maintained with monthly releases and supports both CommonJS and ESM. Compared to full gRPC implementations, this package offers minimal overhead and easier setup for WebSocket-based RPC, though it lacks advanced features like streaming or authentication.

npm install websocket-grpc
INSTALL
IMPORT
SIG · WEBSOCKET-GRPC
W
websocket-grpc
messagingjavascriptv1.1.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.

WsProto
import WsProto from 'websocket-grpc'
const { WsProto } = require('websocket-grpc')
Default export, not named. ESM import uses default syntax.
WsProto
const WsProto = require('websocket-grpc')
const wsproto = require('websocket-grpc')
CommonJS require returns the default export as the module, not an object. Variable name is arbitrary but typically capitalized.
WsProto as default
import WsProto from 'websocket-grpc'
import { WsProto } from 'websocket-grpc'
There is no named export 'WsProto'; it's the default export.

Initializes a WebSocket gRPC connection and sends a request using the default export WsProto.

const WsProto = require('websocket-grpc'); const wsproto = new WsProto(); const wsUrl = "ws://127.0.0.1"; const protoFilePath = "./ws.proto"; const requestType = "ReqMsgUpload"; const responseType = "RespMsg"; (async () => { await wsproto.init(wsUrl, protoFilePath, requestType, responseType); const payload = { data: "hello" }; const res = await wsproto.request(payload); console.log(res); })();
Debug
Known issues
gotchaInit must be awaited before calling request; otherwise request fails silently.
fix
Ensure init() is awaited: await wsproto.init(...);
affects: >=1.0.0
gotchaWebSocket connection is not auto-reconnected on disconnect; manual retry needed.
fix
Implement custom reconnection logic or use a wrapper.
affects: >=1.0.0
gotchaProto file path must be absolute or relative to process.cwd(); no path resolution from __dirname.
fix
Use path.join(__dirname, './ws.proto') in Node.js
affects: >=1.0.0
gotchaOnly unary RPC calls are supported; streaming is not implemented.
fix
Use other libraries like @grpc/grpc-js for streaming.
affects: >=1.0.0
gotchaNo built-in error handling for malformed proto files; throws opaque errors.
fix
Wrap init in try-catch and validate proto files externally.
affects: >=1.0.0
Errors
Common errors & fixes
WsProto is not a constructor
Using destructured require with named import instead of default import.
fix
Change to: const WsProto = require('websocket-grpc');
Cannot read property 'request' of undefined
init() not awaited or WebSocket connection failed.
fix
Ensure await wsproto.init(...) resolves successfully before calling request.
Error: ENOENT: no such file or directory, open './ws.proto'
Proto file path is relative to cwd, not the script location.
fix
Use absolute path or path.join(__dirname, './ws.proto')
Upgrade
Version history
1.1.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
websocket-grpc — npm install websocket-grpc · libregistry