react-native-bluebreeze 0.0.12 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -13
- package/android/build.gradle +9 -3
- package/android/generated/jni/CMakeLists.txt +1 -9
- package/android/generated/jni/RNBlueBreezeSpec-generated.cpp +1 -1
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI.h +234 -279
- package/android/src/main/java/com/bluebreeze/BlueBreezeModule.kt +140 -120
- package/ios/BlueBreezeImpl.swift +30 -24
- package/ios/Bluebreeze.h +1 -1
- package/ios/Bluebreeze.mm +2 -7
- package/ios/generated/{RNBlueBreezeSpecJSI.h → ReactCodegen/RNBlueBreezeSpecJSI.h} +234 -279
- package/lib/commonjs/implementation/bluebreeze_characteristic.js +42 -11
- package/lib/commonjs/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_connection_status.js +2 -0
- package/lib/commonjs/implementation/bluebreeze_connection_status.js.map +1 -0
- package/lib/commonjs/implementation/bluebreeze_device.js +53 -13
- package/lib/commonjs/implementation/bluebreeze_device.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_scan_result.js +19 -0
- package/lib/commonjs/implementation/bluebreeze_scan_result.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_service.js +9 -0
- package/lib/commonjs/implementation/bluebreeze_service.js.map +1 -1
- package/lib/commonjs/implementation/native_bridge.js +108 -0
- package/lib/commonjs/implementation/native_bridge.js.map +1 -0
- package/lib/commonjs/index.js +29 -100
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/module/implementation/bluebreeze_characteristic.js +43 -10
- package/lib/module/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/module/implementation/bluebreeze_connection_status.js +2 -0
- package/lib/module/implementation/bluebreeze_connection_status.js.map +1 -0
- package/lib/module/implementation/bluebreeze_device.js +54 -12
- package/lib/module/implementation/bluebreeze_device.js.map +1 -1
- package/lib/module/implementation/bluebreeze_scan_result.js +19 -0
- package/lib/module/implementation/bluebreeze_scan_result.js.map +1 -1
- package/lib/module/implementation/bluebreeze_service.js +9 -0
- package/lib/module/implementation/bluebreeze_service.js.map +1 -1
- package/lib/module/implementation/native_bridge.js +99 -0
- package/lib/module/implementation/native_bridge.js.map +1 -0
- package/lib/module/index.js +29 -100
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts +1 -1
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_authorization.d.ts +10 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_authorization.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts +29 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_connection_status.d.ts +7 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_connection_status.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts +42 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts +11 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts +6 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_state.d.ts +16 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_state.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts +17 -0
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +0 -13
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts +1 -1
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_authorization.d.ts +10 -1
- package/lib/typescript/module/src/implementation/bluebreeze_authorization.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts +29 -0
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_connection_status.d.ts +7 -0
- package/lib/typescript/module/src/implementation/bluebreeze_connection_status.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts +43 -2
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts +12 -1
- package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts +7 -1
- package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_state.d.ts +16 -1
- package/lib/typescript/module/src/implementation/bluebreeze_state.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/native_bridge.d.ts +17 -0
- package/lib/typescript/module/src/implementation/native_bridge.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +6 -19
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +13 -23
- package/react-native-bluebreeze.podspec +1 -1
- package/src/NativeBlueBreeze.ts +1 -1
- package/src/implementation/bluebreeze_authorization.ts +10 -1
- package/src/implementation/bluebreeze_characteristic.ts +48 -10
- package/src/implementation/bluebreeze_connection_status.ts +6 -0
- package/src/implementation/bluebreeze_device.ts +62 -13
- package/src/implementation/bluebreeze_scan_result.ts +18 -0
- package/src/implementation/bluebreeze_service.ts +8 -0
- package/src/implementation/bluebreeze_state.ts +16 -1
- package/src/implementation/native_bridge.ts +196 -0
- package/src/index.tsx +24 -202
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI-generated.cpp +0 -179
- package/ios/generated/RNBlueBreezeSpecJSI-generated.cpp +0 -179
- /package/ios/generated/{RNBlueBreezeSpec → ReactCodegen/RNBlueBreezeSpec}/RNBlueBreezeSpec-generated.mm +0 -0
- /package/ios/generated/{RNBlueBreezeSpec → ReactCodegen/RNBlueBreezeSpec}/RNBlueBreezeSpec.h +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BlueBreeze React Native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-bluebreeze)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](package.json)
|
|
6
|
+
|
|
7
|
+
BlueBreeze is a modern Bluetooth LE library for React Native, wrapping the native
|
|
8
|
+
[BlueBreeze iOS](https://github.com/like-magic-dev/bluebreeze-ios) and
|
|
9
|
+
[BlueBreeze Android](https://github.com/like-magic-dev/bluebreeze-android) SDKs behind a single
|
|
10
|
+
JS/TypeScript API. All the platform-specific work -- connection state machines, GATT callback
|
|
11
|
+
correlation, per-device request queuing -- happens natively; from JS you just observe state and
|
|
12
|
+
`await` operations.
|
|
13
|
+
|
|
14
|
+
- **Reactive state** -- adapter power, authorization, discovered devices, connection status,
|
|
15
|
+
services, and characteristic data are all exposed as observables
|
|
16
|
+
([`react-native-value-emitter`](https://github.com/like-magic-dev/react-native-value-emitter))
|
|
17
|
+
you subscribe to with `.onValue(...)` and read synchronously via `.value`.
|
|
18
|
+
- **Promise-based operations** -- connect, discover services, read, write, and
|
|
19
|
+
subscribe/unsubscribe are all `async` calls with a built-in timeout on both platforms; no
|
|
20
|
+
native callbacks to correlate yourself.
|
|
21
|
+
- **Automatic per-device request queuing** -- handled natively on both platforms, so you can fire
|
|
22
|
+
off several operations on the same device without worrying about overlapping BLE requests.
|
|
23
|
+
- **Runtime permission handling built in** -- `authorizationStatus`/`authorizationRequest`/
|
|
24
|
+
`authorizationOpenSettings` cover Android's runtime permissions and iOS's Bluetooth usage
|
|
25
|
+
authorization behind one API.
|
|
26
|
+
- **Bluetooth SIG assigned numbers built in** -- known company IDs, service UUIDs, and
|
|
27
|
+
characteristic UUIDs are resolved automatically by the underlying native SDKs.
|
|
28
|
+
- **New Architecture** -- implemented as a TurboModule.
|
|
4
29
|
|
|
5
30
|
## Installation
|
|
6
31
|
|
|
@@ -8,26 +33,85 @@ BlueBreeze bindings for React Native. A modern Bluetooth LE library.
|
|
|
8
33
|
npm install react-native-bluebreeze
|
|
9
34
|
```
|
|
10
35
|
|
|
11
|
-
|
|
36
|
+
iOS additionally requires a pod install:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
cd ios && pod install
|
|
40
|
+
```
|
|
12
41
|
|
|
42
|
+
## Requirements
|
|
13
43
|
|
|
14
|
-
|
|
15
|
-
|
|
44
|
+
- React Native with the New Architecture enabled (this library is a TurboModule)
|
|
45
|
+
- Android API 24+ (minSdk)
|
|
46
|
+
- iOS 15.1+
|
|
47
|
+
- Declare the Bluetooth permissions each platform needs:
|
|
16
48
|
|
|
17
|
-
|
|
49
|
+
**Android** (`android/app/src/main/AndroidManifest.xml`):
|
|
50
|
+
```xml
|
|
51
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
|
|
52
|
+
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
|
|
53
|
+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
|
54
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
|
|
55
|
+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
18
56
|
|
|
19
|
-
|
|
57
|
+
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
|
|
20
58
|
```
|
|
21
59
|
|
|
60
|
+
**iOS** (`ios/Info.plist`):
|
|
61
|
+
```xml
|
|
62
|
+
<key>NSBluetoothAlwaysUsageDescription</key>
|
|
63
|
+
<string>This app uses Bluetooth to connect to nearby devices.</string>
|
|
64
|
+
```
|
|
22
65
|
|
|
23
|
-
##
|
|
66
|
+
## Quick start
|
|
24
67
|
|
|
25
|
-
|
|
68
|
+
```tsx
|
|
69
|
+
import BlueBreeze from 'react-native-bluebreeze'
|
|
26
70
|
|
|
27
|
-
|
|
71
|
+
// Request authorization if needed, then start scanning once the adapter is on
|
|
72
|
+
if (BlueBreeze.authorizationStatus.value !== 'authorized') {
|
|
73
|
+
BlueBreeze.authorizationRequest()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
BlueBreeze.state.onValue((state) => {
|
|
77
|
+
if (state === 'poweredOn') {
|
|
78
|
+
BlueBreeze.scanStart()
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// Observe scan results
|
|
83
|
+
BlueBreeze.scanResults.onValue((result) => {
|
|
84
|
+
console.log(result.name ?? 'Unknown device', result.rssi)
|
|
85
|
+
})
|
|
28
86
|
|
|
29
|
-
|
|
87
|
+
// Connect, discover, and talk to a device
|
|
88
|
+
async function connectToFirstDevice() {
|
|
89
|
+
const device = BlueBreeze.devices.value.values().next().value
|
|
90
|
+
if (device == undefined) return
|
|
30
91
|
|
|
31
|
-
|
|
92
|
+
await device.connect()
|
|
93
|
+
await device.discoverServices()
|
|
94
|
+
|
|
95
|
+
for (const service of device.services.value) {
|
|
96
|
+
for (const characteristic of service.characteristics) {
|
|
97
|
+
if (characteristic.properties.includes('read')) {
|
|
98
|
+
const data = await characteristic.read()
|
|
99
|
+
console.log(characteristic.id, data)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
await device.disconnect()
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
See [`example`](example) for a full app built on top of BlueBreeze.
|
|
109
|
+
|
|
110
|
+
## Documentation
|
|
111
|
+
|
|
112
|
+
The public API is documented with TSDoc directly in the source under
|
|
113
|
+
[`src`](src) -- hover any exported member in your editor to see it, or browse it there directly.
|
|
114
|
+
|
|
115
|
+
## License
|
|
32
116
|
|
|
33
|
-
|
|
117
|
+
BlueBreeze is available under the MIT license. See [LICENSE](LICENSE) for details.
|
package/android/build.gradle
CHANGED
|
@@ -9,7 +9,7 @@ buildscript {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
dependencies {
|
|
12
|
-
classpath "com.android.tools.build:gradle:
|
|
12
|
+
classpath "com.android.tools.build:gradle:9.2.1"
|
|
13
13
|
// noinspection DifferentKotlinGradleVersion
|
|
14
14
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
15
|
}
|
|
@@ -21,7 +21,13 @@ def isNewArchitectureEnabled() {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
apply plugin: "com.android.library"
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
// Some AGP versions register their own "kotlin" extension. We only apply
|
|
26
|
+
// the Kotlin Gradle plugin if that hasn't already happened, to avoid
|
|
27
|
+
// "Cannot add extension with name 'kotlin'" failures.
|
|
28
|
+
if (project.extensions.findByName("kotlin") == null) {
|
|
29
|
+
apply plugin: "kotlin-android"
|
|
30
|
+
}
|
|
25
31
|
|
|
26
32
|
if (isNewArchitectureEnabled()) {
|
|
27
33
|
apply plugin: "com.facebook.react"
|
|
@@ -101,7 +107,7 @@ dependencies {
|
|
|
101
107
|
implementation "com.facebook.react:react-android"
|
|
102
108
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
103
109
|
|
|
104
|
-
implementation "dev.likemagic:bluebreeze:
|
|
110
|
+
implementation "dev.likemagic:bluebreeze:1.0.1"
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
if (isNewArchitectureEnabled()) {
|
|
@@ -25,12 +25,4 @@ target_link_libraries(
|
|
|
25
25
|
reactnative
|
|
26
26
|
)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
react_codegen_RNBlueBreezeSpec
|
|
30
|
-
PRIVATE
|
|
31
|
-
-DLOG_TAG=\"ReactNative\"
|
|
32
|
-
-fexceptions
|
|
33
|
-
-frtti
|
|
34
|
-
-std=c++20
|
|
35
|
-
-Wall
|
|
36
|
-
)
|
|
28
|
+
target_compile_reactnative_options(react_codegen_RNBlueBreezeSpec PRIVATE)
|
|
@@ -150,7 +150,7 @@ NativeBlueBreezeSpecJSI::NativeBlueBreezeSpecJSI(const JavaTurboModule::InitPara
|
|
|
150
150
|
eventEmitterMap_["deviceMTUEmitter"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
|
|
151
151
|
eventEmitterMap_["deviceCharacteristicDataEmitter"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
|
|
152
152
|
eventEmitterMap_["deviceCharacteristicNotifyEnabledEmitter"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
|
|
153
|
-
|
|
153
|
+
configureEventEmitterCallback();
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
std::shared_ptr<TurboModule> RNBlueBreezeSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|