react-native-ble-nitro 1.14.0 → 1.15.1

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 (42) hide show
  1. package/README.md +20 -1
  2. package/android/build.gradle +6 -0
  3. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +110 -10
  4. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/CccdSubscription.kt +38 -0
  5. package/android/src/test/java/com/margelo/nitro/co/zyke/ble/CccdSubscriptionTest.kt +48 -0
  6. package/ios/BleNitroBleManager.swift +4 -0
  7. package/lib/commonjs/index.d.ts +1 -1
  8. package/lib/commonjs/index.d.ts.map +1 -1
  9. package/lib/commonjs/index.js +2 -1
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/manager.d.ts +16 -1
  12. package/lib/commonjs/manager.d.ts.map +1 -1
  13. package/lib/commonjs/manager.js +27 -1
  14. package/lib/commonjs/manager.js.map +1 -1
  15. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +6 -0
  16. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
  17. package/lib/commonjs/specs/NativeBleNitro.nitro.js +7 -1
  18. package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
  19. package/lib/index.d.ts +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/manager.d.ts +16 -1
  22. package/lib/manager.js +26 -1
  23. package/lib/specs/NativeBleNitro.nitro.d.ts +6 -0
  24. package/lib/specs/NativeBleNitro.nitro.js +6 -0
  25. package/nitrogen/generated/android/c++/JAndroidConnectionPriority.hpp +61 -0
  26. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +9 -0
  27. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +1 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/AndroidConnectionPriority.kt +24 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +4 -0
  30. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +3 -0
  31. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +11 -0
  32. package/nitrogen/generated/ios/swift/AndroidConnectionPriority.swift +44 -0
  33. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +1 -0
  34. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +12 -0
  35. package/nitrogen/generated/shared/c++/AndroidConnectionPriority.hpp +63 -0
  36. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
  37. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +4 -0
  38. package/package.json +4 -1
  39. package/src/__tests__/index.test.ts +32 -2
  40. package/src/index.ts +1 -0
  41. package/src/manager.ts +34 -0
  42. package/src/specs/NativeBleNitro.nitro.ts +8 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AndroidScanMode = exports.BLEState = void 0;
3
+ exports.AndroidConnectionPriority = exports.AndroidScanMode = exports.BLEState = void 0;
4
4
  // Nitro constraint: Use numeric enums instead of string unions
5
5
  var BLEState;
6
6
  (function (BLEState) {
@@ -18,4 +18,10 @@ var AndroidScanMode;
18
18
  AndroidScanMode[AndroidScanMode["LowPower"] = 2] = "LowPower";
19
19
  AndroidScanMode[AndroidScanMode["Opportunistic"] = 3] = "Opportunistic";
20
20
  })(AndroidScanMode || (exports.AndroidScanMode = AndroidScanMode = {}));
21
+ var AndroidConnectionPriority;
22
+ (function (AndroidConnectionPriority) {
23
+ AndroidConnectionPriority[AndroidConnectionPriority["Balanced"] = 0] = "Balanced";
24
+ AndroidConnectionPriority[AndroidConnectionPriority["High"] = 1] = "High";
25
+ AndroidConnectionPriority[AndroidConnectionPriority["LowPower"] = 2] = "LowPower";
26
+ })(AndroidConnectionPriority || (exports.AndroidConnectionPriority = AndroidConnectionPriority = {}));
21
27
  //# sourceMappingURL=NativeBleNitro.nitro.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeBleNitro.nitro.js","sourceRoot":"","sources":["../../../src/specs/NativeBleNitro.nitro.ts"],"names":[],"mappings":";;;AAKA,+DAA+D;AAC/D,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,6CAAW,CAAA;IACX,iDAAa,CAAA;IACb,qDAAe,CAAA;IACf,uDAAgB,CAAA;IAChB,mDAAc,CAAA;IACd,iDAAa,CAAA;AACf,CAAC,EAPW,QAAQ,wBAAR,QAAQ,QAOnB;AA+BD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,iEAAc,CAAA;IACd,6DAAY,CAAA;IACZ,6DAAY,CAAA;IACZ,uEAAiB,CAAA;AACnB,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B"}
