munim-bluetooth 0.3.24 → 0.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/android/src/main/AndroidManifest.xml +10 -0
  2. package/android/src/main/java/com/munimbluetooth/HybridMunimBluetooth.kt +87 -0
  3. package/android/src/main/java/com/munimbluetooth/MunimBluetoothBackgroundService.kt +344 -0
  4. package/ios/HybridMunimBluetooth.swift +265 -22
  5. package/lib/commonjs/index.js +21 -0
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/module/index.js +19 -0
  8. package/lib/module/index.js.map +1 -1
  9. package/lib/typescript/src/index.d.ts +15 -2
  10. package/lib/typescript/src/index.d.ts.map +1 -1
  11. package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts +25 -3
  12. package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts.map +1 -1
  13. package/nitrogen/generated/android/c++/JBackgroundSessionOptions.hpp +107 -0
  14. package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.cpp +12 -0
  15. package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.hpp +2 -0
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BackgroundSessionOptions.kt +59 -0
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/HybridMunimBluetoothSpec.kt +28 -20
  18. package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Umbrella.hpp +3 -0
  19. package/nitrogen/generated/ios/c++/HybridMunimBluetoothSpecSwift.hpp +15 -0
  20. package/nitrogen/generated/ios/swift/BackgroundSessionOptions.swift +154 -0
  21. package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec.swift +2 -0
  22. package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec_cxx.swift +43 -21
  23. package/nitrogen/generated/shared/c++/BackgroundSessionOptions.hpp +115 -0
  24. package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.cpp +2 -0
  25. package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.hpp +5 -0
  26. package/package.json +1 -1
  27. package/src/index.ts +23 -0
  28. package/src/specs/munim-bluetooth.nitro.ts +28 -3
@@ -58,6 +58,16 @@ export interface AdvertisingOptions {
58
58
  manufacturerData?: string;
59
59
  advertisingData?: AdvertisingDataTypes;
60
60
  }
