{"id":28330170,"url":"https://github.com/boardgameio/p2p","last_synced_at":"2026-02-25T20:03:41.118Z","repository":{"id":37033026,"uuid":"413164228","full_name":"boardgameio/p2p","owner":"boardgameio","description":"Experimental peer-to-peer multiplayer transport for boardgame.io","archived":false,"fork":false,"pushed_at":"2023-11-03T07:19:25.000Z","size":1350,"stargazers_count":23,"open_issues_count":13,"forks_count":9,"subscribers_count":2,"default_branch":"latest","last_synced_at":"2025-12-06T05:51:01.878Z","etag":null,"topics":["boardgame-io","multiplayer","p2p","peerjs"],"latest_commit_sha":null,"homepage":"https://codesandbox.io/s/boardgame-io-p2p-demo-0loyd?file=/src/App.tsx","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/boardgameio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["boardgameio"],"open_collective":"boardgameio"}},"created_at":"2021-10-03T18:33:46.000Z","updated_at":"2025-05-24T09:36:50.000Z","dependencies_parsed_at":"2022-07-04T09:03:42.754Z","dependency_job_id":"dd188ab2-0a35-4480-a338-46a9c320b48e","html_url":"https://github.com/boardgameio/p2p","commit_stats":{"total_commits":303,"total_committers":4,"mean_commits":75.75,"dds":0.1914191419141914,"last_synced_commit":"665a1e786d36f84e46a0fcaf9451d5b0a6ca48dc"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/boardgameio/p2p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boardgameio%2Fp2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boardgameio%2Fp2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boardgameio%2Fp2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boardgameio%2Fp2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boardgameio","download_url":"https://codeload.github.com/boardgameio/p2p/tar.gz/refs/heads/latest","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boardgameio%2Fp2p/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29837464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T19:08:47.527Z","status":"ssl_error","status_checked_at":"2026-02-25T18:59:04.705Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["boardgame-io","multiplayer","p2p","peerjs"],"created_at":"2025-05-26T14:40:45.046Z","updated_at":"2026-02-25T20:03:41.083Z","avatar_url":"https://github.com/boardgameio.png","language":"TypeScript","funding_links":["https://github.com/sponsors/boardgameio","https://opencollective.com/boardgameio","https://opencollective.com/peer"],"categories":[],"sub_categories":[],"readme":"# @boardgame.io/p2p\n\n[![npm version](https://badge.fury.io/js/@boardgame.io%2Fp2p.svg)](https://www.npmjs.com/package/@boardgame.io/p2p)\n[![Unit Tests](https://github.com/boardgameio/p2p/actions/workflows/unit.yml/badge.svg)](https://github.com/boardgameio/p2p/actions/workflows/unit.yml)\n[![Coverage Status](https://coveralls.io/repos/github/boardgameio/p2p/badge.svg?branch=latest)](https://coveralls.io/github/boardgameio/p2p?branch=latest)\n[![Gitter](https://badges.gitter.im/boardgame-io.svg)](https://gitter.im/boardgame-io)\n\n\u003e Experimental peer-to-peer multiplayer transport for [boardgame.io][bgio]\n\nThis package provides an experimental multiplayer transport implementation, which establishes a peer-to-peer connection between clients. Instead of using a Node.js server to maintain authoritative match state and communicate between clients, a host client maintains the authoritative state in their browser and manages connections between all the connected peers.\n\n## Installation\n\n```sh\nnpm install @boardgame.io/p2p\n```\n\n## Usage\n\n```js\nimport { Client } from 'boardgame.io/client';\nimport { P2P } from '@boardgame.io/p2p';\nimport { MyGame } from './game';\n\nconst matchID = 'random-id-string';\n\n// Host clients maintain the authoritative game state and manage\n// communication between all other peers.\nconst hostClient = Client({\n  game: MyGame,\n  matchID,\n  playerID: '0',\n  multiplayer: P2P({ isHost: true }),\n});\n\n// Peer clients look up a host using the `matchID` and communicate\n// with the host much like they would with a server.\nconst peerClient = Client({\n  game: MyGame,\n  matchID,\n  playerID: '1',\n  multiplayer: P2P(),\n});\n```\n\n## API\n\n### `P2P(options?)`\n\nYou can configure the peer-to-peer transport by passing an optional object. It can contain the following fields.\n\n- #### `isHost`\n\n  - **type:** `boolean`\n  - **default:** `false`\n\n  Controls whether or not this instance is a host and controls the authoritative game state. Only one client should have `isHost: true`.\n\n- #### `onError`\n\n  - **type:** `(error: Error) =\u003e void`\n  - **default:** `undefined`\n\n  Callback to subscribe to [PeerJS’s `'error'` event][pje].\n\n- #### `peerOptions`\n\n  - **type:** [`PeerJSOption`][pjo]\n  - **default:** `undefined`\n\n  Passed to PeerJS when creating a new `Peer` connection. [See PeerJS docs for full list of options →][pjo]\n\n## Authenticating players\n\nBy default, any client can connect with any `playerID` and successfully submit moves as that player. If you want to avoid this, you must set `credentials` on your boardgame.io clients. The first client to connect with a given `playerID` will authenticate and all future connections for that `playerID` must also provide the same `credentials` to successfully connect.\n\nThe transport uses [public-key encryption][pk], deterministically generating keys from the value of `credentials`. For optimal security, use the included helper method to generate credentials:\n\n```js\nimport { Client } from 'boardgame.io/client';\nimport { P2P, generateCredentials } from '@boardgame.io/p2p';\n\nconst credentials = generateCredentials();\n\nconst peerClient = Client({\n  multiplayer: P2P(),\n  credentials,\n  // ...\n});\n```\n\n## Notes\n\n### What does experimental mean?\n\nThis package currently works but is liable to change as what is required for peer-to-peer scenarios is better understood. Please try it out and send us feedback, bug reports and feature requests, but be aware that it may change in breaking ways until a more stable API is established.\n\n### Why would I want to use this?\n\nDeploying a Node server to enable multiplayer play can be a serious logistical hurdle and is often more expensive than serving a static website. This transport enables multiplayer play without a game server. If you’re looking for a casual way to play with friends that can be pretty attractive.\n\n### What are the drawbacks?\n\nNo lobby or matchmaking. You have to have a `matchID` to find and connect to the other players. One pattern might be for a host to generate a random `matchID` on your site. Then they could share the `matchID` with friends via their preferred instant messaging service for example.\n\nAdditionally, currently if the host goes offline, the match will stop and potentially all match state will be lost. In the future it may be possible to decentralise this and allow other players to step in as hosts in this case.\n\n### How does this work?\n\nUnder the hood this transport uses [PeerJS][pjs], a library that helps simplify creating peer-to-peer connections. When a host starts running, it registers with a so-called “handshake” server using a `matchID` to identify itself. Then when other clients connect, they can use the same `matchID` to request a connection to the host from the handshake server. Once that peer-to-peer connection is established between clients, all future communication will take place directly between clients and no longer pass via a server.\n\nUnless configured otherwise, this transport will use [PeerJS’s default handshake server][psrvr] to negotiate the initial connection between peers. Consider running your own handshake server or [donating to PeerJS][poc] to help support theirs.\n\n## Contributing\n\nBug reports, suggestions, and pull requests are very welcome! If you run into any problems or have questions, please [open an issue][newissue].\n\nPlease also note [the code of conduct][coc] and be kind to each other.\n\n## License\n\nThe code in this repository is provided under [the MIT License](LICENSE).\n\n[bgio]: https://boardgame.io/\n[pjs]: https://github.com/peers/peerjs\n[psrvr]: https://peerjs.com/peerserver.html\n[poc]: https://opencollective.com/peer\n[pje]: https://peerjs.com/docs.html#peeron-error\n[pjo]: https://peerjs.com/docs.html#peer-options\n[pk]: https://en.wikipedia.org/wiki/Public-key_cryptography\n[newissue]: https://github.com/boardgameio/p2p/issues/new/choose\n[coc]: CODE_OF_CONDUCT.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboardgameio%2Fp2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboardgameio%2Fp2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboardgameio%2Fp2p/lists"}