Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
rpc-websocket-client
Advanced tools
Fast JSON RPC 2.0 written in TypeScript.
TypeScript JSON RPC 2.0 WebSocket implementation with async-await Promises.
I really lacked typescript support or type definitions of rpc-websockets. I kept everything as simple as possible for best performance and used fast-json-strongify for much faster JSON communication. Under the hood id-generation for requests is done using uuid/v1 to provide id uniqueness as an additional feature.
npm i rpc-websocket-client
noRpc()
method to prevent sending jsonrpc: '2.0'
overhead from all messages if you'd like to ignore the JSON RPC 2.0 standard for better performance.changeSocket()
and listenMessages()
methods. Useful if you use REST or GraphQL implementation from another library and want to handle JSON RPC 2.0 when communicating from server to client (that was my use case to develop this package).import { RpcWebSocketClient } from 'rpc-websocket-client';
(async () => {
const rpc = new RpcWebSocketClient();
await rpc.connect(`ws://localhost:4000/`);
// connection established
// let's hope there will be no error or it will be catched in some wrapper
await rpc.call(`auth.login`, [`rpcMaster`, `mySecretPassword`]);
// now lets be pesimistic
await rpc.call(`auth.login`, [`rpcMaster`, `mySecretPassword`]).then(() => {
// woohoo, user logged!
}).catch((err) => {
// err is typeof RpcError (code: number, message: string, data?: any)
await rpc.call(`auth.signup`, {
login: `rpcMaster`,
password: `mySecretPassword`,
});
});
rpc.notify(`btw.iHateYou`, [`over and out`]);
})();
(async () => {
// lets say you use WebSocket implementation for GraphQL Client -> Server communication
// e.g. Apollo, and it's already connected
// but you want to handle some of the Server -> Client communication with RPC
const ws = (apollo as any).client.wsImpl;
const rpc = new RpcWebSocketClient();
rpc.onRequest((data) => { // data is typeof RpcRequest
// controller-like stuff
});
rpc.onNotification((data) => { // data is typeof RpcNotification
// notification handling
});
// here goes magic for listening to already-connected socket
rpc.changeSocket(ws);
rpc.listenMessages();
})();
FAQs
Fast JSO
The npm package rpc-websocket-client receives a total of 347 weekly downloads. As such, rpc-websocket-client popularity was classified as not popular.
We found that rpc-websocket-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.