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.
Files changed (96) hide show
  1. package/README.md +97 -13
  2. package/android/build.gradle +9 -3
  3. package/android/generated/jni/CMakeLists.txt +1 -9
  4. package/android/generated/jni/RNBlueBreezeSpec-generated.cpp +1 -1
  5. package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI.h +234 -279
  6. package/android/src/main/java/com/bluebreeze/BlueBreezeModule.kt +140 -120
  7. package/ios/BlueBreezeImpl.swift +30 -24
  8. package/ios/Bluebreeze.h +1 -1
  9. package/ios/Bluebreeze.mm +2 -7
  10. package/ios/generated/{RNBlueBreezeSpecJSI.h → ReactCodegen/RNBlueBreezeSpecJSI.h} +234 -279
  11. package/lib/commonjs/implementation/bluebreeze_characteristic.js +42 -11
  12. package/lib/commonjs/implementation/bluebreeze_characteristic.js.map +1 -1
  13. package/lib/commonjs/implementation/bluebreeze_connection_status.js +2 -0
  14. package/lib/commonjs/implementation/bluebreeze_connection_status.js.map +1 -0
  15. package/lib/commonjs/implementation/bluebreeze_device.js +53 -13
  16. package/lib/commonjs/implementation/bluebreeze_device.js.map +1 -1
  17. package/lib/commonjs/implementation/bluebreeze_scan_result.js +19 -0
  18. package/lib/commonjs/implementation/bluebreeze_scan_result.js.map +1 -1
  19. package/lib/commonjs/implementation/bluebreeze_service.js +9 -0
  20. package/lib/commonjs/implementation/bluebreeze_service.js.map +1 -1
  21. package/lib/commonjs/implementation/native_bridge.js +108 -0
  22. package/lib/commonjs/implementation/native_bridge.js.map +1 -0
  23. package/lib/commonjs/index.js +29 -100
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/package.json +1 -0
  26. package/lib/module/implementation/bluebreeze_characteristic.js +43 -10
  27. package/lib/module/implementation/bluebreeze_characteristic.js.map +1 -1
  28. package/lib/module/implementation/bluebreeze_connection_status.js +2 -0
  29. package/lib/module/implementation/bluebreeze_connection_status.js.map +1 -0
  30. package/lib/module/implementation/bluebreeze_device.js +54 -12
  31. package/lib/module/implementation/bluebreeze_device.js.map +1 -1
  32. package/lib/module/implementation/bluebreeze_scan_result.js +19 -0
  33. package/lib/module/implementation/bluebreeze_scan_result.js.map +1 -1
  34. package/lib/module/implementation/bluebreeze_service.js +9 -0
  35. package/lib/module/implementation/bluebreeze_service.js.map +1 -1
  36. package/lib/module/implementation/native_bridge.js +99 -0
  37. package/lib/module/implementation/native_bridge.js.map +1 -0
  38. package/lib/module/index.js +29 -100
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/package.json +1 -0
  41. package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts +1 -1
  42. package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/src/implementation/bluebreeze_authorization.d.ts +10 -1
  44. package/lib/typescript/commonjs/src/implementation/bluebreeze_authorization.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts +29 -0
  46. package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/src/implementation/bluebreeze_connection_status.d.ts +7 -0
  48. package/lib/typescript/commonjs/src/implementation/bluebreeze_connection_status.d.ts.map +1 -0
  49. package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts +42 -1
  50. package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts.map +1 -1
  51. package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts +11 -0
  52. package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts +6 -0
  54. package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/src/implementation/bluebreeze_state.d.ts +16 -1
  56. package/lib/typescript/commonjs/src/implementation/bluebreeze_state.d.ts.map +1 -1
  57. package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts +17 -0
  58. package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts.map +1 -0
  59. package/lib/typescript/commonjs/src/index.d.ts +0 -13
  60. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  61. package/lib/typescript/module/src/NativeBlueBreeze.d.ts +1 -1
  62. package/lib/typescript/module/src/NativeBlueBreeze.d.ts.map +1 -1
  63. package/lib/typescript/module/src/implementation/bluebreeze_authorization.d.ts +10 -1
  64. package/lib/typescript/module/src/implementation/bluebreeze_authorization.d.ts.map +1 -1
  65. package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts +29 -0
  66. package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
  67. package/lib/typescript/module/src/implementation/bluebreeze_connection_status.d.ts +7 -0
  68. package/lib/typescript/module/src/implementation/bluebreeze_connection_status.d.ts.map +1 -0
  69. package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts +43 -2
  70. package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts.map +1 -1
  71. package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts +12 -1
  72. package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts.map +1 -1
  73. package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts +7 -1
  74. package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts.map +1 -1
  75. package/lib/typescript/module/src/implementation/bluebreeze_state.d.ts +16 -1
  76. package/lib/typescript/module/src/implementation/bluebreeze_state.d.ts.map +1 -1
  77. package/lib/typescript/module/src/implementation/native_bridge.d.ts +17 -0
  78. package/lib/typescript/module/src/implementation/native_bridge.d.ts.map +1 -0
  79. package/lib/typescript/module/src/index.d.ts +6 -19
  80. package/lib/typescript/module/src/index.d.ts.map +1 -1
  81. package/package.json +13 -23
  82. package/react-native-bluebreeze.podspec +1 -1
  83. package/src/NativeBlueBreeze.ts +1 -1
  84. package/src/implementation/bluebreeze_authorization.ts +10 -1
  85. package/src/implementation/bluebreeze_characteristic.ts +48 -10
  86. package/src/implementation/bluebreeze_connection_status.ts +6 -0
  87. package/src/implementation/bluebreeze_device.ts +62 -13
  88. package/src/implementation/bluebreeze_scan_result.ts +18 -0
  89. package/src/implementation/bluebreeze_service.ts +8 -0
  90. package/src/implementation/bluebreeze_state.ts +16 -1
  91. package/src/implementation/native_bridge.ts +196 -0
  92. package/src/index.tsx +24 -202
  93. package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI-generated.cpp +0 -179
  94. package/ios/generated/RNBlueBreezeSpecJSI-generated.cpp +0 -179
  95. /package/ios/generated/{RNBlueBreezeSpec → ReactCodegen/RNBlueBreezeSpec}/RNBlueBreezeSpec-generated.mm +0 -0
  96. /package/ios/generated/{RNBlueBreezeSpec → ReactCodegen/RNBlueBreezeSpec}/RNBlueBreezeSpec.h +0 -0