61
+ export interface BackgroundSessionOptions {
62
+ serviceUUIDs: string[];
63
+ localName?: string;
64
+ allowDuplicates?: boolean;
65
+ scanMode?: ScanMode;
66
+ androidNotificationChannelId?: string;
67
+ androidNotificationChannelName?: string;
68
+ androidNotificationTitle?: string;
69
+ androidNotificationText?: string;
70
+ }
61
71
  export interface MunimBluetooth extends HybridObject<{
62
72
  ios: 'swift';
63
73
  android: 'kotlin';
@@ -179,10 +189,22 @@ export interface MunimBluetooth extends HybridObject<{
179
189
  /**
180
190
  * Read RSSI (signal strength) for a connected device.
181
191
  *
182
- * @param deviceId - The unique identifier of the connected device.
183
- * @returns Promise resolving to RSSI value in dBm.
184
- */
192
+ * @param deviceId - The unique identifier of the connected device.
193
+ * @returns Promise resolving to RSSI value in dBm.
194
+ */
185
195
  readRSSI(deviceId: string): Promise<number>;
196
+ /**
197
+ * Start a best-effort background BLE session.
198
+ *
199
+ * Android uses a foreground service so BLE can continue after the app leaves the foreground.
200
+ * iOS keeps the central/peripheral managers running and relies on the host app's Bluetooth
201
+ * background modes for best-effort background operation.
202
+ */
203
+ startBackgroundSession(options: BackgroundSessionOptions): void;
204
+ /**
205
+ * Stop the active background BLE session.
206
+ */
207
+ stopBackgroundSession(): void;
186
208
  /**
187
209
  * Add an event listener.
188
210
  *
@@ -1 +1 @@
1
- {"version":3,"file":"munim-bluetooth.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/munim-bluetooth.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAG9D,MAAM,WAAW,gBAAgB;IAC/B,IA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AQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,MAAM,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhB;;;;;;OAMG;IACH,yBAAyB,CACvB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,MAAM,GACzB,IAAI,CAAA;IAEP;;;;;;OAMG;IACH,6BAA6B,CAC3B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,MAAM,GACzB,IAAI,CAAA;IAEP;;;;OAIG;IACH,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAExC;;;;;MAKE;IACF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE3C;;;;;;OAMG;IACH,sBAAsB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAAA;IAE/D;;OAEG;IACH,qBAAqB,IAAI,IAAI,CAAA;IAI7B;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IAEpC;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACrC"}
@@ -0,0 +1,107 @@
1
+ ///
2
+ /// JBackgroundSessionOptions.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
+ #include <fbjni/fbjni.h>
11
+ #include "BackgroundSessionOptions.hpp"
12
+
13
+ #include "JScanMode.hpp"
14
+ #include "ScanMode.hpp"
15
+ #include <optional>
16
+ #include <string>
17
+ #include <vector>
18
+
19
+ namespace margelo::nitro::munimbluetooth {
20
+
21
+ using namespace facebook;
22
+
23
+ /**
24
+ * The C++ JNI bridge between the C++ struct "BackgroundSessionOptions" and the the Kotlin data class "BackgroundSessionOptions".
25
+ */
26
+ struct JBackgroundSessionOptions final: public jni::JavaClass<JBackgroundSessionOptions> {
27
+ public:
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/munimbluetooth/BackgroundSessionOptions;";
29
+
30
+ public:
31
+ /**
32
+ * Convert this Java/Kotlin-based struct to the C++ struct BackgroundSessionOptions by copying all values to C++.
33
+ */
34
+ [[maybe_unused]]
35
+ [[nodiscard]]
36
+ BackgroundSessionOptions toCpp() const {
37
+ static const auto clazz = javaClassStatic();
38
+ static const auto fieldServiceUUIDs = clazz->getField<jni::JArrayClass<jni::JString>>("serviceUUIDs");
39
+ jni::local_ref<jni::JArrayClass<jni::JString>> serviceUUIDs = this->getFieldValue(fieldServiceUUIDs);
40
+ static const auto fieldLocalName = clazz->getField<jni::JString>("localName");
41
+ jni::local_ref<jni::JString> localName = this->getFieldValue(fieldLocalName);
42
+ static const auto fieldAllowDuplicates = clazz->getField<jni::JBoolean>("allowDuplicates");
43
+ jni::local_ref<jni::JBoolean> allowDuplicates = this->getFieldValue(fieldAllowDuplicates);
44
+ static const auto fieldScanMode = clazz->getField<JScanMode>("scanMode");
45
+ jni::local_ref<JScanMode> scanMode = this->getFieldValue(fieldScanMode);
46
+ static const auto fieldAndroidNotificationChannelId = clazz->getField<jni::JString>("androidNotificationChannelId");
47
+ jni::local_ref<jni::JString> androidNotificationChannelId = this->getFieldValue(fieldAndroidNotificationChannelId);
48
+ static const auto fieldAndroidNotificationChannelName = clazz->getField<jni::JString>("androidNotificationChannelName");
49
+ jni::local_ref<jni::JString> androidNotificationChannelName = this->getFieldValue(fieldAndroidNotificationChannelName);
50
+ static const auto fieldAndroidNotificationTitle = clazz->getField<jni::JString>("androidNotificationTitle");
51
+ jni::local_ref<jni::JString> androidNotificationTitle = this->getFieldValue(fieldAndroidNotificationTitle);
52
+ static const auto fieldAndroidNotificationText = clazz->getField<jni::JString>("androidNotificationText");
53
+ jni::local_ref<jni::JString> androidNotificationText = this->getFieldValue(fieldAndroidNotificationText);
54
+ return BackgroundSessionOptions(
55
+ [&]() {
56
+ size_t __size = serviceUUIDs->size();
57
+ std::vector<std::string> __vector;
58
+ __vector.reserve(__size);
59
+ for (size_t __i = 0; __i < __size; __i++) {
60
+ auto __element = serviceUUIDs->getElement(__i);
61
+ __vector.push_back(__element->toStdString());
62
+ }
63
+ return __vector;
64
+ }(),
65
+ localName != nullptr ? std::make_optional(localName->toStdString()) : std::nullopt,
66
+ allowDuplicates != nullptr ? std::make_optional(static_cast<bool>(allowDuplicates->value())) : std::nullopt,
67
+ scanMode != nullptr ? std::make_optional(scanMode->toCpp()) : std::nullopt,
68
+ androidNotificationChannelId != nullptr ? std::make_optional(androidNotificationChannelId->toStdString()) : std::nullopt,
69
+ androidNotificationChannelName != nullptr ? std::make_optional(androidNotificationChannelName->toStdString()) : std::nullopt,
70
+ androidNotificationTitle != nullptr ? std::make_optional(androidNotificationTitle->toStdString()) : std::nullopt,
71
+ androidNotificationText != nullptr ? std::make_optional(androidNotificationText->toStdString()) : std::nullopt
72
+ );
73
+ }
74
+
75
+ public:
76
+ /**
77
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
78
+ */
79
+ [[maybe_unused]]
80
+ static jni::local_ref<JBackgroundSessionOptions::javaobject> fromCpp(const BackgroundSessionOptions& value) {
81
+ using JSignature = JBackgroundSessionOptions(jni::alias_ref<jni::JArrayClass<jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JScanMode>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
82
+ static const auto clazz = javaClassStatic();
83
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
84
+ return create(
85
+ clazz,
86
+ [&]() {
87
+ size_t __size = value.serviceUUIDs.size();
88
+ jni::local_ref<jni::JArrayClass<jni::JString>> __array = jni::JArrayClass<jni::JString>::newArray(__size);
89
+ for (size_t __i = 0; __i < __size; __i++) {
90
+ const auto& __element = value.serviceUUIDs[__i];
91
+ auto __elementJni = jni::make_jstring(__element);
92
+ __array->setElement(__i, *__elementJni);
93
+ }
94
+ return __array;
95
+ }(),
96
+ value.localName.has_value() ? jni::make_jstring(value.localName.value()) : nullptr,
97
+ value.allowDuplicates.has_value() ? jni::JBoolean::valueOf(value.allowDuplicates.value()) : nullptr,
98
+ value.scanMode.has_value() ? JScanMode::fromCpp(value.scanMode.value()) : nullptr,
99
+ value.androidNotificationChannelId.has_value() ? jni::make_jstring(value.androidNotificationChannelId.value()) : nullptr,
100
+ value.androidNotificationChannelName.has_value() ? jni::make_jstring(value.androidNotificationChannelName.value()) : nullptr,
101
+ value.androidNotificationTitle.has_value() ? jni::make_jstring(value.androidNotificationTitle.value()) : nullptr,
102
+ value.androidNotificationText.has_value() ? jni::make_jstring(value.androidNotificationText.value()) : nullptr
103
+ );
104
+ }
105
+ };
106
+
107
+ } // namespace margelo::nitro::munimbluetooth
@@ -25,6 +25,8 @@ namespace margelo::nitro::munimbluetooth { struct ScanOptions; }
25
25
  namespace margelo::nitro::munimbluetooth { enum class ScanMode; }
26
26
  // Forward declaration of `WriteType` to properly resolve imports.
27
27
  namespace margelo::nitro::munimbluetooth { enum class WriteType; }
28
+ // Forward declaration of `BackgroundSessionOptions` to properly resolve imports.
29
+ namespace margelo::nitro::munimbluetooth { struct BackgroundSessionOptions; }
28
30
 
29
31
  #include "AdvertisingDataTypes.hpp"
30
32
  #include <NitroModules/Promise.hpp>
@@ -50,6 +52,8 @@ namespace margelo::nitro::munimbluetooth { enum class WriteType; }
50
52
  #include "JScanMode.hpp"
51
53
  #include "WriteType.hpp"
52
54
  #include "JWriteType.hpp"
55
+ #include "BackgroundSessionOptions.hpp"
56
+ #include "JBackgroundSessionOptions.hpp"
53
57
 
54
58
  namespace margelo::nitro::munimbluetooth {
55
59
 
@@ -289,6 +293,14 @@ namespace margelo::nitro::munimbluetooth {
289
293
  return __promise;
290
294
  }();
291
295
  }
296
+ void JHybridMunimBluetoothSpec::startBackgroundSession(const BackgroundSessionOptions& options) {
297
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JBackgroundSessionOptions> /* options */)>("startBackgroundSession");
298
+ method(_javaPart, JBackgroundSessionOptions::fromCpp(options));
299
+ }
300
+ void JHybridMunimBluetoothSpec::stopBackgroundSession() {
301
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("stopBackgroundSession");
302
+ method(_javaPart);
303
+ }
292
304
  void JHybridMunimBluetoothSpec::addListener(const std::string& eventName) {
293
305
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* eventName */)>("addListener");
294
306
  method(_javaPart, jni::make_jstring(eventName));
@@ -72,6 +72,8 @@ namespace margelo::nitro::munimbluetooth {
72
72
  void unsubscribeFromCharacteristic(const std::string& deviceId, const std::string& serviceUUID, const std::string& characteristicUUID) override;
73
73
  std::shared_ptr<Promise<std::vector<std::string>>> getConnectedDevices() override;
74
74
  std::shared_ptr<Promise<double>> readRSSI(const std::string& deviceId) override;
75
+ void startBackgroundSession(const BackgroundSessionOptions& options) override;
76
+ void stopBackgroundSession() override;
75
77
  void addListener(const std::string& eventName) override;
76
78
  void removeListeners(double count) override;
77
79
 
@@ -0,0 +1,59 @@
1
+ ///
2
+ /// BackgroundSessionOptions.kt
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
+ package com.margelo.nitro.munimbluetooth
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+
14
+ /**
15
+ * Represents the JavaScript object/struct "BackgroundSessionOptions".
16
+ */
17
+ @DoNotStrip
18
+ @Keep
19
+ data class BackgroundSessionOptions(
20
+ @DoNotStrip
21
+ @Keep
22
+ val serviceUUIDs: Array<String>,
23
+ @DoNotStrip
24
+ @Keep
25
+ val localName: String?,
26
+ @DoNotStrip
27
+ @Keep
28
+ val allowDuplicates: Boolean?,
29
+ @DoNotStrip
30
+ @Keep
31
+ val scanMode: ScanMode?,
32
+ @DoNotStrip
33
+ @Keep
34
+ val androidNotificationChannelId: String?,
35
+ @DoNotStrip
36
+ @Keep
37
+ val androidNotificationChannelName: String?,
38
+ @DoNotStrip
39
+ @Keep
40
+ val androidNotificationTitle: String?,
41
+ @DoNotStrip
42
+ @Keep
43
+ val androidNotificationText: String?
44
+ ) {
45
+ /* primary constructor */
46
+
47
+ companion object {
48
+ /**
49
+ * Constructor called from C++
50
+ */
51
+ @DoNotStrip
52
+ @Keep
53
+ @Suppress("unused")
54
+ @JvmStatic
55
+ private fun fromCpp(serviceUUIDs: Array<String>, localName: String?, allowDuplicates: Boolean?, scanMode: ScanMode?, androidNotificationChannelId: String?, androidNotificationChannelName: String?, androidNotificationTitle: String?, androidNotificationText: String?): BackgroundSessionOptions {
56
+ return BackgroundSessionOptions(serviceUUIDs, localName, allowDuplicates, scanMode, androidNotificationChannelId, androidNotificationChannelName, androidNotificationTitle, androidNotificationText)
57
+ }
58
+ }
59
+ }
@@ -26,85 +26,93 @@ import com.margelo.nitro.core.HybridObject
26
26
  )
27
27
  abstract class HybridMunimBluetoothSpec: HybridObject() {
28
28
  // Properties
29
-
29
+
30
30
 
31
31
  // Methods
32
32
  @DoNotStrip
33
33
  @Keep
34
34
  abstract fun startAdvertising(options: AdvertisingOptions): Unit
35
-
35
+
36
36
  @DoNotStrip
37
37
  @Keep
38
38
  abstract fun updateAdvertisingData(advertisingData: AdvertisingDataTypes): Unit
39
-
39
+
40
40
  @DoNotStrip
41
41
  @Keep
42
42
  abstract fun getAdvertisingData(): Promise<AdvertisingDataTypes>
43
-
43
+
44
44
  @DoNotStrip
45
45
  @Keep
46
46
  abstract fun stopAdvertising(): Unit
47
-
47
+
48
48
  @DoNotStrip
49
49
  @Keep
50
50
  abstract fun setServices(services: Array<GATTService>): Unit
51
-
51
+
52
52
  @DoNotStrip
53
53
  @Keep
54
54
  abstract fun isBluetoothEnabled(): Promise<Boolean>
55
-
55
+
56
56
  @DoNotStrip
57
57
  @Keep
58
58
  abstract fun requestBluetoothPermission(): Promise<Boolean>
59
-
59
+
60
60
  @DoNotStrip
61
61
  @Keep
62
62
  abstract fun startScan(options: ScanOptions?): Unit
63
-
63
+
64
64
  @DoNotStrip
65
65
  @Keep
66
66
  abstract fun stopScan(): Unit
67
-
67
+
68
68
  @DoNotStrip
69
69
  @Keep
70
70
  abstract fun connect(deviceId: String): Promise<Unit>
71
-
71
+
72
72
  @DoNotStrip
73
73
  @Keep
74
74
  abstract fun disconnect(deviceId: String): Unit
75
-
75
+
76
76
  @DoNotStrip
77
77
  @Keep
78
78
  abstract fun discoverServices(deviceId: String): Promise<Array<GATTService>>
79
-
79
+
80
80
  @DoNotStrip
81
81
  @Keep
82
82
  abstract fun readCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String): Promise<CharacteristicValue>
83
-
83
+
84
84
  @DoNotStrip
85
85
  @Keep
86
86
  abstract fun writeCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String, value: String, writeType: WriteType?): Promise<Unit>
