react-native-ble-nitro 1.13.0 → 1.15.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.
Files changed (60) hide show
  1. package/README.md +53 -1
  2. package/android/build.gradle +6 -0
  3. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +128 -11
  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 +28 -3
  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 +24 -1
  12. package/lib/commonjs/manager.d.ts.map +1 -1
  13. package/lib/commonjs/manager.js +33 -1
  14. package/lib/commonjs/manager.js.map +1 -1
  15. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +14 -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 +24 -1
  22. package/lib/manager.js +32 -1
  23. package/lib/specs/NativeBleNitro.nitro.d.ts +14 -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++/JBLEDevice.hpp +9 -1
  27. package/nitrogen/generated/android/c++/JFunc_void_std__optional_std__variant_nitro__NullType__BLEDevice___std__optional_std__variant_nitro__NullType__std__string__.hpp +4 -0
  28. package/nitrogen/generated/android/c++/JFunc_void_std__vector_BLEDevice_.hpp +4 -0
  29. package/nitrogen/generated/android/c++/JHybridNativeBleNitroFactorySpec.cpp +8 -0
  30. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +17 -0
  31. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +1 -0
  32. package/nitrogen/generated/android/c++/JServiceData.hpp +80 -0
  33. package/nitrogen/generated/android/c++/JServiceDataEntry.hpp +63 -0
  34. package/nitrogen/generated/android/c++/JVariant_NullType_BLEDevice.hpp +4 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/AndroidConnectionPriority.kt +24 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/BLEDevice.kt +5 -2
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +4 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ServiceData.kt +38 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ServiceDataEntry.kt +41 -0
  40. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +17 -0
  41. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +9 -0
  42. package/nitrogen/generated/ios/c++/HybridNativeBleNitroFactorySpecSwift.hpp +6 -0
  43. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +17 -0
  44. package/nitrogen/generated/ios/swift/AndroidConnectionPriority.swift +44 -0
  45. package/nitrogen/generated/ios/swift/BLEDevice.swift +7 -2
  46. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +1 -0
  47. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +12 -0
  48. package/nitrogen/generated/ios/swift/ServiceData.swift +35 -0
  49. package/nitrogen/generated/ios/swift/ServiceDataEntry.swift +34 -0
  50. package/nitrogen/generated/shared/c++/AndroidConnectionPriority.hpp +63 -0
  51. package/nitrogen/generated/shared/c++/BLEDevice.hpp +8 -1
  52. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
  53. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +4 -0
  54. package/nitrogen/generated/shared/c++/ServiceData.hpp +85 -0
  55. package/nitrogen/generated/shared/c++/ServiceDataEntry.hpp +88 -0
  56. package/package.json +1 -1
  57. package/src/__tests__/index.test.ts +69 -2
  58. package/src/index.ts +3 -0
  59. package/src/manager.ts +50 -0
  60. package/src/specs/NativeBleNitro.nitro.ts +18 -1
@@ -30,9 +30,12 @@
30
30
 
31
31
  // Forward declaration of `ManufacturerData` to properly resolve imports.
32
32
  namespace margelo::nitro::co::zyke::ble { struct ManufacturerData; }
33
+ // Forward declaration of `ServiceData` to properly resolve imports.
34
+ namespace margelo::nitro::co::zyke::ble { struct ServiceData; }
33
35
 
34
36
  #include <string>
35
37
  #include "ManufacturerData.hpp"
38
+ #include "ServiceData.hpp"
36
39
  #include <vector>
37
40
 
