{"id":21893599,"url":"https://github.com/xhmm/react-native-multipeer-connectivity","last_synced_at":"2025-07-31T21:02:00.510Z","repository":{"id":194273667,"uuid":"689402753","full_name":"XHMM/react-native-multipeer-connectivity","owner":"XHMM","description":"API wrapper of apple multipeer-connectivity for react-native","archived":false,"fork":false,"pushed_at":"2023-09-16T18:32:23.000Z","size":366,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-27T01:40:57.640Z","etag":null,"topics":["ios","multipeer-connectivity","react-native"],"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/XHMM.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}},"created_at":"2023-09-09T17:34:19.000Z","updated_at":"2024-04-01T22:29:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"9dbd77e4-5bc7-4f24-9d44-968675e4fcd0","html_url":"https://github.com/XHMM/react-native-multipeer-connectivity","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"9c33bccc194688daecabaff11c378dd5d2578d25"},"previous_names":["xhmm/react-native-multipeer-connectivity"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XHMM%2Freact-native-multipeer-connectivity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XHMM%2Freact-native-multipeer-connectivity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XHMM%2Freact-native-multipeer-connectivity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XHMM%2Freact-native-multipeer-connectivity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XHMM","download_url":"https://codeload.github.com/XHMM/react-native-multipeer-connectivity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249095209,"owners_count":21211884,"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":["ios","multipeer-connectivity","react-native"],"created_at":"2024-11-28T13:15:20.701Z","updated_at":"2025-04-15T15:22:15.839Z","avatar_url":"https://github.com/XHMM.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-multipeer-connectivity\n\nAPI wrapper of apple multipeer-connectivity for react-native\n\n## Installation\n\n```sh\nnpm install react-native-multipeer-connectivity\nnpx pod-install\n```\n\nThen update your `Info.plist` by adding:\n```text\n\u003ckey\u003eNSLocalNetworkUsageDescription\u003c/key\u003e\n\u003cstring\u003e[a]\u003c/string\u003e\n\u003ckey\u003eNSBonjourServices\u003c/key\u003e\n\u003carray\u003e\n    \u003cstring\u003e_[b]._tcp\u003c/string\u003e\n\u003c/array\u003e\n```\n- `[a]` will be used in the system permission request dialog\n- `[b]` is the service name that will be used in our api\n\n\n## API\n```ts\nimport { initSession } from 'react-native-multipeer-connectivity';\nconst session = initSession(options);\n```\n\n\u003e Copied from the generated .d.ts file:\n\n```ts\ntype RNPeerID = string;\nexport interface RNPeer {\n  id: RNPeerID;\n  displayName: string;\n}\nexport declare enum PeerState {\n  notConnected = 0,\n  connecting = 1,\n  connected = 2\n}\nexport interface InitSessionOptions {\n  /**\n   * This name will be used for showing when other peers browsed you.\n   * The peer’s name must be no longer than 63 bytes in UTF-8 encoding.\n   */\n  displayName: string;\n  /**\n   * This is the name corresponding to the value defined in Info.plist\n   */\n  serviceType: string;\n  /**\n   * Custom data available to browsers in the `onFoundPeer` event\n   *\n   * Limitations:\n   *  - Object keys cannot contain an equals sign.\n   *  - Each key and value must be string, and the key-value pair must be no longer than 255 bytes (total) when encoded in UTF-8 format with an equals sign (=) between the key and the value.\n   *  - The total size of the keys and values should be no more than about 400 bytes.\n   *\n   * Check https://developer.apple.com/documentation/multipeerconnectivity/mcnearbyserviceadvertiser/1407102-init for detailed explanation.\n   */\n  discoveryInfo?: Record\u003cstring, string\u003e;\n}\nexport interface MPCSession {\n  peerID: string;\n  /**\n   * Start browsing nearby peers which are advertizing\n   */\n  browse(): Promise\u003cvoid\u003e;\n  /**\n   * Start advertizing so it can be bound by the peers which are browsing\n   */\n  advertize(): Promise\u003cvoid\u003e;\n  /**\n   * Stop browsing\n   */\n  stopBrowsing(): Promise\u003cvoid\u003e;\n  /**\n   * Stop advetizing\n   */\n  stopAdvertizing(): Promise\u003cvoid\u003e;\n  /**\n   * Invite the peer you found\n   */\n  invite(peerID: string): Promise\u003cvoid\u003e;\n  invite(options: {\n    peerID: string;\n    /**\n     * Invite timeout seconds, default 30s\n     */\n    timeout?: number;\n    /**\n     * Context data sent to `onReceivedPeerInvitation` event\n     */\n    context?: Record\u003cstring, any\u003e;\n  }): Promise\u003cvoid\u003e;\n  /**\n   * Send utf-8 text to target peer\n   * @param id\n   * @param text\n   */\n  sendText(id: RNPeerID, text: string): Promise\u003cvoid\u003e;\n  /**\n   * Disconnect all peers\n   */\n  disconnect(): Promise\u003cvoid\u003e;\n  onStartAdvertisingError(fn: (event: {\n    text: string;\n  }) =\u003e void): EmitterSubscription;\n  /**\n   * When you received a invitation by other peer using `invite`, this event will be called\n   * @param fn\n   */\n  onReceivedPeerInvitation(fn: (event: {\n    peer: RNPeer;\n    context?: Record\u003cstring, any\u003e;\n    /**\n     * You need to call this function to decide to accept(true) or reject(true) the invitation\n     * @param accept\n     */\n    handler: (accept: boolean) =\u003e Promise\u003cvoid\u003e;\n  }) =\u003e void): EmitterSubscription;\n  onStartBrowsingError(fn: (event: {\n    text: string;\n  }) =\u003e void): EmitterSubscription;\n  /**\n   * When you (re-)call `advertize` and found a peer, this event will be called, even if the peer has found before\n   */\n  onFoundPeer(fn: (event: {\n    peer: RNPeer;\n    discoveryInfo?: Record\u003cstring, string\u003e;\n  }) =\u003e void): EmitterSubscription;\n  /**\n   * Called when the peer was disconnected, for example, the app was in background\n   * @param fn\n   */\n  onLostPeer(fn: (event: {\n    peer: RNPeer;\n  }) =\u003e void): EmitterSubscription;\n  /**\n   * Called when the peer state changed\n   * @param fn\n   */\n  onPeerStateChanged(fn: (event: {\n    peer: RNPeer;\n    state: PeerState;\n  }) =\u003e void): EmitterSubscription;\n  /**\n   * Called when you received a utf-8 text\n   * @param fn\n   */\n  onReceivedText(fn: (event: {\n    peer: RNPeer;\n    text: string;\n  }) =\u003e void): EmitterSubscription;\n}\n/**\n * Call this function to initiate a session\n * @param options\n */\nexport declare function initSession(options: InitSessionOptions): MPCSession;\n```\n\n## Example\nCheckout [example](./example) for a runnable demo\n\n## Others\nThis [repo](https://github.com/lwansbrough/react-native-multipeer) did the same thing, but it abandoned and seems not work well with latest react-native versions, so I created this repo.\n\n\n## License\n\nMIT\n\n---\n\nMade with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxhmm%2Freact-native-multipeer-connectivity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxhmm%2Freact-native-multipeer-connectivity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxhmm%2Freact-native-multipeer-connectivity/lists"}