react-native-ble-nitro 1.4.1 → 1.6.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 +33 -1
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +43 -2
- package/ios/BleNitroBleManager.swift +20 -1
- package/ios/BlePeripheralDelegate.swift +16 -3
- package/lib/commonjs/manager.d.ts +40 -12
- package/lib/commonjs/manager.d.ts.map +1 -1
- package/lib/commonjs/manager.js +85 -13
- package/lib/commonjs/manager.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +3 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
- package/lib/manager.d.ts +40 -12
- package/lib/manager.js +84 -13
- package/lib/specs/NativeBleNitro.nitro.d.ts +3 -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 +12 -3
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +31 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +8 -2
- 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 +18 -2
- 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 +63 -15
- package/src/manager.ts +92 -13
- package/src/specs/NativeBleNitro.nitro.ts +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeBleNitro.nitro.d.ts","sourceRoot":"","sources":["../../../src/specs/NativeBleNitro.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC;AAGnC,oBAAY,QAAQ;IAClB,OAAO,IAAI;IACX,SAAS,IAAI;IACb,WAAW,IAAI;IACf,YAAY,IAAI;IAChB,UAAU,IAAI;IACd,SAAS,IAAI;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB,EAAE,qBAAqB,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,oBAAY,eAAe;IACzB,UAAU,IAAI;IACd,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,aAAa,IAAI;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,KA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{
|
|
|
72
72
|
* Start scanning for Bluetooth devices
|
|
73
73
|
* @param filter Optional scan filter
|
|
74
74
|
* @param callback Callback function called when a device is found
|
|
75
|
-
* @returns
|
|
75
|
+
* @returns void
|
|
76
76
|
*/
|
|
77
77
|
startScan(filter: ScanFilter | undefined, callback: ScanCallback, onError?: (error: string) => void): void;
|
|
78
78
|
/**
|
|
79
79
|
* Stop scanning for Bluetooth devices
|
|
80
|
-
* @returns
|
|
80
|
+
* @returns void
|
|
81
81
|
*/
|
|
82
82
|
stopScan(): void;
|
|
83
83
|
/**
|
|
84
84
|
* Check if currently scanning for devices
|
|
85
|
-
* @returns
|
|
85
|
+
* @returns Boolean indicating if currently scanning
|
|
86
86
|
*/
|
|
87
87
|
isScanning(): boolean;
|
|
88
88
|
/**
|
|
@@ -95,9 +95,20 @@ export declare class BleNitroManager {
|
|
|
95
95
|
* Connect to a Bluetooth device
|
|
96
96
|
* @param deviceId ID of the device to connect to
|
|
97
97
|
* @param onDisconnect Optional callback for disconnect events
|
|
98
|
-
* @returns Promise resolving when connected
|
|
98
|
+
* @returns Promise resolving deviceId when connected
|
|
99
99
|
*/
|
|
100
|
-
connect(deviceId: string, onDisconnect?: DisconnectEventCallback): Promise<string>;
|
|
100
|
+
connect(deviceId: string, onDisconnect?: DisconnectEventCallback, autoConnectAndroid?: boolean): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Scans for a device and connects to it
|
|
103
|
+
* @param deviceId ID of the device to connect to
|
|
104
|
+
* @param scanTimeout Optional timeout for the scan in milliseconds (default: 5000ms)
|
|
105
|
+
* @returns Promise resolving deviceId when connected
|
|
106
|
+
*/
|
|
107
|
+
findAndConnect(deviceId: string, options?: {
|
|
108
|
+
scanTimeout?: number;
|
|
109
|
+
autoConnectAndroid?: boolean;
|
|
110
|
+
onDisconnect?: DisconnectEventCallback;
|
|
111
|
+
}): Promise<string>;
|
|
101
112
|
/**
|
|
102
113
|
* Disconnect from a Bluetooth device
|
|
103
114
|
* @param deviceId ID of the device to disconnect from
|
|
@@ -107,7 +118,7 @@ export declare class BleNitroManager {
|
|
|
107
118
|
/**
|
|
108
119
|
* Check if connected to a device
|
|
109
120
|
* @param deviceId ID of the device to check
|
|
110
|
-
* @returns
|
|
121
|
+
* @returns Boolean indicating if device is connected
|
|
111
122
|
*/
|
|
112
123
|
isConnected(deviceId: string): boolean;
|
|
113
124
|
/**
|
|
@@ -117,6 +128,12 @@ export declare class BleNitroManager {
|
|
|
117
128
|
* @returns On Android: new MTU size; on iOS: current MTU size as it is handled by iOS itself; on error: -1
|
|
118
129
|
*/
|
|
119
130
|
requestMTU(deviceId: string, mtu: number): number;
|
|
131
|
+
/**
|
|
132
|
+
* Read RSSI for a connected device
|
|
133
|
+
* @param deviceId ID of the device
|
|
134
|
+
* @returns Promise resolving to RSSI value
|
|
135
|
+
*/
|
|
136
|
+
readRSSI(deviceId: string): Promise<number>;
|
|
120
137
|
/**
|
|
121
138
|
* Discover services for a connected device
|
|
122
139
|
* @param deviceId ID of the device
|
|
@@ -133,15 +150,26 @@ export declare class BleNitroManager {
|
|
|
133
150
|
* Get characteristics for a service
|
|
134
151
|
* @param deviceId ID of the device
|
|
135
152
|
* @param serviceId ID of the service
|
|
136
|
-
* @returns
|
|
153
|
+
* @returns array of characteristic UUIDs
|
|
137
154
|
*/
|
|
138
155
|
getCharacteristics(deviceId: string, serviceId: string): string[];
|
|
156
|
+
/**
|
|
157
|
+
* Get services and characteristics for a connected device
|
|
158
|
+
* @param deviceId ID of the device
|
|
159
|
+
* @returns Promise resolving to array of service and characteristic UUIDs
|
|
160
|
+
* @see getServices
|
|
161
|
+
* @see getCharacteristics
|
|
162
|
+
*/
|
|
163
|
+
getServicesWithCharacteristics(deviceId: string): Promise<{
|
|
164
|
+
uuid: string;
|
|
165
|
+
characteristics: string[];
|
|
166
|
+
}[]>;
|
|
139
167
|
/**
|
|
140
168
|
* Read a characteristic value
|
|
141
169
|
* @param deviceId ID of the device
|
|
142
170
|
* @param serviceId ID of the service
|
|
143
171
|
* @param characteristicId ID of the characteristic
|
|
144
|
-
* @returns Promise resolving to the characteristic data as
|
|
172
|
+
* @returns Promise resolving to the characteristic data as ByteArray
|
|
145
173
|
*/
|
|
146
174
|
readCharacteristic(deviceId: string, serviceId: string, characteristicId: string): Promise<ByteArray>;
|
|
147
175
|
/**
|
|
@@ -160,7 +188,7 @@ export declare class BleNitroManager {
|
|
|
160
188
|
* @param serviceId ID of the service
|
|
161
189
|
* @param characteristicId ID of the characteristic
|
|
162
190
|
* @param callback Callback function called when notification is received
|
|
163
|
-
* @returns
|
|
191
|
+
* @returns Subscription
|
|
164
192
|
*/
|
|
165
193
|
subscribeToCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: CharacteristicUpdateCallback): Subscription;
|
|
166
194
|
/**
|
|
@@ -173,7 +201,7 @@ export declare class BleNitroManager {
|
|
|
173
201
|
unsubscribeFromCharacteristic(deviceId: string, serviceId: string, characteristicId: string): Promise<void>;
|
|
174
202
|
/**
|
|
175
203
|
* Check if Bluetooth is enabled
|
|
176
|
-
* @returns
|
|
204
|
+
* @returns returns Boolean according to Bluetooth state
|
|
177
205
|
*/
|
|
178
206
|
isBluetoothEnabled(): boolean;
|
|
179
207
|
/**
|
|
@@ -183,7 +211,7 @@ export declare class BleNitroManager {
|
|
|
183
211
|
requestBluetoothEnable(): Promise<boolean>;
|
|
184
212
|
/**
|
|
185
213
|
* Get the current Bluetooth state
|
|
186
|
-
* @returns
|
|
214
|
+
* @returns Bluetooth state
|
|
187
215
|
* @see BLEState
|
|
188
216
|
*/
|
|
189
217
|
state(): BLEState;
|
|
@@ -191,7 +219,7 @@ export declare class BleNitroManager {
|
|
|
191
219
|
* Subscribe to Bluetooth state changes
|
|
192
220
|
* @param callback Callback function called when state changes
|
|
193
221
|
* @param emitInitial Whether to emit initial state callback
|
|
194
|
-
* @returns
|
|
222
|
+
* @returns Subscription
|
|
195
223
|
* @see BLEState
|
|
196
224
|
*/
|
|
197
225
|
subscribeToStateChange(callback: (state: BLEState) => void, emitInitial?: boolean): Subscription;
|
package/lib/manager.js
CHANGED
|
@@ -104,7 +104,7 @@ export class BleNitroManager {
|
|
|
104
104
|
* Start scanning for Bluetooth devices
|
|
105
105
|
* @param filter Optional scan filter
|
|
106
106
|
* @param callback Callback function called when a device is found
|
|
107
|
-
* @returns
|
|
107
|
+
* @returns void
|
|
108
108
|
*/
|
|
109
109
|
startScan(filter = {}, callback, onError) {
|
|
110
110
|
if (this._isScanning) {
|
|
@@ -135,7 +135,7 @@ export class BleNitroManager {
|
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Stop scanning for Bluetooth devices
|
|
138
|
-
* @returns
|
|
138
|
+
* @returns void
|
|
139
139
|
*/
|
|
140
140
|
stopScan() {
|
|
141
141
|
if (!this._isScanning) {
|
|
@@ -146,7 +146,7 @@ export class BleNitroManager {
|
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Check if currently scanning for devices
|
|
149
|
-
* @returns
|
|
149
|
+
* @returns Boolean indicating if currently scanning
|
|
150
150
|
*/
|
|
151
151
|
isScanning() {
|
|
152
152
|
this._isScanning = BleNitroNative.isScanning();
|
|
@@ -166,9 +166,9 @@ export class BleNitroManager {
|
|
|
166
166
|
* Connect to a Bluetooth device
|
|
167
167
|
* @param deviceId ID of the device to connect to
|
|
168
168
|
* @param onDisconnect Optional callback for disconnect events
|
|
169
|
-
* @returns Promise resolving when connected
|
|
169
|
+
* @returns Promise resolving deviceId when connected
|
|
170
170
|
*/
|
|
171
|
-
connect(deviceId, onDisconnect) {
|
|
171
|
+
connect(deviceId, onDisconnect, autoConnectAndroid) {
|
|
172
172
|
return new Promise((resolve, reject) => {
|
|
173
173
|
// Check if already connected
|
|
174
174
|
if (this._connectedDevices[deviceId]) {
|
|
@@ -187,7 +187,39 @@ export class BleNitroManager {
|
|
|
187
187
|
// Remove from connected devices when disconnected
|
|
188
188
|
delete this._connectedDevices[deviceId];
|
|
189
189
|
onDisconnect(deviceId, interrupted, error);
|
|
190
|
-
} : undefined);
|
|
190
|
+
} : undefined, autoConnectAndroid ?? false);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Scans for a device and connects to it
|
|
195
|
+
* @param deviceId ID of the device to connect to
|
|
196
|
+
* @param scanTimeout Optional timeout for the scan in milliseconds (default: 5000ms)
|
|
197
|
+
* @returns Promise resolving deviceId when connected
|
|
198
|
+
*/
|
|
199
|
+
findAndConnect(deviceId, options) {
|
|
200
|
+
const isConnected = this.isConnected(deviceId);
|
|
201
|
+
if (isConnected) {
|
|
202
|
+
return Promise.resolve(deviceId);
|
|
203
|
+
}
|
|
204
|
+
if (this._isScanning) {
|
|
205
|
+
this.stopScan();
|
|
206
|
+
}
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
const timeoutScan = setTimeout(() => {
|
|
209
|
+
this.stopScan();
|
|
210
|
+
reject(new Error('Scan timed out'));
|
|
211
|
+
}, options?.scanTimeout ?? 5000);
|
|
212
|
+
this.startScan(undefined, (device) => {
|
|
213
|
+
if (device.id === deviceId) {
|
|
214
|
+
this.stopScan();
|
|
215
|
+
clearTimeout(timeoutScan);
|
|
216
|
+
this.connect(deviceId, options?.onDisconnect, options?.autoConnectAndroid).then(async (connectedDeviceId) => {
|
|
217
|
+
resolve(connectedDeviceId);
|
|
218
|
+
}).catch((error) => {
|
|
219
|
+
reject(error);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
191
223
|
});
|
|
192
224
|
}
|
|
193
225
|
/**
|
|
@@ -216,7 +248,7 @@ export class BleNitroManager {
|
|
|
216
248
|
/**
|
|
217
249
|
* Check if connected to a device
|
|
218
250
|
* @param deviceId ID of the device to check
|
|
219
|
-
* @returns
|
|
251
|
+
* @returns Boolean indicating if device is connected
|
|
220
252
|
*/
|
|
221
253
|
isConnected(deviceId) {
|
|
222
254
|
return BleNitroNative.isConnected(deviceId);
|
|
@@ -232,6 +264,28 @@ export class BleNitroManager {
|
|
|
232
264
|
const deviceMtu = BleNitroNative.requestMTU(deviceId, mtu);
|
|
233
265
|
return deviceMtu;
|
|
234
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Read RSSI for a connected device
|
|
269
|
+
* @param deviceId ID of the device
|
|
270
|
+
* @returns Promise resolving to RSSI value
|
|
271
|
+
*/
|
|
272
|
+
readRSSI(deviceId) {
|
|
273
|
+
return new Promise((resolve, reject) => {
|
|
274
|
+
// Check if connected first
|
|
275
|
+
if (!this._connectedDevices[deviceId]) {
|
|
276
|
+
reject(new Error('Device not connected'));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
BleNitroNative.readRSSI(deviceId, (success, rssi, error) => {
|
|
280
|
+
if (success) {
|
|
281
|
+
resolve(rssi);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
reject(new Error(error));
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
}
|
|
235
289
|
/**
|
|
236
290
|
* Discover services for a connected device
|
|
237
291
|
* @param deviceId ID of the device
|
|
@@ -279,7 +333,7 @@ export class BleNitroManager {
|
|
|
279
333
|
* Get characteristics for a service
|
|
280
334
|
* @param deviceId ID of the device
|
|
281
335
|
* @param serviceId ID of the service
|
|
282
|
-
* @returns
|
|
336
|
+
* @returns array of characteristic UUIDs
|
|
283
337
|
*/
|
|
284
338
|
getCharacteristics(deviceId, serviceId) {
|
|
285
339
|
if (!this._connectedDevices[deviceId]) {
|
|
@@ -288,12 +342,29 @@ export class BleNitroManager {
|
|
|
288
342
|
const characteristics = BleNitroNative.getCharacteristics(deviceId, BleNitroManager.normalizeGattUUID(serviceId));
|
|
289
343
|
return BleNitroManager.normalizeGattUUIDs(characteristics);
|
|
290
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Get services and characteristics for a connected device
|
|
347
|
+
* @param deviceId ID of the device
|
|
348
|
+
* @returns Promise resolving to array of service and characteristic UUIDs
|
|
349
|
+
* @see getServices
|
|
350
|
+
* @see getCharacteristics
|
|
351
|
+
*/
|
|
352
|
+
async getServicesWithCharacteristics(deviceId) {
|
|
353
|
+
await this.discoverServices(deviceId);
|
|
354
|
+
const services = await this.getServices(deviceId);
|
|
355
|
+
return services.map((service) => {
|
|
356
|
+
return {
|
|
357
|
+
uuid: service,
|
|
358
|
+
characteristics: this.getCharacteristics(deviceId, service),
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
}
|
|
291
362
|
/**
|
|
292
363
|
* Read a characteristic value
|
|
293
364
|
* @param deviceId ID of the device
|
|
294
365
|
* @param serviceId ID of the service
|
|
295
366
|
* @param characteristicId ID of the characteristic
|
|
296
|
-
* @returns Promise resolving to the characteristic data as
|
|
367
|
+
* @returns Promise resolving to the characteristic data as ByteArray
|
|
297
368
|
*/
|
|
298
369
|
readCharacteristic(deviceId, serviceId, characteristicId) {
|
|
299
370
|
return new Promise((resolve, reject) => {
|
|
@@ -346,7 +417,7 @@ export class BleNitroManager {
|
|
|
346
417
|
* @param serviceId ID of the service
|
|
347
418
|
* @param characteristicId ID of the characteristic
|
|
348
419
|
* @param callback Callback function called when notification is received
|
|
349
|
-
* @returns
|
|
420
|
+
* @returns Subscription
|
|
350
421
|
*/
|
|
351
422
|
subscribeToCharacteristic(deviceId, serviceId, characteristicId, callback) {
|
|
352
423
|
// Check if connected first
|
|
@@ -397,7 +468,7 @@ export class BleNitroManager {
|
|
|
397
468
|
}
|
|
398
469
|
/**
|
|
399
470
|
* Check if Bluetooth is enabled
|
|
400
|
-
* @returns
|
|
471
|
+
* @returns returns Boolean according to Bluetooth state
|
|
401
472
|
*/
|
|
402
473
|
isBluetoothEnabled() {
|
|
403
474
|
return this.state() === BLEState.PoweredOn;
|
|
@@ -420,7 +491,7 @@ export class BleNitroManager {
|
|
|
420
491
|
}
|
|
421
492
|
/**
|
|
422
493
|
* Get the current Bluetooth state
|
|
423
|
-
* @returns
|
|
494
|
+
* @returns Bluetooth state
|
|
424
495
|
* @see BLEState
|
|
425
496
|
*/
|
|
426
497
|
state() {
|
|
@@ -430,7 +501,7 @@ export class BleNitroManager {
|
|
|
430
501
|
* Subscribe to Bluetooth state changes
|
|
431
502
|
* @param callback Callback function called when state changes
|
|
432
503
|
* @param emitInitial Whether to emit initial state callback
|
|
433
|
-
* @returns
|
|
504
|
+
* @returns Subscription
|
|
434
505
|
* @see BLEState
|
|
435
506
|
*/
|
|
436
507
|
subscribeToStateChange(callback, emitInitial = false) {
|
|
@@ -46,6 +46,7 @@ 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
48
|
export type WriteCharacteristicCallback = (success: boolean, responseData: BLEValue, error: string) => void;
|
|
49
|
+
export type ReadRSSICallback = (success: boolean, rssi: number, error: string) => void;
|
|
49
50
|
export type RestoreCallback = (restoredPeripherals: BLEDevice[]) => void;
|
|
50
51
|
export type OperationResult = {
|
|
51
52
|
success: boolean;
|
|
@@ -64,10 +65,11 @@ export interface NativeBleNitro extends HybridObject<{
|
|
|
64
65
|
stopScan(): boolean;
|
|
65
66
|
isScanning(): boolean;
|
|
66
67
|
getConnectedDevices(services: string[]): BLEDevice[];
|
|
67
|
-
connect(deviceId: string, callback: ConnectionCallback, disconnectCallback?: DisconnectionEventCallback): void;
|
|
68
|
+
connect(deviceId: string, callback: ConnectionCallback, disconnectCallback?: DisconnectionEventCallback, autoConnectAndroid?: boolean): void;
|
|
68
69
|
disconnect(deviceId: string, callback: OperationCallback): void;
|
|
69
70
|
isConnected(deviceId: string): boolean;
|
|
70
71
|
requestMTU(deviceId: string, mtu: number): number;
|
|
72
|
+
readRSSI(deviceId: string, callback: ReadRSSICallback): void;
|
|
71
73
|
discoverServices(deviceId: string, callback: OperationCallback): void;
|
|
72
74
|
getServices(deviceId: string): string[];
|
|
73
75
|
getCharacteristics(deviceId: string, serviceId: string): string[];
|
|
@@ -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"
|
|
@@ -122,9 +123,9 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
122
123
|
return __vector;
|
|
123
124
|
}();
|
|
124
125
|
}
|
|
125
|
-
void JHybridNativeBleNitroSpec::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) {
|
|
126
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string_std__string::javaobject> /* callback */, jni::alias_ref<JFunc_void_std__string_bool_std__string::javaobject> /* disconnectCallback */)>("connect_cxx");
|
|
127
|
-
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_std__string_std__string_cxx::fromCpp(callback), disconnectCallback.has_value() ? JFunc_void_std__string_bool_std__string_cxx::fromCpp(disconnectCallback.value()) : nullptr);
|
|
126
|
+
void JHybridNativeBleNitroSpec::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, std::optional<bool> autoConnectAndroid) {
|
|
127
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string_std__string::javaobject> /* callback */, jni::alias_ref<JFunc_void_std__string_bool_std__string::javaobject> /* disconnectCallback */, jni::alias_ref<jni::JBoolean> /* autoConnectAndroid */)>("connect_cxx");
|
|
128
|
+
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_std__string_std__string_cxx::fromCpp(callback), disconnectCallback.has_value() ? JFunc_void_std__string_bool_std__string_cxx::fromCpp(disconnectCallback.value()) : nullptr, autoConnectAndroid.has_value() ? jni::JBoolean::valueOf(autoConnectAndroid.value()) : nullptr);
|
|
128
129
|
}
|
|
129
130
|
void JHybridNativeBleNitroSpec::disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) {
|
|
130
131
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("disconnect_cxx");
|
|
@@ -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));
|
|
@@ -58,10 +58,11 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
58
58
|
bool stopScan() override;
|
|
59
59
|
bool isScanning() override;
|
|
60
60
|
std::vector<BLEDevice> getConnectedDevices(const std::vector<std::string>& services) override;
|
|
61
|
-
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) override;
|
|
61
|
+
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, std::optional<bool> autoConnectAndroid) override;
|
|
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;
|
|
@@ -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
|
@@ -70,12 +70,12 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
|
|
|
70
70
|
@Keep
|
|
71
71
|
abstract fun getConnectedDevices(services: Array<String>): Array<BLEDevice>
|
|
72
72
|
|
|
73
|
-
abstract fun connect(deviceId: String, callback: (success: Boolean, deviceId: String, error: String) -> Unit, disconnectCallback: ((deviceId: String, interrupted: Boolean, error: String) -> Unit)?): Unit
|
|
73
|
+
abstract fun connect(deviceId: String, callback: (success: Boolean, deviceId: String, error: String) -> Unit, disconnectCallback: ((deviceId: String, interrupted: Boolean, error: String) -> Unit)?, autoConnectAndroid: Boolean?): Unit
|
|
74
74
|
|
|
75
75
|
@DoNotStrip
|
|
76
76
|
@Keep
|
|
77
|
-
private fun connect_cxx(deviceId: String, callback: Func_void_bool_std__string_std__string, disconnectCallback: Func_void_std__string_bool_std__string?): Unit {
|
|
78
|
-
val __result = connect(deviceId, callback, disconnectCallback?.let { it })
|
|
77
|
+
private fun connect_cxx(deviceId: String, callback: Func_void_bool_std__string_std__string, disconnectCallback: Func_void_std__string_bool_std__string?, autoConnectAndroid: Boolean?): Unit {
|
|
78
|
+
val __result = connect(deviceId, callback, disconnectCallback?.let { it }, autoConnectAndroid)
|
|
79
79
|
return __result
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -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
|
|
@@ -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);
|