react-native-ble-nitro 1.1.0 → 1.3.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.
Files changed (71) hide show
  1. package/README.md +87 -20
  2. package/android/CMakeLists.txt +32 -0
  3. package/android/build.gradle +140 -0
  4. package/android/fix-prefab.gradle +51 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  8. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +899 -0
  9. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroPackage.kt +38 -0
  10. package/ios/BleNitroBleManager.swift +56 -17
  11. package/ios/BlePeripheralDelegate.swift +36 -8
  12. package/lib/commonjs/index.d.ts +22 -9
  13. package/lib/commonjs/index.d.ts.map +1 -1
  14. package/lib/commonjs/index.js +63 -12
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +14 -5
  17. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
  18. package/lib/commonjs/specs/NativeBleNitro.nitro.js +8 -1
  19. package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
  20. package/lib/index.d.ts +22 -9
  21. package/lib/index.js +61 -10
  22. package/lib/specs/NativeBleNitro.nitro.d.ts +14 -5
  23. package/lib/specs/NativeBleNitro.nitro.js +7 -0
  24. package/nitrogen/generated/android/BleNitroOnLoad.cpp +6 -6
  25. package/nitrogen/generated/android/c++/JAndroidScanMode.hpp +65 -0
  26. package/nitrogen/generated/android/c++/JBLEDevice.hpp +3 -0
  27. package/nitrogen/generated/android/c++/JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp +78 -0
  28. package/nitrogen/generated/android/c++/JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp +86 -0
  29. package/nitrogen/generated/android/c++/JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp +78 -0
  30. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +29 -20
  31. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +5 -4
  32. package/nitrogen/generated/android/c++/JManufacturerData.hpp +3 -0
  33. package/nitrogen/generated/android/c++/JManufacturerDataEntry.hpp +7 -15
  34. package/nitrogen/generated/android/c++/JScanFilter.hpp +8 -2
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/AndroidScanMode.kt +23 -0
  36. 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
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/{Func_void_BLEDevice.kt → Func_void_std__optional_BLEDevice__std__optional_std__string_.kt} +14 -14
  38. 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
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +12 -8
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ManufacturerDataEntry.kt +1 -1
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ScanFilter.kt +4 -1
  42. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +15 -15
  43. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +69 -56
  44. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +6 -0
  45. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +23 -6
  46. package/nitrogen/generated/ios/swift/AndroidScanMode.swift +48 -0
  47. 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
  48. package/nitrogen/generated/ios/swift/Func_void_std__optional_BLEDevice__std__optional_std__string_.swift +59 -0
  49. package/nitrogen/generated/ios/swift/{Func_void_std__string_std__vector_double_.swift → Func_void_std__string_std__shared_ptr_ArrayBuffer_.swift} +11 -11
  50. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +5 -4
  51. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +41 -29
  52. package/nitrogen/generated/ios/swift/ManufacturerDataEntry.swift +5 -17
  53. package/nitrogen/generated/ios/swift/ScanFilter.swift +13 -2
  54. package/nitrogen/generated/shared/c++/AndroidScanMode.hpp +64 -0
  55. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
  56. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +10 -6
  57. package/nitrogen/generated/shared/c++/ManufacturerDataEntry.hpp +8 -7
  58. package/nitrogen/generated/shared/c++/ScanFilter.hpp +9 -3
  59. package/package.json +1 -1
  60. package/plugin/build/index.d.ts +2 -0
  61. package/plugin/build/index.js +2 -0
  62. package/plugin/build/withBleNitro.d.ts +5 -1
  63. package/plugin/build/withBleNitro.js +18 -7
  64. package/react-native.config.js +10 -2
  65. package/src/__tests__/index.test.ts +48 -13
  66. package/src/index.ts +74 -16
  67. package/src/specs/NativeBleNitro.nitro.ts +17 -5
  68. package/nitrogen/generated/android/c++/JFunc_void_BLEDevice.hpp +0 -82
  69. package/nitrogen/generated/android/c++/JFunc_void_bool_std__vector_double__std__string.hpp +0 -86
  70. package/nitrogen/generated/android/c++/JFunc_void_std__string_std__vector_double_.hpp +0 -86
  71. package/nitrogen/generated/ios/swift/Func_void_BLEDevice.swift +0 -47