87
-
87
+
88
88
  @DoNotStrip
89
89
  @Keep
90
90
  abstract fun subscribeToCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String): Unit
91
-
91
+
92
92
  @DoNotStrip
93
93
  @Keep
94
94
  abstract fun unsubscribeFromCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String): Unit
95
-
95
+
96
96
  @DoNotStrip
97
97
  @Keep
98
98
  abstract fun getConnectedDevices(): Promise<Array<String>>
99
-
99
+
100
100
  @DoNotStrip
101
101
  @Keep
102
102
  abstract fun readRSSI(deviceId: String): Promise<Double>
103
-
103
+
104
+ @DoNotStrip
105
+ @Keep
106
+ abstract fun startBackgroundSession(options: BackgroundSessionOptions): Unit
107
+
108
+ @DoNotStrip
109
+ @Keep
110
+ abstract fun stopBackgroundSession(): Unit
111
+
104
112
  @DoNotStrip
105
113
  @Keep
106
114
  abstract fun addListener(eventName: String): Unit
107
-
115
+
108
116
  @DoNotStrip
109
117
  @Keep
110
118
  abstract fun removeListeners(count: Double): Unit
@@ -12,6 +12,8 @@
12
12
  namespace margelo::nitro::munimbluetooth { struct AdvertisingDataTypes; }
