react-native-ble-manager 8.7.0 → 8.8.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 +3 -3
- package/android/src/main/java/it/innove/BleManager.java +15 -0
- package/index.d.ts +140 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -441,7 +441,7 @@ BleManager.writeWithoutResponse(
|
|
|
441
441
|
### readRSSI(peripheralId)
|
|
442
442
|
|
|
443
443
|
Read the current value of the RSSI.
|
|
444
|
-
Returns a `Promise` object.
|
|
444
|
+
Returns a `Promise` object resolving with the updated RSSI value (`number`) if it succeeds.
|
|
445
445
|
|
|
446
446
|
**Arguments**
|
|
447
447
|
|
|
@@ -464,7 +464,7 @@ BleManager.readRSSI("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
|
|
|
464
464
|
### requestConnectionPriority(peripheralId, connectionPriority) [Android only API 21+]
|
|
465
465
|
|
|
466
466
|
Request a connection parameter update.
|
|
467
|
-
Returns a `Promise` object.
|
|
467
|
+
Returns a `Promise` object which fulfills with the status of the request.
|
|
468
468
|
|
|
469
469
|
**Arguments**
|
|
470
470
|
|
|
@@ -708,7 +708,7 @@ The BLE change state.
|
|
|
708
708
|
|
|
709
709
|
**Arguments**
|
|
710
710
|
|
|
711
|
-
- `state` - `String` - the new BLE state (
|
|
711
|
+
- `state` - `String` - the new BLE state. can be one of `unknown` (iOS only), `resetting` (iOS only), `unsupported`, `unauthorized` (iOS only), `on`, `off`, `turning_on` (android only), `turning_off` (android only).
|
|
712
712
|
|
|
713
713
|
**Examples**
|
|
714
714
|
|
|
@@ -470,8 +470,19 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
470
470
|
case BluetoothAdapter.STATE_ON:
|
|
471
471
|
state = "on";
|
|
472
472
|
break;
|
|
473
|
+
case BluetoothAdapter.STATE_TURNING_ON:
|
|
474
|
+
state = "turning_on";
|
|
475
|
+
break;
|
|
473
476
|
case BluetoothAdapter.STATE_OFF:
|
|
474
477
|
state = "off";
|
|
478
|
+
break;
|
|
479
|
+
case BluetoothAdapter.STATE_TURNING_OFF:
|
|
480
|
+
state = "turning_off";
|
|
481
|
+
break;
|
|
482
|
+
default:
|
|
483
|
+
// should not happen as per https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getState()
|
|
484
|
+
state = "off";
|
|
485
|
+
break;
|
|
475
486
|
}
|
|
476
487
|
}
|
|
477
488
|
|
|
@@ -512,6 +523,10 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
512
523
|
case BluetoothAdapter.STATE_TURNING_ON:
|
|
513
524
|
stringState = "turning_on";
|
|
514
525
|
break;
|
|
526
|
+
default:
|
|
527
|
+
// should not happen as per https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
|
|
528
|
+
stringState = "off";
|
|
529
|
+
break;
|
|
515
530
|
}
|
|
516
531
|
|
|
517
532
|
WritableMap map = Arguments.createMap();
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
declare module "react-native-ble-manager" {
|
|
2
|
+
|
|
3
|
+
// android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
|
|
4
|
+
// ios states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
|
|
5
|
+
export enum BleState {
|
|
6
|
+
Unknown = 'unknown', // [iOS only]
|
|
7
|
+
Resetting = 'resetting', // [iOS only]
|
|
8
|
+
Unsupported = 'unsupported',
|
|
9
|
+
Unauthorized = 'unauthorized', // [iOS only]
|
|
10
|
+
On = 'on',
|
|
11
|
+
Off = 'off',
|
|
12
|
+
TurningOn = 'turning_on', // [android only]
|
|
13
|
+
TurningOff = 'turning_off', // [android only]
|
|
14
|
+
}
|
|
15
|
+
|
|
2
16
|
export interface Peripheral {
|
|
3
17
|
id: string;
|
|
4
18
|
rssi: number;
|
|
@@ -9,30 +23,75 @@ declare module "react-native-ble-manager" {
|
|
|
9
23
|
export interface AdvertisingData {
|
|
10
24
|
isConnectable?: boolean;
|
|
11
25
|
localName?: string;
|
|
12
|
-
manufacturerData?:
|
|
26
|
+
manufacturerData?: CustomAdvertisingData,
|
|
27
|
+
serviceData?: CustomAdvertisingData,
|
|
13
28
|
serviceUUIDs?: string[];
|
|
14
29
|
txPowerLevel?: number;
|
|
15
30
|
}
|
|
16
31
|
|
|
32
|
+
export interface CustomAdvertisingData {
|
|
33
|
+
CDVType : 'ArrayBuffer',
|
|
34
|
+
bytes: Uint8Array,
|
|
35
|
+
data: string // base64-encoded string of the data
|
|
36
|
+
}
|
|
37
|
+
|
|
17
38
|
export interface StartOptions {
|
|
18
|
-
showAlert?: boolean;
|
|
19
|
-
restoreIdentifierKey?: string;
|
|
20
|
-
queueIdentifierKey?: string;
|
|
21
|
-
forceLegacy?: boolean;
|
|
39
|
+
showAlert?: boolean; // [iOS only]
|
|
40
|
+
restoreIdentifierKey?: string; // [iOS only]
|
|
41
|
+
queueIdentifierKey?: string; // [iOS only]
|
|
42
|
+
forceLegacy?: boolean; // [android only]
|
|
22
43
|
}
|
|
23
44
|
|
|
24
45
|
export function start(options?: StartOptions): Promise<void>;
|
|
25
46
|
|
|
47
|
+
// [android only]
|
|
48
|
+
// https://developer.android.com/reference/android/bluetooth/le/ScanSettings
|
|
26
49
|
export interface ScanOptions {
|
|
27
|
-
numberOfMatches?:
|
|
28
|
-
matchMode?:
|
|
29
|
-
callbackType?:
|
|
30
|
-
scanMode?:
|
|
50
|
+
numberOfMatches?: BleScanMatchCount;
|
|
51
|
+
matchMode?: BleScanMatchMode;
|
|
52
|
+
callbackType?: BleScanCallbackType;
|
|
53
|
+
scanMode?: BleScanMode;
|
|
31
54
|
reportDelay?: number;
|
|
32
|
-
phy?:
|
|
55
|
+
phy?: BleScanPhyMode;
|
|
33
56
|
legacy?: boolean;
|
|
34
57
|
}
|
|
35
58
|
|
|
59
|
+
// [android only]
|
|
60
|
+
export enum BleScanMode {
|
|
61
|
+
Opportunistic = -1,
|
|
62
|
+
LowPower = 0,
|
|
63
|
+
Balanced = 1,
|
|
64
|
+
LowLatency = 2,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// [android only]
|
|
68
|
+
export enum BleScanMatchMode {
|
|
69
|
+
Aggressive = 1,
|
|
70
|
+
Sticky = 2,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// [android only]
|
|
74
|
+
export enum BleScanCallbackType {
|
|
75
|
+
AllMatches = 1,
|
|
76
|
+
FirstMatch = 2,
|
|
77
|
+
MatchLost = 4,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// [android only]
|
|
81
|
+
export enum BleScanMatchCount {
|
|
82
|
+
OneAdvertisement = 1,
|
|
83
|
+
FewAdvertisements = 2,
|
|
84
|
+
MaxAdvertisements = 3,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// [android only]
|
|
88
|
+
export enum BleScanPhyMode {
|
|
89
|
+
LE_1M = 1,
|
|
90
|
+
LE_2M = 2,
|
|
91
|
+
LE_CODED = 3,
|
|
92
|
+
ALL_SUPPORTED = 255,
|
|
93
|
+
}
|
|
94
|
+
|
|
36
95
|
export function scan(
|
|
37
96
|
serviceUUIDs: string[],
|
|
38
97
|
seconds: number,
|
|
@@ -45,14 +104,16 @@ declare module "react-native-ble-manager" {
|
|
|
45
104
|
peripheralID: string,
|
|
46
105
|
force?: boolean
|
|
47
106
|
): Promise<void>;
|
|
107
|
+
|
|
48
108
|
export function checkState(): void;
|
|
109
|
+
|
|
49
110
|
export function startNotification(
|
|
50
111
|
peripheralID: string,
|
|
51
112
|
serviceUUID: string,
|
|
52
113
|
characteristicUUID: string
|
|
53
114
|
): Promise<void>;
|
|
54
115
|
|
|
55
|
-
|
|
116
|
+
// [android only]
|
|
56
117
|
export function startNotificationUseBuffer(
|
|
57
118
|
peripheralID: string,
|
|
58
119
|
serviceUUID: string,
|
|
@@ -71,6 +132,7 @@ declare module "react-native-ble-manager" {
|
|
|
71
132
|
serviceUUID: string,
|
|
72
133
|
characteristicUUID: string
|
|
73
134
|
): Promise<any>;
|
|
135
|
+
|
|
74
136
|
export function write(
|
|
75
137
|
peripheralID: string,
|
|
76
138
|
serviceUUID: string,
|
|
@@ -78,6 +140,7 @@ declare module "react-native-ble-manager" {
|
|
|
78
140
|
data: any,
|
|
79
141
|
maxByteSize?: number
|
|
80
142
|
): Promise<void>;
|
|
143
|
+
|
|
81
144
|
export function writeWithoutResponse(
|
|
82
145
|
peripheralID: string,
|
|
83
146
|
serviceUUID: string,
|
|
@@ -87,12 +150,14 @@ declare module "react-native-ble-manager" {
|
|
|
87
150
|
queueSleepTime?: number
|
|
88
151
|
): Promise<void>;
|
|
89
152
|
|
|
90
|
-
export function readRSSI(peripheralID: string): Promise<
|
|
153
|
+
export function readRSSI(peripheralID: string): Promise<number>;
|
|
91
154
|
|
|
92
155
|
export function getConnectedPeripherals(
|
|
93
156
|
serviceUUIDs: string[]
|
|
94
157
|
): Promise<Peripheral[]>;
|
|
158
|
+
|
|
95
159
|
export function getDiscoveredPeripherals(): Promise<Peripheral[]>;
|
|
160
|
+
|
|
96
161
|
export function isPeripheralConnected(
|
|
97
162
|
peripheralID: string,
|
|
98
163
|
serviceUUIDs: string[]
|
|
@@ -104,14 +169,19 @@ declare module "react-native-ble-manager" {
|
|
|
104
169
|
high = 1,
|
|
105
170
|
low = 2,
|
|
106
171
|
}
|
|
172
|
+
|
|
173
|
+
// [Android only 21+]
|
|
107
174
|
export function requestConnectionPriority(
|
|
108
175
|
peripheralID: string,
|
|
109
176
|
connectionPriority: ConnectionPriority
|
|
110
|
-
): Promise<
|
|
111
|
-
|
|
177
|
+
): Promise<boolean>;
|
|
178
|
+
|
|
179
|
+
// [Android only]
|
|
112
180
|
export function enableBluetooth(): Promise<void>;
|
|
181
|
+
|
|
113
182
|
// [Android only]
|
|
114
183
|
export function refreshCache(peripheralID: string): Promise<void>;
|
|
184
|
+
|
|
115
185
|
// [Android only API 21+]
|
|
116
186
|
export function requestMTU(peripheralID: string, mtu: number): Promise<number>;
|
|
117
187
|
|
|
@@ -119,8 +189,11 @@ declare module "react-native-ble-manager" {
|
|
|
119
189
|
peripheralID: string,
|
|
120
190
|
peripheralPin?: string
|
|
121
191
|
): Promise<void>;
|
|
192
|
+
|
|
122
193
|
export function removeBond(peripheralID: string): Promise<void>;
|
|
194
|
+
|
|
123
195
|
export function getBondedPeripherals(): Promise<Peripheral[]>;
|
|
196
|
+
|
|
124
197
|
export function removePeripheral(peripheralID: string): Promise<void>;
|
|
125
198
|
|
|
126
199
|
// [Android only]
|
|
@@ -165,4 +238,57 @@ declare module "react-native-ble-manager" {
|
|
|
165
238
|
peripheralID: string,
|
|
166
239
|
serviceUUIDs?: string[]
|
|
167
240
|
): Promise<PeripheralInfo>;
|
|
241
|
+
|
|
242
|
+
export enum BleEventType {
|
|
243
|
+
BleManagerDidUpdateState = 'BleManagerDidUpdateState',
|
|
244
|
+
BleManagerStopScan = 'BleManagerStopScan',
|
|
245
|
+
BleManagerDiscoverPeripheral = 'BleManagerDiscoverPeripheral',
|
|
246
|
+
BleManagerDidUpdateValueForCharacteristic = 'BleManagerDidUpdateValueForCharacteristic',
|
|
247
|
+
BleManagerConnectPeripheral = 'BleManagerConnectPeripheral',
|
|
248
|
+
BleManagerDisconnectPeripheral = 'BleManagerDisconnectPeripheral',
|
|
249
|
+
BleManagerPeripheralDidBond = 'BleManagerPeripheralDidBond', // [Android only]
|
|
250
|
+
BleManagerCentralManagerWillRestoreState = 'BleManagerCentralManagerWillRestoreState', // [iOS only]
|
|
251
|
+
BleManagerDidUpdateNotificationStateFor = 'BleManagerDidUpdateNotificationStateFor', // [iOS only]
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface BleStopScanEvent {
|
|
255
|
+
status?: number; // [iOS only]
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface BleManagerDidUpdateStateEvent {
|
|
259
|
+
state: BleState;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface BleConnectPeripheralEvent {
|
|
263
|
+
readonly peripheral: string; // peripheral id
|
|
264
|
+
readonly status?: number; // [android only]
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export type BleDiscoverPeripheralEvent = Peripheral;
|
|
268
|
+
|
|
269
|
+
// [Android only]
|
|
270
|
+
export type BleBondedPeripheralEvent = Peripheral;
|
|
271
|
+
|
|
272
|
+
export interface BleDisconnectPeripheralEvent {
|
|
273
|
+
readonly peripheral: string; // peripheral id
|
|
274
|
+
readonly status?: number; // [android only] disconnect reason.
|
|
275
|
+
readonly domain?: string; // [iOS only] disconnect error domain.
|
|
276
|
+
readonly code?: number; // [iOS only] disconnect error code.
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface BleManagerDidUpdateValueForCharacteristicEvent {
|
|
280
|
+
readonly characteristic: string; // characteristic UUID
|
|
281
|
+
readonly peripheral: string; // peripheral id
|
|
282
|
+
readonly service: string; // service UUID
|
|
283
|
+
readonly value: Uint8Array;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// [iOS only]
|
|
287
|
+
export interface BleManagerDidUpdateNotificationStateForEvent {
|
|
288
|
+
readonly peripheral: string; // peripheral id
|
|
289
|
+
readonly characteristic: string; // characteristic UUID
|
|
290
|
+
readonly isNotifying: boolean; // is the characteristic notifying or not
|
|
291
|
+
readonly domain: string; // error domain.
|
|
292
|
+
readonly code: number; // error code.
|
|
293
|
+
}
|
|
168
294
|
}
|