react-native-ble-nitro 1.10.2 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/cpp/cpp-adapter.cpp +4 -1
- package/lib/commonjs/manager.d.ts +2 -3
- package/lib/commonjs/manager.d.ts.map +1 -1
- package/lib/commonjs/manager.js +14 -23
- package/lib/commonjs/manager.js.map +1 -1
- package/lib/manager.d.ts +2 -3
- package/lib/manager.js +14 -23
- package/nitrogen/generated/android/BleNitroOnLoad.cpp +48 -32
- package/nitrogen/generated/android/BleNitroOnLoad.hpp +13 -4
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroFactorySpec.cpp +20 -26
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroFactorySpec.hpp +19 -22
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +43 -49
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +19 -22
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroFactorySpec.kt +15 -18
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +15 -18
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Variant_NullType_BLEDevice.kt +0 -6
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Variant_NullType_String.kt +0 -6
- package/package.json +9 -9
- package/src/__tests__/index.test.ts +22 -1
- package/src/manager.ts +15 -24
|
@@ -18,34 +18,33 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
18
18
|
|
|
19
19
|
using namespace facebook;
|
|
20
20
|
|
|
21
|
-
class JHybridNativeBleNitroFactorySpec: public
|
|
22
|
-
public virtual HybridNativeBleNitroFactorySpec {
|
|
21
|
+
class JHybridNativeBleNitroFactorySpec: public virtual HybridNativeBleNitroFactorySpec, public virtual JHybridObject {
|
|
23
22
|
public:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
HybridBase
|
|
33
|
-
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/HybridNativeBleNitroFactorySpec;";
|
|
25
|
+
std::shared_ptr<JHybridNativeBleNitroFactorySpec> getJHybridNativeBleNitroFactorySpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/HybridNativeBleNitroFactorySpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
34
35
|
|
|
35
36
|
public:
|
|
37
|
+
explicit JHybridNativeBleNitroFactorySpec(const jni::local_ref<JHybridNativeBleNitroFactorySpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridNativeBleNitroFactorySpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
36
41
|
~JHybridNativeBleNitroFactorySpec() override {
|
|
37
42
|
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
43
|
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
public:
|
|
42
|
-
|
|
43
|
-
bool equals(const std::shared_ptr<HybridObject>& other) override;
|
|
44
|
-
void dispose() noexcept override;
|
|
45
|
-
std::string toString() override;
|
|
46
|
-
|
|
47
|
-
public:
|
|
48
|
-
inline const jni::global_ref<JHybridNativeBleNitroFactorySpec::javaobject>& getJavaPart() const noexcept {
|
|
47
|
+
inline const jni::global_ref<JHybridNativeBleNitroFactorySpec::JavaPart>& getJavaPart() const noexcept {
|
|
49
48
|
return _javaPart;
|
|
50
49
|
}
|
|
51
50
|
|
|
@@ -58,9 +57,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
58
57
|
std::shared_ptr<HybridNativeBleNitroSpec> create(const std::optional<std::string>& nativeRestoreStateIdentifier, const std::optional<std::function<void(const std::vector<BLEDevice>& /* peripherals */)>>& restoreStateCallback) override;
|
|
59
58
|
|
|
60
59
|
private:
|
|
61
|
-
|
|
62
|
-
using HybridBase::HybridBase;
|
|
63
|
-
jni::global_ref<JHybridNativeBleNitroFactorySpec::javaobject> _javaPart;
|
|
60
|
+
jni::global_ref<JHybridNativeBleNitroFactorySpec::JavaPart> _javaPart;
|
|
64
61
|
};
|
|
65
62
|
|
|
66
63
|
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -63,75 +63,69 @@ namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
|
|
|
63
63
|
|
|
64
64
|
namespace margelo::nitro::co::zyke::ble {
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
66
|
+
std::shared_ptr<JHybridNativeBleNitroSpec> JHybridNativeBleNitroSpec::JavaPart::getJHybridNativeBleNitroSpec() {
|
|
67
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
68
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridNativeBleNitroSpec>(hybridObject);
|
|
69
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
70
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridNativeBleNitroSpec!");
|
|
71
|
+
}
|
|
72
|
+
return castHybridObject;
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return method(_javaPart);
|
|
75
|
+
jni::local_ref<JHybridNativeBleNitroSpec::CxxPart::jhybriddata> JHybridNativeBleNitroSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
76
|
+
return makeCxxInstance(jThis);
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
std::shared_ptr<JHybridObject> JHybridNativeBleNitroSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
80
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridNativeBleNitroSpec::JavaPart>(javaPart);
|
|
81
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
82
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridNativeBleNitroSpec::JavaPart!");
|
|
84
83
|
}
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
void JHybridNativeBleNitroSpec::dispose() noexcept {
|
|
89
|
-
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
90
|
-
method(_javaPart);
|
|
84
|
+
return std::make_shared<JHybridNativeBleNitroSpec>(castJavaPart);
|
|
91
85
|
}
|
|
92
86
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
void JHybridNativeBleNitroSpec::CxxPart::registerNatives() {
|
|
88
|
+
registerHybrid({
|
|
89
|
+
makeNativeMethod("initHybrid", JHybridNativeBleNitroSpec::CxxPart::initHybrid),
|
|
90
|
+
});
|
|
97
91
|
}
|
|
98
92
|
|
|
99
93
|
// Properties
|
|
100
94
|
std::optional<std::string> JHybridNativeBleNitroSpec::getRestoreStateIdentifier() {
|
|
101
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getRestoreStateIdentifier");
|
|
95
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getRestoreStateIdentifier");
|
|
102
96
|
auto __result = method(_javaPart);
|
|
103
97
|
return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
|
|
104
98
|
}
|
|
105
99
|
void JHybridNativeBleNitroSpec::setRestoreStateIdentifier(const std::optional<std::string>& restoreStateIdentifier) {
|
|
106
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* restoreStateIdentifier */)>("setRestoreStateIdentifier");
|
|
100
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* restoreStateIdentifier */)>("setRestoreStateIdentifier");
|
|
107
101
|
method(_javaPart, restoreStateIdentifier.has_value() ? jni::make_jstring(restoreStateIdentifier.value()) : nullptr);
|
|
108
102
|
}
|
|
109
103
|
|
|
110
104
|
// Methods
|
|
111
105
|
void JHybridNativeBleNitroSpec::setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) {
|
|
112
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__vector_BLEDevice_::javaobject> /* callback */)>("setRestoreStateCallback_cxx");
|
|
106
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__vector_BLEDevice_::javaobject> /* callback */)>("setRestoreStateCallback_cxx");
|
|
113
107
|
method(_javaPart, JFunc_void_std__vector_BLEDevice__cxx::fromCpp(callback));
|
|
114
108
|
}
|
|
115
109
|
void JHybridNativeBleNitroSpec::iosLazyInit() {
|
|
116
|
-
static const auto method = javaClassStatic()->getMethod<void()>("iosLazyInit");
|
|
110
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("iosLazyInit");
|
|
117
111
|
method(_javaPart);
|
|
118
112
|
}
|
|
119
113
|
void JHybridNativeBleNitroSpec::startScan(const ScanFilter& filter, const std::function<void(const std::optional<std::variant<nitro::NullType, BLEDevice>>& /* device */, const std::optional<std::variant<nitro::NullType, std::string>>& /* error */)>& callback) {
|
|
120
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JScanFilter> /* filter */, jni::alias_ref<JFunc_void_std__optional_std__variant_nitro__NullType__BLEDevice___std__optional_std__variant_nitro__NullType__std__string__::javaobject> /* callback */)>("startScan_cxx");
|
|
114
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JScanFilter> /* filter */, jni::alias_ref<JFunc_void_std__optional_std__variant_nitro__NullType__BLEDevice___std__optional_std__variant_nitro__NullType__std__string__::javaobject> /* callback */)>("startScan_cxx");
|
|
121
115
|
method(_javaPart, JScanFilter::fromCpp(filter), JFunc_void_std__optional_std__variant_nitro__NullType__BLEDevice___std__optional_std__variant_nitro__NullType__std__string___cxx::fromCpp(callback));
|
|
122
116
|
}
|
|
123
117
|
bool JHybridNativeBleNitroSpec::stopScan() {
|
|
124
|
-
static const auto method = javaClassStatic()->getMethod<jboolean()>("stopScan");
|
|
118
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("stopScan");
|
|
125
119
|
auto __result = method(_javaPart);
|
|
126
120
|
return static_cast<bool>(__result);
|
|
127
121
|
}
|
|
128
122
|
bool JHybridNativeBleNitroSpec::isScanning() {
|
|
129
|
-
static const auto method = javaClassStatic()->getMethod<jboolean()>("isScanning");
|
|
123
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isScanning");
|
|
130
124
|
auto __result = method(_javaPart);
|
|
131
125
|
return static_cast<bool>(__result);
|
|
132
126
|
}
|
|
133
127
|
std::vector<BLEDevice> JHybridNativeBleNitroSpec::getConnectedDevices(const std::vector<std::string>& services) {
|
|
134
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JBLEDevice>>(jni::alias_ref<jni::JArrayClass<jni::JString>> /* services */)>("getConnectedDevices");
|
|
128
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JBLEDevice>>(jni::alias_ref<jni::JArrayClass<jni::JString>> /* services */)>("getConnectedDevices");
|
|
135
129
|
auto __result = method(_javaPart, [&]() {
|
|
136
130
|
size_t __size = services.size();
|
|
137
131
|
jni::local_ref<jni::JArrayClass<jni::JString>> __array = jni::JArrayClass<jni::JString>::newArray(__size);
|
|
@@ -154,33 +148,33 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
154
148
|
}();
|
|
155
149
|
}
|
|
156
150
|
void JHybridNativeBleNitroSpec::connect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* deviceId */, const std::string& /* error */)>& callback, const std::optional<std::function<void(const std::string& /* deviceId */, bool /* interrupted */, const std::string& /* error */)>>& disconnectCallback, std::optional<bool> autoConnectAndroid) {
|
|
157
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string_std__string::javaobject> /* callback */, jni::alias_ref<JFunc_void_std__string_bool_std__string::javaobject> /* disconnectCallback */, jni::alias_ref<jni::JBoolean> /* autoConnectAndroid */)>("connect_cxx");
|
|
151
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string_std__string::javaobject> /* callback */, jni::alias_ref<JFunc_void_std__string_bool_std__string::javaobject> /* disconnectCallback */, jni::alias_ref<jni::JBoolean> /* autoConnectAndroid */)>("connect_cxx");
|
|
158
152
|
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_std__string_std__string_cxx::fromCpp(callback), disconnectCallback.has_value() ? JFunc_void_std__string_bool_std__string_cxx::fromCpp(disconnectCallback.value()) : nullptr, autoConnectAndroid.has_value() ? jni::JBoolean::valueOf(autoConnectAndroid.value()) : nullptr);
|
|
159
153
|
}
|
|
160
154
|
void JHybridNativeBleNitroSpec::disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) {
|
|
161
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("disconnect_cxx");
|
|
155
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("disconnect_cxx");
|
|
162
156
|
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_std__string_cxx::fromCpp(callback));
|
|
163
157
|
}
|
|
164
158
|
bool JHybridNativeBleNitroSpec::isConnected(const std::string& deviceId) {
|
|
165
|
-
static const auto method = javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* deviceId */)>("isConnected");
|
|
159
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* deviceId */)>("isConnected");
|
|
166
160
|
auto __result = method(_javaPart, jni::make_jstring(deviceId));
|
|
167
161
|
return static_cast<bool>(__result);
|
|
168
162
|
}
|
|
169
163
|
double JHybridNativeBleNitroSpec::requestMTU(const std::string& deviceId, double mtu) {
|
|
170
|
-
static const auto method = javaClassStatic()->getMethod<double(jni::alias_ref<jni::JString> /* deviceId */, double /* mtu */)>("requestMTU");
|
|
164
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<jni::JString> /* deviceId */, double /* mtu */)>("requestMTU");
|
|
171
165
|
auto __result = method(_javaPart, jni::make_jstring(deviceId), mtu);
|
|
172
166
|
return __result;
|
|
173
167
|
}
|
|
174
168
|
void JHybridNativeBleNitroSpec::readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) {
|
|
175
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_double_std__string::javaobject> /* callback */)>("readRSSI_cxx");
|
|
169
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_double_std__string::javaobject> /* callback */)>("readRSSI_cxx");
|
|
176
170
|
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_double_std__string_cxx::fromCpp(callback));
|
|
177
171
|
}
|
|
178
172
|
void JHybridNativeBleNitroSpec::discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) {
|
|
179
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("discoverServices_cxx");
|
|
173
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("discoverServices_cxx");
|
|
180
174
|
method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_std__string_cxx::fromCpp(callback));
|
|
181
175
|
}
|
|
182
176
|
std::vector<std::string> JHybridNativeBleNitroSpec::getServices(const std::string& deviceId) {
|
|
183
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<jni::JString>>(jni::alias_ref<jni::JString> /* deviceId */)>("getServices");
|
|
177
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<jni::JString>>(jni::alias_ref<jni::JString> /* deviceId */)>("getServices");
|
|
184
178
|
auto __result = method(_javaPart, jni::make_jstring(deviceId));
|
|
185
179
|
return [&]() {
|
|
186
180
|
size_t __size = __result->size();
|
|
@@ -194,7 +188,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
194
188
|
}();
|
|
195
189
|
}
|
|
196
190
|
std::vector<std::string> JHybridNativeBleNitroSpec::getCharacteristics(const std::string& deviceId, const std::string& serviceId) {
|
|
197
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<jni::JString>>(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */)>("getCharacteristics");
|
|
191
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<jni::JString>>(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<jni::JString> /* serviceId */)>("getCharacteristics");
|
|
198
192
|
auto __result = method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId));
|
|
199
193
|
return [&]() {
|
|
200
194
|
size_t __size = __result->size();
|
|
@@ -208,42 +202,42 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
208
202
|
}();
|
|
209
203
|
}
|
|
210
204
|
void JHybridNativeBleNitroSpec::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) {
|
|
211
|
-
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");
|
|
205
|
+
static const auto method = _javaPart->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");
|
|
212
206
|
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));
|
|
213
207
|
}
|
|
214
208
|
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) {
|
|
215
|
-
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");
|
|
209
|
+
static const auto method = _javaPart->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");
|
|
216
210
|
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));
|
|
217
211
|
}
|
|
218
212
|
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 */)>& completionCallback) {
|
|
219
|
-
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> /* completionCallback */)>("subscribeToCharacteristic_cxx");
|
|
213
|
+
static const auto method = _javaPart->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> /* completionCallback */)>("subscribeToCharacteristic_cxx");
|
|
220
214
|
method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JFunc_void_std__string_std__shared_ptr_ArrayBuffer__cxx::fromCpp(updateCallback), JFunc_void_bool_std__string_cxx::fromCpp(completionCallback));
|
|
221
215
|
}
|
|
222
216
|
void JHybridNativeBleNitroSpec::unsubscribeFromCharacteristic(const std::string& deviceId, const std::string& serviceId, const std::string& characteristicId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) {
|
|
223
|
-
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__string::javaobject> /* callback */)>("unsubscribeFromCharacteristic_cxx");
|
|
217
|
+
static const auto method = _javaPart->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__string::javaobject> /* callback */)>("unsubscribeFromCharacteristic_cxx");
|
|
224
218
|
method(_javaPart, jni::make_jstring(deviceId), jni::make_jstring(serviceId), jni::make_jstring(characteristicId), JFunc_void_bool_std__string_cxx::fromCpp(callback));
|
|
225
219
|
}
|
|
226
220
|
void JHybridNativeBleNitroSpec::requestBluetoothEnable(const std::function<void(bool /* success */, const std::string& /* error */)>& callback) {
|
|
227
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("requestBluetoothEnable_cxx");
|
|
221
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_bool_std__string::javaobject> /* callback */)>("requestBluetoothEnable_cxx");
|
|
228
222
|
method(_javaPart, JFunc_void_bool_std__string_cxx::fromCpp(callback));
|
|
229
223
|
}
|
|
230
224
|
BLEState JHybridNativeBleNitroSpec::state() {
|
|
231
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JBLEState>()>("state");
|
|
225
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JBLEState>()>("state");
|
|
232
226
|
auto __result = method(_javaPart);
|
|
233
227
|
return __result->toCpp();
|
|
234
228
|
}
|
|
235
229
|
OperationResult JHybridNativeBleNitroSpec::subscribeToStateChange(const std::function<void(BLEState /* state */)>& stateCallback) {
|
|
236
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JOperationResult>(jni::alias_ref<JFunc_void_BLEState::javaobject> /* stateCallback */)>("subscribeToStateChange_cxx");
|
|
230
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JOperationResult>(jni::alias_ref<JFunc_void_BLEState::javaobject> /* stateCallback */)>("subscribeToStateChange_cxx");
|
|
237
231
|
auto __result = method(_javaPart, JFunc_void_BLEState_cxx::fromCpp(stateCallback));
|
|
238
232
|
return __result->toCpp();
|
|
239
233
|
}
|
|
240
234
|
OperationResult JHybridNativeBleNitroSpec::unsubscribeFromStateChange() {
|
|
241
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JOperationResult>()>("unsubscribeFromStateChange");
|
|
235
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JOperationResult>()>("unsubscribeFromStateChange");
|
|
242
236
|
auto __result = method(_javaPart);
|
|
243
237
|
return __result->toCpp();
|
|
244
238
|
}
|
|
245
239
|
std::shared_ptr<Promise<void>> JHybridNativeBleNitroSpec::openSettings() {
|
|
246
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("openSettings");
|
|
240
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("openSettings");
|
|
247
241
|
auto __result = method(_javaPart);
|
|
248
242
|
return [&]() {
|
|
249
243
|
auto __promise = Promise<void>::create();
|
|
@@ -18,34 +18,33 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
18
18
|
|
|
19
19
|
using namespace facebook;
|
|
20
20
|
|
|
21
|
-
class JHybridNativeBleNitroSpec: public
|
|
22
|
-
public virtual HybridNativeBleNitroSpec {
|
|
21
|
+
class JHybridNativeBleNitroSpec: public virtual HybridNativeBleNitroSpec, public virtual JHybridObject {
|
|
23
22
|
public:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
HybridBase
|
|
33
|
-
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec;";
|
|
25
|
+
std::shared_ptr<JHybridNativeBleNitroSpec> getJHybridNativeBleNitroSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
34
35
|
|
|
35
36
|
public:
|
|
37
|
+
explicit JHybridNativeBleNitroSpec(const jni::local_ref<JHybridNativeBleNitroSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridNativeBleNitroSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
36
41
|
~JHybridNativeBleNitroSpec() override {
|
|
37
42
|
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
43
|
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
public:
|
|
42
|
-
|
|
43
|
-
bool equals(const std::shared_ptr<HybridObject>& other) override;
|
|
44
|
-
void dispose() noexcept override;
|
|
45
|
-
std::string toString() override;
|
|
46
|
-
|
|
47
|
-
public:
|
|
48
|
-
inline const jni::global_ref<JHybridNativeBleNitroSpec::javaobject>& getJavaPart() const noexcept {
|
|
47
|
+
inline const jni::global_ref<JHybridNativeBleNitroSpec::JavaPart>& getJavaPart() const noexcept {
|
|
49
48
|
return _javaPart;
|
|
50
49
|
}
|
|
51
50
|
|
|
@@ -81,9 +80,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
81
80
|
std::shared_ptr<Promise<void>> openSettings() override;
|
|
82
81
|
|
|
83
82
|
private:
|
|
84
|
-
|
|
85
|
-
using HybridBase::HybridBase;
|
|
86
|
-
jni::global_ref<JHybridNativeBleNitroSpec::javaobject> _javaPart;
|
|
83
|
+
jni::global_ref<JHybridNativeBleNitroSpec::JavaPart> _javaPart;
|
|
87
84
|
};
|
|
88
85
|
|
|
89
86
|
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -24,23 +24,6 @@ import com.margelo.nitro.core.HybridObject
|
|
|
24
24
|
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
25
25
|
)
|
|
26
26
|
abstract class HybridNativeBleNitroFactorySpec: HybridObject() {
|
|
27
|
-
@DoNotStrip
|
|
28
|
-
private var mHybridData: HybridData = initHybrid()
|
|
29
|
-
|
|
30
|
-
init {
|
|
31
|
-
super.updateNative(mHybridData)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
override fun updateNative(hybridData: HybridData) {
|
|
35
|
-
mHybridData = hybridData
|
|
36
|
-
super.updateNative(hybridData)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Default implementation of `HybridObject.toString()`
|
|
40
|
-
override fun toString(): String {
|
|
41
|
-
return "[HybridObject NativeBleNitroFactory]"
|
|
42
|
-
}
|
|
43
|
-
|
|
44
27
|
// Properties
|
|
45
28
|
|
|
46
29
|
|
|
@@ -54,7 +37,21 @@ abstract class HybridNativeBleNitroFactorySpec: HybridObject() {
|
|
|
54
37
|
return __result
|
|
55
38
|
}
|
|
56
39
|
|
|
57
|
-
|
|
40
|
+
// Default implementation of `HybridObject.toString()`
|
|
41
|
+
override fun toString(): String {
|
|
42
|
+
return "[HybridObject NativeBleNitroFactory]"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// C++ backing class
|
|
46
|
+
@DoNotStrip
|
|
47
|
+
@Keep
|
|
48
|
+
protected open class CxxPart(javaPart: HybridNativeBleNitroFactorySpec): HybridObject.CxxPart(javaPart) {
|
|
49
|
+
// C++ JHybridNativeBleNitroFactorySpec::CxxPart::initHybrid(...)
|
|
50
|
+
external override fun initHybrid(): HybridData
|
|
51
|
+
}
|
|
52
|
+
override fun createCxxPart(): CxxPart {
|
|
53
|
+
return CxxPart(this)
|
|
54
|
+
}
|
|
58
55
|
|
|
59
56
|
companion object {
|
|
60
57
|
protected const val TAG = "HybridNativeBleNitroFactorySpec"
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt
CHANGED
|
@@ -27,23 +27,6 @@ import com.margelo.nitro.core.HybridObject
|
|
|
27
27
|
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
28
28
|
)
|
|
29
29
|
abstract class HybridNativeBleNitroSpec: HybridObject() {
|
|
30
|
-
@DoNotStrip
|
|
31
|
-
private var mHybridData: HybridData = initHybrid()
|
|
32
|
-
|
|
33
|
-
init {
|
|
34
|
-
super.updateNative(mHybridData)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
override fun updateNative(hybridData: HybridData) {
|
|
38
|
-
mHybridData = hybridData
|
|
39
|
-
super.updateNative(hybridData)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Default implementation of `HybridObject.toString()`
|
|
43
|
-
override fun toString(): String {
|
|
44
|
-
return "[HybridObject NativeBleNitro]"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
30
|
// Properties
|
|
48
31
|
@get:DoNotStrip
|
|
49
32
|
@get:Keep
|
|
@@ -204,7 +187,21 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
|
|
|
204
187
|
@Keep
|
|
205
188
|
abstract fun openSettings(): Promise<Unit>
|
|
206
189
|
|
|
207
|
-
|
|
190
|
+
// Default implementation of `HybridObject.toString()`
|
|
191
|
+
override fun toString(): String {
|
|
192
|
+
return "[HybridObject NativeBleNitro]"
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// C++ backing class
|
|
196
|
+
@DoNotStrip
|
|
197
|
+
@Keep
|
|
198
|
+
protected open class CxxPart(javaPart: HybridNativeBleNitroSpec): HybridObject.CxxPart(javaPart) {
|
|
199
|
+
// C++ JHybridNativeBleNitroSpec::CxxPart::initHybrid(...)
|
|
200
|
+
external override fun initHybrid(): HybridData
|
|
201
|
+
}
|
|
202
|
+
override fun createCxxPart(): CxxPart {
|
|
203
|
+
return CxxPart(this)
|
|
204
|
+
}
|
|
208
205
|
|
|
209
206
|
companion object {
|
|
210
207
|
protected const val TAG = "HybridNativeBleNitroSpec"
|
|
@@ -21,12 +21,6 @@ sealed class Variant_NullType_BLEDevice {
|
|
|
21
21
|
@DoNotStrip
|
|
22
22
|
data class Second(@DoNotStrip val value: BLEDevice): Variant_NullType_BLEDevice()
|
|
23
23
|
|
|
24
|
-
@Deprecated("getAs() is not type-safe. Use fold/asFirstOrNull/asSecondOrNull instead.", level = DeprecationLevel.ERROR)
|
|
25
|
-
inline fun <reified T> getAs(): T? = when (this) {
|
|
26
|
-
is First -> value as? T
|
|
27
|
-
is Second -> value as? T
|
|
28
|
-
}
|
|
29
|
-
|
|
30
24
|
val isFirst: Boolean
|
|
31
25
|
get() = this is First
|
|
32
26
|
val isSecond: Boolean
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Variant_NullType_String.kt
CHANGED
|
@@ -21,12 +21,6 @@ sealed class Variant_NullType_String {
|
|
|
21
21
|
@DoNotStrip
|
|
22
22
|
data class Second(@DoNotStrip val value: String): Variant_NullType_String()
|
|
23
23
|
|
|
24
|
-
@Deprecated("getAs() is not type-safe. Use fold/asFirstOrNull/asSecondOrNull instead.", level = DeprecationLevel.ERROR)
|
|
25
|
-
inline fun <reified T> getAs(): T? = when (this) {
|
|
26
|
-
is First -> value as? T
|
|
27
|
-
is Second -> value as? T
|
|
28
|
-
}
|
|
29
|
-
|
|
30
24
|
val isFirst: Boolean
|
|
31
25
|
get() = this is First
|
|
32
26
|
val isSecond: Boolean
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-ble-nitro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|
|
@@ -77,25 +77,25 @@
|
|
|
77
77
|
"url": "https://github.com/zykeco/react-native-ble-nitro/issues"
|
|
78
78
|
},
|
|
79
79
|
"engines": {
|
|
80
|
-
"node": ">=
|
|
80
|
+
"node": ">=20.0.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"react-native": ">=0.76.0",
|
|
84
|
-
"react-native-nitro-modules": ">=0.
|
|
84
|
+
"react-native-nitro-modules": ">=0.35.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@expo/config-plugins": "^
|
|
87
|
+
"@expo/config-plugins": "^55.0.6",
|
|
88
88
|
"@types/jest": "^29.5.0",
|
|
89
|
-
"@types/node": "^
|
|
90
|
-
"@types/react": "^19.2.
|
|
89
|
+
"@types/node": "^24.11.0",
|
|
90
|
+
"@types/react": "^19.2.14",
|
|
91
91
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
92
92
|
"@typescript-eslint/parser": "^6.21.0",
|
|
93
93
|
"eslint": "^8.57.1",
|
|
94
|
-
"expo-module-scripts": "^
|
|
94
|
+
"expo-module-scripts": "^55.0.2",
|
|
95
95
|
"jest": "^29.0.0",
|
|
96
|
-
"nitrogen": "^0.
|
|
96
|
+
"nitrogen": "^0.35.0",
|
|
97
97
|
"react-native": "^0.83.2",
|
|
98
|
-
"react-native-nitro-modules": "^0.
|
|
98
|
+
"react-native-nitro-modules": "^0.35.0",
|
|
99
99
|
"rimraf": "^6.1.3",
|
|
100
100
|
"ts-jest": "^29.4.6",
|
|
101
101
|
"typescript": "^5.9.3"
|
|
@@ -143,6 +143,10 @@ describe('BleNitro', () => {
|
|
|
143
143
|
});
|
|
144
144
|
await BleManager.connect('device-write');
|
|
145
145
|
|
|
146
|
+
mockNative.isConnected.mockImplementation((id: string) => {
|
|
147
|
+
return id === 'device-write';
|
|
148
|
+
});
|
|
149
|
+
|
|
146
150
|
// Mock writeCharacteristic with new signature (success, responseData, error)
|
|
147
151
|
mockNative.writeCharacteristic.mockImplementation((_deviceId: string, _serviceId: string, _charId: string, _data: ArrayBuffer, withResponse: boolean, callback: (success: boolean, responseData: ArrayBuffer, error: string) => void) => {
|
|
148
152
|
// For withResponse=false, return empty ArrayBuffer
|
|
@@ -171,6 +175,10 @@ describe('BleNitro', () => {
|
|
|
171
175
|
});
|
|
172
176
|
await BleManager.connect('device-write-resp');
|
|
173
177
|
|
|
178
|
+
mockNative.isConnected.mockImplementation((id: string) => {
|
|
179
|
+
return id === 'device-write-resp';
|
|
180
|
+
});
|
|
181
|
+
|
|
174
182
|
// Mock writeCharacteristic to return response data
|
|
175
183
|
mockNative.writeCharacteristic.mockImplementation((_deviceId: string, _serviceId: string, _charId: string, _data: ArrayBuffer, withResponse: boolean, callback: (success: boolean, responseData: ArrayBuffer, error: string) => void) => {
|
|
176
184
|
// For withResponse=true, return some response data
|
|
@@ -198,6 +206,9 @@ describe('BleNitro', () => {
|
|
|
198
206
|
callback(true, id, '');
|
|
199
207
|
});
|
|
200
208
|
await BleManager.connect('device');
|
|
209
|
+
mockNative.isConnected.mockImplementation((id: string) => {
|
|
210
|
+
return id === 'device';
|
|
211
|
+
});
|
|
201
212
|
|
|
202
213
|
// Then read
|
|
203
214
|
mockNative.readCharacteristic.mockImplementation((_device: string, _service: string, _char: string, callback: (success: boolean, data: ArrayBuffer, error: string) => void) => {
|
|
@@ -227,6 +238,10 @@ describe('BleNitro', () => {
|
|
|
227
238
|
});
|
|
228
239
|
await BleManager.connect('device');
|
|
229
240
|
|
|
241
|
+
mockNative.isConnected.mockImplementation((id: string) => {
|
|
242
|
+
return id === 'device';
|
|
243
|
+
});
|
|
244
|
+
|
|
230
245
|
// Then disconnect
|
|
231
246
|
mockNative.disconnect.mockImplementation((_id: string, callback: (success: boolean, error: string) => void) => {
|
|
232
247
|
callback(true, '');
|
|
@@ -235,7 +250,7 @@ describe('BleNitro', () => {
|
|
|
235
250
|
const result = await BleManager.disconnect('device');
|
|
236
251
|
|
|
237
252
|
expect(mockNative.disconnect).toHaveBeenCalledWith('device', expect.any(Function));
|
|
238
|
-
expect(result).toBe(
|
|
253
|
+
expect(result).toBe('device');
|
|
239
254
|
});
|
|
240
255
|
|
|
241
256
|
test('subscribeToCharacteristic calls callback', async () => {
|
|
@@ -301,6 +316,9 @@ describe('BleNitro', () => {
|
|
|
301
316
|
callback(true, id, '');
|
|
302
317
|
});
|
|
303
318
|
await BleManager.connect('device-rssi');
|
|
319
|
+
mockNative.isConnected.mockImplementation((id: string) => {
|
|
320
|
+
return id === 'device-rssi';
|
|
321
|
+
});
|
|
304
322
|
|
|
305
323
|
// Mock readRSSI with new signature (success, rssi, error)
|
|
306
324
|
mockNative.readRSSI.mockImplementation((_deviceId: string, callback: (success: boolean, rssi: number, error: string) => void) => {
|
|
@@ -322,6 +340,9 @@ describe('BleNitro', () => {
|
|
|
322
340
|
callback(true, id, '');
|
|
323
341
|
});
|
|
324
342
|
await BleManager.connect('device-rssi-fail');
|
|
343
|
+
mockNative.isConnected.mockImplementation((id: string) => {
|
|
344
|
+
return id === 'device-rssi-fail';
|
|
345
|
+
});
|
|
325
346
|
|
|
326
347
|
// Mock readRSSI failure
|
|
327
348
|
mockNative.readRSSI.mockImplementation((_deviceId: string, callback: (success: boolean, rssi: number, error: string) => void) => {
|