munim-bluetooth 0.2.7 → 0.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/MunimBluetooth.podspec +1 -0
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts +24 -25
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts.map +1 -1
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/MunimBluetooth+autolinking.cmake +81 -0
- package/nitrogen/generated/android/MunimBluetooth+autolinking.gradle +27 -0
- package/nitrogen/generated/android/MunimBluetoothOnLoad.cpp +44 -0
- package/nitrogen/generated/android/MunimBluetoothOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JAdvertisingDataTypes.hpp +345 -0
- package/nitrogen/generated/android/c++/JAdvertisingOptions.hpp +93 -0
- package/nitrogen/generated/android/c++/JCharacteristicValue.hpp +65 -0
- package/nitrogen/generated/android/c++/JGATTCharacteristic.hpp +85 -0
- package/nitrogen/generated/android/c++/JGATTService.hpp +83 -0
- package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.cpp +307 -0
- package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.hpp +85 -0
- package/nitrogen/generated/android/c++/JScanMode.hpp +61 -0
- package/nitrogen/generated/android/c++/JScanOptions.hpp +87 -0
- package/nitrogen/generated/android/c++/JServiceDataEntry.hpp +61 -0
- package/nitrogen/generated/android/c++/JWriteType.hpp +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/AdvertisingDataTypes.kt +89 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/AdvertisingOptions.kt +47 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/CharacteristicValue.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTCharacteristic.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTService.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/HybridMunimBluetoothSpec.kt +134 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MunimBluetoothOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ScanMode.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ScanOptions.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ServiceDataEntry.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/WriteType.kt +23 -0
- package/nitrogen/generated/ios/MunimBluetooth+autolinking.rb +60 -0
- package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Bridge.cpp +97 -0
- package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Bridge.hpp +583 -0
- package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Umbrella.hpp +74 -0
- package/nitrogen/generated/ios/MunimBluetoothAutolinking.mm +33 -0
- package/nitrogen/generated/ios/MunimBluetoothAutolinking.swift +44 -0
- package/nitrogen/generated/ios/c++/HybridMunimBluetoothSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMunimBluetoothSpecSwift.hpp +241 -0
- package/nitrogen/generated/ios/swift/AdvertisingDataTypes.swift +400 -0
- package/nitrogen/generated/ios/swift/AdvertisingOptions.swift +83 -0
- package/nitrogen/generated/ios/swift/CharacteristicValue.swift +40 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_AdvertisingDataTypes.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_CharacteristicValue.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_GATTService_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +47 -0
- package/nitrogen/generated/ios/swift/GATTCharacteristic.swift +59 -0
- package/nitrogen/generated/ios/swift/GATTService.swift +41 -0
- package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec.swift +75 -0
- package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec_cxx.swift +431 -0
- package/nitrogen/generated/ios/swift/ScanMode.swift +44 -0
- package/nitrogen/generated/ios/swift/ScanOptions.swift +78 -0
- package/nitrogen/generated/ios/swift/ServiceDataEntry.swift +35 -0
- package/nitrogen/generated/ios/swift/WriteType.swift +40 -0
- package/nitrogen/generated/shared/c++/AdvertisingDataTypes.hpp +155 -0
- package/nitrogen/generated/shared/c++/AdvertisingOptions.hpp +99 -0
- package/nitrogen/generated/shared/c++/CharacteristicValue.hpp +91 -0
- package/nitrogen/generated/shared/c++/GATTCharacteristic.hpp +93 -0
- package/nitrogen/generated/shared/c++/GATTService.hpp +90 -0
- package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.cpp +40 -0
- package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.hpp +101 -0
- package/nitrogen/generated/shared/c++/ScanMode.hpp +80 -0
- package/nitrogen/generated/shared/c++/ScanOptions.hpp +95 -0
- package/nitrogen/generated/shared/c++/ServiceDataEntry.hpp +87 -0
- package/nitrogen/generated/shared/c++/WriteType.hpp +76 -0
- package/package.json +9 -9
- package/src/specs/munim-bluetooth.nitro.ts +34 -25
- package/lib/module/package.json +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMunimBluetoothSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 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 `AdvertisingOptions` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::munimbluetooth { struct AdvertisingOptions; }
|
|
18
|
+
// Forward declaration of `AdvertisingDataTypes` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::munimbluetooth { struct AdvertisingDataTypes; }
|
|
20
|
+
// Forward declaration of `GATTService` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::munimbluetooth { struct GATTService; }
|
|
22
|
+
// Forward declaration of `ScanOptions` to properly resolve imports.
|
|
23
|
+
namespace margelo::nitro::munimbluetooth { struct ScanOptions; }
|
|
24
|
+
// Forward declaration of `CharacteristicValue` to properly resolve imports.
|
|
25
|
+
namespace margelo::nitro::munimbluetooth { struct CharacteristicValue; }
|
|
26
|
+
// Forward declaration of `WriteType` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::munimbluetooth { enum class WriteType; }
|
|
28
|
+
|
|
29
|
+
#include "AdvertisingOptions.hpp"
|
|
30
|
+
#include "AdvertisingDataTypes.hpp"
|
|
31
|
+
#include <NitroModules/Promise.hpp>
|
|
32
|
+
#include "GATTService.hpp"
|
|
33
|
+
#include <vector>
|
|
34
|
+
#include "ScanOptions.hpp"
|
|
35
|
+
#include <optional>
|
|
36
|
+
#include <string>
|
|
37
|
+
#include "CharacteristicValue.hpp"
|
|
38
|
+
#include "WriteType.hpp"
|
|
39
|
+
|
|
40
|
+
namespace margelo::nitro::munimbluetooth {
|
|
41
|
+
|
|
42
|
+
using namespace margelo::nitro;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An abstract base class for `MunimBluetooth`
|
|
46
|
+
* Inherit this class to create instances of `HybridMunimBluetoothSpec` in C++.
|
|
47
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
48
|
+
* @example
|
|
49
|
+
* ```cpp
|
|
50
|
+
* class HybridMunimBluetooth: public HybridMunimBluetoothSpec {
|
|
51
|
+
* public:
|
|
52
|
+
* HybridMunimBluetooth(...): HybridObject(TAG) { ... }
|
|
53
|
+
* // ...
|
|
54
|
+
* };
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
class HybridMunimBluetoothSpec: public virtual HybridObject {
|
|
58
|
+
public:
|
|
59
|
+
// Constructor
|
|
60
|
+
explicit HybridMunimBluetoothSpec(): HybridObject(TAG) { }
|
|
61
|
+
|
|
62
|
+
// Destructor
|
|
63
|
+
~HybridMunimBluetoothSpec() override = default;
|
|
64
|
+
|
|
65
|
+
public:
|
|
66
|
+
// Properties
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
public:
|
|
70
|
+
// Methods
|
|
71
|
+
virtual void startAdvertising(const AdvertisingOptions& options) = 0;
|
|
72
|
+
virtual void updateAdvertisingData(const AdvertisingDataTypes& advertisingData) = 0;
|
|
73
|
+
virtual std::shared_ptr<Promise<AdvertisingDataTypes>> getAdvertisingData() = 0;
|
|
74
|
+
virtual void stopAdvertising() = 0;
|
|
75
|
+
virtual void setServices(const std::vector<GATTService>& services) = 0;
|
|
76
|
+
virtual std::shared_ptr<Promise<bool>> isBluetoothEnabled() = 0;
|
|
77
|
+
virtual std::shared_ptr<Promise<bool>> requestBluetoothPermission() = 0;
|
|
78
|
+
virtual void startScan(const std::optional<ScanOptions>& options) = 0;
|
|
79
|
+
virtual void stopScan() = 0;
|
|
80
|
+
virtual std::shared_ptr<Promise<void>> connect(const std::string& deviceId) = 0;
|
|
81
|
+
virtual void disconnect(const std::string& deviceId) = 0;
|
|
82
|
+
virtual std::shared_ptr<Promise<std::vector<GATTService>>> discoverServices(const std::string& deviceId) = 0;
|
|
83
|
+
virtual std::shared_ptr<Promise<CharacteristicValue>> readCharacteristic(const std::string& deviceId, const std::string& serviceUUID, const std::string& characteristicUUID) = 0;
|
|
84
|
+
virtual std::shared_ptr<Promise<void>> writeCharacteristic(const std::string& deviceId, const std::string& serviceUUID, const std::string& characteristicUUID, const std::string& value, std::optional<WriteType> writeType) = 0;
|
|
85
|
+
virtual void subscribeToCharacteristic(const std::string& deviceId, const std::string& serviceUUID, const std::string& characteristicUUID) = 0;
|
|
86
|
+
virtual void unsubscribeFromCharacteristic(const std::string& deviceId, const std::string& serviceUUID, const std::string& characteristicUUID) = 0;
|
|
87
|
+
virtual std::shared_ptr<Promise<std::vector<std::string>>> getConnectedDevices() = 0;
|
|
88
|
+
virtual std::shared_ptr<Promise<double>> readRSSI(const std::string& deviceId) = 0;
|
|
89
|
+
virtual void addListener(const std::string& eventName) = 0;
|
|
90
|
+
virtual void removeListeners(double count) = 0;
|
|
91
|
+
|
|
92
|
+
protected:
|
|
93
|
+
// Hybrid Setup
|
|
94
|
+
void loadHybridMethods() override;
|
|
95
|
+
|
|
96
|
+
protected:
|
|
97
|
+
// Tag for logging
|
|
98
|
+
static constexpr auto TAG = "MunimBluetooth";
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
} // namespace margelo::nitro::munimbluetooth
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ScanMode.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::munimbluetooth {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (ScanMode).
|
|
30
|
+
*/
|
|
31
|
+
enum class ScanMode {
|
|
32
|
+
LOWPOWER SWIFT_NAME(lowpower) = 0,
|
|
33
|
+
BALANCED SWIFT_NAME(balanced) = 1,
|
|
34
|
+
LOWLATENCY SWIFT_NAME(lowlatency) = 2,
|
|
35
|
+
} CLOSED_ENUM;
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro::munimbluetooth
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro {
|
|
40
|
+
|
|
41
|
+
// C++ ScanMode <> JS ScanMode (union)
|
|
42
|
+
template <>
|
|
43
|
+
struct JSIConverter<margelo::nitro::munimbluetooth::ScanMode> final {
|
|
44
|
+
static inline margelo::nitro::munimbluetooth::ScanMode fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
45
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
46
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
47
|
+
case hashString("lowPower"): return margelo::nitro::munimbluetooth::ScanMode::LOWPOWER;
|
|
48
|
+
case hashString("balanced"): return margelo::nitro::munimbluetooth::ScanMode::BALANCED;
|
|
49
|
+
case hashString("lowLatency"): return margelo::nitro::munimbluetooth::ScanMode::LOWLATENCY;
|
|
50
|
+
default: [[unlikely]]
|
|
51
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum ScanMode - invalid value!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::munimbluetooth::ScanMode arg) {
|
|
55
|
+
switch (arg) {
|
|
56
|
+
case margelo::nitro::munimbluetooth::ScanMode::LOWPOWER: return JSIConverter<std::string>::toJSI(runtime, "lowPower");
|
|
57
|
+
case margelo::nitro::munimbluetooth::ScanMode::BALANCED: return JSIConverter<std::string>::toJSI(runtime, "balanced");
|
|
58
|
+
case margelo::nitro::munimbluetooth::ScanMode::LOWLATENCY: return JSIConverter<std::string>::toJSI(runtime, "lowLatency");
|
|
59
|
+
default: [[unlikely]]
|
|
60
|
+
throw std::invalid_argument("Cannot convert ScanMode to JS - invalid value: "
|
|
61
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
65
|
+
if (!value.isString()) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
69
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
70
|
+
case hashString("lowPower"):
|
|
71
|
+
case hashString("balanced"):
|
|
72
|
+
case hashString("lowLatency"):
|
|
73
|
+
return true;
|
|
74
|
+
default:
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ScanOptions.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
// Forward declaration of `ScanMode` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::munimbluetooth { enum class ScanMode; }
|
|
33
|
+
|
|
34
|
+
#include <string>
|
|
35
|
+
#include <vector>
|
|
36
|
+
#include <optional>
|
|
37
|
+
#include "ScanMode.hpp"
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::munimbluetooth {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (ScanOptions).
|
|
43
|
+
*/
|
|
44
|
+
struct ScanOptions final {
|
|
45
|
+
public:
|
|
46
|
+
std::optional<std::vector<std::string>> serviceUUIDs SWIFT_PRIVATE;
|
|
47
|
+
std::optional<bool> allowDuplicates SWIFT_PRIVATE;
|
|
48
|
+
std::optional<ScanMode> scanMode SWIFT_PRIVATE;
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
ScanOptions() = default;
|
|
52
|
+
explicit ScanOptions(std::optional<std::vector<std::string>> serviceUUIDs, std::optional<bool> allowDuplicates, std::optional<ScanMode> scanMode): serviceUUIDs(serviceUUIDs), allowDuplicates(allowDuplicates), scanMode(scanMode) {}
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
friend bool operator==(const ScanOptions& lhs, const ScanOptions& rhs) = default;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
} // namespace margelo::nitro::munimbluetooth
|
|
59
|
+
|
|
60
|
+
namespace margelo::nitro {
|
|
61
|
+
|
|
62
|
+
// C++ ScanOptions <> JS ScanOptions (object)
|
|
63
|
+
template <>
|
|
64
|
+
struct JSIConverter<margelo::nitro::munimbluetooth::ScanOptions> final {
|
|
65
|
+
static inline margelo::nitro::munimbluetooth::ScanOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
66
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
67
|
+
return margelo::nitro::munimbluetooth::ScanOptions(
|
|
68
|
+
JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serviceUUIDs"))),
|
|
69
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "allowDuplicates"))),
|
|
70
|
+
JSIConverter<std::optional<margelo::nitro::munimbluetooth::ScanMode>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "scanMode")))
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::munimbluetooth::ScanOptions& arg) {
|
|
74
|
+
jsi::Object obj(runtime);
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "serviceUUIDs"), JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.serviceUUIDs));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "allowDuplicates"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.allowDuplicates));
|
|
77
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "scanMode"), JSIConverter<std::optional<margelo::nitro::munimbluetooth::ScanMode>>::toJSI(runtime, arg.scanMode));
|
|
78
|
+
return obj;
|
|
79
|
+
}
|
|
80
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
81
|
+
if (!value.isObject()) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
jsi::Object obj = value.getObject(runtime);
|
|
85
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serviceUUIDs")))) return false;
|
|
89
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "allowDuplicates")))) return false;
|
|
90
|
+
if (!JSIConverter<std::optional<margelo::nitro::munimbluetooth::ScanMode>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "scanMode")))) return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ServiceDataEntry.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::munimbluetooth {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (ServiceDataEntry).
|
|
39
|
+
*/
|
|
40
|
+
struct ServiceDataEntry final {
|
|
41
|
+
public:
|
|
42
|
+
std::string uuid SWIFT_PRIVATE;
|
|
43
|
+
std::string data SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
ServiceDataEntry() = default;
|
|
47
|
+
explicit ServiceDataEntry(std::string uuid, std::string data): uuid(uuid), data(data) {}
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
friend bool operator==(const ServiceDataEntry& lhs, const ServiceDataEntry& rhs) = default;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
} // namespace margelo::nitro::munimbluetooth
|
|
54
|
+
|
|
55
|
+
namespace margelo::nitro {
|
|
56
|
+
|
|
57
|
+
// C++ ServiceDataEntry <> JS ServiceDataEntry (object)
|
|
58
|
+
template <>
|
|
59
|
+
struct JSIConverter<margelo::nitro::munimbluetooth::ServiceDataEntry> final {
|
|
60
|
+
static inline margelo::nitro::munimbluetooth::ServiceDataEntry fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
61
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
62
|
+
return margelo::nitro::munimbluetooth::ServiceDataEntry(
|
|
63
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uuid"))),
|
|
64
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::munimbluetooth::ServiceDataEntry& arg) {
|
|
68
|
+
jsi::Object obj(runtime);
|
|
69
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "uuid"), JSIConverter<std::string>::toJSI(runtime, arg.uuid));
|
|
70
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "data"), JSIConverter<std::string>::toJSI(runtime, arg.data));
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
74
|
+
if (!value.isObject()) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
jsi::Object obj = value.getObject(runtime);
|
|
78
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uuid")))) return false;
|
|
82
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// WriteType.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::munimbluetooth {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (WriteType).
|
|
30
|
+
*/
|
|
31
|
+
enum class WriteType {
|
|
32
|
+
WRITE SWIFT_NAME(write) = 0,
|
|
33
|
+
WRITEWITHOUTRESPONSE SWIFT_NAME(writewithoutresponse) = 1,
|
|
34
|
+
} CLOSED_ENUM;
|
|
35
|
+
|
|
36
|
+
} // namespace margelo::nitro::munimbluetooth
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro {
|
|
39
|
+
|
|
40
|
+
// C++ WriteType <> JS WriteType (union)
|
|
41
|
+
template <>
|
|
42
|
+
struct JSIConverter<margelo::nitro::munimbluetooth::WriteType> final {
|
|
43
|
+
static inline margelo::nitro::munimbluetooth::WriteType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
44
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
45
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
46
|
+
case hashString("write"): return margelo::nitro::munimbluetooth::WriteType::WRITE;
|
|
47
|
+
case hashString("writeWithoutResponse"): return margelo::nitro::munimbluetooth::WriteType::WRITEWITHOUTRESPONSE;
|
|
48
|
+
default: [[unlikely]]
|
|
49
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum WriteType - invalid value!");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::munimbluetooth::WriteType arg) {
|
|
53
|
+
switch (arg) {
|
|
54
|
+
case margelo::nitro::munimbluetooth::WriteType::WRITE: return JSIConverter<std::string>::toJSI(runtime, "write");
|
|
55
|
+
case margelo::nitro::munimbluetooth::WriteType::WRITEWITHOUTRESPONSE: return JSIConverter<std::string>::toJSI(runtime, "writeWithoutResponse");
|
|
56
|
+
default: [[unlikely]]
|
|
57
|
+
throw std::invalid_argument("Cannot convert WriteType to JS - invalid value: "
|
|
58
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
62
|
+
if (!value.isString()) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
66
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
67
|
+
case hashString("write"):
|
|
68
|
+
case hashString("writeWithoutResponse"):
|
|
69
|
+
return true;
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "munim-bluetooth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A comprehensive React Native library for all your Bluetooth Low Energy (BLE) needs, supporting both peripheral and central roles with Expo support",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -83,15 +83,15 @@
|
|
|
83
83
|
"@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
|
|
84
84
|
"@semantic-release/changelog": "^6.0.3",
|
|
85
85
|
"@semantic-release/git": "^10.0.1",
|
|
86
|
-
"@types/jest": "^29.5.
|
|
87
|
-
"@types/react": "19.
|
|
88
|
-
"nitrogen": "0.
|
|
89
|
-
"react": "19.
|
|
90
|
-
"react-native": "0.
|
|
91
|
-
"react-native-builder-bob": "^0.
|
|
92
|
-
"react-native-nitro-modules": "0.
|
|
86
|
+
"@types/jest": "^29.5.14",
|
|
87
|
+
"@types/react": "19.2.8",
|
|
88
|
+
"nitrogen": "0.33.1",
|
|
89
|
+
"react": "19.2.3",
|
|
90
|
+
"react-native": "0.83.1",
|
|
91
|
+
"react-native-builder-bob": "^0.40.17",
|
|
92
|
+
"react-native-nitro-modules": "0.33.1",
|
|
93
93
|
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
94
|
-
"semantic-release": "^
|
|
94
|
+
"semantic-release": "^25.0.2",
|
|
95
95
|
"typescript": "^5.8.3"
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type HybridObject } from 'react-native-nitro-modules'
|
|
2
2
|
|
|
3
|
+
// Service Data Entry
|
|
4
|
+
export interface ServiceDataEntry {
|
|
5
|
+
uuid: string
|
|
6
|
+
data: string
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
// BLE Advertising Data Types - Only Platform-Supported Types
|
|
4
10
|
export interface AdvertisingDataTypes {
|
|
5
11
|
// 0x01 - Flags (partial support)
|
|
@@ -25,18 +31,9 @@ export interface AdvertisingDataTypes {
|
|
|
25
31
|
serviceSolicitationUUIDs128?: string[]
|
|
26
32
|
|
|
27
33
|
// 0x16, 0x20, 0x21 - Service Data (fully supported)
|
|
28
|
-
serviceData16?:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}>
|
|
32
|
-
serviceData32?: Array<{
|
|
33
|
-
uuid: string
|
|
34
|
-
data: string
|
|
35
|
-
}>
|
|
36
|
-
serviceData128?: Array<{
|
|
37
|
-
uuid: string
|
|
38
|
-
data: string
|
|
39
|
-
}>
|
|
34
|
+
serviceData16?: ServiceDataEntry[]
|
|
35
|
+
serviceData32?: ServiceDataEntry[]
|
|
36
|
+
serviceData128?: ServiceDataEntry[]
|
|
40
37
|
|
|
41
38
|
// 0x19 - Appearance (partial support)
|
|
42
39
|
appearance?: number
|
|
@@ -58,21 +55,27 @@ export interface BLEDevice {
|
|
|
58
55
|
isConnectable?: boolean
|
|
59
56
|
}
|
|
60
57
|
|
|
58
|
+
// Scan mode type
|
|
59
|
+
export type ScanMode = 'lowPower' | 'balanced' | 'lowLatency'
|
|
60
|
+
|
|
61
61
|
// Scan options
|
|
62
62
|
export interface ScanOptions {
|
|
63
63
|
serviceUUIDs?: string[]
|
|
64
64
|
allowDuplicates?: boolean
|
|
65
|
-
scanMode?:
|
|
65
|
+
scanMode?: ScanMode
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// GATT Characteristic
|
|
69
|
+
export interface GATTCharacteristic {
|
|
70
|
+
uuid: string
|
|
71
|
+
properties: string[]
|
|
72
|
+
value?: string
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
// GATT Service
|
|
69
76
|
export interface GATTService {
|
|
70
77
|
uuid: string
|
|
71
|
-
characteristics:
|
|
72
|
-
uuid: string
|
|
73
|
-
properties: string[]
|
|
74
|
-
value?: string
|
|
75
|
-
}>
|
|
78
|
+
characteristics: GATTCharacteristic[]
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
// Characteristic value
|
|
@@ -82,6 +85,17 @@ export interface CharacteristicValue {
|
|
|
82
85
|
characteristicUUID: string
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
// Write type for characteristic writes
|
|
89
|
+
export type WriteType = 'write' | 'writeWithoutResponse'
|
|
90
|
+
|
|
91
|
+
// Advertising options for startAdvertising
|
|
92
|
+
export interface AdvertisingOptions {
|
|
93
|
+
serviceUUIDs: string[]
|
|
94
|
+
localName?: string
|
|
95
|
+
manufacturerData?: string
|
|
96
|
+
advertisingData?: AdvertisingDataTypes
|
|
97
|
+
}
|
|
98
|
+
|
|
85
99
|
export interface MunimBluetooth
|
|
86
100
|
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
87
101
|
// ========== Peripheral Features ==========
|
|
@@ -92,12 +106,7 @@ export interface MunimBluetooth
|
|
|
92
106
|
* @param options - An object with serviceUUIDs (string[]) and supported advertising data types.
|
|
93
107
|
* This must be a plain JS object (no Maps/Sets/functions).
|
|
94
108
|
*/
|
|
95
|
-
startAdvertising(options:
|
|
96
|
-
serviceUUIDs: string[]
|
|
97
|
-
localName?: string
|
|
98
|
-
manufacturerData?: string
|
|
99
|
-
advertisingData?: AdvertisingDataTypes
|
|
100
|
-
}): void
|
|
109
|
+
startAdvertising(options: AdvertisingOptions): void
|
|
101
110
|
|
|
102
111
|
/**
|
|
103
112
|
* Update advertising data while advertising is active.
|
|
@@ -206,7 +215,7 @@ export interface MunimBluetooth
|
|
|
206
215
|
serviceUUID: string,
|
|
207
216
|
characteristicUUID: string,
|
|
208
217
|
value: string,
|
|
209
|
-
writeType?:
|
|
218
|
+
writeType?: WriteType
|
|
210
219
|
): Promise<void>
|
|
211
220
|
|
|
212
221
|
/**
|
package/lib/module/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|