38
41
  namespace margelo::nitro::co::zyke::ble {
@@ -46,13 +49,14 @@ namespace margelo::nitro::co::zyke::ble {
46
49
  std::string name SWIFT_PRIVATE;
47
50
  double rssi SWIFT_PRIVATE;
48
51
  ManufacturerData manufacturerData SWIFT_PRIVATE;
52
+ ServiceData serviceData SWIFT_PRIVATE;
49
53
  std::vector<std::string> serviceUUIDs SWIFT_PRIVATE;
50
54
  bool isConnectable SWIFT_PRIVATE;
51
55
  bool isConnected SWIFT_PRIVATE;
52
56
 
53
57
  public:
54
58
  BLEDevice() = default;
55
- explicit BLEDevice(std::string id, std::string name, double rssi, ManufacturerData manufacturerData, std::vector<std::string> serviceUUIDs, bool isConnectable, bool isConnected): id(id), name(name), rssi(rssi), manufacturerData(manufacturerData), serviceUUIDs(serviceUUIDs), isConnectable(isConnectable), isConnected(isConnected) {}
59
+ explicit BLEDevice(std::string id, std::string name, double rssi, ManufacturerData manufacturerData, ServiceData serviceData, std::vector<std::string> serviceUUIDs, bool isConnectable, bool isConnected): id(id), name(name), rssi(rssi), manufacturerData(manufacturerData), serviceData(serviceData), serviceUUIDs(serviceUUIDs), isConnectable(isConnectable), isConnected(isConnected) {}
56
60
 
57
61
  public:
58
62
  friend bool operator==(const BLEDevice& lhs, const BLEDevice& rhs) = default;
@@ -72,6 +76,7 @@ namespace margelo::nitro {
72
76
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name"))),
73
77
  JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "rssi"))),
74
78
  JSIConverter<margelo::nitro::co::zyke::ble::ManufacturerData>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "manufacturerData"))),
79
+ JSIConverter<margelo::nitro::co::zyke::ble::ServiceData>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serviceData"))),
75
80
  JSIConverter<std::vector<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serviceUUIDs"))),
76
81
  JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isConnectable"))),
77
82
  JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isConnected")))
@@ -83,6 +88,7 @@ namespace margelo::nitro {
83
88
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "name"), JSIConverter<std::string>::toJSI(runtime, arg.name));
84
89
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "rssi"), JSIConverter<double>::toJSI(runtime, arg.rssi));
85
90
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "manufacturerData"), JSIConverter<margelo::nitro::co::zyke::ble::ManufacturerData>::toJSI(runtime, arg.manufacturerData));
91
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "serviceData"), JSIConverter<margelo::nitro::co::zyke::ble::ServiceData>::toJSI(runtime, arg.serviceData));
86
92
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "serviceUUIDs"), JSIConverter<std::vector<std::string>>::toJSI(runtime, arg.serviceUUIDs));
87
93
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "isConnectable"), JSIConverter<bool>::toJSI(runtime, arg.isConnectable));
88
94
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "isConnected"), JSIConverter<bool>::toJSI(runtime, arg.isConnected));
@@ -100,6 +106,7 @@ namespace margelo::nitro {
100
106
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name")))) return false;
101
107
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "rssi")))) return false;
102
108
  if (!JSIConverter<margelo::nitro::co::zyke::ble::ManufacturerData>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "manufacturerData")))) return false;
109
+ if (!JSIConverter<margelo::nitro::co::zyke::ble::ServiceData>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serviceData")))) return false;
103
110
  if (!JSIConverter<std::vector<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "serviceUUIDs")))) return false;
104
111
  if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isConnectable")))) return false;
105
112
  if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isConnected")))) return false;
