react-native-ble-nitro 1.0.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.
Files changed (58) hide show
  1. package/README.md +25 -17
  2. package/ios/BleNitroBleManager.swift +126 -57
  3. package/ios/BlePeripheralDelegate.swift +36 -8
  4. package/lib/commonjs/index.d.ts +29 -20
  5. package/lib/commonjs/index.d.ts.map +1 -1
  6. package/lib/commonjs/index.js +113 -143
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +19 -14
  9. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
  10. package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
  11. package/lib/index.d.ts +29 -20
  12. package/lib/index.js +112 -142
  13. package/lib/specs/NativeBleNitro.nitro.d.ts +19 -14
  14. package/nitrogen/generated/android/BleNitroOnLoad.cpp +6 -12
  15. package/nitrogen/generated/android/c++/JBLEDevice.hpp +3 -0
  16. package/nitrogen/generated/android/c++/JFunc_void_BLEDevice.hpp +3 -0
  17. package/nitrogen/generated/android/c++/JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp +78 -0
  18. package/nitrogen/generated/android/c++/JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp +78 -0
  19. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +111 -65
  20. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +13 -13
  21. package/nitrogen/generated/android/c++/JManufacturerData.hpp +3 -0
  22. package/nitrogen/generated/android/c++/JManufacturerDataEntry.hpp +7 -15
  23. package/nitrogen/generated/android/c++/JOperationResult.hpp +58 -0
  24. 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
  25. 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
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +20 -65
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ManufacturerDataEntry.kt +1 -1
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/OperationResult.kt +32 -0
  29. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +15 -39
  30. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +108 -113
  31. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +6 -0
  32. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +57 -28
  33. 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
  34. package/nitrogen/generated/ios/swift/{Func_void_std__string_std__vector_double_.swift → Func_void_std__string_std__shared_ptr_ArrayBuffer_.swift} +11 -11
  35. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +13 -13
  36. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +84 -136
  37. package/nitrogen/generated/ios/swift/ManufacturerDataEntry.swift +5 -17
  38. package/nitrogen/generated/ios/swift/OperationResult.swift +64 -0
  39. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -1
  40. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +20 -14
  41. package/nitrogen/generated/shared/c++/ManufacturerDataEntry.hpp +8 -7
  42. package/nitrogen/generated/shared/c++/OperationResult.hpp +72 -0
  43. package/package.json +1 -1
  44. package/react-native.config.js +10 -2
  45. package/src/__tests__/index.test.ts +19 -22
  46. package/src/index.ts +147 -164
  47. package/src/specs/NativeBleNitro.nitro.ts +22 -14
  48. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +0 -74
  49. package/nitrogen/generated/android/c++/JFunc_void_bool_std__vector_double__std__string.hpp +0 -86
  50. package/nitrogen/generated/android/c++/JFunc_void_std__string_std__vector_double_.hpp +0 -86
  51. package/nitrogen/generated/android/c++/JFunc_void_std__vector_BLEDevice_.hpp +0 -99
  52. package/nitrogen/generated/android/c++/JFunc_void_std__vector_std__string_.hpp +0 -93
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_bool.kt +0 -81
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_.kt +0 -81
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_std__vector_std__string_.kt +0 -81
  56. package/nitrogen/generated/ios/swift/Func_void_bool.swift +0 -47
  57. package/nitrogen/generated/ios/swift/Func_void_std__vector_BLEDevice_.swift +0 -47
  58. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +0 -47
@@ -15,24 +15,24 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
15
15
 
16
16
  // Methods
17
17
  func startScan(filter: ScanFilter, callback: @escaping (_ device: BLEDevice) -> Void) throws -> Void