1
+ {"version":3,"file":"NativeBleNitro.nitro.js","sourceRoot":"","sources":["../../../src/specs/NativeBleNitro.nitro.ts"],"names":[],"mappings":";;;AAKA,+DAA+D;AAC/D,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,6CAAW,CAAA;IACX,iDAAa,CAAA;IACb,qDAAe,CAAA;IACf,uDAAgB,CAAA;IAChB,mDAAc,CAAA;IACd,iDAAa,CAAA;AACf,CAAC,EAPW,QAAQ,wBAAR,QAAQ,QAOnB;AA+BD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,iEAAc,CAAA;IACd,6DAAY,CAAA;IACZ,6DAAY,CAAA;IACZ,uEAAiB,CAAA;AACnB,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B;AAED,IAAY,yBAIX;AAJD,WAAY,yBAAyB;IACnC,iFAAY,CAAA;IACZ,yEAAQ,CAAA;IACR,iFAAY,CAAA;AACd,CAAC,EAJW,yBAAyB,yCAAzB,yBAAyB,QAIpC"}
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { type ByteArray, type ScanFilter, type BLEDevice, type ScanCallback, type ManufacturerDataEntry, type ManufacturerData, type ServiceDataEntry, type ServiceData, type ConnectionCallback, type DisconnectEventCallback, type OperationCallback, type CharacteristicUpdateCallback, type Subscription, type AsyncSubscription, type BleNitroManagerOptions, BLEState, AndroidScanMode, BleNitroManager, BleTimeoutError, } from "./manager";
1
+ export { type ByteArray, type ScanFilter, type BLEDevice, type ScanCallback, type ManufacturerDataEntry, type ManufacturerData, type ServiceDataEntry, type ServiceData, type ConnectionCallback, type DisconnectEventCallback, type OperationCallback, type CharacteristicUpdateCallback, type Subscription, type AsyncSubscription, type BleNitroManagerOptions, BLEState, AndroidScanMode, AndroidConnectionPriority, BleNitroManager, BleTimeoutError, } from "./manager";
2
2
  export { BleNitro } from './singleton';
package/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { BLEState, AndroidScanMode, BleNitroManager, BleTimeoutError, } from "./manager";
1
+ export { BLEState, AndroidScanMode, AndroidConnectionPriority, BleNitroManager, BleTimeoutError, } from "./manager";
2
2
  export { BleNitro } from './singleton';
package/lib/manager.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BLEDevice as NativeBLEDevice, BLEState as NativeBLEState, AndroidScanMode as NativeAndroidScanMode } from './specs/NativeBleNitro';
1
+ import { BLEDevice as NativeBLEDevice, BLEState as NativeBLEState, AndroidScanMode as NativeAndroidScanMode, AndroidConnectionPriority as NativeAndroidConnectionPriority } from './specs/NativeBleNitro';
2
2
  export declare class BleTimeoutError extends Error {
3
3
  constructor(operation: string, ms: number);
4
4
  }
@@ -59,12 +59,18 @@ export declare enum AndroidScanMode {
59
59
  LowPower = "LowPower",
60
60
  Opportunistic = "Opportunistic"
61
61
  }
62
+ export declare enum AndroidConnectionPriority {
63
+ Balanced = "Balanced",
64
+ High = "High",
65
+ LowPower = "LowPower"
66
+ }
62
67
  export type BleNitroManagerOptions = {
63
68
  restoreIdentifier?: string;
64
69
  onRestoredState?: RestoreStateCallback;
65
70
  };
66
71
  export declare function mapNativeBLEStateToBLEState(nativeState: NativeBLEState): BLEState;
67
72
  export declare function mapAndroidScanModeToNativeAndroidScanMode(scanMode: AndroidScanMode): NativeAndroidScanMode;
73
+ export declare function mapAndroidConnectionPriorityToNativeAndroidConnectionPriority(priority: AndroidConnectionPriority): NativeAndroidConnectionPriority;
68
74
  export declare function convertNativeBleDeviceToBleDevice(nativeBleDevice: NativeBLEDevice): BLEDevice;
69
75
  export declare function arrayBufferToByteArray(buffer: ArrayBuffer): ByteArray;
70
76
  export declare function byteArrayToArrayBuffer(data: ByteArray): ArrayBuffer;