@@ -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;
@@ -0,0 +1,85 @@
1
+ ///
2
+ /// ServiceData.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 `ServiceDataEntry` to properly resolve imports.
32
+ namespace margelo::nitro::co::zyke::ble { struct ServiceDataEntry; }
33
+
34
+ #include "ServiceDataEntry.hpp"
35
+ #include <vector>
36
+
37
+ namespace margelo::nitro::co::zyke::ble {
38
+
39
+ /**
40
+ * A struct which can be represented as a JavaScript object (ServiceData).
41
+ */
42
+ struct ServiceData final {
43
+ public:
44
+ std::vector<ServiceDataEntry> services SWIFT_PRIVATE;
45
+
46
+ public:
47
+ ServiceData() = default;
48
+ explicit ServiceData(std::vector<ServiceDataEntry> services): services(services) {}
49
+
50
+ public:
51
+ friend bool operator==(const ServiceData& lhs, const ServiceData& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::co::zyke::ble
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ ServiceData <> JS ServiceData (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::co::zyke::ble::ServiceData> final {
61
+ static inline margelo::nitro::co::zyke::ble::ServiceData fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::co::zyke::ble::ServiceData(
64
+ JSIConverter<std::vector<margelo::nitro::co::zyke::ble::ServiceDataEntry>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "services")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::co::zyke::ble::ServiceData& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "services"), JSIConverter<std::vector<margelo::nitro::co::zyke::ble::ServiceDataEntry>>::toJSI(runtime, arg.services));
70
+ return obj;
71
+ }
72
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
73
+ if (!value.isObject()) {
74
+ return false;
75
+ }
76
+ jsi::Object obj = value.getObject(runtime);
77
+ if (!nitro::isPlainObject(runtime, obj)) {
78
+ return false;
79
+ }
80
+ if (!JSIConverter<std::vector<margelo::nitro::co::zyke::ble::ServiceDataEntry>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "services")))) return false;
81
+ return true;
82
+ }
83
+ };
84
+
85
+ } // namespace margelo::nitro
@@ -0,0 +1,88 @@
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
+ #include <NitroModules/ArrayBuffer.hpp>
35
+
36
+ namespace margelo::nitro::co::zyke::ble {
37
+
38
+ /**
39
+ * A struct which can be represented as a JavaScript object (ServiceDataEntry).
40
+ */
41
+ struct ServiceDataEntry final {
42
+ public:
43
+ std::string uuid SWIFT_PRIVATE;
44
+ std::shared_ptr<ArrayBuffer> data SWIFT_PRIVATE;
45
+
46
+ public:
47
+ ServiceDataEntry() = default;
48
+ explicit ServiceDataEntry(std::string uuid, std::shared_ptr<ArrayBuffer> data): uuid(uuid), data(data) {}
49
+
50
+ public:
51
+ friend bool operator==(const ServiceDataEntry& lhs, const ServiceDataEntry& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::co::zyke::ble
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ ServiceDataEntry <> JS ServiceDataEntry (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::co::zyke::ble::ServiceDataEntry> final {
61
+ static inline margelo::nitro::co::zyke::ble::ServiceDataEntry fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::co::zyke::ble::ServiceDataEntry(
64
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uuid"))),
65
+ JSIConverter<std::shared_ptr<ArrayBuffer>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))
66
+ );
67
+ }
68
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::co::zyke::ble::ServiceDataEntry& arg) {
69
+ jsi::Object obj(runtime);
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "uuid"), JSIConverter<std::string>::toJSI(runtime, arg.uuid));
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "data"), JSIConverter<std::shared_ptr<ArrayBuffer>>::toJSI(runtime, arg.data));
72
+ return obj;
73
+ }
74
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
75
+ if (!value.isObject()) {
76
+ return false;
77
+ }
78
+ jsi::Object obj = value.getObject(runtime);
79
+ if (!nitro::isPlainObject(runtime, obj)) {
80
+ return false;
81
+ }
82
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "uuid")))) return false;
83
+ if (!JSIConverter<std::shared_ptr<ArrayBuffer>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))) return false;
84
+ return true;
85
+ }
86
+ };
87
+
88
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-nitro",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "High-performance React Native BLE library built on Nitro Modules",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -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;
@@ -85,6 +91,43 @@ describe('BleNitro', () => {
85
91
  );
86
92
  });
87
93
 
