react-native-ble-nitro 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -18
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +140 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +899 -0
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroPackage.kt +38 -0
- package/ios/BleNitroBleManager.swift +7 -3
- package/lib/commonjs/index.d.ts +14 -8
- package/lib/commonjs/index.d.ts.map +1 -1
- package/lib/commonjs/index.js +35 -17
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +8 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js +8 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
- package/lib/index.d.ts +14 -8
- package/lib/index.js +33 -15
- package/lib/specs/NativeBleNitro.nitro.d.ts +8 -1
- package/lib/specs/NativeBleNitro.nitro.js +7 -0
- package/nitrogen/generated/android/BleNitroOnLoad.cpp +2 -2
- package/nitrogen/generated/android/c++/JAndroidScanMode.hpp +65 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp +86 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +8 -4
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JScanFilter.hpp +8 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/AndroidScanMode.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/{Func_void_BLEDevice.kt → Func_void_std__optional_BLEDevice__std__optional_std__string_.kt} +14 -14
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +2 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ScanFilter.kt +4 -1
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +5 -5
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +30 -21
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +5 -2
- package/nitrogen/generated/ios/swift/AndroidScanMode.swift +48 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_BLEDevice__std__optional_std__string_.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +17 -5
- package/nitrogen/generated/ios/swift/ScanFilter.swift +13 -2
- package/nitrogen/generated/shared/c++/AndroidScanMode.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +3 -3
- package/nitrogen/generated/shared/c++/ScanFilter.hpp +9 -3
- package/package.json +1 -1
- package/plugin/build/index.d.ts +2 -0
- package/plugin/build/index.js +2 -0
- package/plugin/build/withBleNitro.d.ts +5 -1
- package/plugin/build/withBleNitro.js +18 -7
- package/src/__tests__/index.test.ts +48 -13
- package/src/index.ts +40 -21
- package/src/specs/NativeBleNitro.nitro.ts +9 -1
- package/nitrogen/generated/android/c++/JFunc_void_BLEDevice.hpp +0 -85
- package/nitrogen/generated/ios/swift/Func_void_BLEDevice.swift +0 -47
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
17
|
|
|
18
18
|
#include "JHybridNativeBleNitroSpec.hpp"
|
|
19
|
-
#include "
|
|
19
|
+
#include "JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp"
|
|
20
20
|
#include "JFunc_void_bool_std__string_std__string.hpp"
|
|
21
21
|
#include "JFunc_void_std__string_bool_std__string.hpp"
|
|
22
22
|
#include "JFunc_void_bool_std__string.hpp"
|
|
@@ -35,7 +35,7 @@ int initialize(JavaVM* vm) {
|
|
|
35
35
|
return facebook::jni::initialize(vm, [] {
|
|
36
36
|
// Register native JNI methods
|
|
37
37
|
margelo::nitro::co::zyke::ble::JHybridNativeBleNitroSpec::registerNatives();
|
|
38
|
-
margelo::nitro::co::zyke::ble::
|
|
38
|
+
margelo::nitro::co::zyke::ble::JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::registerNatives();
|
|
39
39
|
margelo::nitro::co::zyke::ble::JFunc_void_bool_std__string_std__string_cxx::registerNatives();
|
|
40
40
|
margelo::nitro::co::zyke::ble::JFunc_void_std__string_bool_std__string_cxx::registerNatives();
|
|
41
41
|
margelo::nitro::co::zyke::ble::JFunc_void_bool_std__string_cxx::registerNatives();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JAndroidScanMode.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 "AndroidScanMode.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::co::zyke::ble {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The C++ JNI bridge between the C++ enum "AndroidScanMode" and the the Kotlin enum "AndroidScanMode".
|
|
19
|
+
*/
|
|
20
|
+
struct JAndroidScanMode final: public jni::JavaClass<JAndroidScanMode> {
|
|
21
|
+
public:
|
|
22
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/AndroidScanMode;";
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
/**
|
|
26
|
+
* Convert this Java/Kotlin-based enum to the C++ enum AndroidScanMode.
|
|
27
|
+
*/
|
|
28
|
+
[[maybe_unused]]
|
|
29
|
+
[[nodiscard]]
|
|
30
|
+
AndroidScanMode toCpp() const {
|
|
31
|
+
static const auto clazz = javaClassStatic();
|
|
32
|
+
static const auto fieldOrdinal = clazz->getField<int>("value");
|
|
33
|
+
int ordinal = this->getFieldValue(fieldOrdinal);
|
|
34
|
+
return static_cast<AndroidScanMode>(ordinal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* Create a Java/Kotlin-based enum with the given C++ enum's value.
|
|
40
|
+
*/
|
|
41
|
+
[[maybe_unused]]
|
|
42
|
+
static jni::alias_ref<JAndroidScanMode> fromCpp(AndroidScanMode value) {
|
|
43
|
+
static const auto clazz = javaClassStatic();
|
|
44
|
+
static const auto fieldLOWLATENCY = clazz->getStaticField<JAndroidScanMode>("LOWLATENCY");
|
|
45
|
+
static const auto fieldBALANCED = clazz->getStaticField<JAndroidScanMode>("BALANCED");
|
|
46
|
+
static const auto fieldLOWPOWER = clazz->getStaticField<JAndroidScanMode>("LOWPOWER");
|
|
47
|
+
static const auto fieldOPPORTUNISTIC = clazz->getStaticField<JAndroidScanMode>("OPPORTUNISTIC");
|
|
48
|
+
|
|
49
|
+
switch (value) {
|
|
50
|
+
case AndroidScanMode::LOWLATENCY:
|
|
51
|
+
return clazz->getStaticFieldValue(fieldLOWLATENCY);
|
|
52
|
+
case AndroidScanMode::BALANCED:
|
|
53
|
+
return clazz->getStaticFieldValue(fieldBALANCED);
|
|
54
|
+
case AndroidScanMode::LOWPOWER:
|
|
55
|
+
return clazz->getStaticFieldValue(fieldLOWPOWER);
|
|
56
|
+
case AndroidScanMode::OPPORTUNISTIC:
|
|
57
|
+
return clazz->getStaticFieldValue(fieldOPPORTUNISTIC);
|
|
58
|
+
default:
|
|
59
|
+
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
60
|
+
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include <functional>
|
|
12
|
+
|
|
13
|
+
#include "BLEDevice.hpp"
|
|
14
|
+
#include <optional>
|
|
15
|
+
#include <string>
|
|
16
|
+
#include <functional>
|
|
17
|
+
#include "JBLEDevice.hpp"
|
|
18
|
+
#include "ManufacturerData.hpp"
|
|
19
|
+
#include "JManufacturerData.hpp"
|
|
20
|
+
#include "ManufacturerDataEntry.hpp"
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include "JManufacturerDataEntry.hpp"
|
|
23
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
24
|
+
#include <NitroModules/JArrayBuffer.hpp>
|
|
25
|
+
#include <NitroModules/JUnit.hpp>
|
|
26
|
+
|
|
27
|
+
namespace margelo::nitro::co::zyke::ble {
|
|
28
|
+
|
|
29
|
+
using namespace facebook;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Represents the Java/Kotlin callback `(device: BLEDevice?, error: String?) -> Unit`.
|
|
33
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
34
|
+
*/
|
|
35
|
+
struct JFunc_void_std__optional_BLEDevice__std__optional_std__string_: public jni::JavaClass<JFunc_void_std__optional_BLEDevice__std__optional_std__string_> {
|
|
36
|
+
public:
|
|
37
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__optional_BLEDevice__std__optional_std__string_;";
|
|
38
|
+
|
|
39
|
+
public:
|
|
40
|
+
/**
|
|
41
|
+
* Invokes the function this `JFunc_void_std__optional_BLEDevice__std__optional_std__string_` instance holds through JNI.
|
|
42
|
+
*/
|
|
43
|
+
void invoke(const std::optional<BLEDevice>& device, const std::optional<std::string>& error) const {
|
|
44
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JBLEDevice> /* device */, jni::alias_ref<jni::JString> /* error */)>("invoke");
|
|
45
|
+
method(self(), device.has_value() ? JBLEDevice::fromCpp(device.value()) : nullptr, error.has_value() ? jni::make_jstring(error.value()) : nullptr);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* An implementation of Func_void_std__optional_BLEDevice__std__optional_std__string_ that is backed by a C++ implementation (using `std::function<...>`)
|
|
51
|
+
*/
|
|
52
|
+
struct JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx final: public jni::HybridClass<JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx, JFunc_void_std__optional_BLEDevice__std__optional_std__string_> {
|
|
53
|
+
public:
|
|
54
|
+
static jni::local_ref<JFunc_void_std__optional_BLEDevice__std__optional_std__string_::javaobject> fromCpp(const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& func) {
|
|
55
|
+
return JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::newObjectCxxArgs(func);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
/**
|
|
60
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx` instance holds.
|
|
61
|
+
*/
|
|
62
|
+
void invoke_cxx(jni::alias_ref<JBLEDevice> device, jni::alias_ref<jni::JString> error) {
|
|
63
|
+
_func(device != nullptr ? std::make_optional(device->toCpp()) : std::nullopt, error != nullptr ? std::make_optional(error->toStdString()) : std::nullopt);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public:
|
|
67
|
+
[[nodiscard]]
|
|
68
|
+
inline const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& getFunction() const {
|
|
69
|
+
return _func;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public:
|
|
73
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__optional_BLEDevice__std__optional_std__string__cxx;";
|
|
74
|
+
static void registerNatives() {
|
|
75
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::invoke_cxx)});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private:
|
|
79
|
+
explicit JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx(const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& func): _func(func) { }
|
|
80
|
+
|
|
81
|
+
private:
|
|
82
|
+
friend HybridBase;
|
|
83
|
+
std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)> _func;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -21,6 +21,8 @@ namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
|
|
|
21
21
|
namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
|
|
22
22
|
// Forward declaration of `ScanFilter` to properly resolve imports.
|
|
23
23
|
namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
|
|
24
|
+
// Forward declaration of `AndroidScanMode` to properly resolve imports.
|
|
25
|
+
namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
|
|
24
26
|
|
|
25
27
|
#include "BLEDevice.hpp"
|
|
26
28
|
#include <vector>
|
|
@@ -42,8 +44,10 @@ namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
|
|
|
42
44
|
#include <NitroModules/JPromise.hpp>
|
|
43
45
|
#include "ScanFilter.hpp"
|
|
44
46
|
#include "JScanFilter.hpp"
|
|
47
|
+
#include "AndroidScanMode.hpp"
|
|
48
|
+
#include "JAndroidScanMode.hpp"
|
|
45
49
|
#include <functional>
|
|
46
|
-
#include "
|
|
50
|
+
#include "JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp"
|
|
47
51
|
#include "JFunc_void_bool_std__string_std__string.hpp"
|
|
48
52
|
#include "JFunc_void_std__string_bool_std__string.hpp"
|
|
49
53
|
#include "JFunc_void_bool_std__string.hpp"
|
|
@@ -77,9 +81,9 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
77
81
|
|
|
78
82
|
|
|
79
83
|
// Methods
|
|
80
|
-
void JHybridNativeBleNitroSpec::startScan(const ScanFilter& filter, const std::function<void(const BLEDevice
|
|
81
|
-
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JScanFilter> /* filter */, jni::alias_ref<
|
|
82
|
-
method(_javaPart, JScanFilter::fromCpp(filter),
|
|
84
|
+
void JHybridNativeBleNitroSpec::startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) {
|
|
85
|
+
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
|
+
method(_javaPart, JScanFilter::fromCpp(filter), JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::fromCpp(callback));
|
|
83
87
|
}
|
|
84
88
|
bool JHybridNativeBleNitroSpec::stopScan() {
|
|
85
89
|
static const auto method = javaClassStatic()->getMethod<jboolean()>("stopScan");
|
|
@@ -53,7 +53,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
53
53
|
|
|
54
54
|
public:
|
|
55
55
|
// Methods
|
|
56
|
-
void startScan(const ScanFilter& filter, const std::function<void(const BLEDevice
|
|
56
|
+
void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) override;
|
|
57
57
|
bool stopScan() override;
|
|
58
58
|
bool isScanning() override;
|
|
59
59
|
std::vector<BLEDevice> getConnectedDevices(const std::vector<std::string>& services) override;
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
#include <fbjni/fbjni.h>
|
|
11
11
|
#include "ScanFilter.hpp"
|
|
12
12
|
|
|
13
|
+
#include "AndroidScanMode.hpp"
|
|
14
|
+
#include "JAndroidScanMode.hpp"
|
|
13
15
|
#include <string>
|
|
14
16
|
#include <vector>
|
|
15
17
|
|
|
@@ -38,6 +40,8 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
38
40
|
double rssiThreshold = this->getFieldValue(fieldRssiThreshold);
|
|
39
41
|
static const auto fieldAllowDuplicates = clazz->getField<jboolean>("allowDuplicates");
|
|
40
42
|
jboolean allowDuplicates = this->getFieldValue(fieldAllowDuplicates);
|
|
43
|
+
static const auto fieldAndroidScanMode = clazz->getField<JAndroidScanMode>("androidScanMode");
|
|
44
|
+
jni::local_ref<JAndroidScanMode> androidScanMode = this->getFieldValue(fieldAndroidScanMode);
|
|
41
45
|
return ScanFilter(
|
|
42
46
|
[&]() {
|
|
43
47
|
size_t __size = serviceUUIDs->size();
|
|
@@ -50,7 +54,8 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
50
54
|
return __vector;
|
|
51
55
|
}(),
|
|
52
56
|
rssiThreshold,
|
|
53
|
-
static_cast<bool>(allowDuplicates)
|
|
57
|
+
static_cast<bool>(allowDuplicates),
|
|
58
|
+
androidScanMode->toCpp()
|
|
54
59
|
);
|
|
55
60
|
}
|
|
56
61
|
|
|
@@ -71,7 +76,8 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
71
76
|
return __array;
|
|
72
77
|
}(),
|
|
73
78
|
value.rssiThreshold,
|
|
74
|
-
value.allowDuplicates
|
|
79
|
+
value.allowDuplicates,
|
|
80
|
+
JAndroidScanMode::fromCpp(value.androidScanMode)
|
|
75
81
|
);
|
|
76
82
|
}
|
|
77
83
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AndroidScanMode.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.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents the JavaScript enum/union "AndroidScanMode".
|
|
15
|
+
*/
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
@Keep
|
|
18
|
+
enum class AndroidScanMode(@DoNotStrip @Keep val value: Int) {
|
|
19
|
+
LOWLATENCY(0),
|
|
20
|
+
BALANCED(1),
|
|
21
|
+
LOWPOWER(2),
|
|
22
|
+
OPPORTUNISTIC(3);
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// Func_void_std__optional_BLEDevice__std__optional_std__string_.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
@@ -15,25 +15,25 @@ import dalvik.annotation.optimization.FastNative
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Represents the JavaScript callback `(device:
|
|
18
|
+
* Represents the JavaScript callback `(device: optional, error: optional) => void`.
|
|
19
19
|
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
20
20
|
* or in Kotlin/Java (in which case it is a native callback).
|
|
21
21
|
*/
|
|
22
22
|
@DoNotStrip
|
|
23
23
|
@Keep
|
|
24
24
|
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
25
|
-
fun interface
|
|
25
|
+
fun interface Func_void_std__optional_BLEDevice__std__optional_std__string_: (BLEDevice?, String?) -> Unit {
|
|
26
26
|
/**
|
|
27
27
|
* Call the given JS callback.
|
|
28
28
|
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
29
29
|
*/
|
|
30
30
|
@DoNotStrip
|
|
31
31
|
@Keep
|
|
32
|
-
override fun invoke(device: BLEDevice): Unit
|
|
32
|
+
override fun invoke(device: BLEDevice?, error: String?): Unit
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Represents the JavaScript callback `(device:
|
|
36
|
+
* Represents the JavaScript callback `(device: optional, error: optional) => void`.
|
|
37
37
|
* This is implemented in C++, via a `std::function<...>`.
|
|
38
38
|
* The callback might be coming from JS.
|
|
39
39
|
*/
|
|
@@ -44,7 +44,7 @@ fun interface Func_void_BLEDevice: (BLEDevice) -> Unit {
|
|
|
44
44
|
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
45
45
|
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
46
46
|
)
|
|
47
|
-
class
|
|
47
|
+
class Func_void_std__optional_BLEDevice__std__optional_std__string__cxx: Func_void_std__optional_BLEDevice__std__optional_std__string_ {
|
|
48
48
|
@DoNotStrip
|
|
49
49
|
@Keep
|
|
50
50
|
private val mHybridData: HybridData
|
|
@@ -57,25 +57,25 @@ class Func_void_BLEDevice_cxx: Func_void_BLEDevice {
|
|
|
57
57
|
|
|
58
58
|
@DoNotStrip
|
|
59
59
|
@Keep
|
|
60
|
-
override fun invoke(device: BLEDevice): Unit
|
|
61
|
-
= invoke_cxx(device)
|
|
60
|
+
override fun invoke(device: BLEDevice?, error: String?): Unit
|
|
61
|
+
= invoke_cxx(device,error)
|
|
62
62
|
|
|
63
63
|
@FastNative
|
|
64
|
-
private external fun invoke_cxx(device: BLEDevice): Unit
|
|
64
|
+
private external fun invoke_cxx(device: BLEDevice?, error: String?): Unit
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Represents the JavaScript callback `(device:
|
|
69
|
-
* This is implemented in Java/Kotlin, via a `(BLEDevice) -> Unit`.
|
|
68
|
+
* Represents the JavaScript callback `(device: optional, error: optional) => void`.
|
|
69
|
+
* This is implemented in Java/Kotlin, via a `(BLEDevice?, String?) -> Unit`.
|
|
70
70
|
* The callback is always coming from native.
|
|
71
71
|
*/
|
|
72
72
|
@DoNotStrip
|
|
73
73
|
@Keep
|
|
74
74
|
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
75
|
-
class
|
|
75
|
+
class Func_void_std__optional_BLEDevice__std__optional_std__string__java(private val function: (BLEDevice?, String?) -> Unit): Func_void_std__optional_BLEDevice__std__optional_std__string_ {
|
|
76
76
|
@DoNotStrip
|
|
77
77
|
@Keep
|
|
78
|
-
override fun invoke(device: BLEDevice): Unit {
|
|
79
|
-
return this.function(device)
|
|
78
|
+
override fun invoke(device: BLEDevice?, error: String?): Unit {
|
|
79
|
+
return this.function(device, error)
|
|
80
80
|
}
|
|
81
81
|
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt
CHANGED
|
@@ -40,11 +40,11 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
// Methods
|
|
43
|
-
abstract fun startScan(filter: ScanFilter, callback: (device: BLEDevice) -> Unit): Unit
|
|
43
|
+
abstract fun startScan(filter: ScanFilter, callback: (device: BLEDevice?, error: String?) -> Unit): Unit
|
|
44
44
|
|
|
45
45
|
@DoNotStrip
|
|
46
46
|
@Keep
|
|
47
|
-
private fun startScan_cxx(filter: ScanFilter, callback:
|
|
47
|
+
private fun startScan_cxx(filter: ScanFilter, callback: Func_void_std__optional_BLEDevice__std__optional_std__string_): Unit {
|
|
48
48
|
val __result = startScan(filter, callback)
|
|
49
49
|
return __result
|
|
50
50
|
}
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
|
|
14
14
|
namespace margelo::nitro::co::zyke::ble::bridge::swift {
|
|
15
15
|
|
|
16
|
-
// pragma MARK: std::function<void(const BLEDevice
|
|
17
|
-
|
|
18
|
-
auto swiftClosure = BleNitro::
|
|
19
|
-
return [swiftClosure = std::move(swiftClosure)](const BLEDevice
|
|
20
|
-
swiftClosure.call(device);
|
|
16
|
+
// pragma MARK: std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>
|
|
17
|
+
Func_void_std__optional_BLEDevice__std__optional_std__string_ create_Func_void_std__optional_BLEDevice__std__optional_std__string_(void* _Nonnull swiftClosureWrapper) {
|
|
18
|
+
auto swiftClosure = BleNitro::Func_void_std__optional_BLEDevice__std__optional_std__string_::fromUnsafe(swiftClosureWrapper);
|
|
19
|
+
return [swiftClosure = std::move(swiftClosure)](const std::optional<BLEDevice>& device, const std::optional<std::string>& error) mutable -> void {
|
|
20
|
+
swiftClosure.call(device, error);
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -76,26 +76,44 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
|
|
|
76
76
|
return vector;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
// pragma MARK: std::
|
|
79
|
+
// pragma MARK: std::optional<BLEDevice>
|
|
80
80
|
/**
|
|
81
|
-
* Specialized version of `std::
|
|
81
|
+
* Specialized version of `std::optional<BLEDevice>`.
|
|
82
82
|
*/
|
|
83
|
-
using
|
|
83
|
+
using std__optional_BLEDevice_ = std::optional<BLEDevice>;
|
|
84
|
+
inline std::optional<BLEDevice> create_std__optional_BLEDevice_(const BLEDevice& value) {
|
|
85
|
+
return std::optional<BLEDevice>(value);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// pragma MARK: std::optional<std::string>
|
|
89
|
+
/**
|
|
90
|
+
* Specialized version of `std::optional<std::string>`.
|
|
91
|
+
*/
|
|
92
|
+
using std__optional_std__string_ = std::optional<std::string>;
|
|
93
|
+
inline std::optional<std::string> create_std__optional_std__string_(const std::string& value) {
|
|
94
|
+
return std::optional<std::string>(value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// pragma MARK: std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>
|
|
84
98
|
/**
|
|
85
|
-
*
|
|
99
|
+
* Specialized version of `std::function<void(const std::optional<BLEDevice>&, const std::optional<std::string>&)>`.
|
|
86
100
|
*/
|
|
87
|
-
|
|
101
|
+
using Func_void_std__optional_BLEDevice__std__optional_std__string_ = std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>;
|
|
102
|
+
/**
|
|
103
|
+
* Wrapper class for a `std::function<void(const std::optional<BLEDevice>& / * device * /, const std::optional<std::string>& / * error * /)>`, this can be used from Swift.
|
|
104
|
+
*/
|
|
105
|
+
class Func_void_std__optional_BLEDevice__std__optional_std__string__Wrapper final {
|
|
88
106
|
public:
|
|
89
|
-
explicit
|
|
90
|
-
inline void call(BLEDevice device) const {
|
|
91
|
-
_function->operator()(device);
|
|
107
|
+
explicit Func_void_std__optional_BLEDevice__std__optional_std__string__Wrapper(std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>&& func): _function(std::make_unique<std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>>(std::move(func))) {}
|
|
108
|
+
inline void call(std::optional<BLEDevice> device, std::optional<std::string> error) const {
|
|
109
|
+
_function->operator()(device, error);
|
|
92
110
|
}
|
|
93
111
|
private:
|
|
94
|
-
std::unique_ptr<std::function<void(const BLEDevice
|
|
112
|
+
std::unique_ptr<std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>> _function;
|
|
95
113
|
} SWIFT_NONCOPYABLE;
|
|
96
|
-
|
|
97
|
-
inline
|
|
98
|
-
return
|
|
114
|
+
Func_void_std__optional_BLEDevice__std__optional_std__string_ create_Func_void_std__optional_BLEDevice__std__optional_std__string_(void* _Nonnull swiftClosureWrapper);
|
|
115
|
+
inline Func_void_std__optional_BLEDevice__std__optional_std__string__Wrapper wrap_Func_void_std__optional_BLEDevice__std__optional_std__string_(Func_void_std__optional_BLEDevice__std__optional_std__string_ value) {
|
|
116
|
+
return Func_void_std__optional_BLEDevice__std__optional_std__string__Wrapper(std::move(value));
|
|
99
117
|
}
|
|
100
118
|
|
|
101
119
|
// pragma MARK: std::vector<BLEDevice>
|
|
@@ -228,15 +246,6 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
|
|
|
228
246
|
return Func_void_std__string_std__shared_ptr_ArrayBuffer__Wrapper(std::move(value));
|
|
229
247
|
}
|
|
230
248
|
|
|
231
|
-
// pragma MARK: std::optional<std::string>
|
|
232
|
-
/**
|
|
233
|
-
* Specialized version of `std::optional<std::string>`.
|
|
234
|
-
*/
|
|
235
|
-
using std__optional_std__string_ = std::optional<std::string>;
|
|
236
|
-
inline std::optional<std::string> create_std__optional_std__string_(const std::string& value) {
|
|
237
|
-
return std::optional<std::string>(value);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
249
|
// pragma MARK: std::function<void(BLEState /* state */)>
|
|
241
250
|
/**
|
|
242
251
|
* Specialized version of `std::function<void(BLEState)>`.
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
|
+
// Forward declaration of `AndroidScanMode` to properly resolve imports.
|
|
12
|
+
namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
|
|
11
13
|
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
12
14
|
namespace NitroModules { class ArrayBuffer; }
|
|
13
15
|
// Forward declaration of `BLEDevice` to properly resolve imports.
|
|
@@ -26,6 +28,7 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
|
|
|
26
28
|
namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
|
|
27
29
|
|
|
28
30
|
// Include C++ defined types
|
|
31
|
+
#include "AndroidScanMode.hpp"
|
|
29
32
|
#include "BLEDevice.hpp"
|
|
30
33
|
#include "BLEState.hpp"
|
|
31
34
|
#include "HybridNativeBleNitroSpec.hpp"
|
|
@@ -14,6 +14,8 @@ namespace BleNitro { class HybridNativeBleNitroSpec_cxx; }
|
|
|
14
14
|
|
|
15
15
|
// Forward declaration of `ScanFilter` to properly resolve imports.
|
|
16
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; }
|
|
17
19
|
// Forward declaration of `BLEDevice` to properly resolve imports.
|
|
18
20
|
namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
|
|
19
21
|
// Forward declaration of `ManufacturerData` to properly resolve imports.
|
|
@@ -32,13 +34,14 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
|
|
|
32
34
|
#include "ScanFilter.hpp"
|
|
33
35
|
#include <string>
|
|
34
36
|
#include <vector>
|
|
37
|
+
#include "AndroidScanMode.hpp"
|
|
35
38
|
#include "BLEDevice.hpp"
|
|
39
|
+
#include <optional>
|
|
36
40
|
#include <functional>
|
|
37
41
|
#include "ManufacturerData.hpp"
|
|
38
42
|
#include "ManufacturerDataEntry.hpp"
|
|
39
43
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
40
44
|
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
41
|
-
#include <optional>
|
|
42
45
|
#include "BLEState.hpp"
|
|
43
46
|
#include "OperationResult.hpp"
|
|
44
47
|
#include <NitroModules/Promise.hpp>
|
|
@@ -84,7 +87,7 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
84
87
|
|
|
85
88
|
public:
|
|
86
89
|
// Methods
|
|
87
|
-
inline void startScan(const ScanFilter& filter, const std::function<void(const BLEDevice
|
|
90
|
+
inline void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) override {
|
|
88
91
|
auto __result = _swiftPart.startScan(filter, callback);
|
|
89
92
|
if (__result.hasError()) [[unlikely]] {
|
|
90
93
|
std::rethrow_exception(__result.error());
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AndroidScanMode.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
|
+
/**
|
|
9
|
+
* Represents the JS enum `AndroidScanMode`, backed by a C++ enum.
|
|
10
|
+
*/
|
|
11
|
+
public typealias AndroidScanMode = margelo.nitro.co.zyke.ble.AndroidScanMode
|
|
12
|
+
|
|
13
|
+
public extension AndroidScanMode {
|
|
14
|
+
/**
|
|
15
|
+
* Get a AndroidScanMode for the given String value, or
|
|
16
|
+
* return `nil` if the given value was invalid/unknown.
|
|
17
|
+
*/
|
|
18
|
+
init?(fromString string: String) {
|
|
19
|
+
switch string {
|
|
20
|
+
case "LowLatency":
|
|
21
|
+
self = .lowlatency
|
|
22
|
+
case "Balanced":
|
|
23
|
+
self = .balanced
|
|
24
|
+
case "LowPower":
|
|
25
|
+
self = .lowpower
|
|
26
|
+
case "Opportunistic":
|
|
27
|
+
self = .opportunistic
|
|
28
|
+
default:
|
|
29
|
+
return nil
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get the String value this AndroidScanMode represents.
|
|
35
|
+
*/
|
|
36
|
+
var stringValue: String {
|
|
37
|
+
switch self {
|
|
38
|
+
case .lowlatency:
|
|
39
|
+
return "LowLatency"
|
|
40
|
+
case .balanced:
|
|
41
|
+
return "Balanced"
|
|
42
|
+
case .lowpower:
|
|
43
|
+
return "LowPower"
|
|
44
|
+
case .opportunistic:
|
|
45
|
+
return "Opportunistic"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__optional_BLEDevice__std__optional_std__string_.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 `(_ device: BLEDevice?, _ error: String?) -> 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__optional_BLEDevice__std__optional_std__string_ {
|
|
16
|
+
public typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ device: BLEDevice?, _ error: String?) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ device: BLEDevice?, _ error: String?) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
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 {
|
|
34
|
+
return String(__unwrapped)
|
|
35
|
+
} else {
|
|
36
|
+
return nil
|
|
37
|
+
}
|
|
38
|
+
}())
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
43
|
+
* This acquires one additional strong reference on the object!
|
|
44
|
+
*/
|
|
45
|
+
@inline(__always)
|
|
46
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
47
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Casts an unsafe pointer to a `Func_void_std__optional_BLEDevice__std__optional_std__string_`.
|
|
52
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__optional_BLEDevice__std__optional_std__string_>`.
|
|
53
|
+
* This removes one strong reference from the object!
|
|
54
|
+
*/
|
|
55
|
+
@inline(__always)
|
|
56
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__optional_BLEDevice__std__optional_std__string_ {
|
|
57
|
+
return Unmanaged<Func_void_std__optional_BLEDevice__std__optional_std__string_>.fromOpaque(pointer).takeRetainedValue()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -14,7 +14,7 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
// Methods
|
|
17
|
-
func startScan(filter: ScanFilter, callback: @escaping (_ device: BLEDevice) -> Void) throws -> Void
|
|
17
|
+
func startScan(filter: ScanFilter, callback: @escaping (_ device: BLEDevice?, _ error: String?) -> Void) throws -> Void
|
|
18
18
|
func stopScan() throws -> Bool
|
|
19
19
|
func isScanning() throws -> Bool
|
|
20
20
|
func getConnectedDevices(services: [String]) throws -> [BLEDevice]
|