react-native-ble-nitro 1.7.0 → 1.8.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 (44) hide show
  1. package/README.md +12 -5
  2. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +15 -20
  3. package/ios/BleNitroBleManager.swift +10 -12
  4. package/lib/commonjs/index.d.ts +1 -1
  5. package/lib/commonjs/index.d.ts.map +1 -1
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/manager.d.ts +4 -1
  8. package/lib/commonjs/manager.d.ts.map +1 -1
  9. package/lib/commonjs/manager.js +9 -10
  10. package/lib/commonjs/manager.js.map +1 -1
  11. package/lib/commonjs/singleton.js +1 -1
  12. package/lib/commonjs/singleton.js.map +1 -1
  13. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +1 -1
  14. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
  15. package/lib/index.d.ts +1 -1
  16. package/lib/manager.d.ts +4 -1
  17. package/lib/manager.js +9 -10
  18. package/lib/singleton.js +1 -1
  19. package/lib/specs/NativeBleNitro.nitro.d.ts +1 -1
  20. package/nitrogen/generated/android/BleNitro+autolinking.cmake +7 -4
  21. package/nitrogen/generated/android/BleNitroOnLoad.cpp +2 -4
  22. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +8 -7
  23. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +1 -1
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +3 -3
  25. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +15 -15
  26. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +105 -74
  27. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +8 -6
  28. package/nitrogen/generated/ios/swift/Func_void_std__optional_BLEDevice__std__optional_std__string_.swift +3 -8
  29. package/nitrogen/generated/ios/swift/HybridNativeBleNitroFactorySpec_cxx.swift +4 -2
  30. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +1 -1
  31. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +9 -11
  32. package/nitrogen/generated/ios/swift/OperationResult.swift +2 -1
  33. package/nitrogen/generated/shared/c++/BLEDevice.hpp +8 -0
  34. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +4 -4
  35. package/nitrogen/generated/shared/c++/ManufacturerData.hpp +8 -0
  36. package/nitrogen/generated/shared/c++/ManufacturerDataEntry.hpp +8 -0
  37. package/nitrogen/generated/shared/c++/OperationResult.hpp +8 -0
  38. package/nitrogen/generated/shared/c++/ScanFilter.hpp +8 -0
  39. package/package.json +11 -11
  40. package/src/__tests__/index.test.ts +4 -3
  41. package/src/index.ts +1 -0
  42. package/src/manager.ts +17 -13
  43. package/src/singleton.ts +1 -1
  44. package/src/specs/NativeBleNitro.nitro.ts +1 -1
@@ -26,10 +26,10 @@ namespace NitroModules { class ArrayBufferHolder; }
26
26
  namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
27
27
  // Forward declaration of `AndroidScanMode` to properly resolve imports.
28
28
  namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
29
- // Forward declaration of `BLEState` to properly resolve imports.
30
- namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
31
29
  // Forward declaration of `OperationResult` to properly resolve imports.
32
30
  namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
31
+ // Forward declaration of `BLEState` to properly resolve imports.
32
+ namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
33
33
 
34
34
  #include <string>
35
35
  #include <optional>
@@ -42,8 +42,8 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
42
42
  #include <NitroModules/ArrayBufferHolder.hpp>
43
43
  #include "ScanFilter.hpp"
44
44
  #include "AndroidScanMode.hpp"
45
- #include "BLEState.hpp"
46
45
  #include "OperationResult.hpp"
46
+ #include "BLEState.hpp"
47
47
  #include <NitroModules/Promise.hpp>
48
48
 
49
49
  #include "BleNitro-Swift-Cxx-Umbrella.hpp"
@@ -100,7 +100,7 @@ namespace margelo::nitro::co::zyke::ble {
100
100
  }
101
101
  }
102
102
  inline void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) override {
103
- auto __result = _swiftPart.startScan(filter, callback);
103
+ auto __result = _swiftPart.startScan(std::forward<decltype(filter)>(filter), callback);
104
104
  if (__result.hasError()) [[unlikely]] {
105
105
  std::rethrow_exception(__result.error());
106
106
  }
@@ -197,11 +197,13 @@ namespace margelo::nitro::co::zyke::ble {
197
197
  std::rethrow_exception(__result.error());
198
198
  }
199
199
  }
