{"id":28559263,"url":"https://github.com/kanreisa/jsonrpc2-ws","last_synced_at":"2025-06-10T08:36:38.680Z","repository":{"id":35039093,"uuid":"146336468","full_name":"kanreisa/jsonrpc2-ws","owner":"kanreisa","description":"Simple, Fast, Robust Implementation of JSON-RPC 2.0 over WebSocket for Node.js w/ TypeScript","archived":false,"fork":false,"pushed_at":"2024-06-18T23:38:39.000Z","size":245,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T02:48:52.794Z","etag":null,"topics":["chat","javascript","json-rpc","json-rpc2","jsonrpc","jsonrpc2","jsonrpc2-ws","multiplayer","node-js","nodejs","rpc","rpc-api","rpc-framework","rpc-server","server","typescript","websocket","websocket-server","websockets"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kanreisa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-27T18:17:02.000Z","updated_at":"2023-07-27T05:48:21.000Z","dependencies_parsed_at":"2023-01-15T12:33:08.049Z","dependency_job_id":null,"html_url":"https://github.com/kanreisa/jsonrpc2-ws","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanreisa%2Fjsonrpc2-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanreisa%2Fjsonrpc2-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanreisa%2Fjsonrpc2-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanreisa%2Fjsonrpc2-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanreisa","download_url":"https://codeload.github.com/kanreisa/jsonrpc2-ws/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanreisa%2Fjsonrpc2-ws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258984246,"owners_count":22788210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat","javascript","json-rpc","json-rpc2","jsonrpc","jsonrpc2","jsonrpc2-ws","multiplayer","node-js","nodejs","rpc","rpc-api","rpc-framework","rpc-server","server","typescript","websocket","websocket-server","websockets"],"created_at":"2025-06-10T08:36:21.024Z","updated_at":"2025-06-10T08:36:38.672Z","avatar_url":"https://github.com/kanreisa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonrpc2-ws\n\nSimple, Fast, Robust Implementation of [JSON-RPC 2.0](https://www.jsonrpc.org/specification) over WebSocket for Node.js w/ TypeScript\n\n[![npm][npm-img]][npm-url]\n[![build][travis-img]][travis-url]\n\n## Installation\n\n```sh\nnpm install jsonrpc2-ws --save\n```\n\n## How to use\n\n### Standalone\n\n```ts\n// TypeScript\nimport { Server as RPCServer } from \"jsonrpc2-ws\";\n\nconst rpc = new RPCServer({\n    wss: {\n        port: 3000\n    }\n});\n\nrpc.on(\"connection\", (socket, req) =\u003e {\n    console.log(`${socket.id} connected!`);\n\n    socket.on(\"close\", () =\u003e {\n        console.log(`${socket.id} disconnected!`);\n    });\n\n    rpc.broadcast(\"count\", { count: rpc.sockets.size });\n\n    // room\n    socket.joinTo(\"general\");\n    rpc.notifyTo(\"general\", \"general.count\", { count: rpc.in(\"general\").size });\n});\n\nrpc.methods.set(\"nick\", (socket, params) =\u003e {\n    // socket#data is Map to store custom data.\n    socket.data.set(\"nick\", params.nick);\n});\n\nrpc.methods.set(\"join\", (socket, params) =\u003e {\n    if (socket.joinTo(params.ch) === true) {\n        rpc.notifyTo(params.ch, `${params.ch}.count`, { count: rpc.in(params.ch).size });\n        return;\n    } else {\n        throw new Error(\"Already joined\");\n    }\n});\n\nrpc.methods.set(\"chat\", (socket, params) =\u003e {\n    if (!params || !params.ch || !params.message) {\n        throw new Error(\"Invalid request\");\n    }\n\n    rpc.notifyTo(params.ch, \"chat\", {\n        time: Date.now(),\n        id: socket.id,\n        nick: socket.data.get(\"nick\") || \"anonymous\",\n        ch: params.ch,\n        message: params.message\n    });\n});\n\n// note: rpc method supports async/await or Promise.\nrpc.methods.set(\"something-async-method\", async (socket, params) =\u003e {\n    const res = await somethingAsyncMethod();\n    return res;\n});\n```\n\n### w/ HTTP server\n\n```ts\n// TypeScript\nimport * as http from \"http\";\nimport { Server as RPCServer } from \"jsonrpc2-ws\";\n\nconst server = http.createServer();\nconst rpc = new RPCServer({ wss: { server } });\n```\n\n### w/ Express\n\n```ts\n// TypeScript\nimport express = require(\"express\");\nimport * as http from \"http\";\nimport { Server as RPCServer } from \"jsonrpc2-ws\";\n\nconst app = express();\nconst server = http.createServer(app);\nconst rpc = new RPCServer({ wss: { server } });\n```\n\n## Compatibility\n\n- [StreamJsonRpc](https://github.com/microsoft/vs-streamjsonrpc) (.NET)\n\n## :heart:\n\nBTC: `1CsARqdT2PDLdWng8r2h5pzmyC6xkVnxKw`\n\n![](https://chart.googleapis.com/chart?chs=150x150\u0026cht=qr\u0026chl=1CsARqdT2PDLdWng8r2h5pzmyC6xkVnxKw)\n\n## License\n\n[MIT](LICENSE)\n\n[npm-img]: https://img.shields.io/npm/v/jsonrpc2-ws.svg\n[npm-url]: https://www.npmjs.com/package/jsonrpc2-ws\n[travis-img]: https://img.shields.io/travis/kanreisa/jsonrpc2-ws.svg\n[travis-url]: https://travis-ci.org/kanreisa/jsonrpc2-ws\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanreisa%2Fjsonrpc2-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanreisa%2Fjsonrpc2-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanreisa%2Fjsonrpc2-ws/lists"}