{"id":18309640,"url":"https://github.com/manga-download/websocket-rpc","last_synced_at":"2025-04-05T17:32:57.669Z","repository":{"id":64931981,"uuid":"579699196","full_name":"manga-download/websocket-rpc","owner":"manga-download","description":"A typesafe RPC implementation for WebSockets","archived":false,"fork":false,"pushed_at":"2025-01-28T18:49:17.000Z","size":119,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T13:03:21.279Z","etag":null,"topics":["rpc","websocket"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/websocket-rpc","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manga-download.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-18T15:34:31.000Z","updated_at":"2025-01-28T18:48:08.000Z","dependencies_parsed_at":"2024-12-04T16:42:20.581Z","dependency_job_id":"07e2cf31-8567-453b-b91d-9cef7eb05514","html_url":"https://github.com/manga-download/websocket-rpc","commit_stats":{"total_commits":33,"total_committers":2,"mean_commits":16.5,"dds":0.1515151515151515,"last_synced_commit":"d355cb44ed5a794ffd838e214c34322d9232f6e3"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manga-download%2Fwebsocket-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manga-download%2Fwebsocket-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manga-download%2Fwebsocket-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manga-download%2Fwebsocket-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manga-download","download_url":"https://codeload.github.com/manga-download/websocket-rpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247375596,"owners_count":20929060,"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":["rpc","websocket"],"created_at":"2024-11-05T16:12:01.393Z","updated_at":"2025-04-05T17:32:52.660Z","avatar_url":"https://github.com/manga-download.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebSocket RPC\n\nA typesafe RPC implementation for WebSockets based on the popular [ws](https://www.npmjs.com/package/ws) package.\n\n## Pre-Conditions\n\n- The WebSocket server must be run in a NodeJS environment\n- The WebSocket client should be run in a Browser environment\n\n## Install\n\n### [ℹ️](https://www.pluralsight.com/resources/blog/guides/install-npm-packages-from-gitgithub) From GitHub\n- [Latest](https://github.com/manga-download/websocket-rpc): `npm install github:manga-download/websocket-rpc`\n- [Specific version](https://github.com/manga-download/websocket-rpc/tags): `npm install github:manga-download/websocket-rpc#v1.2.4`\n\n### From NPM\n- [Latest](https://www.npmjs.com/package/websocket-rpc): `npm install websocket-rpc`\n- [Specific version](https://www.npmjs.com/package/websocket-rpc?activeTab=versions): `npm install websocket-rpc@1.2.4`\n\n## Quick Start\n\n### Contract\n\nThe contract is a class providing all methods on the RPC server that can be invoked remotely with the RPC client.\nAll methods must fulfill the following criterias:\n- Must be async\n- Must be void or return a JSON serializable result\n- Must have zero or more parameters, each must be JSON serializable\n\n_MyContract.ts_\n```typescript\nimport type { RemoteContract } from 'websocket-rpc';\n\nexport class MyContract implements RemoteContract\u003cMyContract\u003e {\n\n    async Divide(a: number, b: number): Promise\u003cnumber\u003e {\n        if(b === 0) {\n            throw new Error('Division by zero!');\n        } else {\n            return a / b;\n        }\n    }\n}\n```\n\n### Server\n\nStart a WebSocket server which exposes the RPC methods from `MyContract`.\n\n_MyServer.ts_\n```typescript\nimport { CreateServer } from 'websocket-rpc/server';\nimport { MyContract } from './MyContract';\n\nconst contract = new MyContract();\nconst wsConnectionInfo = { path: '/rpc', port: 8080 };\n\n// The server is the same as from the 'ws' package, but extended with RPC capabilities\nconst server = await CreateServer(contract, wsConnectionInfo);\n```\n\n### Client\n\nConnect to a WebSocket server and invoke the RPC methods from `MyContract`.\n\n_MyClient.ts_\n```typescript\nimport { CreateClient } from 'websocket-rpc/client';\nimport type { MyContract } from './MyContract';\n\nconst client = await CreateClient\u003cMyContract\u003e('http://localhost:8080/rpc');\n\n// TODO: Ensure the client is properly connected before invoking calls...\nsetTimeout(async () =\u003e {\n    // All defined methods from the contract can now be invoked via the RPC property\n    const result = await client.RPC.Divide(19, 7);\n}, 1000);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanga-download%2Fwebsocket-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanga-download%2Fwebsocket-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanga-download%2Fwebsocket-rpc/lists"}