@@ -158,6 +164,15 @@ export declare class BleNitroManager {
158
164
  * @returns On Android: new MTU size; on iOS: current MTU size as it is handled by iOS itself; on error: -1
159
165
  */
160
166
  requestMTU(deviceId: string, mtu: number): number;
167
+ /**
168
+ * Request an Android connection priority for an active connection.
169
+ * @param deviceId ID of the device
170
+ * @param priority Desired Android connection priority
171
+ * @returns On Android: true if the request was successfully initiated (the
172
+ * priority change itself is applied asynchronously); on iOS, an error, or a
173
+ * disconnected device: false
174
+ */
175
+ requestConnectionPriority(deviceId: string, priority: AndroidConnectionPriority): boolean;
161
176
  /**
162
177
  * Read RSSI for a connected device
163
178
  * @param deviceId ID of the device
package/lib/manager.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import BleNitroNativeFactory from './specs/NativeBleNitroFactory';
2
- import { AndroidScanMode as NativeAndroidScanMode, } from './specs/NativeBleNitro';
2
+ import { AndroidScanMode as NativeAndroidScanMode, AndroidConnectionPriority as NativeAndroidConnectionPriority, } from './specs/NativeBleNitro';
3
3
  export class BleTimeoutError extends Error {
4
4
  constructor(operation, ms) {
5
5
  super(`${operation} timed out after ${ms}ms`);
@@ -30,6 +30,12 @@ export var AndroidScanMode;
30
30
  AndroidScanMode["LowPower"] = "LowPower";
31
31
  AndroidScanMode["Opportunistic"] = "Opportunistic";
32
32
  })(AndroidScanMode || (AndroidScanMode = {}));
33
+ export var AndroidConnectionPriority;
34
+ (function (AndroidConnectionPriority) {
35
+ AndroidConnectionPriority["Balanced"] = "Balanced";
36
+ AndroidConnectionPriority["High"] = "High";
37
+ AndroidConnectionPriority["LowPower"] = "LowPower";
38
+ })(AndroidConnectionPriority || (AndroidConnectionPriority = {}));
33
39
  export function mapNativeBLEStateToBLEState(nativeState) {
34
40
  const map = {
35
41
  0: BLEState.Unknown,
@@ -50,6 +56,14 @@ export function mapAndroidScanModeToNativeAndroidScanMode(scanMode) {
50
56
  };
51
57
  return map[scanMode];
52
58
  }
59
+ export function mapAndroidConnectionPriorityToNativeAndroidConnectionPriority(priority) {
60
+ const map = {
61
+ Balanced: NativeAndroidConnectionPriority.Balanced,
62
+ High: NativeAndroidConnectionPriority.High,
63
+ LowPower: NativeAndroidConnectionPriority.LowPower,
64
+ };
65
+ return map[priority];
66
+ }
53
67
  export function convertNativeBleDeviceToBleDevice(nativeBleDevice) {
54
68
  return {
55
69
  ...nativeBleDevice,
@@ -297,6 +311,17 @@ export class BleNitroManager {
297
311
  const deviceMtu = this.Instance.requestMTU(deviceId, mtu);
298
312
  return deviceMtu;
299
313
  }
314
+ /**
315
+ * Request an Android connection priority for an active connection.
316
+ * @param deviceId ID of the device
317
+ * @param priority Desired Android connection priority
318
+ * @returns On Android: true if the request was successfully initiated (the
319
+ * priority change itself is applied asynchronously); on iOS, an error, or a
320
+ * disconnected device: false
321
+ */
322
+ requestConnectionPriority(deviceId, priority) {
323
+ return this.Instance.requestConnectionPriority(deviceId, mapAndroidConnectionPriorityToNativeAndroidConnectionPriority(priority));
324
+ }
300
325
  /**
301
326
  * Read RSSI for a connected device
302
327
  * @param deviceId ID of the device
@@ -38,6 +38,11 @@ export declare enum AndroidScanMode {
38
38
  LowPower = 2,
39
39
  Opportunistic = 3
40
40
  }
41
+ export declare enum AndroidConnectionPriority {
42
+ Balanced = 0,
43
+ High = 1,
44
+ LowPower = 2
45
+ }
41
46
  export interface ScanFilter {
42
47
  serviceUUIDs: string[];
43
48
  rssiThreshold: number;
@@ -80,6 +85,7 @@ export interface NativeBleNitro extends HybridObject<{
80
85
  disconnect(deviceId: string, callback: OperationCallback): void;
81
86
  isConnected(deviceId: string): boolean;
82
87
  requestMTU(deviceId: string, mtu: number): number;
88
+ requestConnectionPriority(deviceId: string, androidConnectionPriority: AndroidConnectionPriority): boolean;
83
89
  readRSSI(deviceId: string, callback: ReadRSSICallback): void;
84
90
  discoverServices(deviceId: string, callback: OperationCallback): void;
85
91
  /** Discover services and wait for all characteristic discovery to complete before resolving. */
@@ -15,3 +15,9 @@ export var AndroidScanMode;
15
15
  AndroidScanMode[AndroidScanMode["LowPower"] = 2] = "LowPower";
16
16
  AndroidScanMode[AndroidScanMode["Opportunistic"] = 3] = "Opportunistic";
17
17
  })(AndroidScanMode || (AndroidScanMode = {}));
