react-native-ble-nitro 1.3.1 → 1.4.1

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 (38) hide show
  1. package/README.md +37 -13
  2. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +48 -7
  3. package/ios/BleNitroBleManager.swift +95 -6
  4. package/ios/BlePeripheralDelegate.swift +13 -3
  5. package/lib/commonjs/index.d.ts +4 -194
  6. package/lib/commonjs/index.d.ts.map +1 -1
  7. package/lib/commonjs/index.js +6 -441
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/manager.d.ts +204 -0
  10. package/lib/commonjs/manager.d.ts.map +1 -0
  11. package/lib/commonjs/manager.js +471 -0
  12. package/lib/commonjs/manager.js.map +1 -0
  13. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +4 -1
  14. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
  15. package/lib/index.d.ts +4 -194
  16. package/lib/index.js +3 -436
  17. package/lib/manager.d.ts +203 -0
  18. package/lib/manager.js +457 -0
  19. package/lib/specs/NativeBleNitro.nitro.d.ts +4 -1
  20. package/nitrogen/generated/android/BleNitroOnLoad.cpp +2 -0
  21. package/nitrogen/generated/android/c++/JFunc_void_std__vector_BLEDevice_.hpp +102 -0
  22. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +9 -4
  23. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +2 -1
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_.kt +81 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +11 -2
  26. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +8 -0
  27. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +38 -16
  28. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +16 -10
  29. package/nitrogen/generated/ios/swift/Func_void_std__vector_BLEDevice_.swift +47 -0
  30. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +2 -1
  31. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +27 -5
  32. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
  33. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +7 -6
  34. package/package.json +9 -1
  35. package/src/__tests__/index.test.ts +75 -15
  36. package/src/index.ts +24 -609
  37. package/src/manager.ts +629 -0
  38. package/src/specs/NativeBleNitro.nitro.ts +6 -1
@@ -16,6 +16,7 @@
16
16
  #include <NitroModules/HybridObjectRegistry.hpp>
17
17
 
18
18
  #include "JHybridNativeBleNitroSpec.hpp"
19
+ #include "JFunc_void_std__vector_BLEDevice_.hpp"
19
20
  #include "JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp"
20
21
  #include "JFunc_void_bool_std__string_std__string.hpp"
21
22
  #include "JFunc_void_std__string_bool_std__string.hpp"
