{"id":4718,"url":"https://github.com/lwansbrough/react-native-multipeer","last_synced_at":"2025-04-10T01:07:31.954Z","repository":{"id":33449640,"uuid":"37095033","full_name":"lwansbrough/react-native-multipeer","owner":"lwansbrough","description":"Communicate over ad hoc wifi using Multipeer Connectivity","archived":false,"fork":false,"pushed_at":"2017-04-02T11:54:34.000Z","size":12,"stargazers_count":226,"open_issues_count":7,"forks_count":31,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-10T01:07:25.944Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","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/lwansbrough.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}},"created_at":"2015-06-08T21:53:56.000Z","updated_at":"2025-03-28T13:20:50.000Z","dependencies_parsed_at":"2022-09-08T12:11:39.681Z","dependency_job_id":null,"html_url":"https://github.com/lwansbrough/react-native-multipeer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwansbrough%2Freact-native-multipeer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwansbrough%2Freact-native-multipeer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwansbrough%2Freact-native-multipeer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwansbrough%2Freact-native-multipeer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lwansbrough","download_url":"https://codeload.github.com/lwansbrough/react-native-multipeer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137888,"owners_count":21053775,"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-01-05T20:17:21.212Z","updated_at":"2025-04-10T01:07:31.926Z","avatar_url":"https://github.com/lwansbrough.png","language":"Objective-C","readme":"# react-native-multipeer\n\nCommunicate over ad hoc wifi using Multipeer Connectivity.\n\n## Known Issues\nBelow is a list of known issues. Pull requests are welcome for any of these issues!\n\n- No support for streams in React Native, so streaming is currently unavailable.\n- No support for resource transfers: I want this to work seamlessly with other file resources for other uses, so I'm waiting for those specs to be finalized.\n\n## Getting started\n\n1. `npm install react-native-multipeer@latest --save`\n2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`\n3. Go to `node_modules` ➜ `react-native-multipeer` and add `RCTMultipeerConnectivity.xcodeproj`\n4. In XCode, in the project navigator, select your project. Add `libRCTMultipeerConnectivity.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`\n5. Click `RCTMultipeerConnectivity.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React` - mark both as `recursive`.\n5. Run your project (`Cmd+R`)\n\n## Usage\n\nAll you need is to `require` the `react-native-multipeer` module and then you can start using the singleton instance.\n\n```javascript\nvar React = require('react-native');\nvar {\n  AppRegistry,\n  ListView,\n  StyleSheet,\n  Text,\n  View,\n  TouchableHighlight\n} = React;\nvar MultipeerConnectivity = require('react-native-multipeer');\n\nfunction getStateFromSources() {\n  var ds = new ListView.DataSource({rowHasChanged: (r1, r2) =\u003e r1 !== r2});\n    return {\n      dataSource: ds.cloneWithRows(MultipeerConnectivity.getAllPeers())\n    };\n}\n\nvar peerApp = React.createClass({\n  getInitialState: function() {\n    return getStateFromSources()\n  },\n  componentDidMount() {\n    MultipeerConnectivity.on('peerFound', this._onChange);\n    MultipeerConnectivity.on('peerLost', this._onChange);\n    MultipeerConnectivity.on('invite', ((event) =\u003e {\n      // Automatically accept invitations\n      MultipeerConnectivity.rsvp(event.invite.id, true);\n    }).bind(this));\n    MultipeerConnectivity.on('peerConnected', (event) =\u003e {\n      alert(event.peer.id + ' connected!');\n    });\n    MultipeerConnectivity.advertise('channel1', { name: 'User-' + Math.round(1e6 * Math.random()) });\n    MultipeerConnectivity.browse('channel1');\n  },\n\n  renderRow(peer) {\n    return (\n      \u003cTouchableHighlight onPress={this.invite.bind(this, peer)} style={styles.row}\u003e\n        \u003cView\u003e\n          \u003cText\u003e{peer.name}\u003c/Text\u003e\n        \u003c/View\u003e\n      \u003c/TouchableHighlight\u003e\n    );\n  },\n  \n  render: function() {\n    return (\n      \u003cView style={styles.container}\u003e\n        \u003cListView\n          style={styles.peers}\n          dataSource={this.state.dataSource}\n          renderRow={this.renderRow}\n        /\u003e\n      \u003c/View\u003e\n    );\n  },\n  \n  _invite(peer) {\n    MultipeerConnectivity.invite(peer.id);\n  },\n  \n  _onChange() {\n    this.setState(getStateFromSources());\n  }\n});\n\n\nvar styles = StyleSheet.create({\n  container: {\n    flex: 1,\n    justifyContent: 'center',\n    alignItems: 'center',\n    backgroundColor: 'transparent',\n  },\n  welcome: {\n    fontSize: 20,\n    textAlign: 'center',\n    margin: 10,\n  },\n  instructions: {\n    textAlign: 'center',\n    color: '#333333',\n  },\n});\n\nAppRegistry.registerComponent('peerApp', () =\u003e peerApp);\n```\n\n## `MultipeerConnectivity` methods\n\n### Channels\n\n#### `advertise(channelId, info)`\n\nAllow discovery of yourself as a peer in a given channel. `channelId` can be any string. `info` is an object containing data which will be passed to other peers when you join the channel.\n\n#### `browse(channelId)`\n\nBrowse for peers on a given channel.\n\n#### `getAllPeers()`\n\nGets all the peers in the current channel.\n\n\n### Sessions\n\n#### `getConnectedPeers()`\n\nGets all the peers in the current session.\n\n\n#### `disconnect([callback])`\n\nDisconnect from the current session.\n\n\n#### `invite(peerId [, callback])`\n\nInvite a peer from your channel into your session.\n\n\n#### `rsvp(inviteId, accept [, callback])`\n\nAccept/decline a session invitation.\n\n\n### Communication\n\n#### `broadcast(data [, callback\u003cerr\u003e])`\n\nSend data to all connected peers in the current channel.\n\n\n#### `send(data, recipients [, callback\u003cerr\u003e])`\n\nSend data to specific peers in the current channel. `recipients` is an array of peer IDs or `Peer`s.\n\n### `MultipeerConnectivity` Events\n\n`MultipeerConnectivity` inherits from `EventEmitter` - as such the `.on` method is available for listening to important events. Below is a list of those events.\n\n#### `data`\n\nEvent properties: `Peer sender`, `data`\n\nFired when new data is received from `sender`.\n\n#### `peerFound`\n\nEvent properties: `peer`\n\nA new peer was found in the current channel.\n\n\n#### `peerLost`\n\nEvent properties: `peer`\n\nA peer left the current channel.\n\n#### `peerConnected`\n\nEvent properties: `peer`\n\nA peer has connected to your session.\n\n#### `peerConnecting`\n\nEvent properties: `peer`\n\nA peer is connecting to your session.\n\n#### `peerDisconnected`\n\nEvent properties: `peer`\n\nA peer disconnected from your session.\n\n#### `invite`\n\nEvent properties: `sender`, `invite`\n\nYou have been invited to a session.\n\n\n## `Peer` methods\n\n### Events\n\n#### `connected`\n\nThe peer connected to the current session.\n\n\n#### `connecting`\n\nThe peer is connecting to the current session.\n\n\n#### `disconnected`\n\nThe peer disconnected from the current session.\n\n#### `lost`\n\nThe peer left the current channel.\n\n\n## Todo\nThese are some features I think would be important/beneficial to have included with this module. Pull requests welcome!\n\n- [ ] Stream support\n- [ ] Resource transfers\n","funding_links":[],"categories":["Components"],"sub_categories":["Backend"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwansbrough%2Freact-native-multipeer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flwansbrough%2Freact-native-multipeer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwansbrough%2Freact-native-multipeer/lists"}