18
+ export var AndroidConnectionPriority;
19
+ (function (AndroidConnectionPriority) {
20
+ AndroidConnectionPriority[AndroidConnectionPriority["Balanced"] = 0] = "Balanced";
21
+ AndroidConnectionPriority[AndroidConnectionPriority["High"] = 1] = "High";
22
+ AndroidConnectionPriority[AndroidConnectionPriority["LowPower"] = 2] = "LowPower";
23
+ })(AndroidConnectionPriority || (AndroidConnectionPriority = {}));
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JAndroidConnectionPriority.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 "AndroidConnectionPriority.hpp"
12
+
13
+ namespace margelo::nitro::co::zyke::ble {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "AndroidConnectionPriority" and the the Kotlin enum "AndroidConnectionPriority".
19
+ */
20
+ struct JAndroidConnectionPriority final: public jni::JavaClass<JAndroidConnectionPriority> {
21
+ public:
22
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/AndroidConnectionPriority;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum AndroidConnectionPriority.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ AndroidConnectionPriority toCpp() const {
31
+ static const auto clazz = javaClassStatic();
32
+ static const auto fieldOrdinal = clazz->getField<int>("value");
33
+ int ordinal = this->getFieldValue(fieldOrdinal);
34
+ return static_cast<AndroidConnectionPriority>(ordinal);
35
+ }
36
+
37
+ public:
38
+ /**
39
+ * Create a Java/Kotlin-based enum with the given C++ enum's value.
40
+ */
41
+ [[maybe_unused]]
42
+ static jni::alias_ref<JAndroidConnectionPriority> fromCpp(AndroidConnectionPriority value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case AndroidConnectionPriority::BALANCED:
46
+ static const auto fieldBALANCED = clazz->getStaticField<JAndroidConnectionPriority>("BALANCED");
47
+ return clazz->getStaticFieldValue(fieldBALANCED);
48
+ case AndroidConnectionPriority::HIGH:
49
+ static const auto fieldHIGH = clazz->getStaticField<JAndroidConnectionPriority>("HIGH");
50
+ return clazz->getStaticFieldValue(fieldHIGH);
51
+ case AndroidConnectionPriority::LOWPOWER:
52
+ static const auto fieldLOWPOWER = clazz->getStaticField<JAndroidConnectionPriority>("LOWPOWER");
53
+ return clazz->getStaticFieldValue(fieldLOWPOWER);
54
+ default:
55
+ std::string stringValue = std::to_string(static_cast<int>(value));
56
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
57
+ }
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::co::zyke::ble
@@ -25,6 +25,8 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
25
25
  namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
26
26
  // Forward declaration of `AndroidScanMode` to properly resolve imports.
27
27
  namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
28
+ // Forward declaration of `AndroidConnectionPriority` to properly resolve imports.
29
+ namespace margelo::nitro::co::zyke::ble { enum class AndroidConnectionPriority; }
28
30
 
29
31
  #include <string>
30
32
  #include <optional>
@@ -64,6 +66,8 @@ namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
64
66
  #include "JFunc_void_bool_std__string_std__string.hpp"
65
67
  #include "JFunc_void_std__string_bool_std__string.hpp"
66
68
  #include "JFunc_void_bool_std__string.hpp"
69
+ #include "AndroidConnectionPriority.hpp"
70
+ #include "JAndroidConnectionPriority.hpp"
67
71
  #include "JFunc_void_bool_double_std__string.hpp"
68
72
  #include "JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp"
69
73
  #include "JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp"
@@ -173,6 +177,11 @@ namespace margelo::nitro::co::zyke::ble {
173
177
  auto __result = method(_javaPart, jni::make_jstring(deviceId), mtu);
174
178
  return __result;
175
179
  }
180
+ bool JHybridNativeBleNitroSpec::requestConnectionPriority(const std::string& deviceId, AndroidConnectionPriority androidConnectionPriority) {
181
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JAndroidConnectionPriority> /* androidConnectionPriority */)>("requestConnectionPriority");
182
+ auto __result = method(_javaPart, jni::make_jstring(deviceId), JAndroidConnectionPriority::fromCpp(androidConnectionPriority));
183
+ return static_cast<bool>(__result);
184
+ }
176
185
  void JHybridNativeBleNitroSpec::readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) {
177
186
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* deviceId */, jni::alias_ref<JFunc_void_bool_double_std__string::javaobject> /* callback */)>("readRSSI_cxx");
178
187
  method(_javaPart, jni::make_jstring(deviceId), JFunc_void_bool_double_std__string_cxx::fromCpp(callback));