@@ -35,6 +36,7 @@ int initialize(JavaVM* vm) {
35
36
  return facebook::jni::initialize(vm, [] {
36
37
  // Register native JNI methods
37
38
  margelo::nitro::co::zyke::ble::JHybridNativeBleNitroSpec::registerNatives();
39
+ margelo::nitro::co::zyke::ble::JFunc_void_std__vector_BLEDevice__cxx::registerNatives();
38
40
  margelo::nitro::co::zyke::ble::JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::registerNatives();
39
41
  margelo::nitro::co::zyke::ble::JFunc_void_bool_std__string_std__string_cxx::registerNatives();
40
42
  margelo::nitro::co::zyke::ble::JFunc_void_std__string_bool_std__string_cxx::registerNatives();
@@ -0,0 +1,102 @@
1
+ ///
2
+ /// JFunc_void_std__vector_BLEDevice_.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "BLEDevice.hpp"
14
+ #include <vector>
15
+ #include <functional>
16
+ #include "JBLEDevice.hpp"
17
+ #include <string>
18
+ #include "ManufacturerData.hpp"
19
+ #include "JManufacturerData.hpp"
20
+ #include "ManufacturerDataEntry.hpp"
21
+ #include "JManufacturerDataEntry.hpp"
22
+ #include <NitroModules/ArrayBuffer.hpp>
23
+ #include <NitroModules/JArrayBuffer.hpp>
24
+ #include <NitroModules/JUnit.hpp>
25
+
26
+ namespace margelo::nitro::co::zyke::ble {
27
+
28
+ using namespace facebook;
29
+
30
+ /**
31
+ * Represents the Java/Kotlin callback `(restoredPeripherals: Array<BLEDevice>) -> Unit`.
32
+ * This can be passed around between C++ and Java/Kotlin.
33
+ */
34
+ struct JFunc_void_std__vector_BLEDevice_: public jni::JavaClass<JFunc_void_std__vector_BLEDevice_> {
35
+ public:
36
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_;";
37
+
38
+ public:
39
+ /**
40
+ * Invokes the function this `JFunc_void_std__vector_BLEDevice_` instance holds through JNI.
41
+ */
42
+ void invoke(const std::vector<BLEDevice>& restoredPeripherals) const {
43
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<JBLEDevice>> /* restoredPeripherals */)>("invoke");
44
+ method(self(), [&]() {
45
+ size_t __size = restoredPeripherals.size();
46
+ jni::local_ref<jni::JArrayClass<JBLEDevice>> __array = jni::JArrayClass<JBLEDevice>::newArray(__size);
47
+ for (size_t __i = 0; __i < __size; __i++) {
48
+ const auto& __element = restoredPeripherals[__i];
49
+ __array->setElement(__i, *JBLEDevice::fromCpp(__element));
50
+ }
51
+ return __array;
52
+ }());
53
+ }
54
+ };
55
+
56
+ /**
57
+ * An implementation of Func_void_std__vector_BLEDevice_ that is backed by a C++ implementation (using `std::function<...>`)
58
+ */
59
+ struct JFunc_void_std__vector_BLEDevice__cxx final: public jni::HybridClass<JFunc_void_std__vector_BLEDevice__cxx, JFunc_void_std__vector_BLEDevice_> {
60
+ public:
61
+ static jni::local_ref<JFunc_void_std__vector_BLEDevice_::javaobject> fromCpp(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& func) {
62
+ return JFunc_void_std__vector_BLEDevice__cxx::newObjectCxxArgs(func);
63
+ }
64
+
65
+ public:
66
+ /**
67
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_BLEDevice__cxx` instance holds.
68
+ */
69
+ void invoke_cxx(jni::alias_ref<jni::JArrayClass<JBLEDevice>> restoredPeripherals) {
70
+ _func([&]() {
71
+ size_t __size = restoredPeripherals->size();
72
+ std::vector<BLEDevice> __vector;
73
+ __vector.reserve(__size);
74
+ for (size_t __i = 0; __i < __size; __i++) {
75
+ auto __element = restoredPeripherals->getElement(__i);
76
+ __vector.push_back(__element->toCpp());
77
+ }
78
+ return __vector;
79
+ }());
80
+ }
81
+
82
+ public:
83
+ [[nodiscard]]
84
+ inline const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& getFunction() const {
85
+ return _func;
86
+ }
87
+
88
+ public:
89
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice__cxx;";
90
+ static void registerNatives() {
91
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__vector_BLEDevice__cxx::invoke_cxx)});
92
+ }
93
+
94
+ private:
95
+ explicit JFunc_void_std__vector_BLEDevice__cxx(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& func): _func(func) { }
96
+
97
+ private:
98
+ friend HybridBase;
99
+ std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)> _func;
100
+ };
101
+
102
+ } // namespace margelo::nitro::co::zyke::ble
@@ -42,11 +42,12 @@ namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
42
42
  #include <optional>
43
43
  #include <NitroModules/Promise.hpp>
44
44
  #include <NitroModules/JPromise.hpp>
45
+ #include <functional>
46
+ #include "JFunc_void_std__vector_BLEDevice_.hpp"
45
47
  #include "ScanFilter.hpp"
46
48
  #include "JScanFilter.hpp"
47
49
  #include "AndroidScanMode.hpp"
48
50
  #include "JAndroidScanMode.hpp"
49
- #include <functional>
50
51
  #include "JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp"
51
52
  #include "JFunc_void_bool_std__string_std__string.hpp"
52
53
  #include "JFunc_void_std__string_bool_std__string.hpp"
@@ -81,6 +82,10 @@ namespace margelo::nitro::co::zyke::ble {
81
82
 
82
83
 
83
84
  // Methods
85
+ void JHybridNativeBleNitroSpec::setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) {
86
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__vector_BLEDevice_::javaobject> /* callback */)>("setRestoreStateCallback_cxx");
87
+ method(_javaPart, JFunc_void_std__vector_BLEDevice__cxx::fromCpp(callback));
88
+ }
84
89
  void JHybridNativeBleNitroSpec::startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) {
85
90
  static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JScanFilter> /* filter */, jni::alias_ref<JFunc_void_std__optional_BLEDevice__std__optional_std__string_::javaobject> /* callback */)>("startScan_cxx");
86
91
  method(_javaPart, JScanFilter::fromCpp(filter), JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::fromCpp(callback));
