react-native-ble-nitro 1.14.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.
- package/README.md +20 -1
- package/android/build.gradle +6 -0
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +109 -10
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/CccdSubscription.kt +38 -0
- package/android/src/test/java/com/margelo/nitro/co/zyke/ble/CccdSubscriptionTest.kt +48 -0
- package/ios/BleNitroBleManager.swift +4 -0
- package/lib/commonjs/index.d.ts +1 -1
- package/lib/commonjs/index.d.ts.map +1 -1
- package/lib/commonjs/index.js +2 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/manager.d.ts +16 -1
- package/lib/commonjs/manager.d.ts.map +1 -1
- package/lib/commonjs/manager.js +27 -1
- package/lib/commonjs/manager.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +6 -0
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js +7 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/manager.d.ts +16 -1
- package/lib/manager.js +26 -1
- package/lib/specs/NativeBleNitro.nitro.d.ts +6 -0
- package/lib/specs/NativeBleNitro.nitro.js +6 -0
- package/nitrogen/generated/android/c++/JAndroidConnectionPriority.hpp +61 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +9 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/AndroidConnectionPriority.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +4 -0
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +11 -0
- package/nitrogen/generated/ios/swift/AndroidConnectionPriority.swift +44 -0
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +12 -0
- package/nitrogen/generated/shared/c++/AndroidConnectionPriority.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +4 -0
- package/package.json +1 -1
- package/src/__tests__/index.test.ts +32 -2
- package/src/index.ts +1 -0
- package/src/manager.ts +34 -0
- package/src/specs/NativeBleNitro.nitro.ts +8 -1
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 {
|
|
@@ -106,6 +107,12 @@ export enum AndroidScanMode {
|
|
|
106
107
|
Opportunistic = 'Opportunistic',
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
export enum AndroidConnectionPriority {
|
|
111
|
+
Balanced = 'Balanced',
|
|
112
|
+
High = 'High',
|
|
113
|
+
LowPower = 'LowPower',
|
|
114
|
+
}
|
|
115
|
+
|
|
109
116
|
export type BleNitroManagerOptions = {
|
|
110
117
|
restoreIdentifier?: string;
|
|
111
118
|
onRestoredState?: RestoreStateCallback;
|
|
@@ -133,6 +140,15 @@ export function mapAndroidScanModeToNativeAndroidScanMode(scanMode: AndroidScanM
|
|
|
133
140
|
return map[scanMode];
|
|
134
141
|
}
|
|
135
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
|
+
|
|
136
152
|
export function convertNativeBleDeviceToBleDevice(nativeBleDevice: NativeBLEDevice): BLEDevice {
|
|
137
153
|
return {
|
|
138
154
|
...nativeBleDevice,
|
|
@@ -422,6 +438,24 @@ export class BleNitroManager {
|
|
|
422
438
|
return deviceMtu;
|
|
423
439
|
}
|
|
424
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
|
+
|
|
425
459
|
/**
|
|
426
460
|
* Read RSSI for a connected device
|
|
427
461
|
* @param deviceId ID of the device
|
|
@@ -49,6 +49,12 @@ export enum AndroidScanMode {
|
|
|
49
49
|
Opportunistic = 3,
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
export enum AndroidConnectionPriority {
|
|
53
|
+
Balanced = 0,
|
|
54
|
+
High = 1,
|
|
55
|
+
LowPower = 2,
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
export interface ScanFilter {
|
|
53
59
|
serviceUUIDs: string[];
|
|
54
60
|
rssiThreshold: number;
|
|
@@ -98,6 +104,7 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
|
|
|
98
104
|
disconnect(deviceId: string, callback: OperationCallback): void;
|
|
99
105
|
isConnected(deviceId: string): boolean;
|
|
100
106
|
requestMTU(deviceId: string, mtu: number): number;
|
|
107
|
+
requestConnectionPriority(deviceId: string, androidConnectionPriority: AndroidConnectionPriority): boolean;
|
|
101
108
|
readRSSI(deviceId: string, callback: ReadRSSICallback): void;
|
|
102
109
|
|
|
103
110
|
// Service discovery
|
|
@@ -120,4 +127,4 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
|
|
|
120
127
|
subscribeToStateChange(stateCallback: StateCallback): OperationResult;
|
|
121
128
|
unsubscribeFromStateChange(): OperationResult;
|
|
122
129
|
openSettings(): Promise<void>;
|
|
123
|
-
}
|
|
130
|
+
}
|