200
- inline void subscribeToCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(const std::string& /* characteristicId */, const std::shared_ptr<ArrayBuffer>& /* data */)>& updateCallback, const std::function<void(bool /* success */, const std::string& /* error */)>& resultCallback) override {
201
- auto __result = _swiftPart.subscribeToCharacteristic(deviceId, serviceId, characteristicId, updateCallback, resultCallback);
200
+ inline OperationResult 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) override {
201
+ auto __result = _swiftPart.subscribeToCharacteristic(deviceId, serviceId, characteristicId, updateCallback);
202
202
  if (__result.hasError()) [[unlikely]] {
203
203
  std::rethrow_exception(__result.error());
204
204
  }
205
+ auto __value = std::move(__result.value());
206
+ return __value;
205
207
  }
206
208
  inline void unsubscribeFromCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override {
207
209
  auto __result = _swiftPart.unsubscribeFromCharacteristic(deviceId, serviceId, characteristicId, callback);
@@ -23,14 +23,9 @@ public final class Func_void_std__optional_BLEDevice__std__optional_std__string_
23
23
 
24
24
  @inline(__always)
25
25
  public func call(device: bridge.std__optional_BLEDevice_, error: bridge.std__optional_std__string_) -> Void {
26
- self.closure({ () -> BLEDevice? in
27
- if let __unwrapped = device.value {
28
- return __unwrapped
29
- } else {
30
- return nil
31
- }
32
- }(), { () -> String? in
33
- if let __unwrapped = error.value {
26
+ self.closure(device.value, { () -> String? in
27
+ if bridge.has_value_std__optional_std__string_(error) {
28
+ let __unwrapped = bridge.get_std__optional_std__string_(error)
34
29
  return String(__unwrapped)
35
30
  } else {
36
31
  return nil
@@ -113,13 +113,15 @@ open class HybridNativeBleNitroFactorySpec_cxx {
113
113
  public final func create(nativeRestoreStateIdentifier: bridge.std__optional_std__string_, restoreStateCallback: bridge.std__optional_std__function_void_const_std__vector_BLEDevice______peripherals______) -> bridge.Result_std__shared_ptr_HybridNativeBleNitroSpec__ {
114
114
  do {
115
115
  let __result = try self.__implementation.create(nativeRestoreStateIdentifier: { () -> String? in
116
- if let __unwrapped = nativeRestoreStateIdentifier.value {
116
+ if bridge.has_value_std__optional_std__string_(nativeRestoreStateIdentifier) {
117
+ let __unwrapped = bridge.get_std__optional_std__string_(nativeRestoreStateIdentifier)
117
118
  return String(__unwrapped)
118
119
  } else {
119
120
  return nil
120
121
  }
121
122
  }(), restoreStateCallback: { () -> ((_ peripherals: [BLEDevice]) -> Void)? in
122
- if let __unwrapped = restoreStateCallback.value {
123
+ if bridge.has_value_std__optional_std__function_void_const_std__vector_BLEDevice______peripherals______(restoreStateCallback) {
124
+ let __unwrapped = bridge.get_std__optional_std__function_void_const_std__vector_BLEDevice______peripherals______(restoreStateCallback)
123
125
  return { () -> ([BLEDevice]) -> Void in
124
126
  let __wrappedFunction = bridge.wrap_Func_void_std__vector_BLEDevice_(__unwrapped)
125
127
  return { (__peripherals: [BLEDevice]) -> Void in
@@ -29,7 +29,7 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
29
29
  func getCharacteristics(deviceId: String, serviceId: String) throws -> [String]
30
30
  func readCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ data: ArrayBuffer, _ error: String) -> Void) throws -> Void
31
31
  func writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Bool, callback: @escaping (_ success: Bool, _ responseData: ArrayBuffer, _ error: String) -> Void) throws -> Void
32
- func subscribeToCharacteristic(deviceId: String, serviceId: String, characteristicId: String, updateCallback: @escaping (_ characteristicId: String, _ data: ArrayBuffer) -> Void, resultCallback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
32
+ func subscribeToCharacteristic(deviceId: String, serviceId: String, characteristicId: String, updateCallback: @escaping (_ characteristicId: String, _ data: ArrayBuffer) -> Void) throws -> OperationResult
33
33
  func unsubscribeFromCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
34
34
  func requestBluetoothEnable(callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
35
35
  func state() throws -> BLEState
@@ -120,7 +120,8 @@ open class HybridNativeBleNitroSpec_cxx {
120
120
  @inline(__always)
121
121
  set {
122
122
  self.__implementation.restoreStateIdentifier = { () -> String? in
123
- if let __unwrapped = newValue.value {
123
+ if bridge.has_value_std__optional_std__string_(newValue) {
124
+ let __unwrapped = bridge.get_std__optional_std__string_(newValue)
124
125
  return String(__unwrapped)
125
126
  } else {
126
127
  return nil
@@ -231,7 +232,8 @@ open class HybridNativeBleNitroSpec_cxx {
231
232
  __wrappedFunction.call(__success, std.string(__deviceId), std.string(__error))
232
233
  }
233
234
  }(), disconnectCallback: { () -> ((_ deviceId: String, _ interrupted: Bool, _ error: String) -> Void)? in
234
- if let __unwrapped = disconnectCallback.value {
235
+ if bridge.has_value_std__optional_std__function_void_const_std__string_____deviceId_____bool____interrupted_____const_std__string_____error______(disconnectCallback) {
236
+ let __unwrapped = bridge.get_std__optional_std__function_void_const_std__string_____deviceId_____bool____interrupted_____const_std__string_____error______(disconnectCallback)
235
237
  return { () -> (String, Bool, String) -> Void in
236
238
  let __wrappedFunction = bridge.wrap_Func_void_std__string_bool_std__string(__unwrapped)
237
239
  return { (__deviceId: String, __interrupted: Bool, __error: String) -> Void in
@@ -390,23 +392,19 @@ open class HybridNativeBleNitroSpec_cxx {
390
392
  }
391
393
 
392
394
  @inline(__always)
393
- 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_ {
395
+ public final func subscribeToCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, updateCallback: bridge.Func_void_std__string_std__shared_ptr_ArrayBuffer_) -> bridge.Result_OperationResult_ {
394
396
  do {
395
- try self.__implementation.subscribeToCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), updateCallback: { () -> (String, ArrayBuffer) -> Void in
397
+ let __result = try self.__implementation.subscribeToCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), updateCallback: { () -> (String, ArrayBuffer) -> Void in
396
398
  let __wrappedFunction = bridge.wrap_Func_void_std__string_std__shared_ptr_ArrayBuffer_(updateCallback)
397
399
  return { (__characteristicId: String, __data: ArrayBuffer) -> Void in
398
400
  __wrappedFunction.call(std.string(__characteristicId), __data)
399
401
  }
400
- }(), resultCallback: { () -> (Bool, String) -> Void in
401
- let __wrappedFunction = bridge.wrap_Func_void_bool_std__string(resultCallback)
402
- return { (__success: Bool, __error: String) -> Void in
403
- __wrappedFunction.call(__success, std.string(__error))
404
- }
405
402
  }())
406
- return bridge.create_Result_void_()
403
+ let __resultCpp = __result
404
+ return bridge.create_Result_OperationResult_(__resultCpp)
407
405
  } catch (let __error) {
408
406
  let __exceptionPtr = __error.toCpp()
409
- return bridge.create_Result_void_(__exceptionPtr)
407
+ return bridge.create_Result_OperationResult_(__exceptionPtr)
410
408
  }
411
409
  }
412
410
 
@@ -43,7 +43,8 @@ public extension OperationResult {
43
43
  @inline(__always)
44
44
  get {
45
45
  return { () -> String? in
46
- if let __unwrapped = self.__error.value {
46
+ if bridge.has_value_std__optional_std__string_(self.__error) {
47
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__error)
47
48
  return String(__unwrapped)
48
49
  } else {
49
50
  return nil
@@ -17,6 +17,11 @@
17
17
  #else
18
18
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
19
  #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
20
25
 
21
26
  // Forward declaration of `ManufacturerData` to properly resolve imports.
22
27
  namespace margelo::nitro::co::zyke::ble { struct ManufacturerData; }
@@ -80,6 +85,9 @@ namespace margelo::nitro {
80
85
  return false;
81
86
  }
82
87
  jsi::Object obj = value.getObject(runtime);
88
+ if (!nitro::isPlainObject(runtime, obj)) {
89
+ return false;
90
+ }
83
91
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "id"))) return false;
84
92
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "name"))) return false;
85
93
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "rssi"))) return false;
@@ -19,10 +19,10 @@ namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
19
19
  namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
20
20
  // Forward declaration of `ArrayBuffer` to properly resolve imports.
21
21
  namespace NitroModules { class ArrayBuffer; }
22
- // Forward declaration of `BLEState` to properly resolve imports.
23
- namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
24
22
  // Forward declaration of `OperationResult` to properly resolve imports.
25
23
  namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
24
+ // Forward declaration of `BLEState` to properly resolve imports.
25
+ namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
26
26
 
27
27
  #include <string>
28
28
  #include <optional>
@@ -31,8 +31,8 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
31
31
  #include <functional>
32
32
  #include "ScanFilter.hpp"
33
33
  #include <NitroModules/ArrayBuffer.hpp>
34
- #include "BLEState.hpp"
35
34
  #include "OperationResult.hpp"
35
+ #include "BLEState.hpp"
36
36
  #include <NitroModules/Promise.hpp>
37
37
 
38
38
  namespace margelo::nitro::co::zyke::ble {
@@ -82,7 +82,7 @@ namespace margelo::nitro::co::zyke::ble {
82
82
  virtual std::vector<std::string> getCharacteristics(const std::string& deviceId, const std::string& serviceId) = 0;
83
83
  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;
84
84
  virtual void writeCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::shared_ptr<ArrayBuffer>& data, bool withResponse, const std::function<void(bool /* success */, const std::shared_ptr<ArrayBuffer>& /* responseData */, const std::string& /* error */)>& callback) = 0;
85
- 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;
85
+ virtual OperationResult 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) = 0;
86
86
  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;
87
87
  virtual void requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
88
88
  virtual BLEState state() = 0;
@@ -17,6 +17,11 @@
17
17
  #else
18
18
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
19
  #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
20
25
 
21
26
  // Forward declaration of `ManufacturerDataEntry` to properly resolve imports.
22
27
  namespace margelo::nitro::co::zyke::ble { struct ManufacturerDataEntry; }
@@ -61,6 +66,9 @@ namespace margelo::nitro {
61
66
  return false;
62
67
  }
63
68
  jsi::Object obj = value.getObject(runtime);
69
+ if (!nitro::isPlainObject(runtime, obj)) {
70
+ return false;
71
+ }
64
72
  if (!JSIConverter<std::vector<margelo::nitro::co::zyke::ble::ManufacturerDataEntry>>::canConvert(runtime, obj.getProperty(runtime, "companyIdentifiers"))) return false;
65
73
  return true;
66
74
  }
@@ -17,6 +17,11 @@
17
17
  #else
18
18
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
19
  #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
20
25
 
21
26
  // Forward declaration of `ArrayBuffer` to properly resolve imports.
22
27
  namespace NitroModules { class ArrayBuffer; }
@@ -64,6 +69,9 @@ namespace margelo::nitro {
64
69
  return false;
65
70
  }
66
71
  jsi::Object obj = value.getObject(runtime);
72
+ if (!nitro::isPlainObject(runtime, obj)) {
73
+ return false;
74
+ }
67
75
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "id"))) return false;
68
76
  if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, "data"))) return false;
69
77
  return true;
@@ -17,6 +17,11 @@
17
17
  #else
18
18
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
19
  #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
20
25
 
21
26
 
22
27
 
@@ -63,6 +68,9 @@ namespace margelo::nitro {
63
68
  return false;
64
69
  }
65
70
  jsi::Object obj = value.getObject(runtime);
71
+ if (!nitro::isPlainObject(runtime, obj)) {
72
+ return false;
73
+ }
66
74
  if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "success"))) return false;
67
75
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "error"))) return false;
68
76
  return true;
@@ -17,6 +17,11 @@
17
17
  #else
18
18
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
19
  #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
20
25
 
21
26
  // Forward declaration of `AndroidScanMode` to properly resolve imports.
22
27
  namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
@@ -71,6 +76,9 @@ namespace margelo::nitro {
71
76
  return false;
72
77
  }
73
78
  jsi::Object obj = value.getObject(runtime);
79
+ if (!nitro::isPlainObject(runtime, obj)) {
80
+ return false;
81
+ }
74
82
  if (!JSIConverter<std::vector<std::string>>::canConvert(runtime, obj.getProperty(runtime, "serviceUUIDs"))) return false;
75
83
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "rssiThreshold"))) return false;
76
84
  if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "allowDuplicates"))) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-nitro",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "High-performance React Native BLE library built on Nitro Modules",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  "build:commonjs": "tsc --project tsconfig.commonjs.json",