@@ -1 +1 @@
1
- {"version":3,"file":"NativeBleNitro.nitro.js","sourceRoot":"","sources":["../../../src/specs/NativeBleNitro.nitro.ts"],"names":[],"mappings":";;;AAEA,+DAA+D;AAC/D,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,6CAAW,CAAA;IACX,iDAAa,CAAA;IACb,qDAAe,CAAA;IACf,uDAAgB,CAAA;IAChB,mDAAc,CAAA;IACd,iDAAa,CAAA;AACf,CAAC,EAPW,QAAQ,wBAAR,QAAQ,QAOnB"}
1
+ {"version":3,"file":"NativeBleNitro.nitro.js","sourceRoot":"","sources":["../../../src/specs/NativeBleNitro.nitro.ts"],"names":[],"mappings":";;;AAKA,+DAA+D;AAC/D,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,6CAAW,CAAA;IACX,iDAAa,CAAA;IACb,qDAAe,CAAA;IACf,uDAAgB,CAAA;IAChB,mDAAc,CAAA;IACd,iDAAa,CAAA;AACf,CAAC,EAPW,QAAQ,wBAAR,QAAQ,QAOnB;AAoBD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,iEAAc,CAAA;IACd,6DAAY,CAAA;IACZ,6DAAY,CAAA;IACZ,uEAAiB,CAAA;AACnB,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B"}
package/lib/index.d.ts CHANGED
@@ -2,10 +2,11 @@ export interface ScanFilter {
2
2
  serviceUUIDs?: string[];
3
3
  rssiThreshold?: number;
4
4
  allowDuplicates?: boolean;
5
+ androidScanMode?: AndroidScanMode;
5
6
  }
6
7
  export interface ManufacturerDataEntry {
7
8
  id: string;
8
- data: number[];
9
+ data: ArrayBuffer;
9
10
  }
