react-native-ble-nitro 1.6.0 → 1.7.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 +27 -11
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +8 -3
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManagerFactory.kt +21 -0
- package/ios/BleNitroBleManager.swift +36 -23
- package/ios/BleNitroBleManagerFactory.swift +19 -0
- package/lib/commonjs/index.d.ts +2 -5
- package/lib/commonjs/index.d.ts.map +1 -1
- package/lib/commonjs/index.js +7 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/manager.d.ts +9 -0
- package/lib/commonjs/manager.d.ts.map +1 -1
- package/lib/commonjs/manager.js +44 -30
- package/lib/commonjs/manager.js.map +1 -1
- package/lib/commonjs/singleton.d.ts +10 -0
- package/lib/commonjs/singleton.d.ts.map +1 -0
- package/lib/commonjs/singleton.js +20 -0
- package/lib/commonjs/singleton.js.map +1 -0
- package/lib/commonjs/specs/NativeBleNitro.d.ts +1 -1
- package/lib/commonjs/specs/NativeBleNitro.d.ts.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.js +1 -0
- package/lib/commonjs/specs/NativeBleNitro.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +2 -0
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitroFactory.d.ts +5 -0
- package/lib/commonjs/specs/NativeBleNitroFactory.d.ts.map +1 -0
- package/lib/commonjs/specs/NativeBleNitroFactory.js +23 -0
- package/lib/commonjs/specs/NativeBleNitroFactory.js.map +1 -0
- package/lib/commonjs/specs/NativeBleNitroFactory.nitro.d.ts +9 -0
- package/lib/commonjs/specs/NativeBleNitroFactory.nitro.d.ts.map +1 -0
- package/lib/commonjs/specs/NativeBleNitroFactory.nitro.js +3 -0
- package/lib/commonjs/specs/NativeBleNitroFactory.nitro.js.map +1 -0
- package/lib/index.d.ts +2 -5
- package/lib/index.js +2 -11
- package/lib/manager.d.ts +9 -0
- package/lib/manager.js +38 -25
- package/lib/singleton.d.ts +9 -0
- package/lib/singleton.js +15 -0
- package/lib/specs/NativeBleNitro.d.ts +1 -1
- package/lib/specs/NativeBleNitro.js +1 -0
- package/lib/specs/NativeBleNitro.nitro.d.ts +2 -0
- package/lib/specs/NativeBleNitroFactory.d.ts +4 -0
- package/lib/specs/NativeBleNitroFactory.js +6 -0
- package/lib/specs/NativeBleNitroFactory.nitro.d.ts +8 -0
- package/lib/specs/NativeBleNitroFactory.nitro.js +1 -0
- package/nitro.json +4 -0
- package/nitrogen/generated/android/BleNitro+autolinking.cmake +2 -0
- package/nitrogen/generated/android/BleNitroOnLoad.cpp +11 -0
- package/nitrogen/generated/android/c++/JBLEDevice.hpp +6 -2
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_BLEDevice_.hpp +12 -12
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroFactorySpec.cpp +71 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroFactorySpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +11 -3
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/BLEDevice.kt +4 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_.kt +9 -9
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroFactorySpec.kt +57 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +5 -1
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +44 -9
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +5 -0
- package/nitrogen/generated/ios/BleNitroAutolinking.mm +8 -0
- package/nitrogen/generated/ios/BleNitroAutolinking.swift +15 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroFactorySpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroFactorySpecSwift.hpp +94 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +9 -3
- package/nitrogen/generated/ios/swift/BLEDevice.swift +13 -2
- package/nitrogen/generated/ios/swift/Func_void_std__vector_BLEDevice_.swift +5 -5
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroFactorySpec.swift +49 -0
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroFactorySpec_cxx.swift +149 -0
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +22 -1
- package/nitrogen/generated/shared/c++/BLEDevice.hpp +6 -2
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroFactorySpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroFactorySpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +4 -3
- package/package.json +9 -1
- package/src/__tests__/index.test.ts +36 -26
- package/src/index.ts +2 -13
- package/src/manager.ts +41 -25
- package/src/singleton.ts +17 -0
- package/src/specs/NativeBleNitro.nitro.ts +2 -0
- package/src/specs/NativeBleNitro.ts +2 -1
- package/src/specs/NativeBleNitroFactory.nitro.ts +6 -0
- package/src/specs/NativeBleNitroFactory.ts +9 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeBleNitroFactorySpecSwift.cpp
|
|
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
|
+
#include "HybridNativeBleNitroFactorySpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::co::zyke::ble {
|
|
11
|
+
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeBleNitroFactorySpecSwift.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 "HybridNativeBleNitroFactorySpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridNativeBleNitroFactorySpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace BleNitro { class HybridNativeBleNitroFactorySpec_cxx; }
|
|
14
|
+
|
|
15
|
+
// Forward declaration of `HybridNativeBleNitroSpec` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::co::zyke::ble { class HybridNativeBleNitroSpec; }
|
|
17
|
+
// Forward declaration of `BLEDevice` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
|
|
19
|
+
// Forward declaration of `ManufacturerData` to properly resolve imports.
|
|
20
|
+
namespace margelo::nitro::co::zyke::ble { struct ManufacturerData; }
|
|
21
|
+
// Forward declaration of `ManufacturerDataEntry` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::co::zyke::ble { struct ManufacturerDataEntry; }
|
|
23
|
+
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
24
|
+
namespace NitroModules { class ArrayBuffer; }
|
|
25
|
+
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
|
|
26
|
+
namespace NitroModules { class ArrayBufferHolder; }
|
|
27
|
+
|
|
28
|
+
#include <memory>
|
|
29
|
+
#include "HybridNativeBleNitroSpec.hpp"
|
|
30
|
+
#include <string>
|
|
31
|
+
#include <optional>
|
|
32
|
+
#include "BLEDevice.hpp"
|
|
33
|
+
#include <vector>
|
|
34
|
+
#include <functional>
|
|
35
|
+
#include "ManufacturerData.hpp"
|
|
36
|
+
#include "ManufacturerDataEntry.hpp"
|
|
37
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
38
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
39
|
+
|
|
40
|
+
#include "BleNitro-Swift-Cxx-Umbrella.hpp"
|
|
41
|
+
|
|
42
|
+
namespace margelo::nitro::co::zyke::ble {
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The C++ part of HybridNativeBleNitroFactorySpec_cxx.swift.
|
|
46
|
+
*
|
|
47
|
+
* HybridNativeBleNitroFactorySpecSwift (C++) accesses HybridNativeBleNitroFactorySpec_cxx (Swift), and might
|
|
48
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
49
|
+
*
|
|
50
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
51
|
+
* the future, HybridNativeBleNitroFactorySpec_cxx can directly inherit from the C++ class HybridNativeBleNitroFactorySpec
|
|
52
|
+
* to simplify the whole structure and memory management.
|
|
53
|
+
*/
|
|
54
|
+
class HybridNativeBleNitroFactorySpecSwift: public virtual HybridNativeBleNitroFactorySpec {
|
|
55
|
+
public:
|
|
56
|
+
// Constructor from a Swift instance
|
|
57
|
+
explicit HybridNativeBleNitroFactorySpecSwift(const BleNitro::HybridNativeBleNitroFactorySpec_cxx& swiftPart):
|
|
58
|
+
HybridObject(HybridNativeBleNitroFactorySpec::TAG),
|
|
59
|
+
_swiftPart(swiftPart) { }
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
// Get the Swift part
|
|
63
|
+
inline BleNitro::HybridNativeBleNitroFactorySpec_cxx& getSwiftPart() noexcept {
|
|
64
|
+
return _swiftPart;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public:
|
|
68
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
69
|
+
return _swiftPart.getMemorySize();
|
|
70
|
+
}
|
|
71
|
+
void dispose() noexcept override {
|
|
72
|
+
_swiftPart.dispose();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public:
|
|
76
|
+
// Properties
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
public:
|
|
80
|
+
// Methods
|
|
81
|
+
inline std::shared_ptr<HybridNativeBleNitroSpec> create(const std::optional<std::string>& nativeRestoreStateIdentifier, const std::optional<std::function<void(const std::vector<BLEDevice>& /* peripherals */)>>& restoreStateCallback) override {
|
|
82
|
+
auto __result = _swiftPart.create(nativeRestoreStateIdentifier, restoreStateCallback);
|
|
83
|
+
if (__result.hasError()) [[unlikely]] {
|
|
84
|
+
std::rethrow_exception(__result.error());
|
|
85
|
+
}
|
|
86
|
+
auto __value = std::move(__result.value());
|
|
87
|
+
return __value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private:
|
|
91
|
+
BleNitro::HybridNativeBleNitroFactorySpec_cxx _swiftPart;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -31,17 +31,17 @@ 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 <string>
|
|
35
|
+
#include <optional>
|
|
34
36
|
#include "BLEDevice.hpp"
|
|
35
37
|
#include <vector>
|
|
36
38
|
#include <functional>
|
|
37
|
-
#include <string>
|
|
38
39
|
#include "ManufacturerData.hpp"
|
|
39
40
|
#include "ManufacturerDataEntry.hpp"
|
|
40
41
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
41
42
|
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
42
43
|
#include "ScanFilter.hpp"
|
|
43
44
|
#include "AndroidScanMode.hpp"
|
|
44
|
-
#include <optional>
|
|
45
45
|
#include "BLEState.hpp"
|
|
46
46
|
#include "OperationResult.hpp"
|
|
47
47
|
#include <NitroModules/Promise.hpp>
|
|
@@ -83,7 +83,13 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
83
83
|
|
|
84
84
|
public:
|
|
85
85
|
// Properties
|
|
86
|
-
|
|
86
|
+
inline std::optional<std::string> getRestoreStateIdentifier() noexcept override {
|
|
87
|
+
auto __result = _swiftPart.getRestoreStateIdentifier();
|
|
88
|
+
return __result;
|
|
89
|
+
}
|
|
90
|
+
inline void setRestoreStateIdentifier(const std::optional<std::string>& restoreStateIdentifier) noexcept override {
|
|
91
|
+
_swiftPart.setRestoreStateIdentifier(restoreStateIdentifier);
|
|
92
|
+
}
|
|
87
93
|
|
|
88
94
|
public:
|
|
89
95
|
// Methods
|
|
@@ -18,14 +18,14 @@ public extension BLEDevice {
|
|
|
18
18
|
/**
|
|
19
19
|
* Create a new instance of `BLEDevice`.
|
|
20
20
|
*/
|
|
21
|
-
init(id: String, name: String, rssi: Double, manufacturerData: ManufacturerData, serviceUUIDs: [String], isConnectable: Bool) {
|
|
21
|
+
init(id: String, name: String, rssi: Double, manufacturerData: ManufacturerData, serviceUUIDs: [String], isConnectable: Bool, isConnected: Bool) {
|
|
22
22
|
self.init(std.string(id), std.string(name), rssi, manufacturerData, { () -> bridge.std__vector_std__string_ in
|
|
23
23
|
var __vector = bridge.create_std__vector_std__string_(serviceUUIDs.count)
|
|
24
24
|
for __item in serviceUUIDs {
|
|
25
25
|
__vector.push_back(std.string(__item))
|
|
26
26
|
}
|
|
27
27
|
return __vector
|
|
28
|
-
}(), isConnectable)
|
|
28
|
+
}(), isConnectable, isConnected)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
var id: String {
|
|
@@ -99,4 +99,15 @@ public extension BLEDevice {
|
|
|
99
99
|
self.__isConnectable = newValue
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
var isConnected: Bool {
|
|
104
|
+
@inline(__always)
|
|
105
|
+
get {
|
|
106
|
+
return self.__isConnected
|
|
107
|
+
}
|
|
108
|
+
@inline(__always)
|
|
109
|
+
set {
|
|
110
|
+
self.__isConnected = newValue
|
|
111
|
+
}
|
|
112
|
+
}
|
|
102
113
|
}
|
|
@@ -9,21 +9,21 @@ import NitroModules
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Wraps a Swift `(_
|
|
12
|
+
* Wraps a Swift `(_ peripherals: [BLEDevice]) -> Void` as a class.
|
|
13
13
|
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
14
|
*/
|
|
15
15
|
public final class Func_void_std__vector_BLEDevice_ {
|
|
16
16
|
public typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
|
|
17
17
|
|
|
18
|
-
private let closure: (_
|
|
18
|
+
private let closure: (_ peripherals: [BLEDevice]) -> Void
|
|
19
19
|
|
|
20
|
-
public init(_ closure: @escaping (_
|
|
20
|
+
public init(_ closure: @escaping (_ peripherals: [BLEDevice]) -> Void) {
|
|
21
21
|
self.closure = closure
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
@inline(__always)
|
|
25
|
-
public func call(
|
|
26
|
-
self.closure(
|
|
25
|
+
public func call(peripherals: bridge.std__vector_BLEDevice_) -> Void {
|
|
26
|
+
self.closure(peripherals.map({ __item in __item }))
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeBleNitroFactorySpec.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 Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/// See ``HybridNativeBleNitroFactorySpec``
|
|
12
|
+
public protocol HybridNativeBleNitroFactorySpec_protocol: HybridObject {
|
|
13
|
+
// Properties
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// Methods
|
|
17
|
+
func create(nativeRestoreStateIdentifier: String?, restoreStateCallback: ((_ peripherals: [BLEDevice]) -> Void)?) throws -> (any HybridNativeBleNitroSpec)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// See ``HybridNativeBleNitroFactorySpec``
|
|
21
|
+
open class HybridNativeBleNitroFactorySpec_base {
|
|
22
|
+
private weak var cxxWrapper: HybridNativeBleNitroFactorySpec_cxx? = nil
|
|
23
|
+
public init() { }
|
|
24
|
+
public func getCxxWrapper() -> HybridNativeBleNitroFactorySpec_cxx {
|
|
25
|
+
#if DEBUG
|
|
26
|
+
guard self is HybridNativeBleNitroFactorySpec else {
|
|
27
|
+
fatalError("`self` is not a `HybridNativeBleNitroFactorySpec`! Did you accidentally inherit from `HybridNativeBleNitroFactorySpec_base` instead of `HybridNativeBleNitroFactorySpec`?")
|
|
28
|
+
}
|
|
29
|
+
#endif
|
|
30
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
31
|
+
return cxxWrapper
|
|
32
|
+
} else {
|
|
33
|
+
let cxxWrapper = HybridNativeBleNitroFactorySpec_cxx(self as! HybridNativeBleNitroFactorySpec)
|
|
34
|
+
self.cxxWrapper = cxxWrapper
|
|
35
|
+
return cxxWrapper
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A Swift base-protocol representing the NativeBleNitroFactory HybridObject.
|
|
42
|
+
* Implement this protocol to create Swift-based instances of NativeBleNitroFactory.
|
|
43
|
+
* ```swift
|
|
44
|
+
* class HybridNativeBleNitroFactory : HybridNativeBleNitroFactorySpec {
|
|
45
|
+
* // ...
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
public typealias HybridNativeBleNitroFactorySpec = HybridNativeBleNitroFactorySpec_protocol & HybridNativeBleNitroFactorySpec_base
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeBleNitroFactorySpec_cxx.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 Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridNativeBleNitroFactorySpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridNativeBleNitroFactorySpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::co::zyke::ble::bridge::swift`)
|
|
23
|
+
* from `BleNitro-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridNativeBleNitroFactorySpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridNativeBleNitroFactorySpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridNativeBleNitroFactorySpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridNativeBleNitroFactorySpec_cxx` that wraps the given `HybridNativeBleNitroFactorySpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridNativeBleNitroFactorySpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridNativeBleNitroFactorySpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridNativeBleNitroFactorySpec() -> any HybridNativeBleNitroFactorySpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridNativeBleNitroFactorySpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridNativeBleNitroFactorySpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNativeBleNitroFactorySpec_cxx {
|
|
70
|
+
return Unmanaged<HybridNativeBleNitroFactorySpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridNativeBleNitroFactorySpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridNativeBleNitroFactorySpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if cachedCxxPart.__convertToBool() {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridNativeBleNitroFactorySpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridNativeBleNitroFactorySpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Call dispose() on the Swift class.
|
|
101
|
+
* This _may_ be called manually from JS.
|
|
102
|
+
*/
|
|
103
|
+
@inline(__always)
|
|
104
|
+
public func dispose() {
|
|
105
|
+
self.__implementation.dispose()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Properties
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
// Methods
|
|
112
|
+
@inline(__always)
|
|
113
|
+
public final func create(nativeRestoreStateIdentifier: bridge.std__optional_std__string_, restoreStateCallback: bridge.std__optional_std__function_void_const_std__vector_BLEDevice______peripherals______) -> bridge.Result_std__shared_ptr_HybridNativeBleNitroSpec__ {
|
|
114
|
+
do {
|
|
115
|
+
let __result = try self.__implementation.create(nativeRestoreStateIdentifier: { () -> String? in
|
|
116
|
+
if let __unwrapped = nativeRestoreStateIdentifier.value {
|
|
117
|
+
return String(__unwrapped)
|
|
118
|
+
} else {
|
|
119
|
+
return nil
|
|
120
|
+
}
|
|
121
|
+
}(), restoreStateCallback: { () -> ((_ peripherals: [BLEDevice]) -> Void)? in
|
|
122
|
+
if let __unwrapped = restoreStateCallback.value {
|
|
123
|
+
return { () -> ([BLEDevice]) -> Void in
|
|
124
|
+
let __wrappedFunction = bridge.wrap_Func_void_std__vector_BLEDevice_(__unwrapped)
|
|
125
|
+
return { (__peripherals: [BLEDevice]) -> Void in
|
|
126
|
+
__wrappedFunction.call({ () -> bridge.std__vector_BLEDevice_ in
|
|
127
|
+
var __vector = bridge.create_std__vector_BLEDevice_(__peripherals.count)
|
|
128
|
+
for __item in __peripherals {
|
|
129
|
+
__vector.push_back(__item)
|
|
130
|
+
}
|
|
131
|
+
return __vector
|
|
132
|
+
}())
|
|
133
|
+
}
|
|
134
|
+
}()
|
|
135
|
+
} else {
|
|
136
|
+
return nil
|
|
137
|
+
}
|
|
138
|
+
}())
|
|
139
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_HybridNativeBleNitroSpec_ in
|
|
140
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
141
|
+
return __cxxWrapped.getCxxPart()
|
|
142
|
+
}()
|
|
143
|
+
return bridge.create_Result_std__shared_ptr_HybridNativeBleNitroSpec__(__resultCpp)
|
|
144
|
+
} catch (let __error) {
|
|
145
|
+
let __exceptionPtr = __error.toCpp()
|
|
146
|
+
return bridge.create_Result_std__shared_ptr_HybridNativeBleNitroSpec__(__exceptionPtr)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -11,7 +11,7 @@ import NitroModules
|
|
|
11
11
|
/// See ``HybridNativeBleNitroSpec``
|
|
12
12
|
public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
|
|
13
13
|
// Properties
|
|
14
|
-
|
|
14
|
+
var restoreStateIdentifier: String? { get set }
|
|
15
15
|
|
|
16
16
|
// Methods
|
|
17
17
|
func setRestoreStateCallback(callback: @escaping (_ restoredPeripherals: [BLEDevice]) -> Void) throws -> Void
|
|
@@ -106,7 +106,28 @@ open class HybridNativeBleNitroSpec_cxx {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// Properties
|
|
109
|
-
|
|
109
|
+
public final var restoreStateIdentifier: bridge.std__optional_std__string_ {
|
|
110
|
+
@inline(__always)
|
|
111
|
+
get {
|
|
112
|
+
return { () -> bridge.std__optional_std__string_ in
|
|
113
|
+
if let __unwrappedValue = self.__implementation.restoreStateIdentifier {
|
|
114
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
115
|
+
} else {
|
|
116
|
+
return .init()
|
|
117
|
+
}
|
|
118
|
+
}()
|
|
119
|
+
}
|
|
120
|
+
@inline(__always)
|
|
121
|
+
set {
|
|
122
|
+
self.__implementation.restoreStateIdentifier = { () -> String? in
|
|
123
|
+
if let __unwrapped = newValue.value {
|
|
124
|
+
return String(__unwrapped)
|
|
125
|
+
} else {
|
|
126
|
+
return nil
|
|
127
|
+
}
|
|
128
|
+
}()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
110
131
|
|
|
111
132
|
// Methods
|
|
112
133
|
@inline(__always)
|
|
@@ -38,10 +38,11 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
38
38
|
ManufacturerData manufacturerData SWIFT_PRIVATE;
|
|
39
39
|
std::vector<std::string> serviceUUIDs SWIFT_PRIVATE;
|
|
40
40
|
bool isConnectable SWIFT_PRIVATE;
|
|
41
|
+
bool isConnected SWIFT_PRIVATE;
|
|
41
42
|
|
|
42
43
|
public:
|
|
43
44
|
BLEDevice() = default;
|
|
44
|
-
explicit BLEDevice(std::string id, std::string name, double rssi, ManufacturerData manufacturerData, std::vector<std::string> serviceUUIDs, bool isConnectable): id(id), name(name), rssi(rssi), manufacturerData(manufacturerData), serviceUUIDs(serviceUUIDs), isConnectable(isConnectable) {}
|
|
45
|
+
explicit BLEDevice(std::string id, std::string name, double rssi, ManufacturerData manufacturerData, std::vector<std::string> serviceUUIDs, bool isConnectable, bool isConnected): id(id), name(name), rssi(rssi), manufacturerData(manufacturerData), serviceUUIDs(serviceUUIDs), isConnectable(isConnectable), isConnected(isConnected) {}
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -59,7 +60,8 @@ namespace margelo::nitro {
|
|
|
59
60
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "rssi")),
|
|
60
61
|
JSIConverter<margelo::nitro::co::zyke::ble::ManufacturerData>::fromJSI(runtime, obj.getProperty(runtime, "manufacturerData")),
|
|
61
62
|
JSIConverter<std::vector<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "serviceUUIDs")),
|
|
62
|
-
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "isConnectable"))
|
|
63
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "isConnectable")),
|
|
64
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "isConnected"))
|
|
63
65
|
);
|
|
64
66
|
}
|
|
65
67
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::co::zyke::ble::BLEDevice& arg) {
|
|
@@ -70,6 +72,7 @@ namespace margelo::nitro {
|
|
|
70
72
|
obj.setProperty(runtime, "manufacturerData", JSIConverter<margelo::nitro::co::zyke::ble::ManufacturerData>::toJSI(runtime, arg.manufacturerData));
|
|
71
73
|
obj.setProperty(runtime, "serviceUUIDs", JSIConverter<std::vector<std::string>>::toJSI(runtime, arg.serviceUUIDs));
|
|
72
74
|
obj.setProperty(runtime, "isConnectable", JSIConverter<bool>::toJSI(runtime, arg.isConnectable));
|
|
75
|
+
obj.setProperty(runtime, "isConnected", JSIConverter<bool>::toJSI(runtime, arg.isConnected));
|
|
73
76
|
return obj;
|
|
74
77
|
}
|
|
75
78
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -83,6 +86,7 @@ namespace margelo::nitro {
|
|
|
83
86
|
if (!JSIConverter<margelo::nitro::co::zyke::ble::ManufacturerData>::canConvert(runtime, obj.getProperty(runtime, "manufacturerData"))) return false;
|
|
84
87
|
if (!JSIConverter<std::vector<std::string>>::canConvert(runtime, obj.getProperty(runtime, "serviceUUIDs"))) return false;
|
|
85
88
|
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "isConnectable"))) return false;
|
|
89
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "isConnected"))) return false;
|
|
86
90
|
return true;
|
|
87
91
|
}
|
|
88
92
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeBleNitroFactorySpec.cpp
|
|
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
|
+
#include "HybridNativeBleNitroFactorySpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::co::zyke::ble {
|
|
11
|
+
|
|
12
|
+
void HybridNativeBleNitroFactorySpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("create", &HybridNativeBleNitroFactorySpec::create);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeBleNitroFactorySpec.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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `HybridNativeBleNitroSpec` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::co::zyke::ble { class HybridNativeBleNitroSpec; }
|
|
18
|
+
// Forward declaration of `BLEDevice` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
|
|
20
|
+
|
|
21
|
+
#include <memory>
|
|
22
|
+
#include "HybridNativeBleNitroSpec.hpp"
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include "BLEDevice.hpp"
|
|
26
|
+
#include <vector>
|
|
27
|
+
#include <functional>
|
|
28
|
+
|
|
29
|
+
namespace margelo::nitro::co::zyke::ble {
|
|
30
|
+
|
|
31
|
+
using namespace margelo::nitro;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An abstract base class for `NativeBleNitroFactory`
|
|
35
|
+
* Inherit this class to create instances of `HybridNativeBleNitroFactorySpec` in C++.
|
|
36
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
37
|
+
* @example
|
|
38
|
+
* ```cpp
|
|
39
|
+
* class HybridNativeBleNitroFactory: public HybridNativeBleNitroFactorySpec {
|
|
40
|
+
* public:
|
|
41
|
+
* HybridNativeBleNitroFactory(...): HybridObject(TAG) { ... }
|
|
42
|
+
* // ...
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
class HybridNativeBleNitroFactorySpec: public virtual HybridObject {
|
|
47
|
+
public:
|
|
48
|
+
// Constructor
|
|
49
|
+
explicit HybridNativeBleNitroFactorySpec(): HybridObject(TAG) { }
|
|
50
|
+
|
|
51
|
+
// Destructor
|
|
52
|
+
~HybridNativeBleNitroFactorySpec() override = default;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Properties
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
// Methods
|
|
60
|
+
virtual std::shared_ptr<HybridNativeBleNitroSpec> create(const std::optional<std::string>& nativeRestoreStateIdentifier, const std::optional<std::function<void(const std::vector<BLEDevice>& /* peripherals */)>>& restoreStateCallback) = 0;
|
|
61
|
+
|
|
62
|
+
protected:
|
|
63
|
+
// Hybrid Setup
|
|
64
|
+
void loadHybridMethods() override;
|
|
65
|
+
|
|
66
|
+
protected:
|
|
67
|
+
// Tag for logging
|
|
68
|
+
static constexpr auto TAG = "NativeBleNitroFactory";
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace margelo::nitro::co::zyke::ble
|
|
@@ -14,6 +14,8 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
14
14
|
HybridObject::loadHybridMethods();
|
|
15
15
|
// load custom methods/properties
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("restoreStateIdentifier", &HybridNativeBleNitroSpec::getRestoreStateIdentifier);
|
|
18
|
+
prototype.registerHybridSetter("restoreStateIdentifier", &HybridNativeBleNitroSpec::setRestoreStateIdentifier);
|
|
17
19
|
prototype.registerHybridMethod("setRestoreStateCallback", &HybridNativeBleNitroSpec::setRestoreStateCallback);
|
|
18
20
|
prototype.registerHybridMethod("startScan", &HybridNativeBleNitroSpec::startScan);
|
|
19
21
|
prototype.registerHybridMethod("stopScan", &HybridNativeBleNitroSpec::stopScan);
|
|
@@ -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 <string>
|
|
28
|
+
#include <optional>
|
|
27
29
|
#include "BLEDevice.hpp"
|
|
28
30
|
#include <vector>
|
|
29
31
|
#include <functional>
|
|
30
32
|
#include "ScanFilter.hpp"
|
|
31
|
-
#include <optional>
|
|
32
|
-
#include <string>
|
|
33
33
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
34
34
|
#include "BLEState.hpp"
|
|
35
35
|
#include "OperationResult.hpp"
|
|
@@ -62,7 +62,8 @@ namespace margelo::nitro::co::zyke::ble {
|
|
|
62
62
|
|
|
63
63
|
public:
|
|
64
64
|
// Properties
|
|
65
|
-
|
|
65
|
+
virtual std::optional<std::string> getRestoreStateIdentifier() = 0;
|
|
66
|
+
virtual void setRestoreStateIdentifier(const std::optional<std::string>& restoreStateIdentifier) = 0;
|
|
66
67
|
|
|
67
68
|
public:
|
|
68
69
|
// Methods
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-ble-nitro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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",
|
|
@@ -23,6 +23,14 @@
|
|
|
23
23
|
"types": "./lib/manager.d.ts",
|
|
24
24
|
"default": "./src/manager.ts"
|
|
25
25
|
},
|
|
26
|
+
"./singleton": {
|
|
27
|
+
"react-native": "./src/singleton.ts",
|
|
28
|
+
"typescript": "./src/singleton.ts",
|
|
29
|
+
"import": "./lib/singleton.js",
|
|
30
|
+
"require": "./lib/commonjs/singleton.js",
|
|
31
|
+
"types": "./lib/singleton.d.ts",
|
|
32
|
+
"default": "./src/singleton.ts"
|
|
33
|
+
},
|
|
26
34
|
"./plugin": {
|
|
27
35
|
"import": "./plugin/build/index.js",
|
|
28
36
|
"require": "./plugin/build/index.js",
|