UNPKG

rn-wifi-p2p

Version:

React Native module for Android P2P communication using Wi-Fi Direct.

87 lines (53 loc) โ€ข 2.69 kB
# rn-wifi-p2p [![CI](https://github.com/matheus-caldeira/rn-wifi-p2p/actions/workflows/ci.yml/badge.svg)](https://github.com/matheus-caldeira/rn-wifi-p2p/actions/workflows/ci.yml) **React Native module for peer-to-peer communication over Wi-Fi Direct on Android.** This library enables Android devices to discover and connect to each other directly without an internet connection, ideal for offline file transfer, messaging, and collaborative apps. > โš ๏ธ This library is **Android-only** and requires runtime permissions to operate correctly. --- ## ๐Ÿ“ฆ Installation Install the package using [Yarn](https://yarnpkg.com): ```bash yarn add rn-wifi-p2p ``` --- ## โš™๏ธ Android Configuration Add the following permissions to your `AndroidManifest.xml`: ```xml <!-- Required to send/receive files from external storage --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- Required to scan and connect to nearby peers on Android 13+ --> <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" android:usesPermissionFlags="neverForLocation" /> <!-- Required for Wi-Fi P2P discovery --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:required="true" android:maxSdkVersion="32" /> ``` > โœ… If your app **requires precise location**, remove the `maxSdkVersion` attribute from `ACCESS_FINE_LOCATION`. > ๐Ÿ” These permissions must also be **requested at runtime** in your JavaScript code, especially from Android 6+ (API 23). --- ## ๐Ÿงช Example App A complete example demonstrating peer discovery, connection, file sharing, and messaging is available in the [`example/`](./example) directory. To learn how to run it locally, refer to the [CONTRIBUTING.md](./CONTRIBUTING.md) guide. --- ## ๐Ÿ“š API Overview The following capabilities are supported: - ๐Ÿ“ก Peer discovery using Wi-Fi Direct - ๐Ÿ”— Device-to-device connection management - ๐Ÿ“ File transfer between devices - ๐Ÿ’ฌ Message exchange using native sockets - ๐Ÿ‘ฅ Group creation and teardown - ๐Ÿ”„ Subscriptions to device, peer, and connection changes > Detailed API documentation is available in the source code and TypeScript typings. --- ## ๐Ÿค Contributing To contribute to this module or run the example app locally, see [CONTRIBUTING.md](./CONTRIBUTING.md) for setup and development guidelines. --- ## ๐Ÿ“„ License [MIT](./LICENSE) --- Created with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)