package/README.md CHANGED
@@ -1,6 +1,31 @@
1
- # react-native-bluebreeze
1
+ # BlueBreeze React Native
2
2
 
3
- BlueBreeze bindings for React Native. A modern Bluetooth LE library.
3
+ [![npm version](https://img.shields.io/npm/v/react-native-bluebreeze.svg)](https://www.npmjs.com/package/react-native-bluebreeze)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+ [![Platform](https://img.shields.io/badge/platform-iOS%20%7C%20Android-lightgrey.svg)](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
- ## Usage
36
+ iOS additionally requires a pod install:
37
+
38
+ ```sh
39
+ cd ios && pod install
40
+ ```
12
41
 
42
+ ## Requirements
13
43
 
14
- ```js
15
- import { multiply } from 'react-native-bluebreeze';
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
- const result = multiply(3, 7);
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
- ## Contributing
66
+ ## Quick start
24
67
 
25
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
68
+ ```tsx
69
+ import BlueBreeze from 'react-native-bluebreeze'
26
70
 
27
- ## License
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
- MIT
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
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
117
+ BlueBreeze is available under the MIT license. See [LICENSE](LICENSE) for details.
@@ -9,7 +9,7 @@ buildscript {
9
9
  }
10
10
 
11
11
  dependencies {
12
- classpath "com.android.tools.build:gradle:8.7.2"
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
- apply plugin: "kotlin-android"
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:0.0.14"
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
- target_compile_options(
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
- setEventEmitterCallback(params.instance);
153
+ configureEventEmitterCallback();
154
154
  }
155
155
 
156
156
  std::shared_ptr<TurboModule> RNBlueBreezeSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {