react-native-ble-nitro 1.4.0 → 1.5.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 +17 -13
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +81 -7
- package/ios/BleNitroBleManager.swift +30 -4
- package/ios/BlePeripheralDelegate.swift +29 -6
- package/lib/commonjs/manager.d.ts +11 -5
- package/lib/commonjs/manager.d.ts.map +1 -1
- package/lib/commonjs/manager.js +33 -9
- package/lib/commonjs/manager.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +4 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
- package/lib/manager.d.ts +11 -5
- package/lib/manager.js +33 -9
- package/lib/specs/NativeBleNitro.nitro.d.ts +4 -1
- package/nitrogen/generated/android/BleNitroOnLoad.cpp +2 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool_double_std__string.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +8 -3
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_bool_double_std__string.kt +81 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +11 -2
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +22 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +7 -1
- package/nitrogen/generated/ios/swift/Func_void_bool_double_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +21 -5
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +2 -1
- package/package.json +1 -1
- package/src/__tests__/index.test.ts +105 -1
- package/src/manager.ts +39 -11
- package/src/specs/NativeBleNitro.nitro.ts +4 -1
package/lib/manager.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare enum AndroidScanMode {
|
|
|
45
45
|
Opportunistic = "Opportunistic"
|
|
46
46
|
}
|
|
47
47
|
export type BleNitroManagerOptions = {
|
|
48
|
-
|
|
48
|
+
onRestoredState?: RestoreStateCallback;
|
|
49
49
|
};
|
|
50
50
|
export declare function mapNativeBLEStateToBLEState(nativeState: NativeBLEState): BLEState;
|
|
51
51
|
export declare function mapAndroidScanModeToNativeAndroidScanMode(scanMode: AndroidScanMode): NativeAndroidScanMode;
|
|
@@ -55,11 +55,11 @@ export declare function byteArrayToArrayBuffer(data: ByteArray): ArrayBuffer;
|
|
|
55
55
|
export declare class BleNitroManager {
|
|
56
56
|
private _isScanning;
|
|
57
57
|
private _connectedDevices;
|
|
58
|
-
private
|
|
58
|
+
private _restoredStateCallback;
|
|
59
59
|
private _restoredState;
|
|
60
60
|
constructor(options?: BleNitroManagerOptions);
|
|
61
61
|
private onNativeRestoreStateCallback;
|
|
62
|
-
|
|
62
|
+
onRestoredState(callback: RestoreStateCallback): void;
|
|
63
63
|
/**
|
|
64
64
|
* Converts a 16- oder 32-Bit UUID to a 128-Bit UUID
|
|
65
65
|
*
|
|
@@ -117,6 +117,12 @@ export declare class BleNitroManager {
|
|
|
117
117
|
* @returns On Android: new MTU size; on iOS: current MTU size as it is handled by iOS itself; on error: -1
|
|
118
118
|
*/
|
|
119
119
|
requestMTU(deviceId: string, mtu: number): number;
|
|
120
|
+
/**
|
|
121
|
+
* Read RSSI for a connected device
|
|
122
|
+
* @param deviceId ID of the device
|
|
123
|
+
* @returns Promise resolving to RSSI value
|
|
124
|
+
*/
|
|
125
|
+
readRSSI(deviceId: string): Promise<number>;
|
|
120
126
|
/**
|
|
121
127
|
* Discover services for a connected device
|
|
122
128
|
* @param deviceId ID of the device
|
|
@@ -151,9 +157,9 @@ export declare class BleNitroManager {
|
|
|
151
157
|
* @param characteristicId ID of the characteristic
|
|
152
158
|
* @param data Data to write as ByteArray (number[])
|
|
153
159
|
* @param withResponse Whether to wait for response
|
|
154
|
-
* @returns Promise resolving
|
|
160
|
+
* @returns Promise resolving with response data (empty ByteArray when withResponse=false)
|
|
155
161
|
*/
|
|
156
|
-
writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: ByteArray, withResponse?: boolean): Promise<
|
|
162
|
+
writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: ByteArray, withResponse?: boolean): Promise<ByteArray>;
|
|
157
163
|
/**
|
|
158
164
|
* Subscribe to characteristic notifications
|
|
159
165
|
* @param deviceId ID of the device
|
package/lib/manager.js
CHANGED
|
@@ -59,26 +59,26 @@ export class BleNitroManager {
|
|
|
59
59
|
constructor(options) {
|
|
60
60
|
this._isScanning = false;
|
|
61
61
|
this._connectedDevices = {};
|
|
62
|
-
this.
|
|
62
|
+
this._restoredStateCallback = null;
|
|
63
63
|
this._restoredState = null;
|
|
64
|
-
this.
|
|
64
|
+
this._restoredStateCallback = options?.onRestoredState || null;
|
|
65
65
|
BleNitroNative.setRestoreStateCallback((peripherals) => this.onNativeRestoreStateCallback(peripherals));
|
|
66
66
|
}
|
|
67
67
|
onNativeRestoreStateCallback(peripherals) {
|
|
68
68
|
const bleDevices = peripherals.map((peripheral) => convertNativeBleDeviceToBleDevice(peripheral));
|
|
69
|
-
if (this.
|
|
70
|
-
this.
|
|
69
|
+
if (this._restoredStateCallback) {
|
|
70
|
+
this._restoredStateCallback(bleDevices);
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
73
|
this._restoredState = bleDevices;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
onRestoredState(callback) {
|
|
77
77
|
if (this._restoredState) {
|
|
78
78
|
callback(this._restoredState);
|
|
79
79
|
this._restoredState = null;
|
|
80
80
|
}
|
|
81
|
-
this.
|
|
81
|
+
this._restoredStateCallback = callback;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Converts a 16- oder 32-Bit UUID to a 128-Bit UUID
|
|
@@ -232,6 +232,28 @@ export class BleNitroManager {
|
|
|
232
232
|
const deviceMtu = BleNitroNative.requestMTU(deviceId, mtu);
|
|
233
233
|
return deviceMtu;
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Read RSSI for a connected device
|
|
237
|
+
* @param deviceId ID of the device
|
|
238
|
+
* @returns Promise resolving to RSSI value
|
|
239
|
+
*/
|
|
240
|
+
readRSSI(deviceId) {
|
|
241
|
+
return new Promise((resolve, reject) => {
|
|
242
|
+
// Check if connected first
|
|
243
|
+
if (!this._connectedDevices[deviceId]) {
|
|
244
|
+
reject(new Error('Device not connected'));
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
BleNitroNative.readRSSI(deviceId, (success, rssi, error) => {
|
|
248
|
+
if (success) {
|
|
249
|
+
resolve(rssi);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
reject(new Error(error));
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
}
|
|
235
257
|
/**
|
|
236
258
|
* Discover services for a connected device
|
|
237
259
|
* @param deviceId ID of the device
|
|
@@ -319,7 +341,7 @@ export class BleNitroManager {
|
|
|
319
341
|
* @param characteristicId ID of the characteristic
|
|
320
342
|
* @param data Data to write as ByteArray (number[])
|
|
321
343
|
* @param withResponse Whether to wait for response
|
|
322
|
-
* @returns Promise resolving
|
|
344
|
+
* @returns Promise resolving with response data (empty ByteArray when withResponse=false)
|
|
323
345
|
*/
|
|
324
346
|
writeCharacteristic(deviceId, serviceId, characteristicId, data, withResponse = true) {
|
|
325
347
|
return new Promise((resolve, reject) => {
|
|
@@ -328,9 +350,11 @@ export class BleNitroManager {
|
|
|
328
350
|
reject(new Error('Device not connected'));
|
|
329
351
|
return;
|
|
330
352
|
}
|
|
331
|
-
BleNitroNative.writeCharacteristic(deviceId, BleNitroManager.normalizeGattUUID(serviceId), BleNitroManager.normalizeGattUUID(characteristicId), byteArrayToArrayBuffer(data), withResponse, (success, error) => {
|
|
353
|
+
BleNitroNative.writeCharacteristic(deviceId, BleNitroManager.normalizeGattUUID(serviceId), BleNitroManager.normalizeGattUUID(characteristicId), byteArrayToArrayBuffer(data), withResponse, (success, responseData, error) => {
|
|
332
354
|
if (success) {
|
|
333
|
-
|
|
355
|
+
// Convert ArrayBuffer response to ByteArray
|
|
356
|
+
const responseByteArray = arrayBufferToByteArray(responseData);
|
|
357
|
+
resolve(responseByteArray);
|
|
334
358
|
}
|
|
335
359
|
else {
|
|
336
360
|
reject(new Error(error));
|
|
@@ -45,6 +45,8 @@ export type StateCallback = (state: BLEState) => void;
|
|
|
45
45
|
export type BooleanCallback = (result: boolean) => void;
|
|
46
46
|
export type StringArrayCallback = (result: string[]) => void;
|
|
47
47
|
export type ReadCharacteristicCallback = (success: boolean, data: BLEValue, error: string) => void;
|
|
48
|
+
export type WriteCharacteristicCallback = (success: boolean, responseData: BLEValue, error: string) => void;
|
|
49
|
+
export type ReadRSSICallback = (success: boolean, rssi: number, error: string) => void;
|
|
48
50
|
export type RestoreCallback = (restoredPeripherals: BLEDevice[]) => void;
|
|
49
51
|
export type OperationResult = {
|
|
50
52
|
success: boolean;
|
|
@@ -67,11 +69,12 @@ export interface NativeBleNitro extends HybridObject<{
|
|
|
67
69
|
disconnect(deviceId: string, callback: OperationCallback): void;
|
|
68
70
|
isConnected(deviceId: string): boolean;
|
|
69
71
|
requestMTU(deviceId: string, mtu: number): number;
|
|
72
|
+
readRSSI(deviceId: string, callback: ReadRSSICallback): void;
|
|
70
73
|
discoverServices(deviceId: string, callback: OperationCallback): void;
|
|
71
74
|
getServices(deviceId: string): string[];
|
|
72
75
|
getCharacteristics(deviceId: string, serviceId: string): string[];
|
|
73
76
|
readCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: ReadCharacteristicCallback): void;
|
|
74
|
-
writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: BLEValue, withResponse: boolean, callback:
|
|
77
|
+
writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: BLEValue, withResponse: boolean, callback: WriteCharacteristicCallback): void;
|
|
75
78
|
subscribeToCharacteristic(deviceId: string, serviceId: string, characteristicId: string, updateCallback: CharacteristicCallback, resultCallback: OperationCallback): void;
|
|
76
79
|
unsubscribeFromCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: OperationCallback): void;
|
|
77
80
|
requestBluetoothEnable(callback: OperationCallback): void;
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
#include "JFunc_void_bool_std__string_std__string.hpp"
|
|
22
22
|
#include "JFunc_void_std__string_bool_std__string.hpp"
|
|
23
23
|
#include "JFunc_void_bool_std__string.hpp"
|
|
24
|
+
#include "JFunc_void_bool_double_std__string.hpp"
|
|
24
25
|
#include "JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp"
|
|
25
26
|
#include "JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp"
|
|
26
27
|
#include "JFunc_void_BLEState.hpp"
|
|
@@ -41,6 +42,7 @@ int initialize(JavaVM* vm) {
|
|
|
41
42
|
margelo::nitro::co::zyke::ble::JFunc_void_bool_std__string_std__string_cxx::registerNatives();
|
|
42
43
|
margelo::nitro::co::zyke::ble::JFunc_void_std__string_bool_std__string_cxx::registerNatives();
|
|
43
44
|
margelo::nitro::co::zyke::ble::JFunc_void_bool_std__string_cxx::registerNatives();
|
|
45
|
+
margelo::nitro::co::zyke::ble::JFunc_void_bool_double_std__string_cxx::registerNatives();
|
|
44
46
|
margelo::nitro::co::zyke::ble::JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::registerNatives();
|
|
45
47
|
margelo::nitro::co::zyke::ble::JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx::registerNatives();
|
|
46
48
|
margelo::nitro::co::zyke::ble::JFunc_void_BLEState_cxx::registerNatives();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_bool_double_std__string.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include <functional>
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <functional>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::co::zyke::ble {
|
|
17
|
+
|
|
18
|
+
using namespace facebook;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents the Java/Kotlin callback `(success: Boolean, rssi: Double, error: String) -> Unit`.
|
|
22
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
23
|
+
*/
|
|
24
|
+
struct JFunc_void_bool_double_std__string: public jni::JavaClass<JFunc_void_bool_double_std__string> {
|
|
25
|
+
public:
|
|
26
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool_double_std__string;";
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
/**
|
|
30
|
+
* Invokes the function this `JFunc_void_bool_double_std__string` instance holds through JNI.
|
|
31
|
+
*/
|
|
32
|
+
void invoke(bool success, double rssi, const std::string& error) const {
|
|
33
|
+
static const auto method = javaClassStatic()->getMethod<void(jboolean /* success */, double /* rssi */, jni::alias_ref<jni::JString> /* error */)>("invoke");
|
|
34
|
+
method(self(), success, rssi, jni::make_jstring(error));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* An implementation of Func_void_bool_double_std__string that is backed by a C++ implementation (using `std::function<...>`)
|
|
40
|
+
*/
|
|
41
|
+
struct JFunc_void_bool_double_std__string_cxx final: public jni::HybridClass<JFunc_void_bool_double_std__string_cxx, JFunc_void_bool_double_std__string> {
|
|
42
|
+
public:
|
|
43
|
+
static jni::local_ref<JFunc_void_bool_double_std__string::javaobject> fromCpp(const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& func) {
|
|
44
|
+
return JFunc_void_bool_double_std__string_cxx::newObjectCxxArgs(func);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
/**
|
|
49
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_bool_double_std__string_cxx` instance holds.
|
|
50
|
+
*/
|
|
51
|
+
void invoke_cxx(jboolean success, double rssi, jni::alias_ref<jni::JString> error) {
|
|
52
|
+
_func(static_cast<bool>(success), rssi, error->toStdString());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
[[nodiscard]]
|
|
57
|
+
inline const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& getFunction() const {
|
|
58
|
+
return _func;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool_double_std__string_cxx;";
|
|
63
|
+
static void registerNatives() {
|
|
64
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_bool_double_std__string_cxx::invoke_cxx)});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private:
|
|
68
|
+
explicit JFunc_void_bool_double_std__string_cxx(const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& func): _func(func) { }
|
|
69
|
+
|
|
70
|
+
private:
|
|
71
|
+
friend HybridBase;
|
|
72
|
+
std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)> _func;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -52,6 +52,7 @@ namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
|
|
|
52
52
|
#include "JFunc_void_bool_std__string_std__string.hpp"
|
|
53
53
|
#include "JFunc_void_std__string_bool_std__string.hpp"
|
|
54
54
|
#include "JFunc_void_bool_std__string.hpp"
|
|
55
|
+
#include "JFunc_void_bool_double_std__string.hpp"
|
|
55
56
|
#include "JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp"
|
|
56
57
|
#include "JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp"
|
|
57
58
|
#include "JFunc_void_BLEState.hpp"
|
|
@@ -140,6 +141,10 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
140
141
|
auto __result = method(_javaPart, jni::make_jstring(deviceId), mtu);
|
|
141
142
|
return __result;
|
|
142
143
|
}
|
|
144
|
+
void JHybridNativeBleNitroSpec::readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) {
|
|
145
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_double_std__string::javaobject> /* callback */)>("readRSSI_cxx");
|
|
146
|
+
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_double_std__string_cxx::fromCpp(callback));
|
|
147
|
+
}
|
|
143
148
|
void JHybridNativeBleNitroSpec::discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) {
|
|
144
149
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("discoverServices_cxx");
|
|
145
150
|
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_std__string_cxx::fromCpp(callback));
|
|
@@ -176,9 +181,9 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
176
181
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string::javaobject> /* callback */)>("readCharacteristic_cxx");
|
|
177
182
|
method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::fromCpp(callback));
|
|
178
183
|
}
|
|
179
|
-
void JHybridNativeBleNitroSpec::writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) {
|
|
180
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JArrayBuffer::javaobject> /* data */, jboolean /* withResponse */, jni::alias_ref<
|
|
181
|
-
method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JArrayBuffer::wrap(data), withResponse,
|
|
184
|
+
void JHybridNativeBleNitroSpec::writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* responseData */, const std::string& /* error */)>& callback) {
|
|
185
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JArrayBuffer::javaobject> /* data */, jboolean /* withResponse */, jni::alias_ref<JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string::javaobject> /* callback */)>("writeCharacteristic_cxx");
|
|
186
|
+
method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JArrayBuffer::wrap(data), withResponse, JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::fromCpp(callback));
|
|
182
187
|
}
|
|
183
188
|
void JHybridNativeBleNitroSpec::subscribeToCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)>& updateCallback, const std::function<void(bool /* success */, const std::string& /* error */)>& resultCallback) {
|
|
184
189
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JFunc_void_std__string_std__shared_ptr_ArrayBuffer_::javaobject> /* updateCallback */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* resultCallback */)>("subscribeToCharacteristic_cxx");
|
|
@@ -62,11 +62,12 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
62
62
|
void disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
|
|
63
63
|
bool isConnected(const std::string& deviceId) override;
|
|
64
64
|
double requestMTU(const std::string& deviceId, double mtu) override;
|
|
65
|
+
void readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) override;
|
|
65
66
|
void discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
|
|
66
67
|
std::vector<std::string> getServices(const std::string& deviceId) override;
|
|
67
68
|
std::vector<std::string> getCharacteristics(const std::string& deviceId, const std::string& serviceId) override;
|
|
68
69
|
void readCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)>& callback) override;
|
|
69
|
-
void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
|
|
70
|
+
void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* responseData */, const std::string& /* error */)>& callback) override;
|
|
70
71
|
void subscribeToCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)>& updateCallback, const std::function<void(bool /* success */, const std::string& /* error */)>& resultCallback) override;
|
|
71
72
|
void unsubscribeFromCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
|
|
72
73
|
void requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_bool_double_std__string.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.co.zyke.ble
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.*
|
|
14
|
+
import dalvik.annotation.optimization.FastNative
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Represents the JavaScript callback `(success: boolean, rssi: number, error: string) => void`.
|
|
19
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
20
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
21
|
+
*/
|
|
22
|
+
@DoNotStrip
|
|
23
|
+
@Keep
|
|
24
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
25
|
+
fun interface Func_void_bool_double_std__string: (Boolean, Double, String) -> Unit {
|
|
26
|
+
/**
|
|
27
|
+
* Call the given JS callback.
|
|
28
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
29
|
+
*/
|
|
30
|
+
@DoNotStrip
|
|
31
|
+
@Keep
|
|
32
|
+
override fun invoke(success: Boolean, rssi: Double, error: String): Unit
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Represents the JavaScript callback `(success: boolean, rssi: number, error: string) => void`.
|
|
37
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
38
|
+
* The callback might be coming from JS.
|
|
39
|
+
*/
|
|
40
|
+
@DoNotStrip
|
|
41
|
+
@Keep
|
|
42
|
+
@Suppress(
|
|
43
|
+
"KotlinJniMissingFunction", "unused",
|
|
44
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
45
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
46
|
+
)
|
|
47
|
+
class Func_void_bool_double_std__string_cxx: Func_void_bool_double_std__string {
|
|
48
|
+
@DoNotStrip
|
|
49
|
+
@Keep
|
|
50
|
+
private val mHybridData: HybridData
|
|
51
|
+
|
|
52
|
+
@DoNotStrip
|
|
53
|
+
@Keep
|
|
54
|
+
private constructor(hybridData: HybridData) {
|
|
55
|
+
mHybridData = hybridData
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@DoNotStrip
|
|
59
|
+
@Keep
|
|
60
|
+
override fun invoke(success: Boolean, rssi: Double, error: String): Unit
|
|
61
|
+
= invoke_cxx(success,rssi,error)
|
|
62
|
+
|
|
63
|
+
@FastNative
|
|
64
|
+
private external fun invoke_cxx(success: Boolean, rssi: Double, error: String): Unit
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Represents the JavaScript callback `(success: boolean, rssi: number, error: string) => void`.
|
|
69
|
+
* This is implemented in Java/Kotlin, via a `(Boolean, Double, String) -> Unit`.
|
|
70
|
+
* The callback is always coming from native.
|
|
71
|
+
*/
|
|
72
|
+
@DoNotStrip
|
|
73
|
+
@Keep
|
|
74
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
75
|
+
class Func_void_bool_double_std__string_java(private val function: (Boolean, Double, String) -> Unit): Func_void_bool_double_std__string {
|
|
76
|
+
@DoNotStrip
|
|
77
|
+
@Keep
|
|
78
|
+
override fun invoke(success: Boolean, rssi: Double, error: String): Unit {
|
|
79
|
+
return this.function(success, rssi, error)
|
|
80
|
+
}
|
|
81
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt
CHANGED
|
@@ -96,6 +96,15 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
|
|
|
96
96
|
@Keep
|
|
97
97
|
abstract fun requestMTU(deviceId: String, mtu: Double): Double
|
|
98
98
|
|
|
99
|
+
abstract fun readRSSI(deviceId: String, callback: (success: Boolean, rssi: Double, error: String) -> Unit): Unit
|
|
100
|
+
|
|
101
|
+
@DoNotStrip
|
|
102
|
+
@Keep
|
|
103
|
+
private fun readRSSI_cxx(deviceId: String, callback: Func_void_bool_double_std__string): Unit {
|
|
104
|
+
val __result = readRSSI(deviceId, callback)
|
|
105
|
+
return __result
|
|
106
|
+
}
|
|
107
|
+
|
|
99
108
|
abstract fun discoverServices(deviceId: String, callback: (success: Boolean, error: String) -> Unit): Unit
|
|
100
109
|
|
|
101
110
|
@DoNotStrip
|
|
@@ -122,11 +131,11 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
|
|
|
122
131
|
return __result
|
|
123
132
|
}
|
|
124
133
|
|
|
125
|
-
abstract fun writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback: (success: Boolean, error: String) -> Unit): Unit
|
|
134
|
+
abstract fun writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback: (success: Boolean, responseData: ArrayBuffer, error: String) -> Unit): Unit
|
|
126
135
|
|
|
127
136
|
@DoNotStrip
|
|
128
137
|
@Keep
|
|
129
|
-
private fun writeCharacteristic_cxx(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback:
|
|
138
|
+
private fun writeCharacteristic_cxx(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback: Func_void_bool_std__shared_ptr_ArrayBuffer__std__string): Unit {
|
|
130
139
|
val __result = writeCharacteristic(deviceId, serviceId, characteristicId, data, withResponse, callback)
|
|
131
140
|
return __result
|
|
132
141
|
}
|
|
@@ -53,6 +53,14 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// pragma MARK: std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>
|
|
57
|
+
Func_void_bool_double_std__string create_Func_void_bool_double_std__string(void* _Nonnull swiftClosureWrapper) {
|
|
58
|
+
auto swiftClosure = BleNitro::Func_void_bool_double_std__string::fromUnsafe(swiftClosureWrapper);
|
|
59
|
+
return [swiftClosure = std::move(swiftClosure)](bool success, double rssi, const std::string& error) mutable -> void {
|
|
60
|
+
swiftClosure.call(success, rssi, error);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
// pragma MARK: std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)>
|
|
57
65
|
Func_void_bool_std__shared_ptr_ArrayBuffer__std__string create_Func_void_bool_std__shared_ptr_ArrayBuffer__std__string(void* _Nonnull swiftClosureWrapper) {
|
|
58
66
|
auto swiftClosure = BleNitro::Func_void_bool_std__shared_ptr_ArrayBuffer__std__string::fromUnsafe(swiftClosureWrapper);
|
|
@@ -224,6 +224,28 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
|
|
|
224
224
|
return Func_void_bool_std__string_Wrapper(std::move(value));
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
// pragma MARK: std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>
|
|
228
|
+
/**
|
|
229
|
+
* Specialized version of `std::function<void(bool, double, const std::string&)>`.
|
|
230
|
+
*/
|
|
231
|
+
using Func_void_bool_double_std__string = std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>;
|
|
232
|
+
/**
|
|
233
|
+
* Wrapper class for a `std::function<void(bool / * success * /, double / * rssi * /, const std::string& / * error * /)>`, this can be used from Swift.
|
|
234
|
+
*/
|
|
235
|
+
class Func_void_bool_double_std__string_Wrapper final {
|
|
236
|
+
public:
|
|
237
|
+
explicit Func_void_bool_double_std__string_Wrapper(std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>&& func): _function(std::make_unique<std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>>(std::move(func))) {}
|
|
238
|
+
inline void call(bool success, double rssi, std::string error) const {
|
|
239
|
+
_function->operator()(success, rssi, error);
|
|
240
|
+
}
|
|
241
|
+
private:
|
|
242
|
+
std::unique_ptr<std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>> _function;
|
|
243
|
+
} SWIFT_NONCOPYABLE;
|
|
244
|
+
Func_void_bool_double_std__string create_Func_void_bool_double_std__string(void* _Nonnull swiftClosureWrapper);
|
|
245
|
+
inline Func_void_bool_double_std__string_Wrapper wrap_Func_void_bool_double_std__string(Func_void_bool_double_std__string value) {
|
|
246
|
+
return Func_void_bool_double_std__string_Wrapper(std::move(value));
|
|
247
|
+
}
|
|
248
|
+
|
|
227
249
|
// pragma MARK: std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)>
|
|
228
250
|
/**
|
|
229
251
|
* Specialized version of `std::function<void(bool, const std::shared_ptr<ArrayBuffer>&, const std::string&)>`.
|
|
@@ -151,6 +151,12 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
151
151
|
auto __value = std::move(__result.value());
|
|
152
152
|
return __value;
|
|
153
153
|
}
|
|
154
|
+
inline void readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) override {
|
|
155
|
+
auto __result = _swiftPart.readRSSI(deviceId, callback);
|
|
156
|
+
if (__result.hasError()) [[unlikely]] {
|
|
157
|
+
std::rethrow_exception(__result.error());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
154
160
|
inline void discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override {
|
|
155
161
|
auto __result = _swiftPart.discoverServices(deviceId, callback);
|
|
156
162
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -179,7 +185,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
179
185
|
std::rethrow_exception(__result.error());
|
|
180
186
|
}
|
|
181
187
|
}
|
|
182
|
-
inline void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override {
|
|
188
|
+
inline void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* responseData */, const std::string& /* error */)>& callback) override {
|
|
183
189
|
auto __result = _swiftPart.writeCharacteristic(deviceId, serviceId, characteristicId, ArrayBufferHolder(data), std::forward<decltype(withResponse)>(withResponse), callback);
|
|
184
190
|
if (__result.hasError()) [[unlikely]] {
|
|
185
191
|
std::rethrow_exception(__result.error());
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_bool_double_std__string.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ success: Bool, _ rssi: Double, _ error: String) -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void_bool_double_std__string {
|
|
16
|
+
public typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ success: Bool, _ rssi: Double, _ error: String) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ success: Bool, _ rssi: Double, _ error: String) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(success: Bool, rssi: Double, error: std.string) -> Void {
|
|
26
|
+
self.closure(success, rssi, String(error))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
31
|
+
* This acquires one additional strong reference on the object!
|
|
32
|
+
*/
|
|
33
|
+
@inline(__always)
|
|
34
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
35
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Casts an unsafe pointer to a `Func_void_bool_double_std__string`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_bool_double_std__string>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_bool_double_std__string {
|
|
45
|
+
return Unmanaged<Func_void_bool_double_std__string>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -23,11 +23,12 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
|
|
|
23
23
|
func disconnect(deviceId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
|
|
24
24
|
func isConnected(deviceId: String) throws -> Bool
|
|
25
25
|
func requestMTU(deviceId: String, mtu: Double) throws -> Double
|
|
26
|
+
func readRSSI(deviceId: String, callback: @escaping (_ success: Bool, _ rssi: Double, _ error: String) -> Void) throws -> Void
|
|
26
27
|
func discoverServices(deviceId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
|
|
27
28
|
func getServices(deviceId: String) throws -> [String]
|
|
28
29
|
func getCharacteristics(deviceId: String, serviceId: String) throws -> [String]
|
|
29
30
|
func readCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ data: ArrayBuffer, _ error: String) -> Void) throws -> Void
|
|
30
|
-
func writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Bool, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
|
|
31
|
+
func writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Bool, callback: @escaping (_ success: Bool, _ responseData: ArrayBuffer, _ error: String) -> Void) throws -> Void
|
|
31
32
|
func subscribeToCharacteristic(deviceId: String, serviceId: String, characteristicId: String, updateCallback: @escaping (_ characteristicId: String, _ data: ArrayBuffer) -> Void, resultCallback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
|
|
32
33
|
func unsubscribeFromCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
|
|
33
34
|
func requestBluetoothEnable(callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
|
|
@@ -268,6 +268,22 @@ open class HybridNativeBleNitroSpec_cxx {
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
@inline(__always)
|
|
272
|
+
public final func readRSSI(deviceId: std.string, callback: bridge.Func_void_bool_double_std__string) -> bridge.Result_void_ {
|
|
273
|
+
do {
|
|
274
|
+
try self.__implementation.readRSSI(deviceId: String(deviceId), callback: { () -> (Bool, Double, String) -> Void in
|
|
275
|
+
let __wrappedFunction = bridge.wrap_Func_void_bool_double_std__string(callback)
|
|
276
|
+
return { (__success: Bool, __rssi: Double, __error: String) -> Void in
|
|
277
|
+
__wrappedFunction.call(__success, __rssi, std.string(__error))
|
|
278
|
+
}
|
|
279
|
+
}())
|
|
280
|
+
return bridge.create_Result_void_()
|
|
281
|
+
} catch (let __error) {
|
|
282
|
+
let __exceptionPtr = __error.toCpp()
|
|
283
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
271
287
|
@inline(__always)
|
|
272
288
|
public final func discoverServices(deviceId: std.string, callback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
|
|
273
289
|
do {
|
|
@@ -337,12 +353,12 @@ open class HybridNativeBleNitroSpec_cxx {
|
|
|
337
353
|
}
|
|
338
354
|
|
|
339
355
|
@inline(__always)
|
|
340
|
-
public final func writeCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, data: ArrayBuffer, withResponse: Bool, callback: bridge.
|
|
356
|
+
public final func writeCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, data: ArrayBuffer, withResponse: Bool, callback: bridge.Func_void_bool_std__shared_ptr_ArrayBuffer__std__string) -> bridge.Result_void_ {
|
|
341
357
|
do {
|
|
342
|
-
try self.__implementation.writeCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), data: data, withResponse: withResponse, callback: { () -> (Bool, String) -> Void in
|
|
343
|
-
let __wrappedFunction = bridge.
|
|
344
|
-
return { (__success: Bool, __error: String) -> Void in
|
|
345
|
-
__wrappedFunction.call(__success, std.string(__error))
|
|
358
|
+
try self.__implementation.writeCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), data: data, withResponse: withResponse, callback: { () -> (Bool, ArrayBuffer, String) -> Void in
|
|
359
|
+
let __wrappedFunction = bridge.wrap_Func_void_bool_std__shared_ptr_ArrayBuffer__std__string(callback)
|
|
360
|
+
return { (__success: Bool, __responseData: ArrayBuffer, __error: String) -> Void in
|
|
361
|
+
__wrappedFunction.call(__success, __responseData, std.string(__error))
|
|
346
362
|
}
|
|
347
363
|
}())
|
|
348
364
|
return bridge.create_Result_void_()
|
|
@@ -23,6 +23,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
23
23
|
prototype.registerHybridMethod("disconnect", &HybridNativeBleNitroSpec::disconnect);
|
|
24
24
|
prototype.registerHybridMethod("isConnected", &HybridNativeBleNitroSpec::isConnected);
|
|
25
25
|
prototype.registerHybridMethod("requestMTU", &HybridNativeBleNitroSpec::requestMTU);
|
|
26
|
+
prototype.registerHybridMethod("readRSSI", &HybridNativeBleNitroSpec::readRSSI);
|
|
26
27
|
prototype.registerHybridMethod("discoverServices", &HybridNativeBleNitroSpec::discoverServices);
|
|
27
28
|
prototype.registerHybridMethod("getServices", &HybridNativeBleNitroSpec::getServices);
|
|
28
29
|
prototype.registerHybridMethod("getCharacteristics", &HybridNativeBleNitroSpec::getCharacteristics);
|
|
@@ -75,11 +75,12 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
75
75
|
virtual void disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|
|
76
76
|
virtual bool isConnected(const std::string& deviceId) = 0;
|
|
77
77
|
virtual double requestMTU(const std::string& deviceId, double mtu) = 0;
|
|
78
|
+
virtual void readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) = 0;
|
|
78
79
|
virtual void discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|
|
79
80
|
virtual std::vector<std::string> getServices(const std::string& deviceId) = 0;
|
|
80
81
|
virtual std::vector<std::string> getCharacteristics(const std::string& deviceId, const std::string& serviceId) = 0;
|
|
81
82
|
virtual void readCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)>& callback) = 0;
|
|
82
|
-
virtual void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|
|
83
|
+
virtual void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* responseData */, const std::string& /* error */)>& callback) = 0;
|
|
83
84
|
virtual void subscribeToCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)>& updateCallback, const std::function<void(bool /* success */, const std::string& /* error */)>& resultCallback) = 0;
|
|
84
85
|
virtual void unsubscribeFromCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|
|
85
86
|
virtual void requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|