13
13
  // Forward declaration of `AdvertisingOptions` to properly resolve imports.
14
14
  namespace margelo::nitro::munimbluetooth { struct AdvertisingOptions; }
15
+ // Forward declaration of `BackgroundSessionOptions` to properly resolve imports.
16
+ namespace margelo::nitro::munimbluetooth { struct BackgroundSessionOptions; }
15
17
  // Forward declaration of `CharacteristicValue` to properly resolve imports.
16
18
  namespace margelo::nitro::munimbluetooth { struct CharacteristicValue; }
17
19
  // Forward declaration of `GATTCharacteristic` to properly resolve imports.
@@ -32,6 +34,7 @@ namespace margelo::nitro::munimbluetooth { enum class WriteType; }
32
34
  // Include C++ defined types
33
35
  #include "AdvertisingDataTypes.hpp"
34
36
  #include "AdvertisingOptions.hpp"
37
+ #include "BackgroundSessionOptions.hpp"
35
38
  #include "CharacteristicValue.hpp"
36
39
  #include "GATTCharacteristic.hpp"
37
40
  #include "GATTService.hpp"
@@ -30,6 +30,8 @@ namespace margelo::nitro::munimbluetooth { enum class ScanMode; }
30
30
  namespace margelo::nitro::munimbluetooth { struct CharacteristicValue; }
