react-native-ble-nitro 1.1.0 → 1.2.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 +6 -2
- package/ios/BleNitroBleManager.swift +49 -14
- package/ios/BlePeripheralDelegate.swift +36 -8
- package/lib/commonjs/index.d.ts +15 -8
- package/lib/commonjs/index.d.ts.map +1 -1
- package/lib/commonjs/index.js +44 -11
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +6 -4
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
- package/lib/index.d.ts +15 -8
- package/lib/index.js +44 -11
- package/lib/specs/NativeBleNitro.nitro.d.ts +6 -4
- package/nitrogen/generated/android/BleNitroOnLoad.cpp +4 -4
- package/nitrogen/generated/android/c++/JBLEDevice.hpp +3 -0
- package/nitrogen/generated/android/c++/JFunc_void_BLEDevice.hpp +3 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp +78 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp +78 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +21 -16
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +4 -3
- package/nitrogen/generated/android/c++/JManufacturerData.hpp +3 -0
- package/nitrogen/generated/android/c++/JManufacturerDataEntry.hpp +7 -15
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/{Func_void_bool_std__vector_double__std__string.kt → Func_void_bool_std__shared_ptr_ArrayBuffer__std__string.kt} +12 -12
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/{Func_void_std__string_std__vector_double_.kt → Func_void_std__string_std__shared_ptr_ArrayBuffer_.kt} +12 -12
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +10 -6
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ManufacturerDataEntry.kt +1 -1
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +10 -10
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +39 -35
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +18 -4
- package/nitrogen/generated/ios/swift/{Func_void_bool_std__vector_double__std__string.swift → Func_void_bool_std__shared_ptr_ArrayBuffer__std__string.swift} +11 -11
- package/nitrogen/generated/ios/swift/{Func_void_std__string_std__vector_double_.swift → Func_void_std__string_std__shared_ptr_ArrayBuffer_.swift} +11 -11
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +4 -3
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +24 -24
- package/nitrogen/generated/ios/swift/ManufacturerDataEntry.swift +5 -17
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +7 -3
- package/nitrogen/generated/shared/c++/ManufacturerDataEntry.hpp +8 -7
- package/package.json +1 -1
- package/react-native.config.js +10 -2
- package/src/index.ts +56 -17
- package/src/specs/NativeBleNitro.nitro.ts +8 -4
- package/nitrogen/generated/android/c++/JFunc_void_bool_std__vector_double__std__string.hpp +0 -86
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__vector_double_.hpp +0 -86
|
@@ -21,6 +21,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
21
21
|
prototype.registerHybridMethod("connect", &HybridNativeBleNitroSpec::connect);
|
|
22
22
|
prototype.registerHybridMethod("disconnect", &HybridNativeBleNitroSpec::disconnect);
|
|
23
23
|
prototype.registerHybridMethod("isConnected", &HybridNativeBleNitroSpec::isConnected);
|
|
24
|
+
prototype.registerHybridMethod("requestMTU", &HybridNativeBleNitroSpec::requestMTU);
|
|
24
25
|
prototype.registerHybridMethod("discoverServices", &HybridNativeBleNitroSpec::discoverServices);
|
|
25
26
|
prototype.registerHybridMethod("getServices", &HybridNativeBleNitroSpec::getServices);
|
|
26
27
|
prototype.registerHybridMethod("getCharacteristics", &HybridNativeBleNitroSpec::getCharacteristics);
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
|
|
18
18
|
// Forward declaration of `BLEDevice` to properly resolve imports.
|
|
19
19
|
namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
|
|
20
|
+
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
21
|
+
namespace NitroModules { class ArrayBuffer; }
|
|
20
22
|
// Forward declaration of `BLEState` to properly resolve imports.
|
|
21
23
|
namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
|
|
22
24
|
// Forward declaration of `OperationResult` to properly resolve imports.
|
|
@@ -28,6 +30,7 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
|
|
|
28
30
|
#include <vector>
|
|
29
31
|
#include <string>
|
|
30
32
|
#include <optional>
|
|
33
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
31
34
|
#include "BLEState.hpp"
|
|
32
35
|
#include "OperationResult.hpp"
|
|
33
36
|
#include <NitroModules/Promise.hpp>
|
|
@@ -70,12 +73,13 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
70
73
|
virtual void connect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* deviceId */, const std::string& /* error */)>& callback, const std::optional<std::function<void(const std::string& /* deviceId */, bool /* interrupted */, const std::string& /* error */)>>& disconnectCallback) = 0;
|
|
71
74
|
virtual void disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|
|
72
75
|
virtual bool isConnected(const std::string& deviceId) = 0;
|
|
76
|
+
virtual double requestMTU(const std::string& deviceId, double mtu) = 0;
|
|
73
77
|
virtual void discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|
|
74
78
|
virtual std::vector<std::string> getServices(const std::string& deviceId) = 0;
|
|
75
79
|
virtual std::vector<std::string> getCharacteristics(const std::string& deviceId, const std::string& serviceId) = 0;
|
|
76
|
-
virtual void readCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::
|
|
77
|
-
virtual void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::
|
|
78
|
-
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::
|
|
80
|
+
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;
|
|
81
|
+
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;
|
|
82
|
+
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;
|
|
79
83
|
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;
|
|
80
84
|
virtual void requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
|
|
81
85
|
virtual BLEState state() = 0;
|
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
19
|
#endif
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
22
|
+
namespace NitroModules { class ArrayBuffer; }
|
|
22
23
|
|
|
23
24
|
#include <string>
|
|
24
|
-
#include <
|
|
25
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
25
26
|
|
|
26
27
|
namespace margelo::nitro::co::zyke::ble {
|
|
27
28
|
|
|
@@ -31,11 +32,11 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
31
32
|
struct ManufacturerDataEntry {
|
|
32
33
|
public:
|
|
33
34
|
std::string id SWIFT_PRIVATE;
|
|
34
|
-
std::
|
|
35
|
+
std::shared_ptr<ArrayBuffer> data SWIFT_PRIVATE;
|
|
35
36
|
|
|
36
37
|
public:
|
|
37
38
|
ManufacturerDataEntry() = default;
|
|
38
|
-
explicit ManufacturerDataEntry(std::string id, std::
|
|
39
|
+
explicit ManufacturerDataEntry(std::string id, std::shared_ptr<ArrayBuffer> data): id(id), data(data) {}
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -49,13 +50,13 @@ namespace margelo::nitro {
|
|
|
49
50
|
jsi::Object obj = arg.asObject(runtime);
|
|
50
51
|
return margelo::nitro::co::zyke::ble::ManufacturerDataEntry(
|
|
51
52
|
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "id")),
|
|
52
|
-
JSIConverter<std::
|
|
53
|
+
JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, "data"))
|
|
53
54
|
);
|
|
54
55
|
}
|
|
55
56
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::co::zyke::ble::ManufacturerDataEntry& arg) {
|
|
56
57
|
jsi::Object obj(runtime);
|
|
57
58
|
obj.setProperty(runtime, "id", JSIConverter<std::string>::toJSI(runtime, arg.id));
|
|
58
|
-
obj.setProperty(runtime, "data", JSIConverter<std::
|
|
59
|
+
obj.setProperty(runtime, "data", JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.data));
|
|
59
60
|
return obj;
|
|
60
61
|
}
|
|
61
62
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -64,7 +65,7 @@ namespace margelo::nitro {
|
|
|
64
65
|
}
|
|
65
66
|
jsi::Object obj = value.getObject(runtime);
|
|
66
67
|
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "id"))) return false;
|
|
67
|
-
if (!JSIConverter<std::
|
|
68
|
+
if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, "data"))) return false;
|
|
68
69
|
return true;
|
|
69
70
|
}
|
|
70
71
|
};
|
package/package.json
CHANGED
package/react-native.config.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
// https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
dependency: {
|
|
3
5
|
platforms: {
|
|
4
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @type {import('@react-native-community/cli-types').IOSDependencyParams}
|
|
8
|
+
*/
|
|
5
9
|
ios: {},
|
|
10
|
+
/**
|
|
11
|
+
* @type {import('@react-native-community/cli-types').AndroidDependencyParams}
|
|
12
|
+
*/
|
|
13
|
+
android: {},
|
|
6
14
|
},
|
|
7
15
|
},
|
|
8
|
-
}
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
BLEState as NativeBLEState,
|
|
6
6
|
} from './specs/NativeBleNitro';
|
|
7
7
|
|
|
8
|
+
export type ByteArray = number[];
|
|
9
|
+
|
|
8
10
|
export interface ScanFilter {
|
|
9
11
|
serviceUUIDs?: string[];
|
|
10
12
|
rssiThreshold?: number;
|
|
@@ -13,7 +15,7 @@ export interface ScanFilter {
|
|
|
13
15
|
|
|
14
16
|
export interface ManufacturerDataEntry {
|
|
15
17
|
id: string;
|
|
16
|
-
data:
|
|
18
|
+
data: ByteArray;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export interface ManufacturerData {
|
|
@@ -43,7 +45,7 @@ export type DisconnectEventCallback = (
|
|
|
43
45
|
export type OperationCallback = (success: boolean, error: string) => void;
|
|
44
46
|
export type CharacteristicUpdateCallback = (
|
|
45
47
|
characteristicId: string,
|
|
46
|
-
data:
|
|
48
|
+
data: ByteArray
|
|
47
49
|
) => void;
|
|
48
50
|
|
|
49
51
|
export type Subscription = {
|
|
@@ -71,6 +73,14 @@ function mapNativeBLEStateToBLEState(nativeState: NativeBLEState): BLEState {
|
|
|
71
73
|
return map[nativeState];
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
function arrayBufferToByteArray(buffer: ArrayBuffer): ByteArray {
|
|
77
|
+
return Array.from(new Uint8Array(buffer));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function byteArrayToArrayBuffer(data: ByteArray): ArrayBuffer {
|
|
81
|
+
return new Uint8Array(data).buffer;
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
let _instance: BleNitro;
|
|
75
85
|
|
|
76
86
|
export class BleNitro {
|
|
@@ -131,8 +141,18 @@ export class BleNitro {
|
|
|
131
141
|
|
|
132
142
|
// Create callback wrapper
|
|
133
143
|
const scanCallback = (device: NativeBLEDevice) => {
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
// Convert manufacturer data to Uint8Arrays
|
|
145
|
+
const convertedDevice: BLEDevice = {
|
|
146
|
+
...device,
|
|
147
|
+
serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs),
|
|
148
|
+
manufacturerData: {
|
|
149
|
+
companyIdentifiers: device.manufacturerData.companyIdentifiers.map(entry => ({
|
|
150
|
+
id: entry.id,
|
|
151
|
+
data: arrayBufferToByteArray(entry.data)
|
|
152
|
+
}))
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
callback(convertedDevice);
|
|
136
156
|
};
|
|
137
157
|
|
|
138
158
|
// Start scan
|
|
@@ -168,10 +188,16 @@ export class BleNitro {
|
|
|
168
188
|
*/
|
|
169
189
|
public getConnectedDevices(services?: string[]): BLEDevice[] {
|
|
170
190
|
const devices = BleNitroNative.getConnectedDevices(services || []);
|
|
171
|
-
// Normalize service UUIDs
|
|
191
|
+
// Normalize service UUIDs - manufacturer data already comes as ArrayBuffers
|
|
172
192
|
return devices.map(device => ({
|
|
173
193
|
...device,
|
|
174
|
-
serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs)
|
|
194
|
+
serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs),
|
|
195
|
+
manufacturerData: {
|
|
196
|
+
companyIdentifiers: device.manufacturerData.companyIdentifiers.map(entry => ({
|
|
197
|
+
id: entry.id,
|
|
198
|
+
data: arrayBufferToByteArray(entry.data)
|
|
199
|
+
}))
|
|
200
|
+
}
|
|
175
201
|
}));
|
|
176
202
|
}
|
|
177
203
|
|
|
@@ -247,6 +273,18 @@ export class BleNitro {
|
|
|
247
273
|
return BleNitroNative.isConnected(deviceId);
|
|
248
274
|
}
|
|
249
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Request a new MTU size
|
|
278
|
+
* @param deviceId ID of the device
|
|
279
|
+
* @param mtu New MTU size, min is 23, max is 517
|
|
280
|
+
* @returns On Android: new MTU size; on iOS: current MTU size as it is handled by iOS itself; on error: -1
|
|
281
|
+
*/
|
|
282
|
+
public requestMTU(deviceId: string, mtu: number): number {
|
|
283
|
+
mtu = parseInt(mtu.toString(), 10);
|
|
284
|
+
const deviceMtu = BleNitroNative.requestMTU(deviceId, mtu);
|
|
285
|
+
return deviceMtu;
|
|
286
|
+
}
|
|
287
|
+
|
|
250
288
|
/**
|
|
251
289
|
* Discover services for a connected device
|
|
252
290
|
* @param deviceId ID of the device
|
|
@@ -322,13 +360,13 @@ export class BleNitro {
|
|
|
322
360
|
* @param deviceId ID of the device
|
|
323
361
|
* @param serviceId ID of the service
|
|
324
362
|
* @param characteristicId ID of the characteristic
|
|
325
|
-
* @returns Promise resolving to the characteristic data as
|
|
363
|
+
* @returns Promise resolving to the characteristic data as ByteArray
|
|
326
364
|
*/
|
|
327
365
|
public readCharacteristic(
|
|
328
366
|
deviceId: string,
|
|
329
367
|
serviceId: string,
|
|
330
368
|
characteristicId: string
|
|
331
|
-
): Promise<
|
|
369
|
+
): Promise<ByteArray> {
|
|
332
370
|
return new Promise((resolve, reject) => {
|
|
333
371
|
// Check if connected first
|
|
334
372
|
if (!this._connectedDevices[deviceId]) {
|
|
@@ -340,9 +378,9 @@ export class BleNitro {
|
|
|
340
378
|
deviceId,
|
|
341
379
|
BleNitro.normalizeGattUUID(serviceId),
|
|
342
380
|
BleNitro.normalizeGattUUID(characteristicId),
|
|
343
|
-
(success: boolean, data:
|
|
381
|
+
(success: boolean, data: ArrayBuffer, error: string) => {
|
|
344
382
|
if (success) {
|
|
345
|
-
resolve(data);
|
|
383
|
+
resolve(arrayBufferToByteArray(data));
|
|
346
384
|
} else {
|
|
347
385
|
reject(new Error(error));
|
|
348
386
|
}
|
|
@@ -356,7 +394,7 @@ export class BleNitro {
|
|
|
356
394
|
* @param deviceId ID of the device
|
|
357
395
|
* @param serviceId ID of the service
|
|
358
396
|
* @param characteristicId ID of the characteristic
|
|
359
|
-
* @param data Data to write as
|
|
397
|
+
* @param data Data to write as ByteArray(number[])
|
|
360
398
|
* @param withResponse Whether to wait for response
|
|
361
399
|
* @returns Promise resolving when write is complete
|
|
362
400
|
*/
|
|
@@ -364,7 +402,7 @@ export class BleNitro {
|
|
|
364
402
|
deviceId: string,
|
|
365
403
|
serviceId: string,
|
|
366
404
|
characteristicId: string,
|
|
367
|
-
data:
|
|
405
|
+
data: ByteArray,
|
|
368
406
|
withResponse: boolean = true
|
|
369
407
|
): Promise<boolean> {
|
|
370
408
|
return new Promise((resolve, reject) => {
|
|
@@ -374,11 +412,13 @@ export class BleNitro {
|
|
|
374
412
|
return;
|
|
375
413
|
}
|
|
376
414
|
|
|
415
|
+
const dataAsArrayBuffer = byteArrayToArrayBuffer(data);
|
|
416
|
+
|
|
377
417
|
BleNitroNative.writeCharacteristic(
|
|
378
418
|
deviceId,
|
|
379
419
|
BleNitro.normalizeGattUUID(serviceId),
|
|
380
420
|
BleNitro.normalizeGattUUID(characteristicId),
|
|
381
|
-
|
|
421
|
+
dataAsArrayBuffer,
|
|
382
422
|
withResponse,
|
|
383
423
|
(success: boolean, error: string) => {
|
|
384
424
|
if (success) {
|
|
@@ -416,8 +456,8 @@ export class BleNitro {
|
|
|
416
456
|
deviceId,
|
|
417
457
|
BleNitro.normalizeGattUUID(serviceId),
|
|
418
458
|
BleNitro.normalizeGattUUID(characteristicId),
|
|
419
|
-
(charId: string, data:
|
|
420
|
-
callback(charId, data);
|
|
459
|
+
(charId: string, data: ArrayBuffer) => {
|
|
460
|
+
callback(charId, arrayBufferToByteArray(data));
|
|
421
461
|
},
|
|
422
462
|
(success, error) => {
|
|
423
463
|
_success = success;
|
|
@@ -484,8 +524,7 @@ export class BleNitro {
|
|
|
484
524
|
}
|
|
485
525
|
|
|
486
526
|
/**
|
|
487
|
-
* Request to enable Bluetooth
|
|
488
|
-
* Only works on Android
|
|
527
|
+
* Request to enable Bluetooth (Android only)
|
|
489
528
|
* @returns Promise resolving when Bluetooth is enabled
|
|
490
529
|
*/
|
|
491
530
|
public requestBluetoothEnable(): Promise<boolean> {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { HybridObject } from 'react-native-nitro-modules';
|
|
2
2
|
|
|
3
|
+
// Type alias for BLE data - ArrayBuffers for efficient binary data handling
|
|
4
|
+
export type BLEValue = ArrayBuffer;
|
|
5
|
+
|
|
3
6
|
// Nitro constraint: Use numeric enums instead of string unions
|
|
4
7
|
export enum BLEState {
|
|
5
8
|
Unknown = 0,
|
|
@@ -12,7 +15,7 @@ export enum BLEState {
|
|
|
12
15
|
|
|
13
16
|
export interface ManufacturerDataEntry {
|
|
14
17
|
id: string;
|
|
15
|
-
data:
|
|
18
|
+
data: BLEValue;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
export interface ManufacturerData {
|
|
@@ -39,11 +42,11 @@ export type DevicesCallback = (devices: BLEDevice[]) => void;
|
|
|
39
42
|
export type ConnectionCallback = (success: boolean, deviceId: string, error: string) => void;
|
|
40
43
|
export type DisconnectionEventCallback = (deviceId: string, interrupted: boolean, error: string) => void;
|
|
41
44
|
export type OperationCallback = (success: boolean, error: string) => void;
|
|
42
|
-
export type CharacteristicCallback = (characteristicId: string, data:
|
|
45
|
+
export type CharacteristicCallback = (characteristicId: string, data: BLEValue) => void;
|
|
43
46
|
export type StateCallback = (state: BLEState) => void;
|
|
44
47
|
export type BooleanCallback = (result: boolean) => void;
|
|
45
48
|
export type StringArrayCallback = (result: string[]) => void;
|
|
46
|
-
export type ReadCharacteristicCallback = (success: boolean, data:
|
|
49
|
+
export type ReadCharacteristicCallback = (success: boolean, data: BLEValue, error: string) => void;
|
|
47
50
|
|
|
48
51
|
export type OperationResult = {
|
|
49
52
|
success: boolean;
|
|
@@ -67,6 +70,7 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
|
|
|
67
70
|
connect(deviceId: string, callback: ConnectionCallback, disconnectCallback?: DisconnectionEventCallback): void;
|
|
68
71
|
disconnect(deviceId: string, callback: OperationCallback): void;
|
|
69
72
|
isConnected(deviceId: string): boolean;
|
|
73
|
+
requestMTU(deviceId: string, mtu: number): number;
|
|
70
74
|
|
|
71
75
|
// Service discovery
|
|
72
76
|
discoverServices(deviceId: string, callback: OperationCallback): void;
|
|
@@ -75,7 +79,7 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
|
|
|
75
79
|
|
|
76
80
|
// Characteristic operations
|
|
77
81
|
readCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: ReadCharacteristicCallback): void;
|
|
78
|
-
writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data:
|
|
82
|
+
writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: BLEValue, withResponse: boolean, callback: OperationCallback): void;
|
|
79
83
|
subscribeToCharacteristic(deviceId: string, serviceId: string, characteristicId: string, updateCallback: CharacteristicCallback, resultCallback: OperationCallback): void;
|
|
80
84
|
unsubscribeFromCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: OperationCallback): void;
|
|
81
85
|
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
///
|
|
2
|
-
/// JFunc_void_bool_std__vector_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 <vector>
|
|
14
|
-
#include <string>
|
|
15
|
-
#include <functional>
|
|
16
|
-
|
|
17
|
-
namespace margelo::nitro::co::zyke::ble {
|
|
18
|
-
|
|
19
|
-
using namespace facebook;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Represents the Java/Kotlin callback `(success: Boolean, data: DoubleArray, error: String) -> Unit`.
|
|
23
|
-
* This can be passed around between C++ and Java/Kotlin.
|
|
24
|
-
*/
|
|
25
|
-
struct JFunc_void_bool_std__vector_double__std__string: public jni::JavaClass<JFunc_void_bool_std__vector_double__std__string> {
|
|
26
|
-
public:
|
|
27
|
-
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool_std__vector_double__std__string;";
|
|
28
|
-
|
|
29
|
-
public:
|
|
30
|
-
/**
|
|
31
|
-
* Invokes the function this `JFunc_void_bool_std__vector_double__std__string` instance holds through JNI.
|
|
32
|
-
*/
|
|
33
|
-
void invoke(bool success, const std::vector<double>& data, const std::string& error) const {
|
|
34
|
-
static const auto method = javaClassStatic()->getMethod<void(jboolean /* success */, jni::alias_ref<jni::JArrayDouble> /* data */, jni::alias_ref<jni::JString> /* error */)>("invoke");
|
|
35
|
-
method(self(), success, [&]() {
|
|
36
|
-
size_t __size = data.size();
|
|
37
|
-
jni::local_ref<jni::JArrayDouble> __array = jni::JArrayDouble::newArray(__size);
|
|
38
|
-
__array->setRegion(0, __size, data.data());
|
|
39
|
-
return __array;
|
|
40
|
-
}(), jni::make_jstring(error));
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* An implementation of Func_void_bool_std__vector_double__std__string that is backed by a C++ implementation (using `std::function<...>`)
|
|
46
|
-
*/
|
|
47
|
-
struct JFunc_void_bool_std__vector_double__std__string_cxx final: public jni::HybridClass<JFunc_void_bool_std__vector_double__std__string_cxx, JFunc_void_bool_std__vector_double__std__string> {
|
|
48
|
-
public:
|
|
49
|
-
static jni::local_ref<JFunc_void_bool_std__vector_double__std__string::javaobject> fromCpp(const std::function<void(bool /* success */, const std::vector<double>& /* data */, const std::string& /* error */)>& func) {
|
|
50
|
-
return JFunc_void_bool_std__vector_double__std__string_cxx::newObjectCxxArgs(func);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public:
|
|
54
|
-
/**
|
|
55
|
-
* Invokes the C++ `std::function<...>` this `JFunc_void_bool_std__vector_double__std__string_cxx` instance holds.
|
|
56
|
-
*/
|
|
57
|
-
void invoke_cxx(jboolean success, jni::alias_ref<jni::JArrayDouble> data, jni::alias_ref<jni::JString> error) {
|
|
58
|
-
_func(static_cast<bool>(success), [&]() {
|
|
59
|
-
size_t __size = data->size();
|
|
60
|
-
std::vector<double> __vector(__size);
|
|
61
|
-
data->getRegion(0, __size, __vector.data());
|
|
62
|
-
return __vector;
|
|
63
|
-
}(), error->toStdString());
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public:
|
|
67
|
-
[[nodiscard]]
|
|
68
|
-
inline const std::function<void(bool /* success */, const std::vector<double>& /* data */, const std::string& /* error */)>& getFunction() const {
|
|
69
|
-
return _func;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public:
|
|
73
|
-
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool_std__vector_double__std__string_cxx;";
|
|
74
|
-
static void registerNatives() {
|
|
75
|
-
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_bool_std__vector_double__std__string_cxx::invoke_cxx)});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private:
|
|
79
|
-
explicit JFunc_void_bool_std__vector_double__std__string_cxx(const std::function<void(bool /* success */, const std::vector<double>& /* data */, const std::string& /* error */)>& func): _func(func) { }
|
|
80
|
-
|
|
81
|
-
private:
|
|
82
|
-
friend HybridBase;
|
|
83
|
-
std::function<void(bool /* success */, const std::vector<double>& /* data */, const std::string& /* error */)> _func;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
///
|
|
2
|
-
/// JFunc_void_std__string_std__vector_double_.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 <vector>
|
|
15
|
-
#include <functional>
|
|
16
|
-
|
|
17
|
-
namespace margelo::nitro::co::zyke::ble {
|
|
18
|
-
|
|
19
|
-
using namespace facebook;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Represents the Java/Kotlin callback `(characteristicId: String, data: DoubleArray) -> Unit`.
|
|
23
|
-
* This can be passed around between C++ and Java/Kotlin.
|
|
24
|
-
*/
|
|
25
|
-
struct JFunc_void_std__string_std__vector_double_: public jni::JavaClass<JFunc_void_std__string_std__vector_double_> {
|
|
26
|
-
public:
|
|
27
|
-
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__string_std__vector_double_;";
|
|
28
|
-
|
|
29
|
-
public:
|
|
30
|
-
/**
|
|
31
|
-
* Invokes the function this `JFunc_void_std__string_std__vector_double_` instance holds through JNI.
|
|
32
|
-
*/
|
|
33
|
-
void invoke(const std::string& characteristicId, const std::vector<double>& data) const {
|
|
34
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<jni::JArrayDouble> /* data */)>("invoke");
|
|
35
|
-
method(self(), jni::make_jstring(characteristicId), [&]() {
|
|
36
|
-
size_t __size = data.size();
|
|
37
|
-
jni::local_ref<jni::JArrayDouble> __array = jni::JArrayDouble::newArray(__size);
|
|
38
|
-
__array->setRegion(0, __size, data.data());
|
|
39
|
-
return __array;
|
|
40
|
-
}());
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* An implementation of Func_void_std__string_std__vector_double_ that is backed by a C++ implementation (using `std::function<...>`)
|
|
46
|
-
*/
|
|
47
|
-
struct JFunc_void_std__string_std__vector_double__cxx final: public jni::HybridClass<JFunc_void_std__string_std__vector_double__cxx, JFunc_void_std__string_std__vector_double_> {
|
|
48
|
-
public:
|
|
49
|
-
static jni::local_ref<JFunc_void_std__string_std__vector_double_::javaobject> fromCpp(const std::function<void(const std::string& /* characteristicId */, const std::vector<double>& /* data */)>& func) {
|
|
50
|
-
return JFunc_void_std__string_std__vector_double__cxx::newObjectCxxArgs(func);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public:
|
|
54
|
-
/**
|
|
55
|
-
* Invokes the C++ `std::function<...>` this `JFunc_void_std__string_std__vector_double__cxx` instance holds.
|
|
56
|
-
*/
|
|
57
|
-
void invoke_cxx(jni::alias_ref<jni::JString> characteristicId, jni::alias_ref<jni::JArrayDouble> data) {
|
|
58
|
-
_func(characteristicId->toStdString(), [&]() {
|
|
59
|
-
size_t __size = data->size();
|
|
60
|
-
std::vector<double> __vector(__size);
|
|
61
|
-
data->getRegion(0, __size, __vector.data());
|
|
62
|
-
return __vector;
|
|
63
|
-
}());
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public:
|
|
67
|
-
[[nodiscard]]
|
|
68
|
-
inline const std::function<void(const std::string& /* characteristicId */, const std::vector<double>& /* data */)>& getFunction() const {
|
|
69
|
-
return _func;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public:
|
|
73
|
-
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__string_std__vector_double__cxx;";
|
|
74
|
-
static void registerNatives() {
|
|
75
|
-
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__string_std__vector_double__cxx::invoke_cxx)});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private:
|
|
79
|
-
explicit JFunc_void_std__string_std__vector_double__cxx(const std::function<void(const std::string& /* characteristicId */, const std::vector<double>& /* data */)>& func): _func(func) { }
|
|
80
|
-
|
|
81
|
-
private:
|
|
82
|
-
friend HybridBase;
|
|
83
|
-
std::function<void(const std::string& /* characteristicId */, const std::vector<double>& /* data */)> _func;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
} // namespace margelo::nitro::co::zyke::ble
|