{"id":17272778,"url":"https://github.com/kirillzyusko/react-native-wifi-p2p","last_synced_at":"2025-12-26T12:01:42.326Z","repository":{"id":49836379,"uuid":"131610762","full_name":"kirillzyusko/react-native-wifi-p2p","owner":"kirillzyusko","description":"Library that provide access for working with wi-fi direct (p2p) module in android.","archived":false,"fork":false,"pushed_at":"2023-08-21T07:44:26.000Z","size":470,"stargazers_count":192,"open_issues_count":26,"forks_count":33,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-26T11:44:00.916Z","etag":null,"topics":["p2p","react-native","wifi","wifi-direct","wifi-p2p-manager"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kirillzyusko.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"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},"funding":{"github":"kirillzyusko"}},"created_at":"2018-04-30T15:09:24.000Z","updated_at":"2025-10-06T16:03:54.000Z","dependencies_parsed_at":"2024-06-18T23:07:48.830Z","dependency_job_id":null,"html_url":"https://github.com/kirillzyusko/react-native-wifi-p2p","commit_stats":null,"previous_names":["kirikzyusko1996/react-native-wifi-p2p"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/kirillzyusko/react-native-wifi-p2p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillzyusko%2Freact-native-wifi-p2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillzyusko%2Freact-native-wifi-p2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillzyusko%2Freact-native-wifi-p2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillzyusko%2Freact-native-wifi-p2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kirillzyusko","download_url":"https://codeload.github.com/kirillzyusko/react-native-wifi-p2p/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirillzyusko%2Freact-native-wifi-p2p/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28054228,"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","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["p2p","react-native","wifi","wifi-direct","wifi-p2p-manager"],"created_at":"2024-10-15T08:49:28.346Z","updated_at":"2025-12-26T12:01:42.303Z","avatar_url":"https://github.com/kirillzyusko.png","language":"Java","funding_links":["https://github.com/sponsors/kirillzyusko"],"categories":[],"sub_categories":[],"readme":"# react-native-wifi-p2p\n\n`react-native-wifi-p2p` is a library to provide WiFi Direct (Peer-To-Peer, P2P) service to react-native.\n\n**_Important_**: currently only **Android** support realized.\nIf you want to provide iOS support, then you should to note to [react-native-multipeer](https://github.com/lwansbrough/react-native-multipeer) repository.\n\n**This library will not work on emulator. If you want to use this library, you should test working it on real devices.**\n\nTest project with all API cases you can find [here](https://github.com/kirillzyusko/react-native-wifi-p2p-example).\n\n## React Native Compatibility\n\nTo use this library you need to ensure you match up with the correct version of React Native you are using.\n\np.s. React Native introduced AndroidX support in 0.60, which is a **breaking change** for most libraries (incl. this one) using native Android functionality.\n\n| `react-native-wifi-p2p` version | Required React Native Version                                                              |\n| ----------------------------------------- | --------------------------------------------------------------------------------- |\n| `1.x.x`                                   | `\u003e= 0.60`                                                                         |\n| `0.x.x`                                   | `\u003c= 0.59`                                                                         |\n\n# Contents\n\n* [Installation](#installation)\n  * [npm install](#install-library-from-npm)\n  * [grand permissions](#allow-grant-permission-to-wifi-module)\n  * [link library](#link-library)\n* [Overview API](#overview)\n  * [API methods](#api)\n  * [Consts usage](#constants)\n  * [Caveats](#caveats)\n* [Example of usage](#example-of-usage)\n\n## Installation\n\n### Install library from `npm`\n\n```sh\nnpm install react-native-wifi-p2p --save\n# or with yarn\n# yarn add react-native-wifi-p2p\n```\n\n### Allow grant permission to WiFi module\n\n```diff\n\u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"io.wifi.p2p\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\"\u003e\n\n    \u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.SYSTEM_ALERT_WINDOW\"/\u003e\n+   \u003cuses-permission\n+               android:required=\"true\"\n+               android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/\u003e\n+   \u003cuses-permission\n+           android:required=\"true\"\n+           android:name=\"android.permission.ACCESS_WIFI_STATE\"/\u003e\n+   \u003cuses-permission\n+           android:required=\"true\"\n+           android:name=\"android.permission.CHANGE_WIFI_STATE\"/\u003e\n+   \u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" /\u003e\n+   \u003cuses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/\u003e\n+   \u003c!-- If your app targets Android 13 (API level 33) or higher, you must declare the NEARBY_WIFI_DEVICES permission. --\u003e\n+   \u003cuses-permission android:name=\"android.permission.NEARBY_WIFI_DEVICES\"\n+   \u003c!-- If your app derives location information from Wi-Fi APIs, don't include the \"usesPermissionFlags\" attribute. --\u003e\n+        android:usesPermissionFlags=\"neverForLocation\" /\u003e\n    ...\n```\n\n### Link library\n\n\u003e **Note**: You should skip it if you use react-native \u003e0.60\n\n* Append the following lines to `android/settings.gradle`\n\n```gradle\ninclude ':react-native-wifi-p2p'\nproject(':react-native-wifi-p2p').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wifi-p2p/android')\n```\n\n* Insert the following lines inside the dependencies block in `android/app/build.gradle`:\n\n```gradle\ncompile project(':react-native-wifi-p2p')\n```\n\n* Open up `android/app/src/main/java/[...]/MainApplication.java`\n    \n  - Add import `import io.wifi.p2p.WiFiP2PManagerPackage;` to the imports at the top of the file.\n  - Add `new WiFiP2PManagerPackage()` to the list returned by the `getPackages()` method. Add a comma to the previous item if there's already something there.\n\n# Overview\n\n## API\n\n### Initialization\n\n* [initialize()](#initialize)\n* [startDiscoveringPeers()](#startdiscoveringpeers)\n* [stopDiscoveringPeers()](#stopdiscoveringpeers)\n\n### Subscribers \u0026 Actions annunciators\n\n* [subscribeOnPeersUpdates(callback)](#subscribeonpeersupdatescallback)\n* [subscribeOnConnectionInfoUpdates(callback)](#subscribeonconnectioninfoupdatescallback)\n* [subscribeOnThisDeviceChanged(callback)](#subscribeonthisdevicechangedcallback)\n\n### Interaction with other devices\n\n* [getAvailablePeers()](#getavailablepeers)\n* [connect(deviceAddress)](#connectdeviceaddress)\n* [connectWithConfig(connectionArgs)](#connectwithconfigconnectionargs)\n* [cancelConnect()](#cancelconnect)\n* [createGroup()](#creategroup)\n* [removeGroup()](#removegroup)\n* [getGroupInfo()](#getgroupinfo)\n* [getConnectionInfo()](#getconnectioninfo)\n* [sendFile(pathToFile)](#sendfilepathtofile)\n* [sendFileTo(pathToFile, address)](#sendfiletopathtofile-address)\n* [sendMessage(message)](#sendmessagemessage)\n* [sendMessageTo(message, address)](#sendmessagetomessage-address)\n* [receiveFile(folder, fileName, forceToScanGallery)](#receivefilefolder-filename-forcetoscangallery)\n* [receiveMessage()](#receivemessage)\n\n### CONSTANTS\n\n* [WifiP2pDevice statuses](#wifip2pdevice-statuses)\n* [Events of library](#events-of-library)\n\n## API\n\n## Initialization\n\n### initialize()\n\nThis method must calling before any using of others method, because here happened start initialization of `react-native-wifi-p2p` module.\nRecommend to initialize it on root files, but if your application has specific logic, then you can call it before directly using.\nNotice, that recommend called only once.\n\n```javascript\ninitialize()\n    .then((isInitializedSuccessfully) =\u003e console.log('isInitializedSuccessfully: ', isInitializedSuccessfully))\n    .catch((err) =\u003e console.log('initialization was failed. Err: ', err));\n```\n\n### startDiscoveringPeers()\n\n`startDiscoveringPeers()` starting emit action to discover available devices. Note, that this function doesn't return any information about available devices/peers. It return information about successfully start.\n\n```javascript\nstartDiscoveringPeers()\n    .then(() =\u003e console.log('Starting of discovering was successful'))\n    .catch(err =\u003e console.error(`Something is gone wrong. Maybe your WiFi is disabled? Error details: ${err}`));\n```\n\n### stopDiscoveringPeers()\n\n`stopDiscoveringPeers()` prevent emit action to discover available devices. Note, that this function doesn't return any information about available devices/peers. It return information about successfully stopping of discovering.\n\n```javascript\nstopDiscoveringPeers()\n    .then(() =\u003e console.log('Stop discovering was successful'))\n    .catch(err =\u003e console.error(`Something is gone wrong. Maybe your WiFi is disabled? Error details: ${err}`));\n```\n\n## Subscribers \u0026 Actions annunciators\n\n### subscribeOnPeersUpdates(callback)\n\n`subscribeOnPeersUpdates(callback)` allow to subscribe on events, that will notify about availability of nearby devices.\n\n```javascript\nconst subscription = subscribeOnPeersUpdates(({ devices }) =\u003e {\n    console.log(`New devices available: ${devices}`);\n});\n\n// in order to remove a subscription (on unmount for example)\nsubscription.remove();\n```\n\n### subscribeOnConnectionInfoUpdates(callback)\n\n```javascript\nconst subscription = subscribeOnConnectionInfoUpdates((event) =\u003e {\n    console.log('Connection Info Updates: ', event);\n});\n\n// in order to remove a subscription (on unmount for example)\nsubscription.remove();\n```\n\n### subscribeOnThisDeviceChanged(callback)\n\n```javascript\nconst subscription = subscribeOnThisDeviceChanged((event) =\u003e {\n    console.log('This device changed: ', event);\n});\n\n// in order to remove a subscription (on unmount for example)\nsubscription.remove();\n```\n\n## Interaction with other devices\n\n### getAvailablePeers()\n\nIf you don't want to always get notification from event emitter, when peers list has changed, you can use this method. This method will return info about nearby devices, that is available for searching, at the time of the call this method.\n\n**Important:** before using this method you also need to call `startDiscoveringPeers`. In other case you always will get empty array.\n\n```javascript\ngetAvailablePeers()\n    .then(({ devices }) =\u003e console.log(devices))\n```\n\n### connect(deviceAddress)\n\nConnect to network. The devices found from the `subscribeOnPeersUpdates` method. Should use `deviceAddress` field from necessary device from array. This field represent a `MAC address` that is used to connect.\n\n```javascript\nconnect('22:47:da:9d:58:83')\n    .then(() =\u003e console.log('Successfully connected'))\n    .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n```\n\n### connectWithConfig(connectionArgs)\n\nConnect to network. The method takes two arguments `deviceAddress` and an optional \n`groupOwnerIntent`. `groupOwnerIntent` specifies to the OS the intentsity with which the device initiaiting the connection wants to be the group Owner.(i.e the server). It takes a value between `0` and `15`, 0 and 15 being the least and most likely group owners respectively. i.e device specifying `groupOwnerIntent 15` is more likely to be a group owner.\nLink to andrdoid documentation [https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pConfig]\n\n```javascript\nconnectWithConfig({ deviceAddress: '22:47:da:9d:58:83', groupOwnerIntent: 15 })\n    .then(() =\u003e console.log('Successfully connected as group Owner.'))\n    .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n```\n\n### cancelConnect()\n\nCancel connection from network. Should use when you want to reconnect or turn off wifi.\n\n```javascript\ncancelConnect()\n    .then(() =\u003e console.log('Connection successfully canceled'))\n    .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n```\n\nIf you want to [disconnect](https://stackoverflow.com/questions/18679481/wifi-direct-end-connection-to-peer-on-android/18792707#18792707), then you can use the following chain of functions:\n\n```javascript\ngetGroupInfo()\n    .then(() =\u003e removeGroup())\n    .then(() =\u003e console.log('Succesfully disconnected!'))\n    .catch(err =\u003e console.error('Something gone wrong. Details: ', err))\n```\n\n### createGroup()\n\nP2P **STAR** is a peer-to-peer strategy that supports a **1-to-N**, or **star-shaped**, connection topology. In other words, this enables connecting devices within radio range (~100m) in a star shape, where each device can, at any given time, play the role of either a hub (where it can accept incoming connections from N other devices), or a spoke (where it can initiate an outgoing connection to a single hub), but not both. So achieve this goal you can use `createGroup` method, so create your own group.\n\n```javascript\ncreateGroup()\n    .then(() =\u003e console.log('Group created successfully!'))\n    .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n```\n\n### removeGroup()\n\nBefore exit of application you need to call this method, if earlier you created group via `createGroup()` method.\n\n```javascript\nremoveGroup()\n    .then(() =\u003e console.log('Currently you don\\'t belong to group!'))\n    .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n```\n\n```javascript\ncreateGroup()\n      .then(() =\u003e {\n        setTimeout(() =\u003e {\n          getGroupPassphraseInfo().then(passphrase =\u003e console.log(passphrase));\n        }, 3000);\n      })\n      .catch(err =\u003e console.error(\"Something gone wrong. Details: \", err));\n```\n\n### getGroupInfo()\n\nYou can call it after `createGroup()` method is executed. Info from this method also is available in `subscribeOnThisDeviceChanged`. This method was created basically for supporting API \u003c= 17. See [issue](https://github.com/kirillzyusko/react-native-wifi-p2p/issues/21) thread.\n\n### getConnectionInfo()\n\nThis method in the main is used in `sendFile()` flow. It's needed for saving `WifiP2pInfo` internally of this library. Also this method returns actual connection information. Fot its usage see description of `sendFile` method.\n\n### sendFile(pathToFile)\n\nYou should call this method if you want to copy file from client side to server using wi-fi p2p feature. Before sending you should execute next steps:\n\n1. Create group on server side\n2. Connect to server-group from client side\n3. After establishing connection you should call `getConnectionInfo()` on client side\n4. Call `receiveFile(directory, fileName)` on server side (`receiveFile` return `Promise\u003cstring\u003e` - path to saved file)\n5. Call `sendFile(pathToFile)` on client side, after resolving `getConnectionInfo()`\n\n```javascript\nimport { PermissionsAndroid } from 'react-native';\n\nPermissionsAndroid.request(\n                  PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,\n                  {\n                      'title': 'Access to read',\n                      'message': 'READ_EXTERNAL_STORAGE'\n                  }\n              )\n          .then(granted =\u003e {\n              if (granted === PermissionsAndroid.RESULTS.GRANTED) {\n                  console.log(\"You can use read operation\")\n              } else {\n                  console.log(\"Read operation permission denied\")\n              }\n          })\n          .then(() =\u003e {\n              return PermissionsAndroid.request(\n                  PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,\n                  {\n                      'title': 'Access to write',\n                      'message': 'WRITE_EXTERNAL_STORAGE'\n                  }\n              )\n          })\n          .then(() =\u003e {\n              // `/storage/emulated/0/Music/Bullet For My Valentine:Letting You Go.mp3` - example of `pathToFIle`\n              return sendFile('path/to/file')\n                  .then((metaInfo) =\u003e console.log('File sent successfully:', metaInfo))\n                  .catch(err =\u003e console.log('Error while file sending', err));\n          })\n          .catch(err =\u003e console.log(err));\n```\n\n### sendFileTo(pathToFile, address)\n\nSame function as above but you can specify the address (a peer address in the same group as this device is).\n\n### sendMessage(message)\n\nYou should call this method if you want to send from client side to server (group) using wi-fi p2p feature. Before sending you should execute next steps:\n\n1. Create group on server side (side, which will receive message)\n2. Connect to server-group from client side\n3. After establishing connection you should call `getConnectionInfo()` on client side (also recommend do it on group-server side)\n4. Call `receiveMessage()` on server side (`receiveMessage` return `Promise\u003cstring\u003e` - message from client)\n5. Call `sendMessage(message)` on client side, after resolving `getConnectionInfo()`\n\n_Note_: you cannot send character encoding for string and by default this library uses `UTF-8`.\n\n### sendMessageTo(message, address)\n\nSame function as above but you can specify the address (a peer address in the same group as this device is).\n\n### receiveFile(folder, fileName, forceToScanGallery)\n\nIf you expect, that someone may send you a file - you can call this method in order to receive it.\n\nIf you want to save file with the same name as it's on client device, then before sending file you can `sendMessage` about its `fileName`.\n\n`forceToScanGallery` is an optional parameter, which indicate whether should we scan and detect new files or not in order to show them in Gallery app. By default it's `false`.\n\n_Note:_ if you expect file to be received you should request permissions for writing to the storage:\n\n```javascript\nPermissionsAndroid.request(\n          PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,\n          {\n              'title': 'Access to read',\n              'message': 'READ_EXTERNAL_STORAGE'\n          }\n      )\n          .then(granted =\u003e {\n              if (granted === PermissionsAndroid.RESULTS.GRANTED) {\n                  console.log(\"You can use the storage\")\n              } else {\n                  console.log(\"Storage permission denied\")\n              }\n          })\n          .then(() =\u003e {\n              return PermissionsAndroid.request(\n                  PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,\n                  {\n                      'title': 'Access to write',\n                      'message': 'WRITE_EXTERNAL_STORAGE'\n                  }\n              )\n          })\n          .then(() =\u003e {\n              return receiveFile('/storage/emulated/0/Music/', 'BFMV:Letting You Go.mp3')\n                  .then(() =\u003e console.log('File received successfully'))\n                  .catch(err =\u003e console.log('Error while file receiving', err))\n          })\n          .catch(err =\u003e console.log(err));\n```\n\n### receiveMessage()\n\nIf you expect, that someone may send you a message - you can call this method in order to receive it. This opens a port to listen to ONE incoming message.\n\n```javascript\nreceiveMessage()\n    .then(message =\u003e console.log(`Received message: ${message}`))\n```\n\n### stopReceivingMessage()\n\nIf you didn't receive the message from receiveMessage() as expected, stopReceivingMessage() closes the listening port. If the port is already closed, this method does nothing.\n\n## CONSTANTS\n\n### WifiP2pDevice statuses\n\n```javascript\nimport {\n    CONNECTED,\n    INVITED,\n    FAILED,\n    AVAILABLE,\n    UNAVAILABLE\n} from 'react-native-wifi-p2p/device-info-statuses';\n```\n\n### Events of library\n\n```javascript\nimport {\n    PEERS_UPDATED_ACTION,\n    CONNECTION_INFO_UPDATED_ACTION,\n    THIS_DEVICE_CHANGED_ACTION\n } from 'react-native-wifi-p2p';\nimport {subscribeOnEvent} from 'react-native-wifi-p2p';\n\n// example of usage\nsubscribeOnEvent(PEERS_UPDATED_ACTION, (event) =\u003e {\n    console.log(event);\n});\n```\n\n## Caveats\n\nOn Android \u003e= 6.0 you should ask permissions before usage of this library (since this grants are required):\n\n\u003e **Note**: you should ask this grants before `startDiscoveringPeers`\n\n\u003e **Note**: on Android 10 you will probably need to ask `ACCESS_FINE_LOCATION` instead of `ACCESS_COARSE_LOCATION`.\n\n\u003e **Note**: if you are targeting Android 13+ you also need to ask `NEARBY_WIFI_DEVICES` permission in runtime. You can do it using `react-native-permissions` library, if you are using react-native \u003c 0.70\n\n```javascript\nimport { PermissionsAndroid } from 'react-native';\n...\nPermissionsAndroid.request(\n                  PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,\n                  {\n                      'title': 'Access to wi-fi P2P mode',\n                      'message': 'ACCESS_COARSE_LOCATION'\n                  }\n              )\n          .then(granted =\u003e {\n              if (granted === PermissionsAndroid.RESULTS.GRANTED) {\n                  console.log(\"You can use the p2p mode\")\n              } else {\n                  console.log(\"Permission denied: p2p mode will not work\")\n              }\n          })\n```\n\nIf you are using Android Oreo (8.0) or higher, then you also need to request `FINE_LOCATION` permission, and location [should be enabled](https://stackoverflow.com/questions/50475371/android-wifi-direct-p2p-not-able-to-find-peers-on-android-8/53149375#53149375).\n\n### Example of usage\n\n```javascript\nimport React, { PureComponent } from 'react';\nimport {\n  StyleSheet,\n  View,\n  Button\n} from 'react-native';\nimport {\n  initialize,\n  startDiscoveringPeers,\n  stopDiscoveringPeers,\n  subscribeOnConnectionInfoUpdates,\n  subscribeOnThisDeviceChanged,\n  subscribeOnPeersUpdates,\n  connect,\n  cancelConnect,\n  createGroup,\n  removeGroup,\n  getAvailablePeers,\n  sendFile,\n  receiveFile,\n  getConnectionInfo,\n  getGroupInfo,\n  receiveMessage,\n  sendMessage,\n} from 'react-native-wifi-p2p';\nimport { PermissionsAndroid } from 'react-native';\n\ntype Props = {};\nexport default class App extends PureComponent\u003cProps\u003e {\n  peersUpdatesSubscription;\n  connectionInfoUpdatesSubscription;\n  thisDeviceChangedSubscription;\n\n  state = {\n    devices: []\n  };\n\n  async componentDidMount() {\n      try {\n          await initialize();\n          // since it's required in Android \u003e= 6.0\n          const granted = await PermissionsAndroid.request(\n              PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,\n              {\n                  'title': 'Access to wi-fi P2P mode',\n                  'message': 'ACCESS_COARSE_LOCATION'\n              }\n          );\n\n          console.log(granted === PermissionsAndroid.RESULTS.GRANTED ? \"You can use the p2p mode\" : \"Permission denied: p2p mode will not work\");\n\n          this.peersUpdatesSubscription = subscribeOnPeersUpdates(this.handleNewPeers);\n          this.connectionInfoUpdatesSubscription = subscribeOnConnectionInfoUpdates(this.handleNewInfo);\n          this.thisDeviceChangedSubscription = subscribeOnThisDeviceChanged(this.handleThisDeviceChanged);\n\n          const status = await startDiscoveringPeers();\n          console.log('startDiscoveringPeers status: ', status);\n      } catch (e) {\n          console.error(e);\n      }\n  }\n\n  componentWillUnmount() {\n    this.peersUpdatesSubscription?.remove();\n    this.connectionInfoUpdatesSubscription?.remove();\n    this.thisDeviceChangedSubscription?.remove();\n  }\n\n  handleNewInfo = (info) =\u003e {\n    console.log('OnConnectionInfoUpdated', info);\n  };\n\n  handleNewPeers = ({ devices }) =\u003e {\n    console.log('OnPeersUpdated', devices);\n    this.setState({ devices: devices });\n  };\n\n  handleThisDeviceChanged = (groupInfo) =\u003e {\n      console.log('THIS_DEVICE_CHANGED_ACTION', groupInfo);\n  };\n\n  connectToFirstDevice = () =\u003e {\n      console.log('Connect to: ', this.state.devices[0]);\n      connect(this.state.devices[0].deviceAddress)\n          .then(() =\u003e console.log('Successfully connected'))\n          .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n  };\n\n  onCancelConnect = () =\u003e {\n      cancelConnect()\n          .then(() =\u003e console.log('cancelConnect', 'Connection successfully canceled'))\n          .catch(err =\u003e console.error('cancelConnect', 'Something gone wrong. Details: ', err));\n  };\n\n  onCreateGroup = () =\u003e {\n      createGroup()\n          .then(() =\u003e console.log('Group created successfully!'))\n          .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n  };\n\n  onRemoveGroup = () =\u003e {\n      removeGroup()\n          .then(() =\u003e console.log('Currently you don\\'t belong to group!'))\n          .catch(err =\u003e console.error('Something gone wrong. Details: ', err));\n  };\n\n  onStopInvestigation = () =\u003e {\n      stopDiscoveringPeers()\n          .then(() =\u003e console.log('Stopping of discovering was successful'))\n          .catch(err =\u003e console.error(`Something is gone wrong. Maybe your WiFi is disabled? Error details`, err));\n  };\n\n  onStartInvestigate = () =\u003e {\n      startDiscoveringPeers()\n          .then(status =\u003e console.log('startDiscoveringPeers', `Status of discovering peers: ${status}`))\n          .catch(err =\u003e console.error(`Something is gone wrong. Maybe your WiFi is disabled? Error details: ${err}`));\n  };\n\n  onGetAvailableDevices = () =\u003e {\n      getAvailablePeers()\n          .then(peers =\u003e console.log(peers));\n  };\n\n  onSendFile = () =\u003e {\n      //const url = '/storage/sdcard0/Music/Rammstein:Amerika.mp3';\n      const url = '/storage/emulated/0/Music/Bullet For My Valentine:Letting You Go.mp3';\n      PermissionsAndroid.request(\n                  PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,\n                  {\n                      'title': 'Access to read',\n                      'message': 'READ_EXTERNAL_STORAGE'\n                  }\n              )\n          .then(granted =\u003e {\n              if (granted === PermissionsAndroid.RESULTS.GRANTED) {\n                  console.log(\"You can use the storage\")\n              } else {\n                  console.log(\"Storage permission denied\")\n              }\n          })\n          .then(() =\u003e {\n              return PermissionsAndroid.request(\n                  PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,\n                  {\n                      'title': 'Access to write',\n                      'message': 'WRITE_EXTERNAL_STORAGE'\n                  }\n              )\n          })\n          .then(() =\u003e {\n              return sendFile(url)\n                  .then((metaInfo) =\u003e console.log('File sent successfully', metaInfo))\n                  .catch(err =\u003e console.log('Error while file sending', err));\n          })\n          .catch(err =\u003e console.log(err));\n  };\n\n  onReceiveFile = () =\u003e {\n      PermissionsAndroid.request(\n          PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,\n          {\n              'title': 'Access to read',\n              'message': 'READ_EXTERNAL_STORAGE'\n          }\n      )\n          .then(granted =\u003e {\n              if (granted === PermissionsAndroid.RESULTS.GRANTED) {\n                  console.log(\"You can use the storage\")\n              } else {\n                  console.log(\"Storage permission denied\")\n              }\n          })\n          .then(() =\u003e {\n              return PermissionsAndroid.request(\n                  PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,\n                  {\n                      'title': 'Access to write',\n                      'message': 'WRITE_EXTERNAL_STORAGE'\n                  }\n              )\n          })\n          .then(() =\u003e {\n              return receiveFile('/storage/emulated/0/Music/', 'BFMV:Letting You Go.mp3')\n                  .then(() =\u003e console.log('File received successfully'))\n                  .catch(err =\u003e console.log('Error while file receiving', err))\n          })\n          .catch(err =\u003e console.log(err));\n  };\n\n  onSendMessage = () =\u003e {\n      sendMessage(\"Hello world!\")\n        .then((metaInfo) =\u003e console.log('Message sent successfully', metaInfo))\n        .catch(err =\u003e console.log('Error while message sending', err));\n  };\n\n  onReceiveMessage = () =\u003e {\n      receiveMessage()\n          .then((msg) =\u003e console.log('Message received successfully', msg))\n          .catch(err =\u003e console.log('Error while message receiving', err))\n  };\n\n  onGetConnectionInfo = () =\u003e {\n    getConnectionInfo()\n        .then(info =\u003e console.log('getConnectionInfo', info));\n  };\n\n  onGetGroupInfo = () =\u003e {\n      getGroupInfo()\n        .then(info =\u003e console.log('getGroupInfo', info));\n  };\n\n  render() {\n    return (\n      \u003cView style={styles.container}\u003e\n        \u003cButton\n          title=\"Connect\"\n          onPress={this.connectToFirstDevice}\n        /\u003e\n        \u003cButton\n          title=\"Cancel connect\"\n          onPress={this.onCancelConnect}\n        /\u003e\n        \u003cButton\n          title=\"Create group\"\n          onPress={this.onCreateGroup}\n        /\u003e\n        \u003cButton\n          title=\"Remove group\"\n          onPress={this.onRemoveGroup}\n        /\u003e\n        \u003cButton\n          title=\"Investigate\"\n          onPress={this.onStartInvestigate}\n        /\u003e\n        \u003cButton\n          title=\"Prevent Investigation\"\n          onPress={this.onStopInvestigation}\n        /\u003e\n        \u003cButton\n          title=\"Get Available Devices\"\n          onPress={this.onGetAvailableDevices}\n        /\u003e\n        \u003cButton\n          title=\"Get connection Info\"\n          onPress={this.onGetConnectionInfo}\n        /\u003e\n        \u003cButton\n          title=\"Get group info\"\n          onPress={this.onGetGroupInfo}\n        /\u003e\n        \u003cButton\n          title=\"Send file\"\n          onPress={this.onSendFile}\n        /\u003e\n        \u003cButton\n          title=\"Receive file\"\n          onPress={this.onReceiveFile}\n        /\u003e\n        \u003cButton\n          title=\"Send message\"\n          onPress={this.onSendMessage}\n        /\u003e\n        \u003cButton\n          title=\"Receive message\"\n          onPress={this.onReceiveMessage}\n        /\u003e\n      \u003c/View\u003e\n    );\n  }\n}\n\nconst styles = StyleSheet.create({\n  container: {\n    flex: 1,\n    justifyContent: 'center',\n    alignItems: 'center',\n    backgroundColor: '#F5FCFF',\n  },\n  welcome: {\n    fontSize: 20,\n    textAlign: 'center',\n    margin: 10,\n  },\n  instructions: {\n    textAlign: 'center',\n    color: '#333333',\n    marginBottom: 5,\n  },\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirillzyusko%2Freact-native-wifi-p2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirillzyusko%2Freact-native-wifi-p2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirillzyusko%2Freact-native-wifi-p2p/lists"}