@@ -171,9 +176,9 @@ namespace margelo::nitro::co::zyke::ble {
171
176
  static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string::javaobject> /* callback */)>("readCharacteristic_cxx");
172
177
  method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::fromCpp(callback));
173
178
  }
174
- void JHybridNativeBleNitroSpec::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) {
175
- static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JArrayBuffer::javaobject> /* data */, jboolean /* withResponse */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("writeCharacteristic_cxx");
176
- method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JArrayBuffer::wrap(data), withResponse, JFunc_void_bool_std__string_cxx::fromCpp(callback));
179
+ void JHybridNativeBleNitroSpec::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) {
180
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JArrayBuffer::javaobject> /* data */, jboolean /* withResponse */, jni::alias_ref<JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string::javaobject> /* callback */)>("writeCharacteristic_cxx");
181
+ method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JArrayBuffer::wrap(data), withResponse, JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string_cxx::fromCpp(callback));
177
182
  }
178
183
  void JHybridNativeBleNitroSpec::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) {
179
184
  static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */, jni::alias_ref<jni::JString> /* characteristicId */, jni::alias_ref<JFunc_void_std__string_std__shared_ptr_ArrayBuffer_::javaobject> /* updateCallback */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* resultCallback */)>("subscribeToCharacteristic_cxx");
@@ -53,6 +53,7 @@ namespace margelo::nitro::co::zyke::ble {
53
53
 
54
54
  public:
55
55
  // Methods
56
+ void setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) override;
56
57
  void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) override;
57
58
  bool stopScan() override;
58
59
  bool isScanning() override;
@@ -65,7 +66,7 @@ namespace margelo::nitro::co::zyke::ble {
65
66
  std::vector<std::string> getServices(const std::string& deviceId) override;
66
67
  std::vector<std::string> getCharacteristics(const std::string& deviceId, const std::string& serviceId) override;
67
68
  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) override;
68
- 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) override;
69
+ 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) override;
69
70
  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;
70
71
  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;
71
72
  void requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
@@ -0,0 +1,81 @@
1
+ ///
2
+ /// Func_void_std__vector_BLEDevice_.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 `(restoredPeripherals: array) => 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_std__vector_BLEDevice_: (Array<BLEDevice>) -> 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(restoredPeripherals: Array<BLEDevice>): Unit
33
+ }
34
+
35
+ /**
36
+ * Represents the JavaScript callback `(restoredPeripherals: array) => 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_std__vector_BLEDevice__cxx: Func_void_std__vector_BLEDevice_ {
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(restoredPeripherals: Array<BLEDevice>): Unit
61
+ = invoke_cxx(restoredPeripherals)
62
+
63
+ @FastNative
64
+ private external fun invoke_cxx(restoredPeripherals: Array<BLEDevice>): Unit
65
+ }
66
+
67
+ /**
68
+ * Represents the JavaScript callback `(restoredPeripherals: array) => void`.
69
+ * This is implemented in Java/Kotlin, via a `(Array<BLEDevice>) -> Unit`.
70
+ * The callback is always coming from native.
71
+ */
72
+ @DoNotStrip
73
+ @Keep
74
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
75
+ class Func_void_std__vector_BLEDevice__java(private val function: (Array<BLEDevice>) -> Unit): Func_void_std__vector_BLEDevice_ {
76
+ @DoNotStrip
77
+ @Keep
78
+ override fun invoke(restoredPeripherals: Array<BLEDevice>): Unit {
79
+ return this.function(restoredPeripherals)
80
+ }
81
+ }
@@ -40,6 +40,15 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
40
40
 
41
41
 
42
42
  // Methods
43
+ abstract fun setRestoreStateCallback(callback: (restoredPeripherals: Array<BLEDevice>) -> Unit): Unit
44
+
45
+ @DoNotStrip
46
+ @Keep
47
+ private fun setRestoreStateCallback_cxx(callback: Func_void_std__vector_BLEDevice_): Unit {
48
+ val __result = setRestoreStateCallback(callback)
49
+ return __result
50
+ }
51
+
43
52
  abstract fun startScan(filter: ScanFilter, callback: (device: BLEDevice?, error: String?) -> Unit): Unit
44
53
 
45
54
  @DoNotStrip
@@ -113,11 +122,11 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
113
122
  return __result
114
123
  }
115
124
 
116
- abstract fun writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback: (success: Boolean, error: String) -> Unit): Unit
125
+ abstract fun writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback: (success: Boolean, responseData: ArrayBuffer, error: String) -> Unit): Unit
117
126
 
