{"id":20068685,"url":"https://github.com/radarsu/rpc-websocket-client","last_synced_at":"2025-05-05T19:31:28.559Z","repository":{"id":39802136,"uuid":"156018261","full_name":"radarsu/rpc-websocket-client","owner":"radarsu","description":"Fast and simple JSON-RPC 2.0 WebSocket Client implementation in TypeScript. Allows bi-directional communication with async await Promises 🐼","archived":false,"fork":false,"pushed_at":"2023-02-28T04:12:26.000Z","size":2286,"stargazers_count":38,"open_issues_count":9,"forks_count":9,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-09T03:05:10.842Z","etag":null,"topics":["bidirectional","communication","fast","fast-json-stringify","javascript","javascript-library","jsonrpc2","lightweight","notifications","requests","rpc","rpc-client","rpc-websockets","typescript","typescript-library","uuid","websocket","websocket-client"],"latest_commit_sha":null,"homepage":"https://radarsu.radrat.pl/rpc-websocket-client/","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/radarsu.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-11-03T19:49:03.000Z","updated_at":"2024-11-05T10:19:35.000Z","dependencies_parsed_at":"2023-01-31T20:01:27.089Z","dependency_job_id":null,"html_url":"https://github.com/radarsu/rpc-websocket-client","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/radarsu%2Frpc-websocket-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radarsu%2Frpc-websocket-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radarsu%2Frpc-websocket-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radarsu%2Frpc-websocket-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radarsu","download_url":"https://codeload.github.com/radarsu/rpc-websocket-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252562830,"owners_count":21768350,"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":["bidirectional","communication","fast","fast-json-stringify","javascript","javascript-library","jsonrpc2","lightweight","notifications","requests","rpc","rpc-client","rpc-websockets","typescript","typescript-library","uuid","websocket","websocket-client"],"created_at":"2024-11-13T14:08:08.045Z","updated_at":"2025-05-05T19:31:23.551Z","avatar_url":"https://github.com/radarsu.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\r\n    \u003ca href=\"https://github.com/radarsu/rpc-websocket-client/\" target=\"blank\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/radarsu/rpc-websocket-client/master/assets/logo.png\" alt=\"rpc-websocket-client\" /\u003e\u003c/a\u003e\u003cbr/\u003e\r\n    \u003cstrong\u003eFast JSON RPC 2.0 written in TypeScript.\u003c/strong\u003e\r\n\u003c/p\u003e\r\n\r\n\u003cp align=\"center\"\u003e\r\n\u003ca href=\"https://github.com/Microsoft/TypeScript\" target=\"blank\"\u003eTypeScript\u003c/a\u003e \u003ca href=\"https://www.jsonrpc.org/specification\" target=\"_blank\" alt=\"JSON RPC 2.0\"\u003eJSON RPC 2.0\u003c/a\u003e WebSocket implementation with async-await Promises.\u003cbr/\u003e\r\n\u003c/p\u003e\r\n\r\n\u003cp align=\"center\"\u003e\r\n\t\u003ca href=\"https://www.npmjs.com/package/rpc-websocket-client\" target=\"_blank\" alt=\"npm rpc-websocket-client\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/rpc-websocket-client.svg\" alt=\"npm\" /\u003e\u003c/a\u003e\r\n\t\u003cimg src=\"https://img.shields.io/github/license/radarsu/rpc-websocket-client.svg\" /\u003e\r\n\t\u003cimg src=\"https://img.shields.io/github/stars/radarsu/rpc-websocket-client.svg\" /\u003e\r\n\t\u003ca href=\"https://twitter.com/radarsujs\"\u003e\u003cimg src=\"https://img.shields.io/twitter/url/https/github.com/radarsu/rpc-websocket-client.svg?style=social\" /\u003e\u003c/a\u003e\r\n\u003c/p\u003e\r\n\r\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/radarsu)\r\n## Description\r\n\r\nI really lacked typescript support or type definitions of \u003ca href=\"https://github.com/elpheria/rpc-websockets\" target=\"_blank\" alt=\"rpc-websockets\"\u003erpc-websockets\u003c/a\u003e. I kept everything as simple as possible for \u003cstrong\u003ebest performance\u003c/strong\u003e and in principle \u003cstrong\u003estay close to the metal\u003c/strong\u003e. Under the hood id-generation for requests is done using \u003ca href=\"https://github.com/kelektiv/node-uuid\" target=\"_blank\" alt=\"uuid\"\u003euuid/v1\u003c/a\u003e to provide id uniqueness as an additional feature.\r\n\r\n## Installation\r\n\r\n```sh\r\nnpm i rpc-websocket-client\r\n```\r\n\r\n## Features\r\n\r\n- \u003cstrong\u003eTypeScript\u003c/strong\u003e with documentation in comments.\r\n- \u003cstrong\u003eUnique RPC identifiers\u003c/strong\u003e by \u003ca href=\"https://github.com/kelektiv/node-uuid\" target=\"_blank\" alt=\"uuid\"\u003euuid/v1\u003c/a\u003e.\r\n- \u003cstrong\u003eLightweight\u003c/strong\u003e. Allows you to call `noRpc()` method to prevent sending `jsonrpc: '2.0'` overhead from all messages if you'd like to ignore the \u003ca href=\"https://www.jsonrpc.org/specification\" target=\"_blank\" alt=\"JSON RPC 2.0\"\u003eJSON RPC 2.0\u003c/a\u003e standard for better performance.\r\n- Option to \u003cstrong\u003econnect RpcWebSocketClient with already existing WebSocket\u003c/strong\u003e with `changeSocket()` and `listenMessages()` methods. Useful if you use \u003cstrong\u003eREST\u003c/strong\u003e or \u003cstrong\u003eGraphQL implementation\u003c/strong\u003e from another library and want to handle \u003ca href=\"https://www.jsonrpc.org/specification\" target=\"_blank\" alt=\"JSON RPC 2.0\"\u003eJSON RPC 2.0\u003c/a\u003e when communicating from server to client (that was my use case to develop this package).\r\n\r\n## Basic Usage\r\n```ts\r\nimport { RpcWebSocketClient } from 'rpc-websocket-client';\r\n\r\n(async () =\u003e {\r\n\r\n    const rpc = new RpcWebSocketClient();\r\n    await rpc.connect(`ws://localhost:4000/`);\r\n    // Connection is established now.\r\n\r\n    // Let's hope there will be no error or it will be catched in some wrapper.\r\n    await rpc.call(`auth.login`, [`rpcMaster`, `mySecretPassword`]);\r\n\r\n    // Now lets be pesimistic.\r\n    const res = await rpc.call(`auth.login`, [`rpcMaster`, `mySecretPassword`]).then(() =\u003e {\r\n        // Woohoo, user logged!\r\n    }).catch((err) =\u003e {\r\n\r\n        // Err is typeof RpcError (code: number, message: string, data?: any).\r\n        await rpc.call(`auth.signup`, {\r\n            login: `rpcMaster`,\r\n            password: `mySecretPassword`,\r\n        });\r\n\r\n        return false;\r\n    });\r\n\r\n    // If catch wrapper returned false, let's not continue.\r\n    if (res === false) {\r\n        return;\r\n    }\r\n\r\n    rpc.notify(`btw.iHateYou`, [`over and out`]);\r\n\r\n    // Close the connection by using native ws.close().\r\n    rpc.ws.close();\r\n\r\n})();\r\n```\r\n\r\n## Advanced Usage\r\n```ts\r\nimport { RpcWebSocketClient } from 'rpc-websocket-client';\r\n\r\n(async () =\u003e {\r\n    // lets say you use WebSocket implementation for GraphQL Client -\u003e Server communication\r\n    // e.g. Apollo, and it's already connected\r\n    // but you want to handle some of the Server -\u003e Client communication with RPC\r\n\r\n    const ws = (apollo as any).client.wsImpl;\r\n    const rpc = new RpcWebSocketClient();\r\n\r\n    rpc.onRequest.push((data) =\u003e {       // data is typeof RpcRequest\r\n        // controller-like stuff\r\n    });\r\n\r\n    rpc.onNotification.push((data) =\u003e {  // data is typeof RpcNotification\r\n        // notification handling\r\n    });\r\n\r\n    // here goes magic for listening to already-connected socket\r\n    rpc.changeSocket(ws);\r\n    rpc.listenMessages();\r\n})();\r\n```\r\n","funding_links":["https://www.buymeacoffee.com/radarsu"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradarsu%2Frpc-websocket-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradarsu%2Frpc-websocket-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradarsu%2Frpc-websocket-client/lists"}