react-native-bluechat
v0.1.1
Published
Chatting module based on Bluetooth
Downloads
3
Readme
React Native Bluechat
Simple one-on-one bluetooh chatting module using Bluetooth Low Energy (BLE)
This library was created as part of a learning exercise to explore and expose native Android events to JS using Turbo Modules.
Initial usage was meant for during-flight communication through Bluetooth.
It only supporst New Architecture and backward compatability will not be implemented.
[!WARNING] Android only: This library currently supports Android only. There are no plans for iOS support at this time.
This library is not suitable for production use. It is intended as a refererence implementation.
Features
- Advertise your device
- Scan for nearby BLE devices
- Connect to a selected BLE device
- Send and receive messages between connected devices
Getting started
npm i react-native-bluechatyarn add react-native-bluechatbun add react-native-bluechatSetup Android
Add required permission to your AndroidManifest.xml file.
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<!-- For Android 12 (API 31) or higher -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />You can use react-native-permissions or similar for requesting permissions.
Usage
//Hook
import { useBluechat } from 'react-native-bluechat';
// ...
const {
startScan,
stopScan,
startAdvertising,
stopAdvertising,
connectToDevice,
disconnectFromDevice,
btEnabled,
isScanning,
sendMessage,
scannedDevices,
messages,
connectionState,
isAdvertising,
} = useBluechat();
// ...See Example
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made as learning process by Aironas Kulvelis
