{"id":20942185,"url":"https://github.com/getstation/stream-json-rpc","last_synced_at":"2025-05-13T23:32:35.078Z","repository":{"id":34158616,"uuid":"157220842","full_name":"getstation/stream-json-rpc","owner":"getstation","description":"Easy bi-directionnal RPC for node/electron/browser, using the transport that you need.","archived":false,"fork":false,"pushed_at":"2023-10-05T18:06:31.000Z","size":773,"stargazers_count":2,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-02T16:55:25.136Z","etag":null,"topics":[],"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/getstation.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-12T13:51:27.000Z","updated_at":"2022-05-19T14:35:40.000Z","dependencies_parsed_at":"2024-06-21T16:42:57.634Z","dependency_job_id":null,"html_url":"https://github.com/getstation/stream-json-rpc","commit_stats":{"total_commits":136,"total_committers":3,"mean_commits":"45.333333333333336","dds":"0.19852941176470584","last_synced_commit":"3a910cb64c24a19841f2fac987aa57109e8eeb78"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getstation%2Fstream-json-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getstation%2Fstream-json-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getstation%2Fstream-json-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getstation%2Fstream-json-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getstation","download_url":"https://codeload.github.com/getstation/stream-json-rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253960308,"owners_count":21990842,"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":[],"created_at":"2024-11-18T23:24:18.740Z","updated_at":"2025-05-13T23:32:30.056Z","avatar_url":"https://github.com/getstation.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stream-json-rpc\nEasy bi-directionnal RPC for node/electron/browser, using the transport that you need.\n\n## Usage\nAs the transport layer must implement the `stream.Duplex` interface, some helpers are already\navailable for [electron ipcMain/ipcRenderer](packages/stream-electron-ipc) and\n[node-ipc](packages/stream-node-ipc).\n\n### Example\n##### Process 1\n```typescript\nimport rpcchannel from 'stream-json-rpc';\nimport { getServer, NodeIpcServerDuplex, firstConnectionHandler } from 'stream-node-ipc';\n\n// This process acts as a node-ipc server\n// But it actually being a \"server\" is not really relevant,\n// as any process can call any other process if they can directly communicate.\n\nconst ipcServer = getServer('my-namespace'); // Instance of NodeIPC.Server\n\n// Whenever a new client is connected, the callback will be called with\n// the Duplex stream already created\nfirstConnectionHandler(ipcServer, (duplex: NodeIpcServerDuplex) =\u003e {\n  const channel = rpcchannel(duplex, {\n    // defaultRequestTimeout?: number, // defaults: 2000 (ms)\n    // forwardErrors?: boolean, // defaults: false (if true, errors during requests are fully forwarded to requester)\n  });\n  // Get a named connection\n  // On the other side, the same call must be done, with the same id, to finish the handshake\n  const peer = channel.peer('connection-id');\n  \n  // Register handlers\n  peer.setRequestHandler('inc', ({ value }: any) =\u003e {\n    return value + 1;\n  });\n});\n```\n\n##### Process 2\n```typescript\nimport rpcchannel from 'stream-json-rpc';\nimport { getClient, NodeIpcClientDuplex } from 'stream-node-ipc';\n\n// This process acts as node-ipc client\n\n// Instance of NodeIPC.Client, connected to the server\nconst ipcClient = getClient('my-namespace');\nconst channel = rpcchannel(new NodeIpcClientDuplex(ipcClient));\n// Get a named connection\n// On the other side, the same call must be done, with the same id, to finish the handshake\nconst peer = channel.peer('connection-id');\n\n// Call remote method on process 1\npeer\n  .request('inc', {\n    value: 1,\n  })\n  .then((result) =\u003e {\n    console.log('Result should be 2:', result);\n  });\n\n// You could also create any handler here with `addRequestHandler`\n// or `addNotificationHandler`, and process1 would be able to call them.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetstation%2Fstream-json-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetstation%2Fstream-json-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetstation%2Fstream-json-rpc/lists"}