10
11
  export interface ManufacturerData {
11
12
  companyIdentifiers: ManufacturerDataEntry[];
@@ -22,7 +23,7 @@ export type ScanCallback = (device: BLEDevice) => void;
22
23
  export type ConnectionCallback = (success: boolean, deviceId: string, error: string) => void;
23
24
  export type DisconnectEventCallback = (deviceId: string, interrupted: boolean, error: string) => void;
24
25
  export type OperationCallback = (success: boolean, error: string) => void;
25
- export type CharacteristicUpdateCallback = (characteristicId: string, data: number[]) => void;
26
+ export type CharacteristicUpdateCallback = (characteristicId: string, data: ArrayBuffer) => void;
26
27
  export type Subscription = {
27
28
  remove: () => void;
28
29
  };
@@ -34,6 +35,12 @@ export declare enum BLEState {
34
35
  PoweredOff = "PoweredOff",
35
36
  PoweredOn = "PoweredOn"
36
37
  }
38
+ export declare enum AndroidScanMode {
39
+ LowLatency = "LowLatency",
40
+ Balanced = "Balanced",
41
+ LowPower = "LowPower",
42
+ Opportunistic = "Opportunistic"
43
+ }
37
44
  export declare class BleNitro {
38
45
  private _isScanning;
39
46
  private _connectedDevices;
@@ -52,7 +59,7 @@ export declare class BleNitro {
52
59
  * @param callback Callback function called when a device is found
53
60
  * @returns Promise resolving to success state
54
61
  */
55
- startScan(filter: ScanFilter | undefined, callback: ScanCallback): void;
62
+ startScan(filter: ScanFilter | undefined, callback: ScanCallback, onError?: (error: string) => void): void;
56
63
  /**
57
64
  * Stop scanning for Bluetooth devices
58
65
  * @returns Promise resolving to success state
@@ -88,6 +95,13 @@ export declare class BleNitro {
88
95
  * @returns Promise resolving to connection state
89
96
  */
90
97
  isConnected(deviceId: string): boolean;
98
+ /**
99
+ * Request a new MTU size
100
+ * @param deviceId ID of the device
101
+ * @param mtu New MTU size, min is 23, max is 517
102
+ * @returns On Android: new MTU size; on iOS: current MTU size as it is handled by iOS itself; on error: -1
103
+ */
104
+ requestMTU(deviceId: string, mtu: number): number;
91
105
  /**
92
106
  * Discover services for a connected device
93
107
  * @param deviceId ID of the device
@@ -112,19 +126,19 @@ export declare class BleNitro {
112
126
  * @param deviceId ID of the device
113
127
  * @param serviceId ID of the service
114
128
  * @param characteristicId ID of the characteristic
115
- * @returns Promise resolving to the characteristic data as byte array
129
+ * @returns Promise resolving to the characteristic data as ArrayBuffer
116
130
  */
117
- readCharacteristic(deviceId: string, serviceId: string, characteristicId: string): Promise<number[]>;
131
+ readCharacteristic(deviceId: string, serviceId: string, characteristicId: string): Promise<ArrayBuffer>;
118
132
  /**
119
133
  * Write a value to a characteristic
120
134
  * @param deviceId ID of the device
121
135
  * @param serviceId ID of the service
122
136
  * @param characteristicId ID of the characteristic
123
- * @param data Data to write as an array of bytes
137
+ * @param data Data to write as ArrayBuffer
124
138
  * @param withResponse Whether to wait for response
125
139
  * @returns Promise resolving when write is complete
126
140
  */
127
- writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: number[], withResponse?: boolean): Promise<boolean>;
141
+ writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: ArrayBuffer, withResponse?: boolean): Promise<boolean>;
128
142
  /**
129
143
  * Subscribe to characteristic notifications
130
144
  * @param deviceId ID of the device
@@ -148,8 +162,7 @@ export declare class BleNitro {
148
162
  */
149
163
  isBluetoothEnabled(): boolean;
150
164
  /**
151
- * Request to enable Bluetooth
152
- * Only works on Android
165
+ * Request to enable Bluetooth (Android only)
153
166
  * @returns Promise resolving when Bluetooth is enabled
154
167
  */
155
168
  requestBluetoothEnable(): Promise<boolean>;
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import BleNitroNative from './specs/NativeBleNitro';
2
+ import { AndroidScanMode as NativeAndroidScanMode, } from './specs/NativeBleNitro';
2
3
  export var BLEState;
3
4
  (function (BLEState) {
4
5
  BLEState["Unknown"] = "Unknown";
@@ -9,6 +10,13 @@ export var BLEState;
9
10
  BLEState["PoweredOn"] = "PoweredOn";
10
11
  })(BLEState || (BLEState = {}));
11
12
  ;
13
+ export var AndroidScanMode;
14
+ (function (AndroidScanMode) {
15
+ AndroidScanMode["LowLatency"] = "LowLatency";
16
+ AndroidScanMode["Balanced"] = "Balanced";
17
+ AndroidScanMode["LowPower"] = "LowPower";
18
+ AndroidScanMode["Opportunistic"] = "Opportunistic";
19
+ })(AndroidScanMode || (AndroidScanMode = {}));
12
20
  function mapNativeBLEStateToBLEState(nativeState) {
13
21
  const map = {
14
22
  0: BLEState.Unknown,
@@ -20,6 +28,15 @@ function mapNativeBLEStateToBLEState(nativeState) {
20
28
  };
21
29
  return map[nativeState];
22
30
  }
31
+ function mapAndroidScanModeToNativeAndroidScanMode(scanMode) {
32
+ const map = {
33
+ LowLatency: NativeAndroidScanMode.LowLatency,
34
+ Balanced: NativeAndroidScanMode.Balanced,
35
+ LowPower: NativeAndroidScanMode.LowPower,
36
+ Opportunistic: NativeAndroidScanMode.Opportunistic,
37
+ };
38
+ return map[scanMode];
39
+ }
23
40
  let _instance;
24
41
  export class BleNitro {
25
42
  constructor() {
@@ -58,7 +75,7 @@ export class BleNitro {
58
75
  * @param callback Callback function called when a device is found
59
76
  * @returns Promise resolving to success state
60
77
  */
61
- startScan(filter = {}, callback) {
78
+ startScan(filter = {}, callback, onError) {
62
79
  if (this._isScanning) {
63
80
  return;
64
81
  }
@@ -67,11 +84,28 @@ export class BleNitro {
67
84
  serviceUUIDs: filter.serviceUUIDs || [],
68
85
  rssiThreshold: filter.rssiThreshold ?? -100,
69
86
  allowDuplicates: filter.allowDuplicates ?? false,
87
+ androidScanMode: mapAndroidScanModeToNativeAndroidScanMode(filter.androidScanMode ?? AndroidScanMode.Balanced),
70
88
  };
71
89
  // Create callback wrapper
72
- const scanCallback = (device) => {
73
- device.serviceUUIDs = BleNitro.normalizeGattUUIDs(device.serviceUUIDs);
74
- callback(device);
90
+ const scanCallback = (device, error) => {
91
+ if (error && !device) {
92
+ this._isScanning = false;
93
+ onError?.(error);
94
+ return;
95
+ }
96
+ device = device; // eslint-disable-line @typescript-eslint/no-non-null-assertion
97
+ // Convert manufacturer data to Uint8Arrays
98
+ const convertedDevice = {
99
+ ...device,
100
+ serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs),
101
+ manufacturerData: {
102
+ companyIdentifiers: device.manufacturerData.companyIdentifiers.map(entry => ({
103
+ id: entry.id,
104
+ data: entry.data
105
+ }))
106
+ }
107
+ };
108
+ callback(convertedDevice);
75
109
  };
76
110
  // Start scan
77
111
  BleNitroNative.startScan(nativeFilter, scanCallback);
@@ -86,6 +120,7 @@ export class BleNitro {
86
120
  return;
87
121
  }
88
122
  BleNitroNative.stopScan();
123
+ this._isScanning = false;
89
124
  }
90
125
  /**
91
126
  * Check if currently scanning for devices
@@ -102,10 +137,16 @@ export class BleNitro {
102
137
  */
103
138
  getConnectedDevices(services) {
104
139
  const devices = BleNitroNative.getConnectedDevices(services || []);
105
- // Normalize service UUIDs for connected devices
140
+ // Normalize service UUIDs - manufacturer data already comes as ArrayBuffers
106
141
  return devices.map(device => ({
107
142
  ...device,
108
- serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs)
143
+ serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs),
144
+ manufacturerData: {
145
+ companyIdentifiers: device.manufacturerData.companyIdentifiers.map(entry => ({
146
+ id: entry.id,
147
+ data: entry.data
148
+ }))
149
+ }
109
150
  }));
110
151
  }
111
152
  /**
@@ -167,6 +208,17 @@ export class BleNitro {
167
208
  isConnected(deviceId) {
168
209
  return BleNitroNative.isConnected(deviceId);
169
210
  }
211
+ /**
212
+ * Request a new MTU size
213
+ * @param deviceId ID of the device
214
+ * @param mtu New MTU size, min is 23, max is 517
215
+ * @returns On Android: new MTU size; on iOS: current MTU size as it is handled by iOS itself; on error: -1
216
+ */
217
+ requestMTU(deviceId, mtu) {
218
+ mtu = parseInt(mtu.toString(), 10);
219
+ const deviceMtu = BleNitroNative.requestMTU(deviceId, mtu);
220
+ return deviceMtu;
221
+ }
170
222
  /**
171
223
  * Discover services for a connected device
172
224
  * @param deviceId ID of the device
@@ -228,7 +280,7 @@ export class BleNitro {
228
280
  * @param deviceId ID of the device
229
281
  * @param serviceId ID of the service
230
282
  * @param characteristicId ID of the characteristic
231
- * @returns Promise resolving to the characteristic data as byte array
283
+ * @returns Promise resolving to the characteristic data as ArrayBuffer
232
284
  */
233
285
  readCharacteristic(deviceId, serviceId, characteristicId) {
234
286
  return new Promise((resolve, reject) => {
@@ -252,7 +304,7 @@ export class BleNitro {
252
304
  * @param deviceId ID of the device
253
305
  * @param serviceId ID of the service
254
306
  * @param characteristicId ID of the characteristic
255
- * @param data Data to write as an array of bytes
307
+ * @param data Data to write as ArrayBuffer
256
308
  * @param withResponse Whether to wait for response
257
309
  * @returns Promise resolving when write is complete
258
310
  */
@@ -336,8 +388,7 @@ export class BleNitro {
336
388
  return this.state() === BLEState.PoweredOn;
337
389
  }
338
390
  /**
339
- * Request to enable Bluetooth
340
- * Only works on Android
391
+ * Request to enable Bluetooth (Android only)
341
392
  * @returns Promise resolving when Bluetooth is enabled
342
393
  */
343
394
  requestBluetoothEnable() {
@@ -1,4 +1,5 @@
1
1
  import { HybridObject } from 'react-native-nitro-modules';
2
+ export type BLEValue = ArrayBuffer;
2
3
  export declare enum BLEState {
3
4
  Unknown = 0,
4
5
  Resetting = 1,
@@ -9,7 +10,7 @@ export declare enum BLEState {
9
10
  }
10
11
  export interface ManufacturerDataEntry {
11
12
  id: string;
12
- data: number[];
13
+ data: BLEValue;
13
14
  }
14
15
  export interface ManufacturerData {
15
16
  companyIdentifiers: ManufacturerDataEntry[];
@@ -22,21 +23,28 @@ export interface BLEDevice {
22
23
  serviceUUIDs: string[];
23
24
  isConnectable: boolean;
24
25
  }
26
+ export declare enum AndroidScanMode {
27
+ LowLatency = 0,
28
+ Balanced = 1,
29
+ LowPower = 2,
30
+ Opportunistic = 3
31
+ }
25
32
  export interface ScanFilter {
26
33
  serviceUUIDs: string[];
27
34
  rssiThreshold: number;
28
35
  allowDuplicates: boolean;
36
+ androidScanMode: AndroidScanMode;
29
37
  }
30
- export type ScanCallback = (device: BLEDevice) => void;
38
+ export type ScanCallback = (device: BLEDevice | null, error: string | null) => void;
31
39
  export type DevicesCallback = (devices: BLEDevice[]) => void;
32
40
  export type ConnectionCallback = (success: boolean, deviceId: string, error: string) => void;
33
41
  export type DisconnectionEventCallback = (deviceId: string, interrupted: boolean, error: string) => void;
34
42
  export type OperationCallback = (success: boolean, error: string) => void;
35
- export type CharacteristicCallback = (characteristicId: string, data: number[]) => void;
43
+ export type CharacteristicCallback = (characteristicId: string, data: BLEValue) => void;
36
44
  export type StateCallback = (state: BLEState) => void;
37
45
  export type BooleanCallback = (result: boolean) => void;
38
46
  export type StringArrayCallback = (result: string[]) => void;
39
- export type ReadCharacteristicCallback = (success: boolean, data: number[], error: string) => void;
47
+ export type ReadCharacteristicCallback = (success: boolean, data: BLEValue, error: string) => void;
40
48
  export type OperationResult = {
41
49
  success: boolean;
42
50
  error?: string;
@@ -56,11 +64,12 @@ export interface NativeBleNitro extends HybridObject<{
56
64
  connect(deviceId: string, callback: ConnectionCallback, disconnectCallback?: DisconnectionEventCallback): void;
57
65
  disconnect(deviceId: string, callback: OperationCallback): void;
58
66
  isConnected(deviceId: string): boolean;
67
+ requestMTU(deviceId: string, mtu: number): number;
59
68
  discoverServices(deviceId: string, callback: OperationCallback): void;
60
69
  getServices(deviceId: string): string[];
61
70
  getCharacteristics(deviceId: string, serviceId: string): string[];
62
71
  readCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: ReadCharacteristicCallback): void;
63
- writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: number[], withResponse: boolean, callback: OperationCallback): void;
72
+ writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: BLEValue, withResponse: boolean, callback: OperationCallback): void;
64
73
  subscribeToCharacteristic(deviceId: string, serviceId: string, characteristicId: string, updateCallback: CharacteristicCallback, resultCallback: OperationCallback): void;
65
74
  unsubscribeFromCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: OperationCallback): void;
66
75
  requestBluetoothEnable(callback: OperationCallback): void;
@@ -8,3 +8,10 @@ export var BLEState;
8
8
  BLEState[BLEState["PoweredOff"] = 4] = "PoweredOff";
9
9
  BLEState[BLEState["PoweredOn"] = 5] = "PoweredOn";
10
10
  })(BLEState || (BLEState = {}));
11
+ export var AndroidScanMode;
12
+ (function (AndroidScanMode) {
13
+ AndroidScanMode[AndroidScanMode["LowLatency"] = 0] = "LowLatency";
14
+ AndroidScanMode[AndroidScanMode["Balanced"] = 1] = "Balanced";
15
+ AndroidScanMode[AndroidScanMode["LowPower"] = 2] = "LowPower";
16
+ AndroidScanMode[AndroidScanMode["Opportunistic"] = 3] = "Opportunistic";
17
+ })(AndroidScanMode || (AndroidScanMode = {}));
@@ -16,12 +16,12 @@
16
16
  #include <NitroModules/HybridObjectRegistry.hpp>
17
17
 
18
18
  #include "JHybridNativeBleNitroSpec.hpp"
19
- #include "JFunc_void_BLEDevice.hpp"
19
+ #include "JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp"
20
20
  #include "JFunc_void_bool_std__string_std__string.hpp"
21
21
  #include "JFunc_void_std__string_bool_std__string.hpp"
22
22
  #include "JFunc_void_bool_std__string.hpp"
23
- #include "JFunc_void_bool_std__vector_double__std__string.hpp"
24
- #include "JFunc_void_std__string_std__vector_double_.hpp"
23
+ #include "JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp"
24
+ #include "JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp"
25
25
  #include "JFunc_void_BLEState.hpp"
26
26
  #include <NitroModules/DefaultConstructableObject.hpp>
27
27
 
@@ -35,12 +35,12 @@ int initialize(JavaVM* vm) {
35
35
  return facebook::jni::initialize(vm, [] {
36
36
  // Register native JNI methods
37
37
  margelo::nitro::co::zyke::ble::JHybridNativeBleNitroSpec::registerNatives();
38
- margelo::nitro::co::zyke::ble::JFunc_void_BLEDevice_cxx::registerNatives();
38
+ margelo::nitro::co::zyke::ble::JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::registerNatives();
39
39
  margelo::nitro::co::zyke::ble::JFunc_void_bool_std__string_std__string_cxx::registerNatives();
40
40
  margelo::nitro::co::zyke::ble::JFunc_void_std__string_bool_std__string_cxx::registerNatives();
41
41
  margelo::nitro::co::zyke::ble::JFunc_void_bool_std__string_cxx::registerNatives();
42
- margelo::nitro::co::zyke::ble::JFunc_void_bool_std__vector_double__std__string_cxx::registerNatives();
43
- margelo::nitro::co::zyke::ble::JFunc_void_std__string_std__vector_double__cxx::registerNatives();
42
+ margelo::nitro::co::zyke::ble::JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::registerNatives();
43
+ margelo::nitro::co::zyke::ble::JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx::registerNatives();
44
44
  margelo::nitro::co::zyke::ble::JFunc_void_BLEState_cxx::registerNatives();
45
45
 
46
46
  // Register Nitro Hybrid Objects
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// JAndroidScanMode.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 "AndroidScanMode.hpp"
12
+
13
+ namespace margelo::nitro::co::zyke::ble {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "AndroidScanMode" and the the Kotlin enum "AndroidScanMode".
19
+ */
20
+ struct JAndroidScanMode final: public jni::JavaClass<JAndroidScanMode> {
21
+ public:
22
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/AndroidScanMode;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum AndroidScanMode.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ AndroidScanMode toCpp() const {
31
+ static const auto clazz = javaClassStatic();
32
+ static const auto fieldOrdinal = clazz->getField<int>("value");
33
+ int ordinal = this->getFieldValue(fieldOrdinal);
34
+ return static_cast<AndroidScanMode>(ordinal);
35
+ }
36
+
37
+ public:
38
+ /**
39
+ * Create a Java/Kotlin-based enum with the given C++ enum's value.
40
+ */
41
+ [[maybe_unused]]
42
+ static jni::alias_ref<JAndroidScanMode> fromCpp(AndroidScanMode value) {
43
+ static const auto clazz = javaClassStatic();
44
+ static const auto fieldLOWLATENCY = clazz->getStaticField<JAndroidScanMode>("LOWLATENCY");
45
+ static const auto fieldBALANCED = clazz->getStaticField<JAndroidScanMode>("BALANCED");
46
+ static const auto fieldLOWPOWER = clazz->getStaticField<JAndroidScanMode>("LOWPOWER");
47
+ static const auto fieldOPPORTUNISTIC = clazz->getStaticField<JAndroidScanMode>("OPPORTUNISTIC");
48
+
49
+ switch (value) {
50
+ case AndroidScanMode::LOWLATENCY:
51
+ return clazz->getStaticFieldValue(fieldLOWLATENCY);
52
+ case AndroidScanMode::BALANCED:
53
+ return clazz->getStaticFieldValue(fieldBALANCED);
54
+ case AndroidScanMode::LOWPOWER:
55
+ return clazz->getStaticFieldValue(fieldLOWPOWER);
56
+ case AndroidScanMode::OPPORTUNISTIC:
57
+ return clazz->getStaticFieldValue(fieldOPPORTUNISTIC);
58
+ default:
59
+ std::string stringValue = std::to_string(static_cast<int>(value));
60
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
61
+ }
62
+ }
63
+ };
64
+
65
+ } // namespace margelo::nitro::co::zyke::ble
@@ -14,6 +14,9 @@
14
14
  #include "JManufacturerDataEntry.hpp"
15
15
  #include "ManufacturerData.hpp"
16
16
  #include "ManufacturerDataEntry.hpp"
17
+ #include <NitroModules/ArrayBuffer.hpp>
18
+ #include <NitroModules/JArrayBuffer.hpp>
19
+ #include <NitroModules/JUnit.hpp>
17
20
  #include <string>
18
21
  #include <vector>
19
22
 
@@ -0,0 +1,78 @@
1
+ ///
2
+ /// JFunc_void_bool_std__shared_ptr_ArrayBuffer__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 <NitroModules/ArrayBuffer.hpp>
14
+ #include <string>
15
+ #include <functional>
16
+ #include <NitroModules/JArrayBuffer.hpp>
17
+ #include <NitroModules/JUnit.hpp>
18
+
19
+ namespace margelo::nitro::co::zyke::ble {
20
+
21
+ using namespace facebook;
22
+
23
+ /**
24
+ * Represents the Java/Kotlin callback `(success: Boolean, data: ArrayBuffer, error: String) -> Unit`.
25
+ * This can be passed around between C++ and Java/Kotlin.
26
+ */
27
+ struct JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string: public jni::JavaClass<JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string> {
28
+ public:
29
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool_std__shared_ptr_ArrayBuffer__std__string;";
30
+
31
+ public:
32
+ /**
33
+ * Invokes the function this `JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string` instance holds through JNI.
34
+ */
35
+ void invoke(bool success, const std::shared_ptr<ArrayBuffer>& data, const std::string& error) const {
36
+ static const auto method = javaClassStatic()->getMethod<void(jboolean /* success */, jni::alias_ref<JArrayBuffer::javaobject> /* data */, jni::alias_ref<jni::JString> /* error */)>("invoke");
37
+ method(self(), success, JArrayBuffer::wrap(data), jni::make_jstring(error));
38
+ }
39
+ };
40
+
41
+ /**
42
+ * An implementation of Func_void_bool_std__shared_ptr_ArrayBuffer__std__string that is backed by a C++ implementation (using `std::function<...>`)
43
+ */
44
+ struct JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx final: public jni::HybridClass<JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx, JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string> {
45
+ public:
46
+ static jni::local_ref<JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string::javaobject> fromCpp(const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)>& func) {
47
+ return JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::newObjectCxxArgs(func);
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Invokes the C++ `std::function<...>` this `JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx` instance holds.
53
+ */
54
+ void invoke_cxx(jboolean success, jni::alias_ref<JArrayBuffer::javaobject> data, jni::alias_ref<jni::JString> error) {
55
+ _func(static_cast<bool>(success), data->cthis()->getArrayBuffer(), error->toStdString());
56
+ }
57
+
58
+ public:
59
+ [[nodiscard]]
60
+ inline const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)>& getFunction() const {
61
+ return _func;
62
+ }
63
+
64
+ public:
65
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx;";
66
+ static void registerNatives() {
67
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::invoke_cxx)});
68
+ }
69
+
70
+ private:
71
+ explicit JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx(const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)>& func): _func(func) { }
72
+
73
+ private:
74
+ friend HybridBase;
75
+ std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* data */, const std::string& /* error */)> _func;
76
+ };
77
+
78
+ } // namespace margelo::nitro::co::zyke::ble
@@ -0,0 +1,86 @@
1
+ ///
2
+ /// JFunc_void_std__optional_BLEDevice__std__optional_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 "BLEDevice.hpp"
14
+ #include <optional>
15
+ #include <string>
16
+ #include <functional>
17
+ #include "JBLEDevice.hpp"
18
+ #include "ManufacturerData.hpp"
19
+ #include "JManufacturerData.hpp"
20
+ #include "ManufacturerDataEntry.hpp"
21
+ #include <vector>
22
+ #include "JManufacturerDataEntry.hpp"
23
+ #include <NitroModules/ArrayBuffer.hpp>
24
+ #include <NitroModules/JArrayBuffer.hpp>
25
+ #include <NitroModules/JUnit.hpp>
26
+
27
+ namespace margelo::nitro::co::zyke::ble {
28
+
29
+ using namespace facebook;
30
+
31
+ /**
32
+ * Represents the Java/Kotlin callback `(device: BLEDevice?, error: String?) -> Unit`.
33
+ * This can be passed around between C++ and Java/Kotlin.
34
+ */
35
+ struct JFunc_void_std__optional_BLEDevice__std__optional_std__string_: public jni::JavaClass<JFunc_void_std__optional_BLEDevice__std__optional_std__string_> {
36
+ public:
37
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__optional_BLEDevice__std__optional_std__string_;";
38
+
39
+ public:
40
+ /**
41
+ * Invokes the function this `JFunc_void_std__optional_BLEDevice__std__optional_std__string_` instance holds through JNI.
42
+ */
43
+ void invoke(const std::optional<BLEDevice>& device, const std::optional<std::string>& error) const {
44
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JBLEDevice> /* device */, jni::alias_ref<jni::JString> /* error */)>("invoke");
45
+ method(self(), device.has_value() ? JBLEDevice::fromCpp(device.value()) : nullptr, error.has_value() ? jni::make_jstring(error.value()) : nullptr);
46
+ }
47
+ };
48
+
49
+ /**
50
+ * An implementation of Func_void_std__optional_BLEDevice__std__optional_std__string_ that is backed by a C++ implementation (using `std::function<...>`)
51
+ */
52
+ struct JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx final: public jni::HybridClass<JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx, JFunc_void_std__optional_BLEDevice__std__optional_std__string_> {
53
+ public:
54
+ static jni::local_ref<JFunc_void_std__optional_BLEDevice__std__optional_std__string_::javaobject> fromCpp(const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& func) {
55
+ return JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::newObjectCxxArgs(func);
56
+ }
57
+
58
+ public:
59
+ /**
60
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx` instance holds.
61
+ */
62
+ void invoke_cxx(jni::alias_ref<JBLEDevice> device, jni::alias_ref<jni::JString> error) {
63
+ _func(device != nullptr ? std::make_optional(device->toCpp()) : std::nullopt, error != nullptr ? std::make_optional(error->toStdString()) : std::nullopt);
64
+ }
65
+
66
+ public:
67
+ [[nodiscard]]
68
+ inline const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<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_std__optional_BLEDevice__std__optional_std__string__cxx;";
74
+ static void registerNatives() {
75
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::invoke_cxx)});
76
+ }
77
+
78
+ private:
79
+ explicit JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx(const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& func): _func(func) { }
80
+
81
+ private:
82
+ friend HybridBase;
83
+ std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)> _func;
84
+ };
85
+
86
+ } // namespace margelo::nitro::co::zyke::ble
@@ -0,0 +1,78 @@
1
+ ///
2
+ /// JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.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 <NitroModules/ArrayBuffer.hpp>
15
+ #include <functional>
16
+ #include <NitroModules/JArrayBuffer.hpp>
17
+ #include <NitroModules/JUnit.hpp>
18
+
19
+ namespace margelo::nitro::co::zyke::ble {
20
+
21
+ using namespace facebook;
22
+
23
+ /**
24
+ * Represents the Java/Kotlin callback `(characteristicId: String, data: ArrayBuffer) -> Unit`.
25
+ * This can be passed around between C++ and Java/Kotlin.
26
+ */
27
+ struct JFunc_void_std__string_std__shared_ptr_ArrayBuffer_: public jni::JavaClass<JFunc_void_std__string_std__shared_ptr_ArrayBuffer_> {
28
+ public:
29
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__string_std__shared_ptr_ArrayBuffer_;";
30
+
31
+ public:
32
+ /**
33
+ * Invokes the function this `JFunc_void_std__string_std__shared_ptr_ArrayBuffer_` instance holds through JNI.
34
+ */
35
+ void invoke(const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data) const {
36
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JArrayBuffer::javaobject> /* data */)>("invoke");
37
+ method(self(), jni::make_jstring(characteristicId), JArrayBuffer::wrap(data));
38
+ }
39
+ };
40
+
41
+ /**
42
+ * An implementation of Func_void_std__string_std__shared_ptr_ArrayBuffer_ that is backed by a C++ implementation (using `std::function<...>`)
43
+ */
44
+ struct JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx final: public jni::HybridClass<JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx, JFunc_void_std__string_std__shared_ptr_ArrayBuffer_> {
45
+ public:
46
+ static jni::local_ref<JFunc_void_std__string_std__shared_ptr_ArrayBuffer_::javaobject> fromCpp(const std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)>& func) {
47
+ return JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx::newObjectCxxArgs(func);
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx` instance holds.
53
+ */
54
+ void invoke_cxx(jni::alias_ref<jni::JString> characteristicId, jni::alias_ref<JArrayBuffer::javaobject> data) {
55
+ _func(characteristicId->toStdString(), data->cthis()->getArrayBuffer());
56
+ }
57
+
58
+ public:
59
+ [[nodiscard]]
60
+ inline const std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)>& getFunction() const {
61
+ return _func;
62
+ }
63
+
64
+ public:
65
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__string_std__shared_ptr_ArrayBuffer__cxx;";
66
+ static void registerNatives() {
67
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx::invoke_cxx)});
68
+ }
69
+
70
+ private:
71
+ explicit JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx(const std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)>& func): _func(func) { }
72
+
73
+ private:
74
+ friend HybridBase;
75
+ std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)> _func;
76
+ };
77
+
78
+ } // namespace margelo::nitro::co::zyke::ble