{"id":15497174,"url":"https://github.com/jwerle/browser-rpc-swarm","last_synced_at":"2025-04-22T21:42:57.568Z","repository":{"id":143865883,"uuid":"182120969","full_name":"jwerle/browser-rpc-swarm","owner":"jwerle","description":"Give control of your browser over RPC to another in a discovery swarm","archived":false,"fork":false,"pushed_at":"2019-05-04T14:20:12.000Z","size":18,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-16T03:07:23.547Z","etag":null,"topics":["browser","rpc","swarm","webrtc"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/jwerle.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":"2019-04-18T16:22:36.000Z","updated_at":"2023-02-06T07:30:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"c132c7f6-f06b-4e35-b3ca-9ec44d773352","html_url":"https://github.com/jwerle/browser-rpc-swarm","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.0714285714285714,"last_synced_commit":"f6afef4cd7005e7e425cb668a9770811467b7be5"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fbrowser-rpc-swarm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fbrowser-rpc-swarm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fbrowser-rpc-swarm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fbrowser-rpc-swarm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/browser-rpc-swarm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250330284,"owners_count":21412956,"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":["browser","rpc","swarm","webrtc"],"created_at":"2024-10-02T08:31:25.746Z","updated_at":"2025-04-22T21:42:57.539Z","avatar_url":"https://github.com/jwerle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"browser-rpc-swarm\n=================\n\nGive control of your browser over RPC to another in a discovery swarm.\nThis module uses\n[rpc-protocol](https://github.com/secure-local-node/rpc-protocol) and\n[webrtc-swarm](https://github.com/mafintosh/webrtc-swarm) to discovery\npeers and initiate a RPC channel.\n\n## Installation\n\n```sh\n$ npm install browser-rpc-swarm\n```\n\n## Usage\n\n```js\nconst signalhub = require('signalhub')\nconst swarm = require('./')\nconst key = '626d55ffe6eafc13e32309ca4985b83cf15c0c015e6ba8f32dcebed2a50e0c27'\nconst hub = signalhub(key, [ 'yourdomain.com' ])\nconst rpc = swarm(hub)\n\nrpc.command({\n  async echo(value) {\n    return value\n  }\n})\n\nrpc.on('peer', (peer) =\u003e {\n  console.log(await peer.echo('hello world')) // 'hello world'\n})\n```\n\n## API\n\n### `rpc = require('browser-rpc-swarm')(signalhub, opts)`\n\nwhere `signalhub` is a\n[signalhub](https://github.com/mafintosh/signalhub) instance and `opts`\nis passed directly to\n[webrtc-swarm](https://github.com/mafintosh/webrtc-swarm).\n\n#### `rpc.command(name, callback)`\n\nCreate a named command with a callback function to resolve a response to\nthe caller.\n\n```js\n// A simple 'echo' command that simply returns the value given to it\nrpc.command('echo', (value) =\u003e value\n```\n\n#### `rpc.command(manifest)`\n\nCreate several commands described by an object with functions that are\ncallbacks to resolve a response to the caller.\n\n```js\nrpc.command({\n  echo(value) {\n    return value\n  }\n})\n```\n\n#### `rpc.destroy()`\n\nAn alias to to `rpc.close()`\n\n#### `rpc.close(callback)`\n\nClose the RPC channel and all of its resources.\n\n#### `rpc.on('peer', peer)`\n\nEmitted when a peer connection has been established and a command\nmanifest has been exchanged. Commands are attached directly to the\ninstance and can be called like normal functions. They return promises\nthat resolve when the peer replying to command issues a response.\n\nConsider a command called `echo()` that a peer defines in their\nmanifest. The command simply returns the input argument given to it.\n\n```js\nrpc.command({\n  echo(value) {\n    return value\n  }\n})\n```\n\nThe caller for this command can call this command after peer discovery\nlike a normal function.\n\n```js\nrpc.on('peer', async (peer) =\u003e {\n  console.log(await rpc.echo('hello world')) // 'hello world'\n})\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fbrowser-rpc-swarm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fbrowser-rpc-swarm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fbrowser-rpc-swarm/lists"}