31
31
  // Forward declaration of `WriteType` to properly resolve imports.
32
32
  namespace margelo::nitro::munimbluetooth { enum class WriteType; }
33
+ // Forward declaration of `BackgroundSessionOptions` to properly resolve imports.
34
+ namespace margelo::nitro::munimbluetooth { struct BackgroundSessionOptions; }
33
35
 
34
36
  #include "AdvertisingOptions.hpp"
35
37
  #include <string>
@@ -44,6 +46,7 @@ namespace margelo::nitro::munimbluetooth { enum class WriteType; }
44
46
  #include "ScanMode.hpp"
45
47
  #include "CharacteristicValue.hpp"
46
48
  #include "WriteType.hpp"
49
+ #include "BackgroundSessionOptions.hpp"
47
50
 
48
51
  #include "MunimBluetooth-Swift-Cxx-Umbrella.hpp"
49
52
 
@@ -221,6 +224,18 @@ namespace margelo::nitro::munimbluetooth {
221
224
  auto __value = std::move(__result.value());
222
225
  return __value;
223
226
  }
227
+ inline void startBackgroundSession(const BackgroundSessionOptions& options) override {
228
+ auto __result = _swiftPart.startBackgroundSession(std::forward<decltype(options)>(options));
229
+ if (__result.hasError()) [[unlikely]] {
230
+ std::rethrow_exception(__result.error());
231
+ }
232
+ }
233
+ inline void stopBackgroundSession() override {
234
+ auto __result = _swiftPart.stopBackgroundSession();
235
+ if (__result.hasError()) [[unlikely]] {
236
+ std::rethrow_exception(__result.error());
237
+ }
238
+ }
224
239
  inline void addListener(const std::string& eventName) override {
225
240
  auto __result = _swiftPart.addListener(eventName);
226
241
  if (__result.hasError()) [[unlikely]] {
@@ -0,0 +1,154 @@
1
+ ///
2
+ /// BackgroundSessionOptions.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `BackgroundSessionOptions`, backed by a C++ struct.
12
+ */
13
+ public typealias BackgroundSessionOptions = margelo.nitro.munimbluetooth.BackgroundSessionOptions
14
+
15
+ public extension BackgroundSessionOptions {
16
+ private typealias bridge = margelo.nitro.munimbluetooth.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `BackgroundSessionOptions`.
20
+ */
21
+ init(serviceUUIDs: [String], localName: String?, allowDuplicates: Bool?, scanMode: ScanMode?, androidNotificationChannelId: String?, androidNotificationChannelName: String?, androidNotificationTitle: String?, androidNotificationText: String?) {
22
+ self.init({ () -> bridge.std__vector_std__string_ in
23
+ var __vector = bridge.create_std__vector_std__string_(serviceUUIDs.count)
24
+ for __item in serviceUUIDs {
25
+ __vector.push_back(std.string(__item))
26
+ }
27
+ return __vector
28
+ }(), { () -> bridge.std__optional_std__string_ in
29
+ if let __unwrappedValue = localName {
30
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
31
+ } else {
32
+ return .init()
33
+ }
34
+ }(), { () -> bridge.std__optional_bool_ in
35
+ if let __unwrappedValue = allowDuplicates {
36
+ return bridge.create_std__optional_bool_(__unwrappedValue)
37
+ } else {
38
+ return .init()
39
+ }
40
+ }(), { () -> bridge.std__optional_ScanMode_ in
41
+ if let __unwrappedValue = scanMode {
42
+ return bridge.create_std__optional_ScanMode_(__unwrappedValue)
43
+ } else {
44
+ return .init()
45
+ }
46
+ }(), { () -> bridge.std__optional_std__string_ in
47
+ if let __unwrappedValue = androidNotificationChannelId {
48
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
49
+ } else {
50
+ return .init()
51
+ }
52
+ }(), { () -> bridge.std__optional_std__string_ in
53
+ if let __unwrappedValue = androidNotificationChannelName {
54
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
55
+ } else {
56
+ return .init()
57
+ }
58
+ }(), { () -> bridge.std__optional_std__string_ in
59
+ if let __unwrappedValue = androidNotificationTitle {
60
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
61
+ } else {
62
+ return .init()
63
+ }
64
+ }(), { () -> bridge.std__optional_std__string_ in
65
+ if let __unwrappedValue = androidNotificationText {
66
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
67
+ } else {
68
+ return .init()
69
+ }
70
+ }())
71
+ }
72
+
73
+ @inline(__always)
74
+ var serviceUUIDs: [String] {
75
+ return self.__serviceUUIDs.map({ __item in String(__item) })
76
+ }
77
+
78
+ @inline(__always)
79
+ var localName: String? {
80
+ return { () -> String? in
81
+ if bridge.has_value_std__optional_std__string_(self.__localName) {
82
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__localName)
83
+ return String(__unwrapped)
84
+ } else {
85
+ return nil
86
+ }
87
+ }()
88
+ }
89
+
90
+ @inline(__always)
91
+ var allowDuplicates: Bool? {
92
+ return { () -> Bool? in
93
+ if bridge.has_value_std__optional_bool_(self.__allowDuplicates) {
94
+ let __unwrapped = bridge.get_std__optional_bool_(self.__allowDuplicates)
95
+ return __unwrapped
96
+ } else {
97
+ return nil
98
+ }
99
+ }()
100
+ }
101
+
102
+ @inline(__always)
103
+ var scanMode: ScanMode? {
104
+ return self.__scanMode.value
105
+ }
106
+
107
+ @inline(__always)
108
+ var androidNotificationChannelId: String? {
109
+ return { () -> String? in
110
+ if bridge.has_value_std__optional_std__string_(self.__androidNotificationChannelId) {
111
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__androidNotificationChannelId)
112
+ return String(__unwrapped)
113
+ } else {
114
+ return nil
115
+ }
116
+ }()
117
+ }
118
+
119
+ @inline(__always)
120
+ var androidNotificationChannelName: String? {
121
+ return { () -> String? in
122
+ if bridge.has_value_std__optional_std__string_(self.__androidNotificationChannelName) {
123
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__androidNotificationChannelName)
124
+ return String(__unwrapped)
125
+ } else {
126
+ return nil
127
+ }
128
+ }()
129
+ }
130
+
131
+ @inline(__always)
132
+ var androidNotificationTitle: String? {
133
+ return { () -> String? in
134
+ if bridge.has_value_std__optional_std__string_(self.__androidNotificationTitle) {
135
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__androidNotificationTitle)
136
+ return String(__unwrapped)
137
+ } else {
138
+ return nil
139
+ }
140
+ }()
141
+ }
142
+
143
+ @inline(__always)
144
+ var androidNotificationText: String? {
145
+ return { () -> String? in
146
+ if bridge.has_value_std__optional_std__string_(self.__androidNotificationText) {
147
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__androidNotificationText)
148
+ return String(__unwrapped)
149
+ } else {
150
+ return nil
151
+ }
152
+ }()
153
+ }
154
+ }
@@ -31,6 +31,8 @@ public protocol HybridMunimBluetoothSpec_protocol: HybridObject {
31
31
  func unsubscribeFromCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws -> Void
32
32
  func getConnectedDevices() throws -> Promise<[String]>
33
33
  func readRSSI(deviceId: String) throws -> Promise<Double>
34
+ func startBackgroundSession(options: BackgroundSessionOptions) throws -> Void
35
+ func stopBackgroundSession() throws -> Void
34
36
  func addListener(eventName: String) throws -> Void
35
37
  func removeListeners(count: Double) throws -> Void
36
38
  }