react-native-bluebreeze 1.0.2 → 1.1.0
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 +31 -4
- package/android/build.gradle +1 -1
- package/android/generated/java/com/bluebreeze/NativeBlueBreezeSpec.java +0 -8
- package/android/generated/jni/RNBlueBreezeSpec-generated.cpp +0 -7
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI.h +0 -78
- package/android/src/main/java/com/bluebreeze/BlueBreezeModule.kt +9 -41
- package/ios/BlueBreezeImpl.swift +10 -25
- package/ios/Bluebreeze.mm +0 -9
- package/ios/generated/ReactCodegen/RNBlueBreezeSpec/RNBlueBreezeSpec-generated.mm +0 -12
- package/ios/generated/ReactCodegen/RNBlueBreezeSpec/RNBlueBreezeSpec.h +0 -4
- package/ios/generated/ReactCodegen/RNBlueBreezeSpecJSI.h +0 -78
- package/lib/commonjs/NativeBlueBreeze.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_characteristic.js +5 -6
- package/lib/commonjs/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_observable.js +53 -0
- package/lib/commonjs/implementation/bluebreeze_observable.js.map +1 -0
- package/lib/commonjs/implementation/native_bridge.js +7 -20
- package/lib/commonjs/implementation/native_bridge.js.map +1 -1
- package/lib/commonjs/index.js +11 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeBlueBreeze.js.map +1 -1
- package/lib/module/implementation/bluebreeze_characteristic.js +6 -7
- package/lib/module/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/module/implementation/bluebreeze_observable.js +49 -0
- package/lib/module/implementation/bluebreeze_observable.js.map +1 -0
- package/lib/module/implementation/native_bridge.js +6 -18
- package/lib/module/implementation/native_bridge.js.map +1 -1
- package/lib/module/index.js +7 -6
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts +0 -8
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts +7 -7
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts +4 -4
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_observable.d.ts +32 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_observable.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts +6 -7
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +7 -6
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts +0 -8
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts +7 -7
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts +4 -4
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_observable.d.ts +32 -0
- package/lib/typescript/module/src/implementation/bluebreeze_observable.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/native_bridge.d.ts +6 -7
- package/lib/typescript/module/src/implementation/native_bridge.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +7 -6
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-bluebreeze.podspec +1 -1
- package/src/NativeBlueBreeze.ts +0 -11
- package/src/implementation/bluebreeze_characteristic.ts +8 -11
- package/src/implementation/bluebreeze_device.ts +4 -4
- package/src/implementation/bluebreeze_observable.ts +48 -0
- package/src/implementation/native_bridge.ts +20 -52
- package/src/index.tsx +7 -5
package/README.md
CHANGED
|
@@ -12,9 +12,11 @@ correlation, per-device request queuing -- happens natively; from JS you just ob
|
|
|
12
12
|
`await` operations.
|
|
13
13
|
|
|
14
14
|
- **Reactive state** -- adapter power, authorization, discovered devices, connection status,
|
|
15
|
-
services, and characteristic data are all exposed as
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
services, and characteristic data are all exposed as `BBObservable`s: read the current
|
|
16
|
+
`.value` synchronously, subscribe to `.values` (the current value, then new ones), or only to
|
|
17
|
+
`.updates`. Streams are
|
|
18
|
+
[`react-native-value-emitter`](https://github.com/like-magic-dev/react-native-value-emitter)
|
|
19
|
+
emitters you subscribe to with `.onValue(...)`.
|
|
18
20
|
- **Promise-based operations** -- connect, discover services, read, write, and
|
|
19
21
|
subscribe/unsubscribe are all `async` calls with a built-in timeout on both platforms; no
|
|
20
22
|
native callbacks to correlate yourself.
|
|
@@ -73,7 +75,7 @@ if (BlueBreeze.authorizationStatus.value !== 'authorized') {
|
|
|
73
75
|
BlueBreeze.authorizationRequest()
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
BlueBreeze.state.onValue((state) => {
|
|
78
|
+
BlueBreeze.state.values.onValue((state) => {
|
|
77
79
|
if (state === 'poweredOn') {
|
|
78
80
|
BlueBreeze.scanStart()
|
|
79
81
|
}
|
|
@@ -105,6 +107,31 @@ async function connectToFirstDevice() {
|
|
|
105
107
|
}
|
|
106
108
|
```
|
|
107
109
|
|
|
110
|
+
### Observing state
|
|
111
|
+
|
|
112
|
+
Every piece of state is a `BBObservable`, which you can query in three ways:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
characteristic.data.value // the current value
|
|
116
|
+
characteristic.data.values.onValue((data) => {}) // the current value, then new values
|
|
117
|
+
characteristic.data.updates.onValue((data) => {}) // only values that arrive from now on
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For example, to receive notifications:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const subscription = characteristic.data.updates.onValue((data) => {
|
|
124
|
+
console.log(characteristic.id, data)
|
|
125
|
+
})
|
|
126
|
+
await characteristic.subscribe()
|
|
127
|
+
|
|
128
|
+
// Later
|
|
129
|
+
subscription.remove()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
In React components, `useValueEmitter(handler, observable.values)` from
|
|
133
|
+
`react-native-value-emitter` removes the subscription automatically on unmount.
|
|
134
|
+
|
|
108
135
|
See [`example`](example) for a full app built on top of BlueBreeze.
|
|
109
136
|
|
|
110
137
|
## Documentation
|
package/android/build.gradle
CHANGED
|
@@ -107,7 +107,7 @@ dependencies {
|
|
|
107
107
|
implementation "com.facebook.react:react-android"
|
|
108
108
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
109
109
|
|
|
110
|
-
implementation "dev.likemagic:bluebreeze:1.0
|
|
110
|
+
implementation "dev.likemagic:bluebreeze:1.1.0"
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
if (isNewArchitectureEnabled()) {
|
|
@@ -76,10 +76,6 @@ public abstract class NativeBlueBreezeSpec extends ReactContextBaseJavaModule im
|
|
|
76
76
|
mEventEmitterCallback.invoke("deviceCharacteristicNotifyEnabledEmitter", value);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
protected final void emitDeviceCharacteristicNotificationsEmitter(ReadableMap value) {
|
|
80
|
-
mEventEmitterCallback.invoke("deviceCharacteristicNotificationsEmitter", value);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
79
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
84
80
|
@DoNotStrip
|
|
85
81
|
public abstract String state();
|
|
@@ -148,10 +144,6 @@ public abstract class NativeBlueBreezeSpec extends ReactContextBaseJavaModule im
|
|
|
148
144
|
@DoNotStrip
|
|
149
145
|
public abstract boolean deviceCharacteristicNotifyEnabled(String id, String serviceId, String characteristicId);
|
|
150
146
|
|
|
151
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
152
|
-
@DoNotStrip
|
|
153
|
-
public abstract WritableArray deviceCharacteristicNotifications(String id, String serviceId, String characteristicId);
|
|
154
|
-
|
|
155
147
|
@ReactMethod
|
|
156
148
|
@DoNotStrip
|
|
157
149
|
public abstract void deviceCharacteristicRead(String id, String serviceId, String characteristicId, Promise promise);
|
|
@@ -97,11 +97,6 @@ static facebook::jsi::Value __hostFunction_NativeBlueBreezeSpecJSI_deviceCharact
|
|
|
97
97
|
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, BooleanKind, "deviceCharacteristicNotifyEnabled", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", args, count, cachedMethodId);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
static facebook::jsi::Value __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicNotifications(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
101
|
-
static jmethodID cachedMethodId = nullptr;
|
|
102
|
-
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "deviceCharacteristicNotifications", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
100
|
static facebook::jsi::Value __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicRead(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
106
101
|
static jmethodID cachedMethodId = nullptr;
|
|
107
102
|
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "deviceCharacteristicRead", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
|
|
@@ -141,7 +136,6 @@ NativeBlueBreezeSpecJSI::NativeBlueBreezeSpecJSI(const JavaTurboModule::InitPara
|
|
|
141
136
|
methodMap_["deviceRequestMTU"] = MethodMetadata {2, __hostFunction_NativeBlueBreezeSpecJSI_deviceRequestMTU};
|
|
142
137
|
methodMap_["deviceCharacteristicData"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicData};
|
|
143
138
|
methodMap_["deviceCharacteristicNotifyEnabled"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicNotifyEnabled};
|
|
144
|
-
methodMap_["deviceCharacteristicNotifications"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicNotifications};
|
|
145
139
|
methodMap_["deviceCharacteristicRead"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicRead};
|
|
146
140
|
methodMap_["deviceCharacteristicWrite"] = MethodMetadata {5, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicWrite};
|
|
147
141
|
methodMap_["deviceCharacteristicSubscribe"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicSubscribe};
|
|
@@ -156,7 +150,6 @@ NativeBlueBreezeSpecJSI::NativeBlueBreezeSpecJSI(const JavaTurboModule::InitPara
|
|
|
156
150
|
eventEmitterMap_["deviceMTUEmitter"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
|
|
157
151
|
eventEmitterMap_["deviceCharacteristicDataEmitter"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
|
|
158
152
|
eventEmitterMap_["deviceCharacteristicNotifyEnabledEmitter"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
|
|
159
|
-
eventEmitterMap_["deviceCharacteristicNotificationsEmitter"] = std::make_shared<AsyncEventEmitter<folly::dynamic>>();
|
|
160
153
|
configureEventEmitterCallback();
|
|
161
154
|
}
|
|
162
155
|
|
package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI.h
CHANGED
|
@@ -74,65 +74,6 @@ struct NativeBlueBreezeBBDeviceCharacteristicDataEventBridging {
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
#pragma mark - NativeBlueBreezeBBDeviceCharacteristicNotificationsEvent
|
|
78
|
-
|
|
79
|
-
template <typename P0, typename P1, typename P2, typename P3>
|
|
80
|
-
struct NativeBlueBreezeBBDeviceCharacteristicNotificationsEvent {
|
|
81
|
-
P0 id{};
|
|
82
|
-
P1 serviceId{};
|
|
83
|
-
P2 characteristicId{};
|
|
84
|
-
P3 value;
|
|
85
|
-
bool operator==(const NativeBlueBreezeBBDeviceCharacteristicNotificationsEvent &other) const {
|
|
86
|
-
return id == other.id && serviceId == other.serviceId && characteristicId == other.characteristicId && value == other.value;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
template <typename T>
|
|
91
|
-
struct NativeBlueBreezeBBDeviceCharacteristicNotificationsEventBridging {
|
|
92
|
-
static T types;
|
|
93
|
-
|
|
94
|
-
static T fromJs(
|
|
95
|
-
jsi::Runtime &rt,
|
|
96
|
-
const jsi::Object &value,
|
|
97
|
-
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
98
|
-
T result{
|
|
99
|
-
bridging::fromJs<decltype(types.id)>(rt, value.getProperty(rt, "id"), jsInvoker),
|
|
100
|
-
bridging::fromJs<decltype(types.serviceId)>(rt, value.getProperty(rt, "serviceId"), jsInvoker),
|
|
101
|
-
bridging::fromJs<decltype(types.characteristicId)>(rt, value.getProperty(rt, "characteristicId"), jsInvoker),
|
|
102
|
-
bridging::fromJs<decltype(types.value)>(rt, value.getProperty(rt, "value"), jsInvoker)};
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
#ifdef DEBUG
|
|
107
|
-
static jsi::String idToJs(jsi::Runtime &rt, decltype(types.id) value) {
|
|
108
|
-
return bridging::toJs(rt, value);
|
|
109
|
-
}
|
|
110
|
-
static jsi::String serviceIdToJs(jsi::Runtime &rt, decltype(types.serviceId) value) {
|
|
111
|
-
return bridging::toJs(rt, value);
|
|
112
|
-
}
|
|
113
|
-
static jsi::String characteristicIdToJs(jsi::Runtime &rt, decltype(types.characteristicId) value) {
|
|
114
|
-
return bridging::toJs(rt, value);
|
|
115
|
-
}
|
|
116
|
-
static jsi::Array valueToJs(jsi::Runtime &rt, decltype(types.value) value) {
|
|
117
|
-
return bridging::toJs(rt, value);
|
|
118
|
-
}
|
|
119
|
-
#endif
|
|
120
|
-
|
|
121
|
-
static jsi::Object toJs(
|
|
122
|
-
jsi::Runtime &rt,
|
|
123
|
-
const T &value,
|
|
124
|
-
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
125
|
-
auto result = facebook::jsi::Object(rt);
|
|
126
|
-
result.setProperty(rt, "id", bridging::toJs(rt, value.id, jsInvoker));
|
|
127
|
-
result.setProperty(rt, "serviceId", bridging::toJs(rt, value.serviceId, jsInvoker));
|
|
128
|
-
result.setProperty(rt, "characteristicId", bridging::toJs(rt, value.characteristicId, jsInvoker));
|
|
129
|
-
result.setProperty(rt, "value", bridging::toJs(rt, value.value, jsInvoker));
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
77
|
#pragma mark - NativeBlueBreezeBBDeviceCharacteristicNotifyEnabledEvent
|
|
137
78
|
|
|
138
79
|
template <typename P0, typename P1, typename P2, typename P3>
|
|
@@ -606,7 +547,6 @@ protected:
|
|
|
606
547
|
methodMap_["deviceRequestMTU"] = MethodMetadata {.argCount = 2, .invoker = __deviceRequestMTU};
|
|
607
548
|
methodMap_["deviceCharacteristicData"] = MethodMetadata {.argCount = 3, .invoker = __deviceCharacteristicData};
|
|
608
549
|
methodMap_["deviceCharacteristicNotifyEnabled"] = MethodMetadata {.argCount = 3, .invoker = __deviceCharacteristicNotifyEnabled};
|
|
609
|
-
methodMap_["deviceCharacteristicNotifications"] = MethodMetadata {.argCount = 3, .invoker = __deviceCharacteristicNotifications};
|
|
610
550
|
methodMap_["deviceCharacteristicRead"] = MethodMetadata {.argCount = 3, .invoker = __deviceCharacteristicRead};
|
|
611
551
|
methodMap_["deviceCharacteristicWrite"] = MethodMetadata {.argCount = 5, .invoker = __deviceCharacteristicWrite};
|
|
612
552
|
methodMap_["deviceCharacteristicSubscribe"] = MethodMetadata {.argCount = 3, .invoker = __deviceCharacteristicSubscribe};
|
|
@@ -621,7 +561,6 @@ protected:
|
|
|
621
561
|
eventEmitterMap_["deviceMTUEmitter"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
|
|
622
562
|
eventEmitterMap_["deviceCharacteristicDataEmitter"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
|
|
623
563
|
eventEmitterMap_["deviceCharacteristicNotifyEnabledEmitter"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
|
|
624
|
-
eventEmitterMap_["deviceCharacteristicNotificationsEmitter"] = std::make_shared<AsyncEventEmitter<jsi::Value>>();
|
|
625
564
|
}
|
|
626
565
|
|
|
627
566
|
template <typename StateEmitterType> void emitStateEmitter(StateEmitterType value) {
|
|
@@ -693,13 +632,6 @@ protected:
|
|
|
693
632
|
return bridging::toJs(rt, eventValue, jsInvoker);
|
|
694
633
|
});
|
|
695
634
|
}
|
|
696
|
-
|
|
697
|
-
template <typename DeviceCharacteristicNotificationsEmitterType> void emitDeviceCharacteristicNotificationsEmitter(DeviceCharacteristicNotificationsEmitterType value) {
|
|
698
|
-
static_assert(bridging::supportsFromJs<DeviceCharacteristicNotificationsEmitterType, jsi::Object>, "value cannnot be converted to jsi::Object");
|
|
699
|
-
static_cast<AsyncEventEmitter<jsi::Value>&>(*eventEmitterMap_["deviceCharacteristicNotificationsEmitter"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value {
|
|
700
|
-
return bridging::toJs(rt, eventValue, jsInvoker);
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
635
|
private:
|
|
704
636
|
static jsi::Value __state(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) {
|
|
705
637
|
static_assert(
|
|
@@ -835,16 +767,6 @@ private:
|
|
|
835
767
|
count <= 2 ? throw jsi::JSError(rt, "Expected argument in position 2 to be passed") : args[2].asString(rt));
|
|
836
768
|
}
|
|
837
769
|
|
|
838
|
-
static jsi::Value __deviceCharacteristicNotifications(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
839
|
-
static_assert(
|
|
840
|
-
bridging::getParameterCount(&T::deviceCharacteristicNotifications) == 4,
|
|
841
|
-
"Expected deviceCharacteristicNotifications(...) to have 4 parameters");
|
|
842
|
-
return bridging::callFromJs<jsi::Array>(rt, &T::deviceCharacteristicNotifications, static_cast<NativeBlueBreezeCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
|
|
843
|
-
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
|
844
|
-
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt),
|
|
845
|
-
count <= 2 ? throw jsi::JSError(rt, "Expected argument in position 2 to be passed") : args[2].asString(rt));
|
|
846
|
-
}
|
|
847
|
-
|
|
848
770
|
static jsi::Value __deviceCharacteristicRead(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
849
771
|
static_assert(
|
|
850
772
|
bridging::getParameterCount(&T::deviceCharacteristicRead) == 4,
|
|
@@ -25,7 +25,6 @@ import kotlinx.coroutines.SupervisorJob
|
|
|
25
25
|
import kotlinx.coroutines.cancel
|
|
26
26
|
import kotlinx.coroutines.flow.Flow
|
|
27
27
|
import kotlinx.coroutines.flow.FlowCollector
|
|
28
|
-
import kotlinx.coroutines.flow.SharedFlow
|
|
29
28
|
import kotlinx.coroutines.launch
|
|
30
29
|
|
|
31
30
|
@ReactModule(name = BlueBreezeModule.NAME)
|
|
@@ -44,7 +43,6 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
44
43
|
// Per characteristic data and notification state subscriptions
|
|
45
44
|
val characteristicDataJobs = mutableMapOf<String, Job>()
|
|
46
45
|
val characteristicIsNotifyingJobs = mutableMapOf<String, Job>()
|
|
47
|
-
val characteristicNotificationsJobs = mutableMapOf<String, Job>()
|
|
48
46
|
|
|
49
47
|
fun cancelCharacteristics() {
|
|
50
48
|
characteristicDataJobs.values.forEach { it.cancel() }
|
|
@@ -52,9 +50,6 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
52
50
|
|
|
53
51
|
characteristicIsNotifyingJobs.values.forEach { it.cancel() }
|
|
54
52
|
characteristicIsNotifyingJobs.clear()
|
|
55
|
-
|
|
56
|
-
characteristicNotificationsJobs.values.forEach { it.cancel() }
|
|
57
|
-
characteristicNotificationsJobs.clear()
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
fun cancelAll() {
|
|
@@ -74,7 +69,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
74
69
|
|
|
75
70
|
// State
|
|
76
71
|
|
|
77
|
-
manager.state.collectAsync {
|
|
72
|
+
manager.state.values.collectAsync {
|
|
78
73
|
safeEmit {
|
|
79
74
|
emitStateEmitter(it.name)
|
|
80
75
|
}
|
|
@@ -82,7 +77,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
82
77
|
|
|
83
78
|
// Authorization
|
|
84
79
|
|
|
85
|
-
manager.authorizationStatus.collectAsync {
|
|
80
|
+
manager.authorizationStatus.values.collectAsync {
|
|
86
81
|
safeEmit {
|
|
87
82
|
emitAuthorizationStatusEmitter(it.toJs)
|
|
88
83
|
}
|
|
@@ -90,7 +85,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
90
85
|
|
|
91
86
|
// Scanning
|
|
92
87
|
|
|
93
|
-
manager.scanEnabled.collectAsync {
|
|
88
|
+
manager.scanEnabled.values.collectAsync {
|
|
94
89
|
safeEmit {
|
|
95
90
|
emitScanEnabledEmitter(it)
|
|
96
91
|
}
|
|
@@ -104,7 +99,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
104
99
|
|
|
105
100
|
// Devices
|
|
106
101
|
|
|
107
|
-
manager.devices.collectAsync { devices ->
|
|
102
|
+
manager.devices.values.collectAsync { devices ->
|
|
108
103
|
safeEmit {
|
|
109
104
|
emitDevicesEmitter(
|
|
110
105
|
devices.map { it.value.toJs }.writableArray
|
|
@@ -128,7 +123,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
128
123
|
private fun setupDeviceTracking(deviceId: String, device: BBDevice, tracking: DeviceTracking) {
|
|
129
124
|
if (tracking.deviceJobs.isNotEmpty()) return
|
|
130
125
|
|
|
131
|
-
tracking.deviceJobs += device.services.collectAsync { services ->
|
|
126
|
+
tracking.deviceJobs += device.services.values.collectAsync { services ->
|
|
132
127
|
safeEmit {
|
|
133
128
|
emitDeviceServicesEmitter(
|
|
134
129
|
writableMapOf(
|
|
@@ -141,7 +136,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
141
136
|
setupDeviceCharacteristics(deviceId, services, tracking)
|
|
142
137
|
}
|
|
143
138
|
|
|
144
|
-
tracking.deviceJobs += device.connectionStatus.collectAsync { value ->
|
|
139
|
+
tracking.deviceJobs += device.connectionStatus.values.collectAsync { value ->
|
|
145
140
|
safeEmit {
|
|
146
141
|
emitDeviceConnectionStatusEmitter(
|
|
147
142
|
writableMapOf(
|
|
@@ -152,7 +147,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
152
147
|
}
|
|
153
148
|
}
|
|
154
149
|
|
|
155
|
-
tracking.deviceJobs += device.mtu.collectAsync { value ->
|
|
150
|
+
tracking.deviceJobs += device.mtu.values.collectAsync { value ->
|
|
156
151
|
safeEmit {
|
|
157
152
|
emitDeviceMTUEmitter(
|
|
158
153
|
writableMapOf(
|
|
@@ -175,7 +170,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
175
170
|
val characteristicId = characteristic.uuid
|
|
176
171
|
val trackingKey = "${serviceId}:${characteristicId}"
|
|
177
172
|
|
|
178
|
-
tracking.characteristicDataJobs[trackingKey] = characteristic.data.collectAsync { value ->
|
|
173
|
+
tracking.characteristicDataJobs[trackingKey] = characteristic.data.values.collectAsync { value ->
|
|
179
174
|
safeEmit {
|
|
180
175
|
emitDeviceCharacteristicDataEmitter(
|
|
181
176
|
writableMapOf(
|
|
@@ -188,7 +183,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
188
183
|
}
|
|
189
184
|
}
|
|
190
185
|
|
|
191
|
-
tracking.characteristicIsNotifyingJobs[trackingKey] = characteristic.isNotifying.collectAsync { value ->
|
|
186
|
+
tracking.characteristicIsNotifyingJobs[trackingKey] = characteristic.isNotifying.values.collectAsync { value ->
|
|
192
187
|
safeEmit {
|
|
193
188
|
emitDeviceCharacteristicNotifyEnabledEmitter(
|
|
194
189
|
writableMapOf(
|
|
@@ -200,19 +195,6 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
200
195
|
)
|
|
201
196
|
}
|
|
202
197
|
}
|
|
203
|
-
|
|
204
|
-
tracking.characteristicNotificationsJobs[trackingKey] = characteristic.notifications.collectAsync { value ->
|
|
205
|
-
safeEmit {
|
|
206
|
-
emitDeviceCharacteristicNotificationsEmitter(
|
|
207
|
-
writableMapOf(
|
|
208
|
-
"id" to deviceId,
|
|
209
|
-
"serviceId" to serviceId.toJs,
|
|
210
|
-
"characteristicId" to characteristicId.toJs,
|
|
211
|
-
"value" to value.toJs
|
|
212
|
-
)
|
|
213
|
-
)
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
198
|
}
|
|
217
199
|
}
|
|
218
200
|
}
|
|
@@ -374,16 +356,6 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
374
356
|
return characteristic.isNotifying.value
|
|
375
357
|
}
|
|
376
358
|
|
|
377
|
-
// Device characteristic notifications
|
|
378
|
-
|
|
379
|
-
override fun deviceCharacteristicNotifications(
|
|
380
|
-
id: String?,
|
|
381
|
-
serviceId: String?,
|
|
382
|
-
characteristicId: String?
|
|
383
|
-
): WritableArray? {
|
|
384
|
-
return emptyWritableArray()
|
|
385
|
-
}
|
|
386
|
-
|
|
387
359
|
// Device characteristic operations
|
|
388
360
|
|
|
389
361
|
override fun deviceCharacteristicRead(
|
|
@@ -558,10 +530,6 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
558
530
|
collector: FlowCollector<T>,
|
|
559
531
|
): Job = moduleScope.launch { collect(collector) }
|
|
560
532
|
|
|
561
|
-
private fun <T> SharedFlow<T>.collectAsync(
|
|
562
|
-
collector: FlowCollector<T>,
|
|
563
|
-
): Job = moduleScope.launch { collect(collector) }
|
|
564
|
-
|
|
565
533
|
// Module name
|
|
566
534
|
|
|
567
535
|
override fun getName(): String {
|
package/ios/BlueBreezeImpl.swift
CHANGED
|
@@ -30,7 +30,6 @@ struct BlueBreezeError : Error {
|
|
|
30
30
|
var deviceMTUObserve: ((String, Int) -> Void)?
|
|
31
31
|
var deviceCharacteristicDataObserve: ((String, String, String, Array<UInt8>) -> Void)?
|
|
32
32
|
var deviceCharacteristicNotifyEnabledObserve: ((String, String, String, Bool) -> Void)?
|
|
33
|
-
var deviceCharacteristicNotificationsObserve: ((String, String, String, Array<UInt8>) -> Void)?
|
|
34
33
|
|
|
35
34
|
@objc public func subscribe(
|
|
36
35
|
stateObserve: (@escaping (String) -> Void),
|
|
@@ -42,8 +41,7 @@ struct BlueBreezeError : Error {
|
|
|
42
41
|
deviceServicesObserve: (@escaping (String, [[String: Any]]) -> Void),
|
|
43
42
|
deviceMTUObserve: (@escaping (String, Int) -> Void),
|
|
44
43
|
deviceCharacteristicDataObserve: (@escaping (String, String, String, Array<UInt8>) -> Void),
|
|
45
|
-
deviceCharacteristicNotifyEnabledObserve: (@escaping (String, String, String, Bool) -> Void)
|
|
46
|
-
deviceCharacteristicNotificationsObserve: (@escaping (String, String, String, Array<UInt8>) -> Void)
|
|
44
|
+
deviceCharacteristicNotifyEnabledObserve: (@escaping (String, String, String, Bool) -> Void)
|
|
47
45
|
) {
|
|
48
46
|
self.stateObserve = stateObserve
|
|
49
47
|
self.authorizationObserve = authorizationObserve
|
|
@@ -55,19 +53,18 @@ struct BlueBreezeError : Error {
|
|
|
55
53
|
self.deviceMTUObserve = deviceMTUObserve
|
|
56
54
|
self.deviceCharacteristicDataObserve = deviceCharacteristicDataObserve
|
|
57
55
|
self.deviceCharacteristicNotifyEnabledObserve = deviceCharacteristicNotifyEnabledObserve
|
|
58
|
-
self.deviceCharacteristicNotificationsObserve = deviceCharacteristicNotificationsObserve
|
|
59
56
|
|
|
60
|
-
manager.state
|
|
57
|
+
manager.state.values
|
|
61
58
|
.receive(on: DispatchQueue.main)
|
|
62
59
|
.sink { self.stateObserve?($0.toJs) }
|
|
63
60
|
.store(in: &disposeBag)
|
|
64
61
|
|
|
65
|
-
manager.authorizationStatus
|
|
62
|
+
manager.authorizationStatus.values
|
|
66
63
|
.receive(on: DispatchQueue.main)
|
|
67
64
|
.sink { self.authorizationObserve?($0.toJs) }
|
|
68
65
|
.store(in: &disposeBag)
|
|
69
66
|
|
|
70
|
-
manager.scanEnabled
|
|
67
|
+
manager.scanEnabled.values
|
|
71
68
|
.receive(on: DispatchQueue.main)
|
|
72
69
|
.sink { self.scanEnabledObserve?($0) }
|
|
73
70
|
.store(in: &disposeBag)
|
|
@@ -77,7 +74,7 @@ struct BlueBreezeError : Error {
|
|
|
77
74
|
.sink { self.scanResultsObserve?($0.toJs) }
|
|
78
75
|
.store(in: &disposeBag)
|
|
79
76
|
|
|
80
|
-
manager.devices
|
|
77
|
+
manager.devices.values
|
|
81
78
|
.receive(on: DispatchQueue.main)
|
|
82
79
|
.sink {
|
|
83
80
|
$0.forEach { (id, device) in
|
|
@@ -95,12 +92,12 @@ struct BlueBreezeError : Error {
|
|
|
95
92
|
|
|
96
93
|
disposeBagDevices[device.id] = []
|
|
97
94
|
|
|
98
|
-
device.connectionStatus
|
|
95
|
+
device.connectionStatus.values
|
|
99
96
|
.receive(on: DispatchQueue.main)
|
|
100
97
|
.sink { self.deviceConnectionStatusObserve?(device.id.toJs, $0.toJs) }
|
|
101
98
|
.store(in: &disposeBagDevices[device.id]!)
|
|
102
99
|
|
|
103
|
-
device.services
|
|
100
|
+
device.services.values
|
|
104
101
|
.receive(on: DispatchQueue.main)
|
|
105
102
|
.sink {
|
|
106
103
|
self.subscribeServices(device, $0)
|
|
@@ -108,7 +105,7 @@ struct BlueBreezeError : Error {
|
|
|
108
105
|
}
|
|
109
106
|
.store(in: &disposeBagDevices[device.id]!)
|
|
110
107
|
|
|
111
|
-
device.mtu
|
|
108
|
+
device.mtu.values
|
|
112
109
|
.receive(on: DispatchQueue.main)
|
|
113
110
|
.sink { self.deviceMTUObserve?(device.id.toJs, $0) }
|
|
114
111
|
.store(in: &disposeBagDevices[device.id]!)
|
|
@@ -139,7 +136,7 @@ struct BlueBreezeError : Error {
|
|
|
139
136
|
|
|
140
137
|
disposeBagServices[device.id]![serviceId]![characteristic.uuid] = []
|
|
141
138
|
|
|
142
|
-
characteristic.data
|
|
139
|
+
characteristic.data.values
|
|
143
140
|
.receive(on: DispatchQueue.main)
|
|
144
141
|
.sink {
|
|
145
142
|
self.deviceCharacteristicDataObserve?(
|
|
@@ -151,7 +148,7 @@ struct BlueBreezeError : Error {
|
|
|
151
148
|
}
|
|
152
149
|
.store(in: &disposeBagServices[device.id]![serviceId]![characteristic.uuid]!)
|
|
153
150
|
|
|
154
|
-
characteristic.isNotifying
|
|
151
|
+
characteristic.isNotifying.values
|
|
155
152
|
.receive(on: DispatchQueue.main)
|
|
156
153
|
.sink {
|
|
157
154
|
self.deviceCharacteristicNotifyEnabledObserve?(
|
|
@@ -162,18 +159,6 @@ struct BlueBreezeError : Error {
|
|
|
162
159
|
)
|
|
163
160
|
}
|
|
164
161
|
.store(in: &disposeBagServices[device.id]![serviceId]![characteristic.uuid]!)
|
|
165
|
-
|
|
166
|
-
characteristic.notifications
|
|
167
|
-
.receive(on: DispatchQueue.main)
|
|
168
|
-
.sink {
|
|
169
|
-
self.deviceCharacteristicNotificationsObserve?(
|
|
170
|
-
device.id.toJs,
|
|
171
|
-
serviceId.toJs,
|
|
172
|
-
characteristic.uuid.toJs,
|
|
173
|
-
$0.toJs
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
.store(in: &disposeBagServices[device.id]![serviceId]![characteristic.uuid]!)
|
|
177
162
|
}
|
|
178
163
|
}
|
|
179
164
|
}
|
package/ios/Bluebreeze.mm
CHANGED
|
@@ -83,15 +83,6 @@ typedef void (^EmitterCallback)();
|
|
|
83
83
|
@"value": [NSNumber numberWithBool:value]
|
|
84
84
|
}];
|
|
85
85
|
}];
|
|
86
|
-
} deviceCharacteristicNotificationsObserve:^(NSString * _Nonnull deviceId, NSString * _Nonnull serviceId, NSString * _Nonnull characteristicId, NSArray<NSNumber *> * _Nonnull value) {
|
|
87
|
-
[self wrapEventEmitter:^{
|
|
88
|
-
[self emitDeviceCharacteristicNotificationsEmitter:@{
|
|
89
|
-
@"id": deviceId,
|
|
90
|
-
@"serviceId": serviceId,
|
|
91
|
-
@"characteristicId": characteristicId,
|
|
92
|
-
@"value": value
|
|
93
|
-
}];
|
|
94
|
-
}];
|
|
95
86
|
}];
|
|
96
87
|
|
|
97
88
|
}
|
|
@@ -55,10 +55,6 @@
|
|
|
55
55
|
{
|
|
56
56
|
_eventEmitterCallback("deviceCharacteristicNotifyEnabledEmitter", value);
|
|
57
57
|
}
|
|
58
|
-
- (void)emitDeviceCharacteristicNotificationsEmitter:(NSDictionary *)value
|
|
59
|
-
{
|
|
60
|
-
_eventEmitterCallback("deviceCharacteristicNotificationsEmitter", value);
|
|
61
|
-
}
|
|
62
58
|
|
|
63
59
|
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper
|
|
64
60
|
{
|
|
@@ -137,10 +133,6 @@ namespace facebook::react {
|
|
|
137
133
|
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, BooleanKind, "deviceCharacteristicNotifyEnabled", @selector(deviceCharacteristicNotifyEnabled:serviceId:characteristicId:), args, count);
|
|
138
134
|
}
|
|
139
135
|
|
|
140
|
-
static facebook::jsi::Value __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicNotifications(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
141
|
-
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, ArrayKind, "deviceCharacteristicNotifications", @selector(deviceCharacteristicNotifications:serviceId:characteristicId:), args, count);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
136
|
static facebook::jsi::Value __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicRead(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
145
137
|
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "deviceCharacteristicRead", @selector(deviceCharacteristicRead:serviceId:characteristicId:resolve:reject:), args, count);
|
|
146
138
|
}
|
|
@@ -211,9 +203,6 @@ namespace facebook::react {
|
|
|
211
203
|
methodMap_["deviceCharacteristicNotifyEnabled"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicNotifyEnabled};
|
|
212
204
|
|
|
213
205
|
|
|
214
|
-
methodMap_["deviceCharacteristicNotifications"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicNotifications};
|
|
215
|
-
|
|
216
|
-
|
|
217
206
|
methodMap_["deviceCharacteristicRead"] = MethodMetadata {3, __hostFunction_NativeBlueBreezeSpecJSI_deviceCharacteristicRead};
|
|
218
207
|
|
|
219
208
|
|
|
@@ -235,7 +224,6 @@ namespace facebook::react {
|
|
|
235
224
|
eventEmitterMap_["deviceMTUEmitter"] = std::make_shared<AsyncEventEmitter<id>>();
|
|
236
225
|
eventEmitterMap_["deviceCharacteristicDataEmitter"] = std::make_shared<AsyncEventEmitter<id>>();
|
|
237
226
|
eventEmitterMap_["deviceCharacteristicNotifyEnabledEmitter"] = std::make_shared<AsyncEventEmitter<id>>();
|
|
238
|
-
eventEmitterMap_["deviceCharacteristicNotificationsEmitter"] = std::make_shared<AsyncEventEmitter<id>>();
|
|
239
227
|
setEventEmitterCallback([&](const std::string &name, id value) {
|
|
240
228
|
static_cast<AsyncEventEmitter<id> &>(*eventEmitterMap_[name]).emit(value);
|
|
241
229
|
});
|
|
@@ -65,9 +65,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
65
65
|
- (NSNumber *)deviceCharacteristicNotifyEnabled:(NSString *)id
|
|
66
66
|
serviceId:(NSString *)serviceId
|
|
67
67
|
characteristicId:(NSString *)characteristicId;
|
|
68
|
-
- (NSArray<NSNumber *> *)deviceCharacteristicNotifications:(NSString *)id
|
|
69
|
-
serviceId:(NSString *)serviceId
|
|
70
|
-
characteristicId:(NSString *)characteristicId;
|
|
71
68
|
- (void)deviceCharacteristicRead:(NSString *)id
|
|
72
69
|
serviceId:(NSString *)serviceId
|
|
73
70
|
characteristicId:(NSString *)characteristicId
|
|
@@ -109,7 +106,6 @@ facebook::react::EventEmitterCallback _eventEmitterCallback;
|
|
|
109
106
|
- (void)emitDeviceMTUEmitter:(NSDictionary *)value;
|
|
110
107
|
- (void)emitDeviceCharacteristicDataEmitter:(NSDictionary *)value;
|
|
111
108
|
- (void)emitDeviceCharacteristicNotifyEnabledEmitter:(NSDictionary *)value;
|
|
112
|
-
- (void)emitDeviceCharacteristicNotificationsEmitter:(NSDictionary *)value;
|
|
113
109
|
@end
|
|
114
110
|
|
|
115
111
|
namespace facebook::react {
|