Gathering detailed insights and metrics for jsonrpc2-ws
Gathering detailed insights and metrics for jsonrpc2-ws
Gathering detailed insights and metrics for jsonrpc2-ws
Gathering detailed insights and metrics for jsonrpc2-ws
Simple, Fast, Robust Implementation of JSON-RPC 2.0 over WebSocket for Node.js w/ TypeScript
npm install jsonrpc2-ws
Typescript
Module System
Node Version
NPM Version
TypeScript (71.64%)
JavaScript (28.36%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
5 Stars
71 Commits
1 Forks
1 Watchers
3 Branches
2 Contributors
Updated on Jul 27, 2023
Latest Version
1.0.0-beta24
Package Id
jsonrpc2-ws@1.0.0-beta24
Unpacked Size
72.93 kB
Size
16.77 kB
File Count
27
NPM Version
8.14.0
Node Version
18.12.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
5
Simple, Fast, Robust Implementation of JSON-RPC 2.0 over WebSocket for Node.js w/ TypeScript
1npm install jsonrpc2-ws --save
1// TypeScript 2import { Server as RPCServer } from "jsonrpc2-ws"; 3 4const rpc = new RPCServer({ 5 wss: { 6 port: 3000 7 } 8}); 9 10rpc.on("connection", (socket, req) => { 11 console.log(`${socket.id} connected!`); 12 13 socket.on("close", () => { 14 console.log(`${socket.id} disconnected!`); 15 }); 16 17 rpc.broadcast("count", { count: rpc.sockets.size }); 18 19 // room 20 socket.joinTo("general"); 21 rpc.notifyTo("general", "general.count", { count: rpc.in("general").size }); 22}); 23 24rpc.methods.set("nick", (socket, params) => { 25 // socket#data is Map to store custom data. 26 socket.data.set("nick", params.nick); 27}); 28 29rpc.methods.set("join", (socket, params) => { 30 if (socket.joinTo(params.ch) === true) { 31 rpc.notifyTo(params.ch, `${params.ch}.count`, { count: rpc.in(params.ch).size }); 32 return; 33 } else { 34 throw new Error("Already joined"); 35 } 36}); 37 38rpc.methods.set("chat", (socket, params) => { 39 if (!params || !params.ch || !params.message) { 40 throw new Error("Invalid request"); 41 } 42 43 rpc.notifyTo(params.ch, "chat", { 44 time: Date.now(), 45 id: socket.id, 46 nick: socket.data.get("nick") || "anonymous", 47 ch: params.ch, 48 message: params.message 49 }); 50}); 51 52// note: rpc method supports async/await or Promise. 53rpc.methods.set("something-async-method", async (socket, params) => { 54 const res = await somethingAsyncMethod(); 55 return res; 56});
1// TypeScript 2import * as http from "http"; 3import { Server as RPCServer } from "jsonrpc2-ws"; 4 5const server = http.createServer(); 6const rpc = new RPCServer({ wss: { server } });
1// TypeScript 2import express = require("express"); 3import * as http from "http"; 4import { Server as RPCServer } from "jsonrpc2-ws"; 5 6const app = express(); 7const server = http.createServer(app); 8const rpc = new RPCServer({ wss: { server } });
BTC: 1CsARqdT2PDLdWng8r2h5pzmyC6xkVnxKw
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
7 existing vulnerabilities detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More