18
- func stopScan(callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
19
- func isScanning(callback: @escaping (_ result: Bool) -> Void) throws -> Void
20
- func getConnectedDevices(callback: @escaping (_ devices: [BLEDevice]) -> Void) throws -> Void
18
+ func stopScan() throws -> Bool
19
+ func isScanning() throws -> Bool
20
+ func getConnectedDevices(services: [String]) throws -> [BLEDevice]
21
21
  func connect(deviceId: String, callback: @escaping (_ success: Bool, _ deviceId: String, _ error: String) -> Void, disconnectCallback: ((_ deviceId: String, _ interrupted: Bool, _ error: String) -> Void)?) throws -> Void
22
22
  func disconnect(deviceId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
23
- func isConnected(deviceId: String, callback: @escaping (_ result: Bool) -> Void) throws -> Void
23
+ func isConnected(deviceId: String) throws -> Bool
24
+ func requestMTU(deviceId: String, mtu: Double) throws -> Double
24
25
  func discoverServices(deviceId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
25
- func getServices(deviceId: String, callback: @escaping (_ result: [String]) -> Void) throws -> Void
26
- func getCharacteristics(deviceId: String, serviceId: String, callback: @escaping (_ result: [String]) -> Void) throws -> Void
27
- func readCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ data: [Double], _ error: String) -> Void) throws -> Void
28
- func writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: [Double], withResponse: Bool, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
29
- func subscribeToCharacteristic(deviceId: String, serviceId: String, characteristicId: String, updateCallback: @escaping (_ characteristicId: String, _ data: [Double]) -> Void, resultCallback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
26
+ func getServices(deviceId: String) throws -> [String]
27
+ func getCharacteristics(deviceId: String, serviceId: String) throws -> [String]
28
+ func readCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ data: ArrayBuffer, _ error: String) -> Void) throws -> Void
29
+ func writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Bool, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
30
+ func subscribeToCharacteristic(deviceId: String, serviceId: String, characteristicId: String, updateCallback: @escaping (_ characteristicId: String, _ data: ArrayBuffer) -> Void, resultCallback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
30
31
  func unsubscribeFromCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
31
- func isBluetoothEnabled(callback: @escaping (_ result: Bool) -> Void) throws -> Void
32
32
  func requestBluetoothEnable(callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
33
- func state(callback: @escaping (_ state: BLEState) -> Void) throws -> Void
34
- func subscribeToStateChange(stateCallback: @escaping (_ state: BLEState) -> Void, resultCallback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
35
- func unsubscribeFromStateChange(resultCallback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
33
+ func state() throws -> BLEState
34
+ func subscribeToStateChange(stateCallback: @escaping (_ state: BLEState) -> Void) throws -> OperationResult
35
+ func unsubscribeFromStateChange() throws -> OperationResult
36
36
  func openSettings() throws -> Promise<Void>
37
37
  }
38
38
 
@@ -126,56 +126,44 @@ open class HybridNativeBleNitroSpec_cxx {
126
126
  }
127
127
 
128
128
  @inline(__always)
129
- public final func stopScan(callback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
129
+ public final func stopScan() -> bridge.Result_bool_ {
130
130
  do {
131
- try self.__implementation.stopScan(callback: { () -> (Bool, String) -> Void in
132
- let __wrappedFunction = bridge.wrap_Func_void_bool_std__string(callback)
133
- return { (__success: Bool, __error: String) -> Void in
134
- __wrappedFunction.call(__success, std.string(__error))
135
- }
136
- }())
137
- return bridge.create_Result_void_()
131
+ let __result = try self.__implementation.stopScan()
132
+ let __resultCpp = __result
133
+ return bridge.create_Result_bool_(__resultCpp)
138
134
  } catch (let __error) {
139
135
  let __exceptionPtr = __error.toCpp()
140
- return bridge.create_Result_void_(__exceptionPtr)
136
+ return bridge.create_Result_bool_(__exceptionPtr)
141
137
  }
142
138
  }
143
139
 
144
140
  @inline(__always)
145
- public final func isScanning(callback: bridge.Func_void_bool) -> bridge.Result_void_ {
141
+ public final func isScanning() -> bridge.Result_bool_ {
146
142
  do {
147
- try self.__implementation.isScanning(callback: { () -> (Bool) -> Void in
148
- let __wrappedFunction = bridge.wrap_Func_void_bool(callback)
149
- return { (__result: Bool) -> Void in
150
- __wrappedFunction.call(__result)
151
- }
152
- }())
153
- return bridge.create_Result_void_()
143
+ let __result = try self.__implementation.isScanning()
144
+ let __resultCpp = __result
145
+ return bridge.create_Result_bool_(__resultCpp)
154
146
  } catch (let __error) {
155
147
  let __exceptionPtr = __error.toCpp()
156
- return bridge.create_Result_void_(__exceptionPtr)
148
+ return bridge.create_Result_bool_(__exceptionPtr)
157
149
  }
158
150
  }
159
151
 
160
152
  @inline(__always)
161
- public final func getConnectedDevices(callback: bridge.Func_void_std__vector_BLEDevice_) -> bridge.Result_void_ {
153
+ public final func getConnectedDevices(services: bridge.std__vector_std__string_) -> bridge.Result_std__vector_BLEDevice__ {
162
154
  do {
163
- try self.__implementation.getConnectedDevices(callback: { () -> ([BLEDevice]) -> Void in
164
- let __wrappedFunction = bridge.wrap_Func_void_std__vector_BLEDevice_(callback)
165
- return { (__devices: [BLEDevice]) -> Void in
166
- __wrappedFunction.call({ () -> bridge.std__vector_BLEDevice_ in
167
- var __vector = bridge.create_std__vector_BLEDevice_(__devices.count)
168
- for __item in __devices {
169
- __vector.push_back(__item)
170
- }
171
- return __vector
172
- }())
155
+ let __result = try self.__implementation.getConnectedDevices(services: services.map({ __item in String(__item) }))
156
+ let __resultCpp = { () -> bridge.std__vector_BLEDevice_ in
157
+ var __vector = bridge.create_std__vector_BLEDevice_(__result.count)
158
+ for __item in __result {
159
+ __vector.push_back(__item)
173
160
  }
174
- }())
175
- return bridge.create_Result_void_()
161
+ return __vector
162
+ }()
163
+ return bridge.create_Result_std__vector_BLEDevice__(__resultCpp)
176
164
  } catch (let __error) {
177
165
  let __exceptionPtr = __error.toCpp()
178
- return bridge.create_Result_void_(__exceptionPtr)
166
+ return bridge.create_Result_std__vector_BLEDevice__(__exceptionPtr)
179
167
  }
180
168
  }
181
169
 
@@ -223,18 +211,26 @@ open class HybridNativeBleNitroSpec_cxx {
223
211
  }
224
212
 
225
213
  @inline(__always)
226
- public final func isConnected(deviceId: std.string, callback: bridge.Func_void_bool) -> bridge.Result_void_ {
214
+ public final func isConnected(deviceId: std.string) -> bridge.Result_bool_ {
227
215
  do {
228
- try self.__implementation.isConnected(deviceId: String(deviceId), callback: { () -> (Bool) -> Void in
229
- let __wrappedFunction = bridge.wrap_Func_void_bool(callback)
230
- return { (__result: Bool) -> Void in
231
- __wrappedFunction.call(__result)
232
- }
233
- }())
234
- return bridge.create_Result_void_()
216
+ let __result = try self.__implementation.isConnected(deviceId: String(deviceId))
217
+ let __resultCpp = __result
218
+ return bridge.create_Result_bool_(__resultCpp)
235
219
  } catch (let __error) {
236
220
  let __exceptionPtr = __error.toCpp()
237
- return bridge.create_Result_void_(__exceptionPtr)
221
+ return bridge.create_Result_bool_(__exceptionPtr)
222
+ }
223
+ }
224
+
225
+ @inline(__always)
226
+ public final func requestMTU(deviceId: std.string, mtu: Double) -> bridge.Result_double_ {
227
+ do {
228
+ let __result = try self.__implementation.requestMTU(deviceId: String(deviceId), mtu: mtu)
229
+ let __resultCpp = __result
230
+ return bridge.create_Result_double_(__resultCpp)
231
+ } catch (let __error) {
232
+ let __exceptionPtr = __error.toCpp()
233
+ return bridge.create_Result_double_(__exceptionPtr)
238
234
  }
239
235
  }
240
236
 
@@ -255,62 +251,48 @@ open class HybridNativeBleNitroSpec_cxx {
255
251
  }
256
252
 
257
253
  @inline(__always)
258
- public final func getServices(deviceId: std.string, callback: bridge.Func_void_std__vector_std__string_) -> bridge.Result_void_ {
254
+ public final func getServices(deviceId: std.string) -> bridge.Result_std__vector_std__string__ {
259
255
  do {
260
- try self.__implementation.getServices(deviceId: String(deviceId), callback: { () -> ([String]) -> Void in
261
- let __wrappedFunction = bridge.wrap_Func_void_std__vector_std__string_(callback)
262
- return { (__result: [String]) -> Void in
263
- __wrappedFunction.call({ () -> bridge.std__vector_std__string_ in
264
- var __vector = bridge.create_std__vector_std__string_(__result.count)
265
- for __item in __result {
266
- __vector.push_back(std.string(__item))
267
- }
268
- return __vector
269
- }())
256
+ let __result = try self.__implementation.getServices(deviceId: String(deviceId))
257
+ let __resultCpp = { () -> bridge.std__vector_std__string_ in
258
+ var __vector = bridge.create_std__vector_std__string_(__result.count)
259
+ for __item in __result {
260
+ __vector.push_back(std.string(__item))
270
261
  }
271
- }())
272
- return bridge.create_Result_void_()
262
+ return __vector
263
+ }()
264
+ return bridge.create_Result_std__vector_std__string__(__resultCpp)
273
265
  } catch (let __error) {
274
266
  let __exceptionPtr = __error.toCpp()
275
- return bridge.create_Result_void_(__exceptionPtr)
267
+ return bridge.create_Result_std__vector_std__string__(__exceptionPtr)
276
268
  }
277
269
  }
278
270
 
279
271
  @inline(__always)
280
- public final func getCharacteristics(deviceId: std.string, serviceId: std.string, callback: bridge.Func_void_std__vector_std__string_) -> bridge.Result_void_ {
272
+ public final func getCharacteristics(deviceId: std.string, serviceId: std.string) -> bridge.Result_std__vector_std__string__ {
281
273
  do {
282
- try self.__implementation.getCharacteristics(deviceId: String(deviceId), serviceId: String(serviceId), callback: { () -> ([String]) -> Void in
283
- let __wrappedFunction = bridge.wrap_Func_void_std__vector_std__string_(callback)
284
- return { (__result: [String]) -> Void in
285
- __wrappedFunction.call({ () -> bridge.std__vector_std__string_ in
286
- var __vector = bridge.create_std__vector_std__string_(__result.count)
287
- for __item in __result {
288
- __vector.push_back(std.string(__item))
289
- }
290
- return __vector
291
- }())
274
+ let __result = try self.__implementation.getCharacteristics(deviceId: String(deviceId), serviceId: String(serviceId))
275
+ let __resultCpp = { () -> bridge.std__vector_std__string_ in
276
+ var __vector = bridge.create_std__vector_std__string_(__result.count)
277
+ for __item in __result {
278
+ __vector.push_back(std.string(__item))
292
279
  }
293
- }())
294
- return bridge.create_Result_void_()
280
+ return __vector
281
+ }()
282
+ return bridge.create_Result_std__vector_std__string__(__resultCpp)
295
283
  } catch (let __error) {
296
284
  let __exceptionPtr = __error.toCpp()
297
- return bridge.create_Result_void_(__exceptionPtr)
285
+ return bridge.create_Result_std__vector_std__string__(__exceptionPtr)
298
286
  }
299
287
  }
300
288
 
301
289
  @inline(__always)
302
- public final func readCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, callback: bridge.Func_void_bool_std__vector_double__std__string) -> bridge.Result_void_ {
290
+ public final func readCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, callback: bridge.Func_void_bool_std__shared_ptr_ArrayBuffer__std__string) -> bridge.Result_void_ {
303
291
  do {
304
- try self.__implementation.readCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), callback: { () -> (Bool, [Double], String) -> Void in
305
- let __wrappedFunction = bridge.wrap_Func_void_bool_std__vector_double__std__string(callback)
306
- return { (__success: Bool, __data: [Double], __error: String) -> Void in
307
- __wrappedFunction.call(__success, { () -> bridge.std__vector_double_ in
308
- var __vector = bridge.create_std__vector_double_(__data.count)
309
- for __item in __data {
310
- __vector.push_back(__item)
311
- }
312
- return __vector
313
- }(), std.string(__error))
292
+ try self.__implementation.readCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), callback: { () -> (Bool, ArrayBuffer, String) -> Void in
293
+ let __wrappedFunction = bridge.wrap_Func_void_bool_std__shared_ptr_ArrayBuffer__std__string(callback)
294
+ return { (__success: Bool, __data: ArrayBuffer, __error: String) -> Void in
295
+ __wrappedFunction.call(__success, __data, std.string(__error))
314
296
  }
315
297
  }())
316
298
  return bridge.create_Result_void_()
@@ -321,9 +303,9 @@ open class HybridNativeBleNitroSpec_cxx {
321
303
  }
322
304
 
323
305
  @inline(__always)
324
- public final func writeCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, data: bridge.std__vector_double_, withResponse: Bool, callback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
306
+ public final func writeCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, data: ArrayBuffer, withResponse: Bool, callback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
325
307
  do {
326
- try self.__implementation.writeCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), data: data.map({ __item in __item }), withResponse: withResponse, callback: { () -> (Bool, String) -> Void in
308
+ try self.__implementation.writeCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), data: data, withResponse: withResponse, callback: { () -> (Bool, String) -> Void in
327
309
  let __wrappedFunction = bridge.wrap_Func_void_bool_std__string(callback)
328
310
  return { (__success: Bool, __error: String) -> Void in
329
311
  __wrappedFunction.call(__success, std.string(__error))
@@ -337,18 +319,12 @@ open class HybridNativeBleNitroSpec_cxx {
337
319
  }
338
320
 
339
321
  @inline(__always)
340
- public final func subscribeToCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, updateCallback: bridge.Func_void_std__string_std__vector_double_, resultCallback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
322
+ public final func subscribeToCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, updateCallback: bridge.Func_void_std__string_std__shared_ptr_ArrayBuffer_, resultCallback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
341
323
  do {
342
- try self.__implementation.subscribeToCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), updateCallback: { () -> (String, [Double]) -> Void in
343
- let __wrappedFunction = bridge.wrap_Func_void_std__string_std__vector_double_(updateCallback)
344
- return { (__characteristicId: String, __data: [Double]) -> Void in
345
- __wrappedFunction.call(std.string(__characteristicId), { () -> bridge.std__vector_double_ in
346
- var __vector = bridge.create_std__vector_double_(__data.count)
347
- for __item in __data {
348
- __vector.push_back(__item)
349
- }
350
- return __vector
351
- }())
324
+ try self.__implementation.subscribeToCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), updateCallback: { () -> (String, ArrayBuffer) -> Void in
325
+ let __wrappedFunction = bridge.wrap_Func_void_std__string_std__shared_ptr_ArrayBuffer_(updateCallback)
326
+ return { (__characteristicId: String, __data: ArrayBuffer) -> Void in
327
+ __wrappedFunction.call(std.string(__characteristicId), __data)
352
328
  }
353
329
  }(), resultCallback: { () -> (Bool, String) -> Void in
354
330
  let __wrappedFunction = bridge.wrap_Func_void_bool_std__string(resultCallback)
@@ -379,22 +355,6 @@ open class HybridNativeBleNitroSpec_cxx {
379
355
  }
380
356
  }
381
357
 
382
- @inline(__always)
383
- public final func isBluetoothEnabled(callback: bridge.Func_void_bool) -> bridge.Result_void_ {
384
- do {
385
- try self.__implementation.isBluetoothEnabled(callback: { () -> (Bool) -> Void in
386
- let __wrappedFunction = bridge.wrap_Func_void_bool(callback)
387
- return { (__result: Bool) -> Void in
388
- __wrappedFunction.call(__result)
389
- }
390
- }())
391
- return bridge.create_Result_void_()
392
- } catch (let __error) {
393
- let __exceptionPtr = __error.toCpp()
394
- return bridge.create_Result_void_(__exceptionPtr)
395
- }
396
- }
397
-
398
358
  @inline(__always)
399
359
  public final func requestBluetoothEnable(callback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
400
360
  do {
@@ -412,55 +372,43 @@ open class HybridNativeBleNitroSpec_cxx {
412
372
  }
413
373
 
414
374
  @inline(__always)
415
- public final func state(callback: bridge.Func_void_BLEState) -> bridge.Result_void_ {
375
+ public final func state() -> bridge.Result_BLEState_ {
416
376
  do {
417
- try self.__implementation.state(callback: { () -> (BLEState) -> Void in
418
- let __wrappedFunction = bridge.wrap_Func_void_BLEState(callback)
419
- return { (__state: BLEState) -> Void in
420
- __wrappedFunction.call(__state.rawValue)
421
- }
422
- }())
423
- return bridge.create_Result_void_()
377
+ let __result = try self.__implementation.state()
378
+ let __resultCpp = __result
379
+ return bridge.create_Result_BLEState_(__resultCpp)
424
380
  } catch (let __error) {
425
381
  let __exceptionPtr = __error.toCpp()
426
- return bridge.create_Result_void_(__exceptionPtr)
382
+ return bridge.create_Result_BLEState_(__exceptionPtr)
427
383
  }
428
384
  }
429
385
 
430
386
  @inline(__always)
431
- public final func subscribeToStateChange(stateCallback: bridge.Func_void_BLEState, resultCallback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
387
+ public final func subscribeToStateChange(stateCallback: bridge.Func_void_BLEState) -> bridge.Result_OperationResult_ {
432
388
  do {
433
- try self.__implementation.subscribeToStateChange(stateCallback: { () -> (BLEState) -> Void in
389
+ let __result = try self.__implementation.subscribeToStateChange(stateCallback: { () -> (BLEState) -> Void in
434
390
  let __wrappedFunction = bridge.wrap_Func_void_BLEState(stateCallback)
435
391
  return { (__state: BLEState) -> Void in
436
392
  __wrappedFunction.call(__state.rawValue)
437
393
  }
438
- }(), resultCallback: { () -> (Bool, String) -> Void in
439
- let __wrappedFunction = bridge.wrap_Func_void_bool_std__string(resultCallback)
440
- return { (__success: Bool, __error: String) -> Void in
441
- __wrappedFunction.call(__success, std.string(__error))
442
- }
443
394
  }())
444
- return bridge.create_Result_void_()
395
+ let __resultCpp = __result
396
+ return bridge.create_Result_OperationResult_(__resultCpp)
445
397
  } catch (let __error) {
446
398
  let __exceptionPtr = __error.toCpp()
447
- return bridge.create_Result_void_(__exceptionPtr)
399
+ return bridge.create_Result_OperationResult_(__exceptionPtr)
448
400
  }
449
401
  }
450
402
 
451
403
  @inline(__always)
452
- public final func unsubscribeFromStateChange(resultCallback: bridge.Func_void_bool_std__string) -> bridge.Result_void_ {
404
+ public final func unsubscribeFromStateChange() -> bridge.Result_OperationResult_ {
453
405
  do {
454
- try self.__implementation.unsubscribeFromStateChange(resultCallback: { () -> (Bool, String) -> Void in
455
- let __wrappedFunction = bridge.wrap_Func_void_bool_std__string(resultCallback)
456
- return { (__success: Bool, __error: String) -> Void in
457
- __wrappedFunction.call(__success, std.string(__error))
458
- }
459
- }())
460
- return bridge.create_Result_void_()
406
+ let __result = try self.__implementation.unsubscribeFromStateChange()
407
+ let __resultCpp = __result
408
+ return bridge.create_Result_OperationResult_(__resultCpp)
461
409
  } catch (let __error) {
462
410
  let __exceptionPtr = __error.toCpp()
463
- return bridge.create_Result_void_(__exceptionPtr)
411
+ return bridge.create_Result_OperationResult_(__exceptionPtr)
464
412
  }
465
413
  }
466
414
 
@@ -18,14 +18,8 @@ public extension ManufacturerDataEntry {
18
18
  /**
19
19
  * Create a new instance of `ManufacturerDataEntry`.
20
20
  */
21
- init(id: String, data: [Double]) {
22
- self.init(std.string(id), { () -> bridge.std__vector_double_ in
23
- var __vector = bridge.create_std__vector_double_(data.count)
24
- for __item in data {
25
- __vector.push_back(__item)
26
- }
27
- return __vector
28
- }())
21
+ init(id: String, data: ArrayBuffer) {
22
+ self.init(std.string(id), data.getArrayBuffer())
29
23
  }
30
24
 
31
25
  var id: String {
@@ -39,20 +33,14 @@ public extension ManufacturerDataEntry {
39
33
  }
40
34
  }
41
35
 
42
- var data: [Double] {
36
+ var data: ArrayBuffer {
43
37
  @inline(__always)
44
38
  get {
45
- return self.__data.map({ __item in __item })
39
+ return ArrayBuffer(self.__data)
46
40
  }
47
41
  @inline(__always)
48
42
  set {
49
- self.__data = { () -> bridge.std__vector_double_ in
50
- var __vector = bridge.create_std__vector_double_(newValue.count)
51
- for __item in newValue {
52
- __vector.push_back(__item)
53
- }
54
- return __vector
55
- }()
43
+ self.__data = newValue.getArrayBuffer()
56
44
  }
57
45
  }
58
46
  }
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// OperationResult.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `OperationResult`, backed by a C++ struct.
12
+ */
13
+ public typealias OperationResult = margelo.nitro.co.zyke.ble.OperationResult
14
+
15
+ public extension OperationResult {
16
+ private typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `OperationResult`.
20
+ */
21
+ init(success: Bool, error: String?) {
22
+ self.init(success, { () -> bridge.std__optional_std__string_ in
23
+ if let __unwrappedValue = error {
24
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
25
+ } else {
26
+ return .init()
27
+ }
28
+ }())
29
+ }
30
+
31
+ var success: Bool {
32
+ @inline(__always)
33
+ get {
34
+ return self.__success
35
+ }
36
+ @inline(__always)
37
+ set {
38
+ self.__success = newValue
39
+ }
40
+ }
41
+
42
+ var error: String? {
43
+ @inline(__always)
44
+ get {
45
+ return { () -> String? in
46
+ if let __unwrapped = self.__error.value {
47
+ return String(__unwrapped)
48
+ } else {
49
+ return nil
50
+ }
51
+ }()
52
+ }
53
+ @inline(__always)
54
+ set {
55
+ self.__error = { () -> bridge.std__optional_std__string_ in
56
+ if let __unwrappedValue = newValue {
57
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
58
+ } else {
59
+ return .init()
60
+ }
61
+ }()
62
+ }
63
+ }
64
+ }
@@ -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);
@@ -28,7 +29,6 @@ namespace margelo::nitro::co::zyke::ble {
28
29
  prototype.registerHybridMethod("writeCharacteristic", &HybridNativeBleNitroSpec::writeCharacteristic);
29
30
  prototype.registerHybridMethod("subscribeToCharacteristic", &HybridNativeBleNitroSpec::subscribeToCharacteristic);
30
31
  prototype.registerHybridMethod("unsubscribeFromCharacteristic", &HybridNativeBleNitroSpec::unsubscribeFromCharacteristic);
31
- prototype.registerHybridMethod("isBluetoothEnabled", &HybridNativeBleNitroSpec::isBluetoothEnabled);
32
32
  prototype.registerHybridMethod("requestBluetoothEnable", &HybridNativeBleNitroSpec::requestBluetoothEnable);
33
33
  prototype.registerHybridMethod("state", &HybridNativeBleNitroSpec::state);
34
34
  prototype.registerHybridMethod("subscribeToStateChange", &HybridNativeBleNitroSpec::subscribeToStateChange);
@@ -17,16 +17,22 @@
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; }
24
+ // Forward declaration of `OperationResult` to properly resolve imports.
25
+ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
22
26
 
23
27
  #include "ScanFilter.hpp"
24
28
  #include "BLEDevice.hpp"
25
29
  #include <functional>
26
- #include <string>
27
30
  #include <vector>
31
+ #include <string>
28
32
  #include <optional>
33
+ #include <NitroModules/ArrayBuffer.hpp>
29
34
  #include "BLEState.hpp"
35
+ #include "OperationResult.hpp"
30
36
  #include <NitroModules/Promise.hpp>
31
37
 
32
38
  namespace margelo::nitro::co::zyke::ble {
@@ -61,24 +67,24 @@ namespace margelo::nitro::co::zyke::ble {
61
67
  public:
62
68
  // Methods
63
69
  virtual void startScan(const ScanFilter& filter, const std::function<void(const BLEDevice& /* device */)>& callback) = 0;
64
- virtual void stopScan(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
65
- virtual void isScanning(const std::function<void(bool /* result */)>& callback) = 0;
66
- virtual void getConnectedDevices(const std::function<void(const std::vector<BLEDevice>& /* devices */)>& callback) = 0;
70
+ virtual bool stopScan() = 0;
71
+ virtual bool isScanning() = 0;
72
+ virtual std::vector<BLEDevice> getConnectedDevices(const std::vector<std::string>& services) = 0;
67
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;
68
74
  virtual void disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
69
- virtual void isConnected(const std::string& deviceId, const std::function<void(bool /* result */)>& callback) = 0;
75
+ virtual bool isConnected(const std::string& deviceId) = 0;
76
+ virtual double requestMTU(const std::string& deviceId, double mtu) = 0;
70
77
  virtual void discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
71
- virtual void getServices(const std::string& deviceId, const std::function<void(const std::vector<std::string>& /* result */)>& callback) = 0;
72
- virtual void getCharacteristics(const std::string& deviceId, const std::string& serviceId, const std::function<void(const std::vector<std::string>& /* result */)>& callback) = 0;
73
- virtual void readCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::vector<double>& /* data */, const std::string& /* error */)>& callback) = 0;
74
- virtual void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::vector<double>& data, bool withResponse, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
75
- 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::vector<double>& /* data */)>& updateCallback, const std::function<void(bool /* success */, const std::string& /* error */)>& resultCallback) = 0;
78
+ virtual std::vector<std::string> getServices(const std::string& deviceId) = 0;
79
+ virtual std::vector<std::string> getCharacteristics(const std::string& deviceId, const std::string& serviceId) = 0;
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;
76
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;
77
- virtual void isBluetoothEnabled(const std::function<void(bool /* result */)>& callback) = 0;
78
84
  virtual void requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
79
- virtual void state(const std::function<void(BLEState /* state */)>& callback) = 0;
80
- virtual void subscribeToStateChange(const std::function<void(BLEState /* state */)>& stateCallback, const std::function<void(bool /* success */, const std::string& /* error */)>& resultCallback) = 0;
81
- virtual void unsubscribeFromStateChange(const std::function<void(bool /* success */, const std::string& /* error */)>& resultCallback) = 0;
85
+ virtual BLEState state() = 0;
86
+ virtual OperationResult subscribeToStateChange(const std::function<void(BLEState /* state */)>& stateCallback) = 0;
87
+ virtual OperationResult unsubscribeFromStateChange() = 0;
82
88
  virtual std::shared_ptr<Promise<void>> openSettings() = 0;
83
89
 
84
90
  protected:
@@ -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 <vector>
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::vector<double> data SWIFT_PRIVATE;
35
+ std::shared_ptr<ArrayBuffer> data SWIFT_PRIVATE;
35
36
 
36
37
  public:
37
38
  ManufacturerDataEntry() = default;
38
- explicit ManufacturerDataEntry(std::string id, std::vector<double> data): id(id), data(data) {}
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::vector<double>>::fromJSI(runtime, obj.getProperty(runtime, "data"))
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::vector<double>>::toJSI(runtime, arg.data));
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::vector<double>>::canConvert(runtime, obj.getProperty(runtime, "data"))) return false;
68
+ if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, "data"))) return false;
68
69
  return true;
69
70
  }
70
71
  };