47
47
  "build:plugin": "tsc --project plugin/tsconfig.json",
48
48
  "prepublishOnly": "npm run build && npm run test",
49
- "nitro-codegen": "nitro-codegen src",
49
+ "nitro-codegen": "nitrogen src",
50
50
  "clean": "rimraf lib && rimraf plugin/build && rimraf nitrogen/generated",
51
51
  "test": "jest",
52
52
  "lint": "eslint src/ --ext .ts,.tsx",
@@ -84,21 +84,21 @@
84
84
  "react-native-nitro-modules": "*"
85
85
  },
86
86
  "devDependencies": {
87
- "@expo/config-plugins": "^10.1.2",
87
+ "@expo/config-plugins": "^54.0.2",
88
88
  "@types/jest": "^29.5.0",
89
- "@types/node": "^20.0.0",
90
- "@types/react": "^19.1.0",
89
+ "@types/node": "^20.19.21",
90
+ "@types/react": "^19.2.2",
91
91
  "@typescript-eslint/eslint-plugin": "^6.21.0",
92
92
  "@typescript-eslint/parser": "^6.21.0",
93
93
  "eslint": "^8.0.0",
94
- "expo-module-scripts": "^4.1.9",
94
+ "expo-module-scripts": "^5.0.7",
95
95
  "jest": "^29.0.0",
96
- "nitro-codegen": "^0.28.0",
97
- "react-native": "^0.81.0",
98
- "react-native-nitro-modules": "^0.28.0",
96
+ "nitrogen": "^0.30.0",
97
+ "react-native": "^0.81.4",
98
+ "react-native-nitro-modules": "^0.30.0",
99
99
  "rimraf": "^6.0.1",
100
- "ts-jest": "^29.4.0",
101
- "typescript": "^5.8.3"
100
+ "ts-jest": "^29.4.5",
101
+ "typescript": "^5.9.3"
102
102
  },