@@ -65,6 +65,7 @@ namespace margelo::nitro::co::zyke::ble {
65
65
  void disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
66
66
  bool isConnected(const std::string& deviceId) override;
67
67
  double requestMTU(const std::string& deviceId, double mtu) override;
68
+ bool requestConnectionPriority(const std::string& deviceId, AndroidConnectionPriority androidConnectionPriority) override;
68
69
  void readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) override;
69
70
  void discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
70
71
  void discoverServicesWithCharacteristics(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) override;
@@ -0,0 +1,24 @@
1
+ ///
2
+ /// AndroidConnectionPriority.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.co.zyke.ble
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+ /**
14
+ * Represents the JavaScript enum/union "AndroidConnectionPriority".
15
+ */
16
+ @DoNotStrip
17
+ @Keep
18
+ enum class AndroidConnectionPriority(@DoNotStrip @Keep val value: Int) {
19
+ BALANCED(0),
20
+ HIGH(1),
21
+ LOWPOWER(2);
22
+
23
+ companion object
24
+ }
@@ -95,6 +95,10 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
95
95
  @Keep
96
96
  abstract fun requestMTU(deviceId: String, mtu: Double): Double
97
97
 
98
+ @DoNotStrip
99
+ @Keep
100
+ abstract fun requestConnectionPriority(deviceId: String, androidConnectionPriority: AndroidConnectionPriority): Boolean
101
+
98
102
  abstract fun readRSSI(deviceId: String, callback: (success: Boolean, rssi: Double, error: String) -> Unit): Unit
99
103
 
100
104
  @DoNotStrip
@@ -8,6 +8,8 @@
8
8
  #pragma once
9
9
 
10
10
  // Forward declarations of C++ defined types
11
+ // Forward declaration of `AndroidConnectionPriority` to properly resolve imports.
12
+ namespace margelo::nitro::co::zyke::ble { enum class AndroidConnectionPriority; }
11
13
  // Forward declaration of `AndroidScanMode` to properly resolve imports.
12
14
  namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
13
15
  // Forward declaration of `BLEDevice` to properly resolve imports.
@@ -32,6 +34,7 @@ namespace margelo::nitro::co::zyke::ble { struct ServiceDataEntry; }
32
34
  namespace margelo::nitro::co::zyke::ble { struct ServiceData; }
33
35
 
34
36
  // Include C++ defined types
37
+ #include "AndroidConnectionPriority.hpp"
35
38
  #include "AndroidScanMode.hpp"
36
39
  #include "BLEDevice.hpp"
37
40
  #include "BLEState.hpp"
@@ -28,6 +28,8 @@ namespace margelo::nitro::co::zyke::ble { struct ServiceDataEntry; }
28
28
  namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
29
29
  // Forward declaration of `AndroidScanMode` to properly resolve imports.
30
30
  namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
31
+ // Forward declaration of `AndroidConnectionPriority` to properly resolve imports.
32
+ namespace margelo::nitro::co::zyke::ble { enum class AndroidConnectionPriority; }
31
33
  // Forward declaration of `BLEState` to properly resolve imports.
