react-native-ble-manager 12.4.2 → 12.4.4

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/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
3
- * ios states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
2
+ * Android states: https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#EXTRA_STATE
3
+ * iOS states: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerstate
4
4
  * */
5
5
  export enum BleState {
6
6
  /**
@@ -19,11 +19,11 @@ export enum BleState {
19
19
  On = 'on',
20
20
  Off = 'off',
21
21
  /**
22
- * [android only]
22
+ * [Android only]
23
23
  */
24
24
  TurningOn = 'turning_on',
25
25
  /**
26
- * [android only]
26
+ * [Android only]
27
27
  */
28
28
  TurningOff = 'turning_off',
29
29
  }
@@ -61,61 +61,84 @@ export interface CustomAdvertisingData {
61
61
 
62
62
  export interface StartOptions {
63
63
  /**
64
- * [iOS only]
64
+ * [iOS only] Show or hide the alert if the bluetooth is turned off during initialization
65
65
  */
66
66
  showAlert?: boolean;
67
67
  /**
68
- * [iOS only]
68
+ * [iOS only] Unique key to use for CoreBluetooth state restoration
69
69
  */
70
70
  restoreIdentifierKey?: string;
71
71
  /**
72
- * [iOS only]
72
+ * [iOS only] Unique key to use for a queue identifier on which CoreBluetooth events will be dispatched
73
73
  */
74
74
  queueIdentifierKey?: string;
75
75
  /**
76
- * [android only]
76
+ * [Android only] Force to use the LegacyScanManager
77
77
  */
78
78
  forceLegacy?: boolean;
79
79
  }
80
80
 
81
81
  export interface ConnectOptions {
82
82
  /**
83
- * [android only]
83
+ * [Android only] whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true) ([`Android doc`](<https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=en#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int)>))
84
84
  */
85
85
  autoconnect?: boolean;
86
86
  /**
87
- * [android only]
87
+ * [Android only] corresponding to the preferred phy channel ([`Android doc`](<https://developer.android.com/reference/android/bluetooth/BluetoothDevice?hl=en#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int,%20int)>))
88
88
  */
89
89
  phy?: BleScanPhyMode;
90
90
  }
91
91
 
92
92
  /**
93
- * [android only]
93
+ * [Android only]
94
94
  * https://developer.android.com/reference/android/bluetooth/le/ScanSettings
95
95
  */
96
96
  export interface ScanOptions {
97
+ /**
98
+ * The UUIDs of the services to look for.
99
+ */
97
100
  serviceUUIDs?: string[];
101
+ /**
102
+ * The amount of seconds to scan. If not set or set to `0`, scans until `stopScan()` is called.
103
+ */
98
104
  seconds?: number;
99
105
  /**
100
- * iOS only: whether to allow duplicate peripheral during a scan
106
+ * In Android this is a ScanFilter, if present it restricts scan results to devices with a specific advertising name.
107
+ * This is a whole word match, not a partial search.
108
+ * Use with caution, it's behavior is tricky and seems to be the following:
109
+ * if `callbackType` is set to `AllMatches`, only the completeLocalName will be used for filtering.
110
+ * if `callbackType` is set to `FirstMatch`, the shortenedLocalName will be used for filtering.
111
+ * https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setDeviceName(java.lang.String)
112
+ *
113
+ * In iOS, this is a whole word match, not a partial search.
114
+ */
115
+ exactAdvertisingName?: string | string[];
116
+ /**
117
+ * [iOS only] whether to allow duplicate peripheral during a scan
101
118
  */
102
119
  allowDuplicates?: boolean;
103
120
  /**
104
- * This will only works if a ScanFilter is active. Otherwise, may not retrieve any result.
121
+ * [Android only] This will only work if a ScanFilter is active. Otherwise, may not retrieve any result.
105
122
  * See https://developer.android.com/reference/android/bluetooth/le/ScanSettings#MATCH_NUM_FEW_ADVERTISEMENT.
106
123
  * */
107
124
  numberOfMatches?: BleScanMatchCount;
125
+ /**
126
+ * [Android only] Defaults to `aggressive`.
127
+ */
108
128
  matchMode?: BleScanMatchMode;
109
129
  /**
110
- * This will only works if a ScanFilter is active. Otherwise, may not retrieve any result.
130
+ * [Android only] This will only work if a ScanFilter is active. Otherwise, may not retrieve any result.
111
131
  * See https://developer.android.com/reference/android/bluetooth/le/ScanSettings#CALLBACK_TYPE_FIRST_MATCH.
112
132
  * Also read [this issue](https://github.com/dariuszseweryn/RxAndroidBle/issues/561#issuecomment-532295346) for a deeper understanding
113
- * of the very brittle stability of ScanSettings on android.
133
+ * of the very brittle stability of ScanSettings on Android. Defaults to `allMatches`.
114
134
  * */
115
135
  callbackType?: BleScanCallbackType;
136
+ /**
137
+ * [Android only] Defaults to `lowPower`.
138
+ */
116
139
  scanMode?: BleScanMode;
117
140
  /**
118
- * This is supposed to push results after a certain delay.
141
+ * [Android only] This is supposed to push results after a certain delay.
119
142
  * In practice it is tricky, use with caution.
120
143
  * Do not set something below 5000ms as it will wait that long anyway before pushing the first results,
121
144
  * or on some phones it will ignore that setting and behave just like it was set to 0.
@@ -124,29 +147,20 @@ export interface ScanOptions {
124
147
  */
125
148
  reportDelay?: number;
126
149
  /**
127
- * Does not work in conjunction with legacy scans. Setting an unsupported PHY will result in a failure to scan,
150
+ * [Android only] Does not work in conjunction with legacy scans. Setting an unsupported PHY will result in a failure to scan,
128
151
  * use with caution.
129
152
  * https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setPhy(int)
130
153
  */
131
154
  phy?: BleScanPhyMode;
132
155
  /**
133
- * true by default for compatibility with older apps.
156
+ * [Android only] true by default for compatibility with older apps.
134
157
  * In that mode, scan will only retrieve advertisements data as specified by BLE 4.2 and below.
135
158
  * Change this if you want to benefit from the extended BLE 5 advertisement spec.
136
159
  * https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setLegacy(boolean)
137
160
  */
138
161
  legacy?: boolean;
139
162
  /**
140
- * an android ScanFilter, used if present to restrict scan results to devices with a specific advertising name.
141
- * This is a whole word match, not a partial search.
142
- * Use with caution, it's behavior is tricky and seems to be the following:
143
- * if `callbackType` is set to `AllMatches`, only the completeLocalName will be used for filtering.
144
- * if `callbackType` is set to `FirstMatch`, the shortenedLocalName will be used for filtering.
145
- * https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder#setDeviceName(java.lang.String)
146
- */
147
- exactAdvertisingName?: string | string[];
148
- /**
149
- * Android only. Filters scan results by manufacturer id and data.
163
+ * [Android only] Filters scan results by manufacturer id and data.
150
164
  * `manufacturerId` usually matches the company id, can be given as a hex, e.g. 0xe4f7.
151
165
  * `manufacturerData` and `manufacturerDataMask` must have the same length. For any bit in the mask, set it to 1 if
152
166
  * it needs to match the one in manufacturer data, otherwise set it to 0.
@@ -157,13 +171,6 @@ export interface ScanOptions {
157
171
  manufacturerData?: number[];
158
172
  manufacturerDataMask?: number[];
159
173
  };
160
- /**
161
- * When using compaion mode, only associate single peripheral.
162
- *
163
- * See: https://developer.android.com/reference/android/companion/AssociationRequest.Builder#setSingleDevice(boolean)
164
- */
165
- single?: boolean;
166
- companion?: boolean;
167
174
  /**
168
175
  * [Android O+] Deliver scan results using a PendingIntent instead of the default callback.
169
176
  */
@@ -172,13 +179,13 @@ export interface ScanOptions {
172
179
 
173
180
  export interface CompanionScanOptions {
174
181
  /**
175
- * Scan only for a single peripheral.
182
+ * Scan only for a single peripheral. See Android's `AssociationRequest.Builder.setSingleDevice`.
176
183
  */
177
184
  single?: boolean;
178
185
  }
179
186
 
180
187
  /**
181
- * [android only]
188
+ * [Android only]
182
189
  */
183
190
  export enum BleScanMode {
184
191
  Opportunistic = -1,
@@ -188,7 +195,7 @@ export enum BleScanMode {
188
195
  }
189
196
 
190
197
  /**
191
- * [android only]
198
+ * [Android only]
192
199
  */
193
200
  export enum BleScanMatchMode {
194
201
  Aggressive = 1,
@@ -196,7 +203,7 @@ export enum BleScanMatchMode {
196
203
  }
197
204
 
198
205
  /**
199
- * [android only]
206
+ * [Android only]
200
207
  */
201
208
  export enum BleScanCallbackType {
202
209
  AllMatches = 1,
@@ -205,7 +212,7 @@ export enum BleScanCallbackType {
205
212
  }
206
213
 
207
214
  /**
208
- * [android only]
215
+ * [Android only]
209
216
  */
210
217
  export enum BleScanMatchCount {
211
218
  OneAdvertisement = 1,
@@ -214,7 +221,7 @@ export enum BleScanMatchCount {
214
221
  }
215
222
 
216
223
  /**
217
- * [android only]
224
+ * [Android only]
218
225
  */
219
226
  export enum BleScanPhyMode {
220
227
  LE_1M = 1,
@@ -224,7 +231,7 @@ export enum BleScanPhyMode {
224
231
  }
225
232
 
226
233
  /**
227
- * [android only API 21+]
234
+ * [Android only API 21+]
228
235
  */
229
236
  export enum ConnectionPriority {
230
237
  balanced = 0,
@@ -268,35 +275,20 @@ export interface PeripheralInfo extends Peripheral {
268
275
  services?: Service[];
269
276
  }
270
277
 
271
- export enum BleEventType {
272
- BleManagerDidUpdateState = 'BleManagerDidUpdateState',
273
- BleManagerStopScan = 'BleManagerStopScan',
274
- BleManagerDiscoverPeripheral = 'BleManagerDiscoverPeripheral',
275
- BleManagerDidUpdateValueForCharacteristic = 'BleManagerDidUpdateValueForCharacteristic',
276
- BleManagerConnectPeripheral = 'BleManagerConnectPeripheral',
277
- BleManagerDisconnectPeripheral = 'BleManagerDisconnectPeripheral',
278
- /**
279
- * [Android only]
280
- */
281
- BleManagerPeripheralDidBond = 'BleManagerPeripheralDidBond',
282
- /**
283
- * [iOS only]
284
- */
285
- BleManagerCentralManagerWillRestoreState = 'BleManagerCentralManagerWillRestoreState',
286
- /**
287
- * [iOS only]
288
- */
289
- BleManagerDidUpdateNotificationStateFor = 'BleManagerDidUpdateNotificationStateFor',
290
- }
278
+ export type EventCallback<T> = (event: T) => void | Promise<void>;
291
279
 
292
280
  export interface BleStopScanEvent {
293
281
  /**
294
- * [iOS only]
282
+ * [iOS] The reason for stopping the scan. Error code 10 is used for timeouts, 0 covers everything else.
283
+ * [Android] The reason for stopping the scan (<https://developer.android.com/reference/android/bluetooth/le/ScanCallback#constants_1>). Error code 10 is used for timeouts
295
284
  */
296
285
  status?: number;
297
286
  }
298
287
 
299
288
  export interface BleManagerDidUpdateStateEvent {
289
+ /**
290
+ * The new BLE state
291
+ */
300
292
  state: BleState;
301
293
  }
302
294
 
@@ -306,7 +298,9 @@ export interface BleConnectPeripheralEvent {
306
298
  */
307
299
  readonly peripheral: string;
308
300
  /**
309
- * [android only]
301
+ * [Android only]
302
+ *
303
+ * Connect reason.
310
304
  */
311
305
  readonly status?: number;
312
306
  }
@@ -324,7 +318,7 @@ export interface BleDisconnectPeripheralEvent {
324
318
  */
325
319
  readonly peripheral: string;
326
320
  /**
327
- * [android only] disconnect reason.
321
+ * [Android only] disconnect reason.
328
322
  */
329
323
  readonly status?: number;
330
324
  /**