103
103
  "files": [
104
104
  "lib/",
@@ -245,12 +245,13 @@ describe('BleNitro', () => {
245
245
  });
246
246
  await BleManager.connect('device');
247
247
 
248
- // Mock subscription
249
- mockNative.subscribeToCharacteristic.mockImplementation((_device: string, _service: string, _char: string, updateCallback: (charId: string, data: ArrayBuffer) => void, resultCallback: (success: boolean, error: string) => void) => {
250
- resultCallback(true, '');
248
+ // Mock subscription - now returns OperationResult
249
+ mockNative.subscribeToCharacteristic.mockImplementation((_device: string, _service: string, _char: string, updateCallback: (charId: string, data: ArrayBuffer) => void) => {
251
250
  // Simulate notification
252
251
  const testData = new Uint8Array([1, 2, 3]);
253
252
  updateCallback('char-id', testData.buffer);
253
+ // Return OperationResult
254
+ return { success: true, error: null };
254
255
  });
255
256
 
256
257
  const notificationCallback = jest.fn();
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export {
10
10
  type OperationCallback,
11
11
  type CharacteristicUpdateCallback,
12
12
  type Subscription,
13
+ type AsyncSubscription,
13
14
  type BleNitroManagerOptions,
14
15
  BLEState,
15
16
  AndroidScanMode,
package/src/manager.ts CHANGED
@@ -57,6 +57,10 @@ export type Subscription = {
57
57
  remove: () => void;
58
58
  };
59
59
 
60
+ export type AsyncSubscription = {
61
+ remove: () => Promise<void>;
62
+ }
63
+
60
64
  export enum BLEState {
61
65
  Unknown = 'Unknown',
62
66
  Resetting = 'Resetting',
@@ -584,41 +588,41 @@ export class BleNitroManager {
584
588
  serviceId: string,
585
589
  characteristicId: string,
586
590
  callback: CharacteristicUpdateCallback
587
- ): Subscription {
591
+ ): AsyncSubscription {
588
592
  // Check if connected first
589
593
  if (!this._connectedDevices[deviceId]) {
590
594
  throw new Error('Device not connected');
591
595
  }
592
596
 
593
- let _success = false;
594
-
595
- this.Instance.subscribeToCharacteristic(
597
+ const { success, error } = this.Instance.subscribeToCharacteristic(
596
598
  deviceId,
597
599
  BleNitroManager.normalizeGattUUID(serviceId),
598
600
  BleNitroManager.normalizeGattUUID(characteristicId),
599
601
  (charId: string, data: ArrayBuffer) => {
600
602
  callback(charId, arrayBufferToByteArray(data));
601
603
  },
602
- (success, error) => {
603
- _success = success;
604
- if (!success) {
605
- throw new Error(error);
606
- }
607
- }
608
604
  );
609
605
 
610
- return {
611
- remove: () => {
606
+ const _success = success;
607
+
608
+ if (!_success) {
609
+ throw new Error(error ?? 'Failed to subscribe to characteristic');
610
+ }
611
+
612
+ const sub: AsyncSubscription = {
613
+ remove: async () => {
612
614
  if (!_success) {
613
615
  return;
614
616
  }
615
- this.unsubscribeFromCharacteristic(
617
+ await this.unsubscribeFromCharacteristic(
616
618
  deviceId,
617
619
  serviceId,
618
620
  characteristicId
619
621
  ).catch(() => {});
620
622
  }
621
623
  };
624
+
625
+ return sub;
622
626
  }
623
627
 
624
628
  /**
package/src/singleton.ts CHANGED
@@ -10,7 +10,7 @@ export class BleNitro extends BleNitroManager {
10
10
  */
11
11
  public static instance(): BleNitroManager {
12
12
  if (!_instance) {
13
- _instance = new BleNitro();
13
+ _instance = new BleNitroManager();
14
14
  }
15
15
  return _instance;
16
16
  }
@@ -97,7 +97,7 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
97
97
  // Characteristic operations
98
98
  readCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: ReadCharacteristicCallback): void;
99
99
  writeCharacteristic(deviceId: string, serviceId: string, characteristicId: string, data: BLEValue, withResponse: boolean, callback: WriteCharacteristicCallback): void;
100
- subscribeToCharacteristic(deviceId: string, serviceId: string, characteristicId: string, updateCallback: CharacteristicCallback, resultCallback: OperationCallback): void;
100
+ subscribeToCharacteristic(deviceId: string, serviceId: string, characteristicId: string, updateCallback: CharacteristicCallback): OperationResult;
101
101
  unsubscribeFromCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: OperationCallback): void;
102
102
 
103
103
  // Bluetooth state management