32
34
  namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
33
35
  // Forward declaration of `OperationResult` to properly resolve imports.
@@ -48,6 +50,7 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
48
50
  #include "AndroidScanMode.hpp"
49
51
  #include <NitroModules/Null.hpp>
50
52
  #include <variant>
53
+ #include "AndroidConnectionPriority.hpp"
51
54
  #include "BLEState.hpp"
52
55
  #include "OperationResult.hpp"
53
56
  #include <NitroModules/Promise.hpp>
@@ -178,6 +181,14 @@ namespace margelo::nitro::co::zyke::ble {
178
181
  auto __value = std::move(__result.value());
179
182
  return __value;
180
183
  }
184
+ inline bool requestConnectionPriority(const std::string& deviceId, AndroidConnectionPriority androidConnectionPriority) override {
185
+ auto __result = _swiftPart.requestConnectionPriority(deviceId, static_cast<int>(androidConnectionPriority));
186
+ if (__result.hasError()) [[unlikely]] {
187
+ std::rethrow_exception(__result.error());
188
+ }
189
+ auto __value = std::move(__result.value());
190
+ return __value;
191
+ }
181
192
  inline void readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) override {
182
193
  auto __result = _swiftPart.readRSSI(deviceId, callback);
183
194
  if (__result.hasError()) [[unlikely]] {
@@ -0,0 +1,44 @@
1
+ ///
2
+ /// AndroidConnectionPriority.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
+ /**
9
+ * Represents the JS enum `AndroidConnectionPriority`, backed by a C++ enum.
10
+ */
11
+ public typealias AndroidConnectionPriority = margelo.nitro.co.zyke.ble.AndroidConnectionPriority
12
+
13
+ public extension AndroidConnectionPriority {
14
+ /**
15
+ * Get a AndroidConnectionPriority for the given String value, or
16
+ * return `nil` if the given value was invalid/unknown.
17
+ */
18
+ init?(fromString string: String) {
19
+ switch string {
20
+ case "Balanced":
21
+ self = .balanced
22
+ case "High":
23
+ self = .high
24
+ case "LowPower":
25
+ self = .lowpower
26
+ default:
27
+ return nil
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Get the String value this AndroidConnectionPriority represents.
33
+ */
34
+ var stringValue: String {
35
+ switch self {
36
+ case .balanced:
37
+ return "Balanced"
38
+ case .high:
39
+ return "High"
40
+ case .lowpower:
41
+ return "LowPower"
42
+ }
43
+ }
44
+ }
@@ -23,6 +23,7 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
23
23
  func disconnect(deviceId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
24
24
  func isConnected(deviceId: String) throws -> Bool
25
25
  func requestMTU(deviceId: String, mtu: Double) throws -> Double
26
+ func requestConnectionPriority(deviceId: String, androidConnectionPriority: AndroidConnectionPriority) throws -> Bool
26
27
  func readRSSI(deviceId: String, callback: @escaping (_ success: Bool, _ rssi: Double, _ error: String) -> Void) throws -> Void
27
28
  func discoverServices(deviceId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
28
29
  func discoverServicesWithCharacteristics(deviceId: String, callback: @escaping (_ success: Bool, _ error: String) -> Void) throws -> Void
@@ -338,6 +338,18 @@ open class HybridNativeBleNitroSpec_cxx {
338
338
  }
339
339
  }
340
340
 
341
+ @inline(__always)
342
+ public final func requestConnectionPriority(deviceId: std.string, androidConnectionPriority: Int32) -> bridge.Result_bool_ {
343
+ do {
344
+ let __result = try self.__implementation.requestConnectionPriority(deviceId: String(deviceId), androidConnectionPriority: margelo.nitro.co.zyke.ble.AndroidConnectionPriority(rawValue: androidConnectionPriority)!)
345
+ let __resultCpp = __result
346
+ return bridge.create_Result_bool_(__resultCpp)
347
+ } catch (let __error) {
348
+ let __exceptionPtr = __error.toCpp()
349
+ return bridge.create_Result_bool_(__exceptionPtr)
350
+ }
351
+ }
352
+
341
353
  @inline(__always)
342
354
  public final func readRSSI(deviceId: std.string, callback: bridge.Func_void_bool_double_std__string) -> bridge.Result_void_ {
343
355
  do {
@@ -0,0 +1,63 @@
1
+ ///
2
+ /// AndroidConnectionPriority.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
+
21
+ namespace margelo::nitro::co::zyke::ble {
22
+
23
+ /**
24
+ * An enum which can be represented as a JavaScript enum (AndroidConnectionPriority).
25
+ */
26
+ enum class AndroidConnectionPriority {
27
+ BALANCED SWIFT_NAME(balanced) = 0,
28
+ HIGH SWIFT_NAME(high) = 1,
29
+ LOWPOWER SWIFT_NAME(lowpower) = 2,
30
+ } CLOSED_ENUM;
31
+
32
+ } // namespace margelo::nitro::co::zyke::ble
33
+
34
+ namespace margelo::nitro {
35
+
36
+ // C++ AndroidConnectionPriority <> JS AndroidConnectionPriority (enum)
37
+ template <>
38
+ struct JSIConverter<margelo::nitro::co::zyke::ble::AndroidConnectionPriority> final {
39
+ static inline margelo::nitro::co::zyke::ble::AndroidConnectionPriority fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
40
+ int enumValue = JSIConverter<int>::fromJSI(runtime, arg);
41
+ return static_cast<margelo::nitro::co::zyke::ble::AndroidConnectionPriority>(enumValue);
42
+ }
43
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::co::zyke::ble::AndroidConnectionPriority arg) {
44
+ int enumValue = static_cast<int>(arg);
45
+ return JSIConverter<int>::toJSI(runtime, enumValue);
46
+ }
47
+ static inline bool canConvert(jsi::Runtime&, const jsi::Value& value) {
48
+ if (!value.isNumber()) {
49
+ return false;
50
+ }
51
+ double number = value.getNumber();
52
+ int integer = static_cast<int>(number);
53
+ if (number != integer) {
54
+ // The integer is not the same value as the double - we truncated floating points.
55
+ // Enums are all integers, so the input floating point number is obviously invalid.
56
+ return false;
57
+ }
58
+ // Check if we are within the bounds of the enum.
59
+ return integer >= 0 && integer <= 2;
60
+ }
61
+ };
62
+
63
+ } // namespace margelo::nitro
@@ -26,6 +26,7 @@ namespace margelo::nitro::co::zyke::ble {
26
26
  prototype.registerHybridMethod("disconnect", &HybridNativeBleNitroSpec::disconnect);
27
27
  prototype.registerHybridMethod("isConnected", &HybridNativeBleNitroSpec::isConnected);
28
28
  prototype.registerHybridMethod("requestMTU", &HybridNativeBleNitroSpec::requestMTU);
29
+ prototype.registerHybridMethod("requestConnectionPriority", &HybridNativeBleNitroSpec::requestConnectionPriority);
29
30
  prototype.registerHybridMethod("readRSSI", &HybridNativeBleNitroSpec::readRSSI);
30
31
  prototype.registerHybridMethod("discoverServices", &HybridNativeBleNitroSpec::discoverServices);
31
32
  prototype.registerHybridMethod("discoverServicesWithCharacteristics", &HybridNativeBleNitroSpec::discoverServicesWithCharacteristics);
@@ -17,6 +17,8 @@
17
17
  namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
18
18
  // Forward declaration of `ScanFilter` to properly resolve imports.
19
19
  namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
20
+ // Forward declaration of `AndroidConnectionPriority` to properly resolve imports.
21
+ namespace margelo::nitro::co::zyke::ble { enum class AndroidConnectionPriority; }
20
22
  // Forward declaration of `BLEState` to properly resolve imports.
21
23
  namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
22
24
  // Forward declaration of `OperationResult` to properly resolve imports.
@@ -30,6 +32,7 @@ namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
30
32
  #include "ScanFilter.hpp"
31
33
  #include <NitroModules/Null.hpp>
32
34
  #include <variant>
35
+ #include "AndroidConnectionPriority.hpp"
33
36
  #include <NitroModules/ArrayBuffer.hpp>
34
37
  #include "BLEState.hpp"
35
38
  #include "OperationResult.hpp"
@@ -77,6 +80,7 @@ namespace margelo::nitro::co::zyke::ble {
77
80
  virtual void disconnect(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
78
81
  virtual bool isConnected(const std::string& deviceId) = 0;
79
82
  virtual double requestMTU(const std::string& deviceId, double mtu) = 0;
83
+ virtual bool requestConnectionPriority(const std::string& deviceId, AndroidConnectionPriority androidConnectionPriority) = 0;
80
84
  virtual void readRSSI(const std::string& deviceId, const std::function<void(bool /* success */, double /* rssi */, const std::string& /* error */)>& callback) = 0;
81
85
  virtual void discoverServices(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
82
86
  virtual void discoverServicesWithCharacteristics(const std::string& deviceId, const std::function<void(bool /* success */, const std::string& /* error */)>& callback) = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-nitro",
3
- "version": "1.14.0",
3
+ "version": "1.15.1",
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",
@@ -119,5 +119,8 @@
119
119
  "ios",
120
120
  "android"
121
121
  ]
122
+ },
123
+ "allowScripts": {
124
+ "fsevents@2.3.3": true
122
125
  }
123
126
  }
@@ -8,6 +8,7 @@ const mockNativeInstance = {
8
8
  disconnect: jest.fn(),
9
9
  isConnected: jest.fn(),
10
10
  requestMTU: jest.fn(),
11
+ requestConnectionPriority: jest.fn(),
11
12
  readRSSI: jest.fn(),
12
13
  discoverServices: jest.fn(),
13
14
  discoverServicesWithCharacteristics: jest.fn(),
@@ -44,6 +45,11 @@ jest.mock('../specs/NativeBleNitro', () => ({
44
45
  LowPower: 2,
45
46
  Opportunistic: 3
46
47
  },
48
+ AndroidConnectionPriority: {
49
+ Balanced: 0,
50
+ High: 1,
51
+ LowPower: 2,
52
+ },
47
53
  }));
48
54
 
49
55
  jest.mock('../specs/NativeBleNitroFactory', () => ({
@@ -53,7 +59,7 @@ jest.mock('../specs/NativeBleNitroFactory', () => ({
53
59
  },
54
60
  }));
55
61
 
56
- import { BleNitro } from '../index';
62
+ import { AndroidConnectionPriority, BleNitro } from '../index';
57
63
 
58
64
  // Get reference to the mocked module
59
65
  const mockNative = mockNativeInstance;
@@ -151,6 +157,30 @@ describe('BleNitro', () => {
151
157
  expect(result).toBe(deviceId);
152
158
  });
153
159
 
160
+ test('connect keeps positional autoConnectAndroid compatibility', async () => {
161
+ const deviceId = 'test-device-autoconnect';
162
+ mockNative.connect.mockImplementation((id: string, callback: (success: boolean, deviceId: string, error: string) => void) => {
163
+ callback(true, id, '');
164
+ });
165
+
166
+ const result = await BleManager.connect(deviceId, undefined, true);
167
+
168
+ expect(mockNative.connect).toHaveBeenCalledWith(deviceId, expect.any(Function), undefined, true);
169
+ expect(result).toBe(deviceId);
170
+ });
171
+
172
+ test('requestConnectionPriority delegates to native with mapped priority', () => {
173
+ mockNative.requestConnectionPriority.mockReturnValueOnce(true);
174
+
175
+ const result = BleManager.requestConnectionPriority(
176
+ 'test-device-priority',
177
+ AndroidConnectionPriority.High
178
+ );
179
+
180
+ expect(mockNative.requestConnectionPriority).toHaveBeenCalledWith('test-device-priority', 1);
181
+ expect(result).toBe(true);
182
+ });
183
+
154
184
  test('connect rejects on error', async () => {
155
185
  mockNative.connect.mockImplementation((id: string, callback: (success: boolean, deviceId: string, error: string) => void, _disconnectCallback?: (deviceId: string, interrupted: boolean, error: string) => void) => {
156
186
  callback(false, '', 'Connection failed');
@@ -520,4 +550,4 @@ describe('BleNitro', () => {
520
550
  expect.any(Function)
521
551
  );
522
552
  });
523
- });
553
+ });
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  type BleNitroManagerOptions,
17
17
  BLEState,
18
18
  AndroidScanMode,
19
+ AndroidConnectionPriority,
19
20
  BleNitroManager,
20
21
  BleTimeoutError,
21
22
  } from "./manager";