118
127
  @DoNotStrip
119
128
  @Keep
120
- private fun writeCharacteristic_cxx(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback: Func_void_bool_std__string): Unit {
129
+ private fun writeCharacteristic_cxx(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Boolean, callback: Func_void_bool_std__shared_ptr_ArrayBuffer__std__string): Unit {
121
130
  val __result = writeCharacteristic(deviceId, serviceId, characteristicId, data, withResponse, callback)
122
131
  return __result
123
132
  }
@@ -13,6 +13,14 @@
13
13
 
14
14
  namespace margelo::nitro::co::zyke::ble::bridge::swift {
15
15
 
16
+ // pragma MARK: std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>
17
+ Func_void_std__vector_BLEDevice_ create_Func_void_std__vector_BLEDevice_(void* _Nonnull swiftClosureWrapper) {
18
+ auto swiftClosure = BleNitro::Func_void_std__vector_BLEDevice_::fromUnsafe(swiftClosureWrapper);
19
+ return [swiftClosure = std::move(swiftClosure)](const std::vector<BLEDevice>& restoredPeripherals) mutable -> void {
20
+ swiftClosure.call(restoredPeripherals);
21
+ };
22
+ }
23
+
16
24
  // pragma MARK: std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>
17
25
  Func_void_std__optional_BLEDevice__std__optional_std__string_ create_Func_void_std__optional_BLEDevice__std__optional_std__string_(void* _Nonnull swiftClosureWrapper) {
18
26
  auto swiftClosure = BleNitro::Func_void_std__optional_BLEDevice__std__optional_std__string_::fromUnsafe(swiftClosureWrapper);
@@ -54,6 +54,17 @@ namespace BleNitro { class HybridNativeBleNitroSpec_cxx; }
54
54
  */
55
55
  namespace margelo::nitro::co::zyke::ble::bridge::swift {
56
56
 
57
+ // pragma MARK: std::vector<ManufacturerDataEntry>
58
+ /**
59
+ * Specialized version of `std::vector<ManufacturerDataEntry>`.
60
+ */
61
+ using std__vector_ManufacturerDataEntry_ = std::vector<ManufacturerDataEntry>;
62
+ inline std::vector<ManufacturerDataEntry> create_std__vector_ManufacturerDataEntry_(size_t size) {
63
+ std::vector<ManufacturerDataEntry> vector;
64
+ vector.reserve(size);
65
+ return vector;
66
+ }
67
+
57
68
  // pragma MARK: std::vector<std::string>
58
69
  /**
59
70
  * Specialized version of `std::vector<std::string>`.
@@ -65,17 +76,39 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
65
76
  return vector;
66
77
  }
67
78
 
68
- // pragma MARK: std::vector<ManufacturerDataEntry>
79
+ // pragma MARK: std::vector<BLEDevice>
69
80
  /**
70
- * Specialized version of `std::vector<ManufacturerDataEntry>`.
81
+ * Specialized version of `std::vector<BLEDevice>`.
71
82
  */
72
- using std__vector_ManufacturerDataEntry_ = std::vector<ManufacturerDataEntry>;
73
- inline std::vector<ManufacturerDataEntry> create_std__vector_ManufacturerDataEntry_(size_t size) {
74
- std::vector<ManufacturerDataEntry> vector;
83
+ using std__vector_BLEDevice_ = std::vector<BLEDevice>;
84
+ inline std::vector<BLEDevice> create_std__vector_BLEDevice_(size_t size) {
85
+ std::vector<BLEDevice> vector;
75
86
  vector.reserve(size);
76
87
  return vector;
77
88
  }
78
89
 
90
+ // pragma MARK: std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>
91
+ /**
92
+ * Specialized version of `std::function<void(const std::vector<BLEDevice>&)>`.
93
+ */
94
+ using Func_void_std__vector_BLEDevice_ = std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>;
95
+ /**
96
+ * Wrapper class for a `std::function<void(const std::vector<BLEDevice>& / * restoredPeripherals * /)>`, this can be used from Swift.
97
+ */
98
+ class Func_void_std__vector_BLEDevice__Wrapper final {
99
+ public:
100
+ explicit Func_void_std__vector_BLEDevice__Wrapper(std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>&& func): _function(std::make_unique<std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>>(std::move(func))) {}
101
+ inline void call(std::vector<BLEDevice> restoredPeripherals) const {
102
+ _function->operator()(restoredPeripherals);
103
+ }
104
+ private:
105
+ std::unique_ptr<std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>> _function;
106
+ } SWIFT_NONCOPYABLE;
107
+ Func_void_std__vector_BLEDevice_ create_Func_void_std__vector_BLEDevice_(void* _Nonnull swiftClosureWrapper);
108
+ inline Func_void_std__vector_BLEDevice__Wrapper wrap_Func_void_std__vector_BLEDevice_(Func_void_std__vector_BLEDevice_ value) {
109
+ return Func_void_std__vector_BLEDevice__Wrapper(std::move(value));
110
+ }
111
+
79
112
  // pragma MARK: std::optional<BLEDevice>
80
113
  /**
81
114
  * Specialized version of `std::optional<BLEDevice>`.
@@ -116,17 +149,6 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
116
149
  return Func_void_std__optional_BLEDevice__std__optional_std__string__Wrapper(std::move(value));
117
150
  }
118
151
 
119
- // pragma MARK: std::vector<BLEDevice>
120
- /**
121
- * Specialized version of `std::vector<BLEDevice>`.
122
- */
123
- using std__vector_BLEDevice_ = std::vector<BLEDevice>;
124
- inline std::vector<BLEDevice> create_std__vector_BLEDevice_(size_t size) {
125
- std::vector<BLEDevice> vector;
126
- vector.reserve(size);
127
- return vector;
128
- }
129
-
130
152
  // pragma MARK: std::function<void(bool /* success */, const std::string& /* deviceId */, const std::string& /* error */)>
131
153
  /**
132
154
  * Specialized version of `std::function<void(bool, const std::string&, const std::string&)>`.
@@ -12,10 +12,6 @@
12
12
  // Forward declaration of `HybridNativeBleNitroSpec_cxx` to properly resolve imports.
13
13
  namespace BleNitro { class HybridNativeBleNitroSpec_cxx; }
14
14
 
15
- // Forward declaration of `ScanFilter` to properly resolve imports.
16
- namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
17
- // Forward declaration of `AndroidScanMode` to properly resolve imports.
18
- namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
19
15
  // Forward declaration of `BLEDevice` to properly resolve imports.
20
16
  namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
21
17
  // Forward declaration of `ManufacturerData` to properly resolve imports.
@@ -26,22 +22,26 @@ namespace margelo::nitro::co::zyke::ble { struct ManufacturerDataEntry; }
26
22
  namespace NitroModules { class ArrayBuffer; }
27
23
  // Forward declaration of `ArrayBufferHolder` to properly resolve imports.
28
24
  namespace NitroModules { class ArrayBufferHolder; }
25
+ // Forward declaration of `ScanFilter` to properly resolve imports.
26
+ namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
27
+ // Forward declaration of `AndroidScanMode` to properly resolve imports.
28
+ namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
29
29
  // Forward declaration of `BLEState` to properly resolve imports.
30
30
  namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
31
31
  // Forward declaration of `OperationResult` to properly resolve imports.
32
32
  namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
33
33
 
34
- #include "ScanFilter.hpp"
35
- #include <string>
36
- #include <vector>
37
- #include "AndroidScanMode.hpp"
38
34
  #include "BLEDevice.hpp"
39
- #include <optional>
35
+ #include <vector>
40
36
  #include <functional>
37
+ #include <string>
41
38
  #include "ManufacturerData.hpp"
42
39
  #include "ManufacturerDataEntry.hpp"
43
40
  #include <NitroModules/ArrayBuffer.hpp>
44
41
  #include <NitroModules/ArrayBufferHolder.hpp>
42
+ #include "ScanFilter.hpp"
43
+ #include "AndroidScanMode.hpp"
44
+ #include <optional>
45
45
  #include "BLEState.hpp"
46
46
  #include "OperationResult.hpp"
47
47
  #include <NitroModules/Promise.hpp>
@@ -87,6 +87,12 @@ namespace margelo::nitro::co::zyke::ble {
87
87
 
88
88
  public:
89
89
  // Methods
90
+ inline void setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) override {
91
+ auto __result = _swiftPart.setRestoreStateCallback(callback);
92
+ if (__result.hasError()) [[unlikely]] {
93
+ std::rethrow_exception(__result.error());
94
+ }
95
+ }
90
96
  inline void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) override {
91
97
  auto __result = _swiftPart.startScan(filter, callback);
92
98
  if (__result.hasError()) [[unlikely]] {
@@ -173,7 +179,7 @@ namespace margelo::nitro::co::zyke::ble {
173
179
  std::rethrow_exception(__result.error());
174
180
  }
175
181
  }
176
- inline 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) override {
182
+ inline 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) override {
177
183
  auto __result = _swiftPart.writeCharacteristic(deviceId, serviceId, characteristicId, ArrayBufferHolder(data), std::forward<decltype(withResponse)>(withResponse), callback);
178
184
  if (__result.hasError()) [[unlikely]] {
179
185
  std::rethrow_exception(__result.error());
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_std__vector_BLEDevice_.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
+ /**
12
+ * Wraps a Swift `(_ restoredPeripherals: [BLEDevice]) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__vector_BLEDevice_ {
16
+ public typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
17
+
18
+ private let closure: (_ restoredPeripherals: [BLEDevice]) -> Void
19
+
20
+ public init(_ closure: @escaping (_ restoredPeripherals: [BLEDevice]) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(restoredPeripherals: bridge.std__vector_BLEDevice_) -> Void {
26
+ self.closure(restoredPeripherals.map({ __item in __item }))
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_std__vector_BLEDevice_`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__vector_BLEDevice_>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_BLEDevice_ {
45
+ return Unmanaged<Func_void_std__vector_BLEDevice_>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -14,6 +14,7 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
14
14
 
15
15
 
16
16
  // Methods
17
+ func setRestoreStateCallback(callback: @escaping (_ restoredPeripherals: [BLEDevice]) -> Void) throws -> Void
17
18
  func startScan(filter: ScanFilter, callback: @escaping (_ device: BLEDevice?, _ error: String?) -> Void) throws -> Void
18
19
  func stopScan() throws -> Bool
19
20
  func isScanning() throws -> Bool
@@ -26,7 +27,7 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
26
27
  func getServices(deviceId: String) throws -> [String]
27
28
  func getCharacteristics(deviceId: String, serviceId: String) throws -> [String]
28
29
  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 writeCharacteristic(deviceId: String, serviceId: String, characteristicId: String, data: ArrayBuffer, withResponse: Bool, callback: @escaping (_ success: Bool, _ responseData: ArrayBuffer, _ error: String) -> Void) throws -> Void
30
31
  func subscribeToCharacteristic(deviceId: String, serviceId: String, characteristicId: String, updateCallback: @escaping (_ characteristicId: String, _ data: ArrayBuffer) -> Void, resultCallback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
31
32
  func unsubscribeFromCharacteristic(deviceId: String, serviceId: String, characteristicId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
32
33
  func requestBluetoothEnable(callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
@@ -109,6 +109,28 @@ open class HybridNativeBleNitroSpec_cxx {
109
109
 
110
110
 
111
111
  // Methods
112
+ @inline(__always)
113
+ public final func setRestoreStateCallback(callback: bridge.Func_void_std__vector_BLEDevice_) -> bridge.Result_void_ {
114
+ do {
115
+ try self.__implementation.setRestoreStateCallback(callback: { () -> ([BLEDevice]) -> Void in
116
+ let __wrappedFunction = bridge.wrap_Func_void_std__vector_BLEDevice_(callback)
117
+ return { (__restoredPeripherals: [BLEDevice]) -> Void in
118
+ __wrappedFunction.call({ () -> bridge.std__vector_BLEDevice_ in
119
+ var __vector = bridge.create_std__vector_BLEDevice_(__restoredPeripherals.count)
120
+ for __item in __restoredPeripherals {
121
+ __vector.push_back(__item)
122
+ }
123
+ return __vector
124
+ }())
125
+ }
126
+ }())
127
+ return bridge.create_Result_void_()
128
+ } catch (let __error) {
129
+ let __exceptionPtr = __error.toCpp()
130
+ return bridge.create_Result_void_(__exceptionPtr)
131
+ }
132
+ }
133
+
112
134
  @inline(__always)
113
135
  public final func startScan(filter: ScanFilter, callback: bridge.Func_void_std__optional_BLEDevice__std__optional_std__string_) -> bridge.Result_void_ {
114
136
  do {
@@ -315,12 +337,12 @@ open class HybridNativeBleNitroSpec_cxx {
315
337
  }
316
338
 
317
339
  @inline(__always)
318
- 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_ {
340
+ public final func writeCharacteristic(deviceId: std.string, serviceId: std.string, characteristicId: std.string, data: ArrayBuffer, withResponse: Bool, callback: bridge.Func_void_bool_std__shared_ptr_ArrayBuffer__std__string) -> bridge.Result_void_ {
319
341
  do {
320
- try self.__implementation.writeCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), data: data, withResponse: withResponse, callback: { () -> (Bool, String) -> Void in
321
- let __wrappedFunction = bridge.wrap_Func_void_bool_std__string(callback)
322
- return { (__success: Bool, __error: String) -> Void in
323
- __wrappedFunction.call(__success, std.string(__error))
342
+ try self.__implementation.writeCharacteristic(deviceId: String(deviceId), serviceId: String(serviceId), characteristicId: String(characteristicId), data: data, withResponse: withResponse, callback: { () -> (Bool, ArrayBuffer, String) -> Void in
343
+ let __wrappedFunction = bridge.wrap_Func_void_bool_std__shared_ptr_ArrayBuffer__std__string(callback)
344
+ return { (__success: Bool, __responseData: ArrayBuffer, __error: String) -> Void in
345
+ __wrappedFunction.call(__success, __responseData, std.string(__error))
324
346
  }
325
347
  }())
326
348
  return bridge.create_Result_void_()
@@ -14,6 +14,7 @@ namespace margelo::nitro::co::zyke::ble {
14
14
  HybridObject::loadHybridMethods();
15
15
  // load custom methods/properties
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("setRestoreStateCallback", &HybridNativeBleNitroSpec::setRestoreStateCallback);
17
18
  prototype.registerHybridMethod("startScan", &HybridNativeBleNitroSpec::startScan);
18
19
  prototype.registerHybridMethod("stopScan", &HybridNativeBleNitroSpec::stopScan);
19
20
  prototype.registerHybridMethod("isScanning", &HybridNativeBleNitroSpec::isScanning);
@@ -13,10 +13,10 @@
13
13
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
14
  #endif
15
15
 
16
- // Forward declaration of `ScanFilter` to properly resolve imports.
17
- namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
18
16
  // Forward declaration of `BLEDevice` to properly resolve imports.
19
17
  namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
18
+ // Forward declaration of `ScanFilter` to properly resolve imports.
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
22
  // Forward declaration of `BLEState` to properly resolve imports.
@@ -24,12 +24,12 @@ namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
24
24
  // Forward declaration of `OperationResult` to properly resolve imports.
25
25
  namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
26
26
 
27
- #include "ScanFilter.hpp"
28
27
  #include "BLEDevice.hpp"
28
+ #include <vector>
29
+ #include <functional>
30
+ #include "ScanFilter.hpp"
29
31
  #include <optional>
30
32
  #include <string>
31
- #include <functional>
32
- #include <vector>
33
33
  #include <NitroModules/ArrayBuffer.hpp>
34
34
  #include "BLEState.hpp"
35
35
  #include "OperationResult.hpp"
@@ -66,6 +66,7 @@ namespace margelo::nitro::co::zyke::ble {
66
66
 
67
67
  public:
68
68
  // Methods
69
+ virtual void setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) = 0;
69
70
  virtual void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) = 0;
70
71
  virtual bool stopScan() = 0;
71
72
  virtual bool isScanning() = 0;
@@ -78,7 +79,7 @@ namespace margelo::nitro::co::zyke::ble {
78
79
  virtual std::vector<std::string> getServices(const std::string& deviceId) = 0;
79
80
  virtual std::vector<std::string> getCharacteristics(const std::string& deviceId, const std::string& serviceId) = 0;
80
81
  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 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;
82
83
  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;
83
84
  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;
84
85
  virtual void requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-nitro",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
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",
@@ -15,6 +15,14 @@
15
15
  "types": "./lib/index.d.ts",
16
16
  "default": "./src/index.ts"
17
17
  },
18
+ "./manager": {
19
+ "react-native": "./src/manager.ts",
20
+ "typescript": "./src/manager.ts",
21
+ "import": "./lib/manager.js",
22
+ "require": "./lib/commonjs/manager.js",
23
+ "types": "./lib/manager.d.ts",
24
+ "default": "./src/manager.ts"
25
+ },
18
26
  "./plugin": {
19
27
  "import": "./plugin/build/index.js",
20
28
  "require": "./plugin/build/index.js",