94
+ test('startScan exposes converted service data to the callback', async () => {
95
+ // Reset any scanning state left over from previous tests
96
+ mockNative.stopScan.mockImplementation(() => true);
97
+ BleManager.stopScan();
98
+
99
+ const nativeDevice = {
100
+ id: 'device-1',
101
+ name: 'Treadmill',
102
+ rssi: -50,
103
+ manufacturerData: { companyIdentifiers: [] },
104
+ serviceData: {
105
+ services: [
106
+ {
107
+ uuid: '1826',
108
+ data: new Uint8Array([0x01, 0x02, 0x03]).buffer,
109
+ },
110
+ ],
111
+ },
112
+ serviceUUIDs: ['1826'],
113
+ isConnectable: true,
114
+ isConnected: false,
115
+ };
116
+
117
+ mockNative.startScan.mockImplementation((filter, callback) => { // eslint-disable-line @typescript-eslint/no-unused-vars
118
+ callback(nativeDevice);
119
+ });
120
+
121
+ const scanCallback = jest.fn();
122
+ BleManager.startScan({}, scanCallback);
123
+
124
+ expect(scanCallback).toHaveBeenCalledTimes(1);
125
+ const device = scanCallback.mock.calls[0][0];
126
+ expect(device.serviceData.services).toHaveLength(1);
127
+ expect(device.serviceData.services[0].uuid).toBe('00001826-0000-1000-8000-00805f9b34fb');
128
+ expect(device.serviceData.services[0].data).toEqual([0x01, 0x02, 0x03]);
129
+ });
130
+
88
131
  test('stopScan calls native and resolves', async () => {
89
132
  // First start a scan to set _isScanning to true
90
133
  mockNative.startScan.mockImplementation((filter, callback) => { // eslint-disable-line @typescript-eslint/no-unused-vars
@@ -114,6 +157,30 @@ describe('BleNitro', () => {
114
157
  expect(result).toBe(deviceId);
115
158
  });
116
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
+
117
184
  test('connect rejects on error', async () => {
118
185
  mockNative.connect.mockImplementation((id: string, callback: (success: boolean, deviceId: string, error: string) => void, _disconnectCallback?: (deviceId: string, interrupted: boolean, error: string) => void) => {
119
186
  callback(false, '', 'Connection failed');
@@ -483,4 +550,4 @@ describe('BleNitro', () => {
483
550
  expect.any(Function)
484
551
  );
485
552
  });
486
- });
553
+ });
package/src/index.ts CHANGED
@@ -5,6 +5,8 @@ export {
5
5
  type ScanCallback,
6
6
  type ManufacturerDataEntry,
7
7
  type ManufacturerData,
8
+ type ServiceDataEntry,
9
+ type ServiceData,
8
10
  type ConnectionCallback,
9
11
  type DisconnectEventCallback,
10
12
  type OperationCallback,
@@ -14,6 +16,7 @@ export {
14
16
  type BleNitroManagerOptions,
15
17
  BLEState,
16
18
  AndroidScanMode,
19
+ AndroidConnectionPriority,
17
20
  BleNitroManager,
18
21
  BleTimeoutError,
19
22
  } from "./manager";
package/src/manager.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  BLEState as NativeBLEState,
6
6
  ScanCallback as NativeScanCallback,
7
7
  AndroidScanMode as NativeAndroidScanMode,
8
+ AndroidConnectionPriority as NativeAndroidConnectionPriority,
8
9
  } from './specs/NativeBleNitro';
9
10
 
10
11
  export class BleTimeoutError extends Error {
@@ -44,11 +45,21 @@ export interface ManufacturerData {
44
45
  companyIdentifiers: ManufacturerDataEntry[];
45
46
  }
46
47
 
48
+ export interface ServiceDataEntry {
49
+ uuid: string;
50
+ data: ByteArray;
51
+ }
52
+
53
+ export interface ServiceData {
54
+ services: ServiceDataEntry[];
55
+ }
56
+
47
57
  export interface BLEDevice {
48
58
  id: string;
49
59
  name: string;
50
60
  rssi: number;
51
61
  manufacturerData: ManufacturerData;
62
+ serviceData: ServiceData;
52
63
  serviceUUIDs: string[];
53
64
  isConnectable: boolean;
54
65
  isConnected: boolean;
@@ -96,6 +107,12 @@ export enum AndroidScanMode {
96
107
  Opportunistic = 'Opportunistic',
97
108
  }
98
109
 
110
+ export enum AndroidConnectionPriority {
111
+ Balanced = 'Balanced',
112
+ High = 'High',
113
+ LowPower = 'LowPower',
114
+ }
115
+
99
116
  export type BleNitroManagerOptions = {
100
117
  restoreIdentifier?: string;
101
118
  onRestoredState?: RestoreStateCallback;
@@ -123,6 +140,15 @@ export function mapAndroidScanModeToNativeAndroidScanMode(scanMode: AndroidScanM
123
140
  return map[scanMode];
124
141
  }
125
142
 
143
+ export function mapAndroidConnectionPriorityToNativeAndroidConnectionPriority(priority: AndroidConnectionPriority): NativeAndroidConnectionPriority {
144
+ const map = {
145
+ Balanced: NativeAndroidConnectionPriority.Balanced,
146
+ High: NativeAndroidConnectionPriority.High,
147
+ LowPower: NativeAndroidConnectionPriority.LowPower,
148
+ }
149
+ return map[priority];
150
+ }
151
+
126
152
  export function convertNativeBleDeviceToBleDevice(nativeBleDevice: NativeBLEDevice): BLEDevice {
127
153
  return {
128
154
  ...nativeBleDevice,
@@ -132,6 +158,12 @@ export function convertNativeBleDeviceToBleDevice(nativeBleDevice: NativeBLEDevi
132
158
  id: entry.id,
133
159
  data: arrayBufferToByteArray(entry.data)
134
160
  }))
161
+ },
162
+ serviceData: {
163
+ services: nativeBleDevice.serviceData.services.map(entry => ({
164
+ uuid: BleNitroManager.normalizeGattUUID(entry.uuid),
165
+ data: arrayBufferToByteArray(entry.data)
166
+ }))
135
167
  }
136
168
  }
137
169
  }
@@ -406,6 +438,24 @@ export class BleNitroManager {
406
438
  return deviceMtu;
407
439
  }
408
440
 
441
+ /**
442
+ * Request an Android connection priority for an active connection.
443
+ * @param deviceId ID of the device
444
+ * @param priority Desired Android connection priority
445
+ * @returns On Android: true if the request was successfully initiated (the
446
+ * priority change itself is applied asynchronously); on iOS, an error, or a
447
+ * disconnected device: false
448
+ */
449
+ public requestConnectionPriority(
450
+ deviceId: string,
451
+ priority: AndroidConnectionPriority
452
+ ): boolean {
453
+ return this.Instance.requestConnectionPriority(
454
+ deviceId,
455
+ mapAndroidConnectionPriorityToNativeAndroidConnectionPriority(priority)
456
+ );
457
+ }
458
+
409
459
  /**
410
460
  * Read RSSI for a connected device
411
461
  * @param deviceId ID of the device
@@ -22,11 +22,21 @@ export interface ManufacturerData {
22
22
  companyIdentifiers: ManufacturerDataEntry[];
23
23
  }
24
24
 
25
+ export interface ServiceDataEntry {
26
+ uuid: string;
27
+ data: BLEValue;
28
+ }
29
+
30
+ export interface ServiceData {
31
+ services: ServiceDataEntry[];
32
+ }
33
+
25
34
  export interface BLEDevice {
26
35
  id: string;
27
36
  name: string;
28
37
  rssi: number;
29
38
  manufacturerData: ManufacturerData;
39
+ serviceData: ServiceData;
30
40
  serviceUUIDs: string[];
31
41
  isConnectable: boolean;
32
42
  isConnected: boolean;
@@ -39,6 +49,12 @@ export enum AndroidScanMode {
39
49
  Opportunistic = 3,
40
50
  }
41
51
 
52
+ export enum AndroidConnectionPriority {
53
+ Balanced = 0,
54
+ High = 1,
55
+ LowPower = 2,
56
+ }
57
+
42
58
  export interface ScanFilter {
43
59
  serviceUUIDs: string[];
44
60
  rssiThreshold: number;
@@ -88,6 +104,7 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
88
104
  disconnect(deviceId: string, callback: OperationCallback): void;
89
105
  isConnected(deviceId: string): boolean;
90
106
  requestMTU(deviceId: string, mtu: number): number;
107
+ requestConnectionPriority(deviceId: string, androidConnectionPriority: AndroidConnectionPriority): boolean;
91
108
  readRSSI(deviceId: string, callback: ReadRSSICallback): void;
92
109
 
93
110
  // Service discovery
@@ -110,4 +127,4 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
110
127
  subscribeToStateChange(stateCallback: StateCallback): OperationResult;
111
128
  unsubscribeFromStateChange(): OperationResult;
112
129
  openSettings(): Promise<void>;
113
- }
130
+ }