@react-native-ohos/react-native-ble-plx 3.2.1-rc.1 → 3.2.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 (65) hide show
  1. package/LICENSE +202 -202
  2. package/README.OpenSource +10 -10
  3. package/README.md +9 -9
  4. package/app.plugin.js +1 -1
  5. package/harmony/rn_bleplx/build-profile.json5 +7 -7
  6. package/harmony/rn_bleplx/hvigorfile.ts +1 -1
  7. package/harmony/rn_bleplx/index.ets +26 -26
  8. package/harmony/rn_bleplx/obfuscation-rules.txt +17 -17
  9. package/harmony/rn_bleplx/oh-package.json5 +13 -13
  10. package/harmony/rn_bleplx/src/main/cpp/BlePlxPackage.h +36 -36
  11. package/harmony/rn_bleplx/src/main/cpp/CMakeLists.txt +9 -9
  12. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/BaseReactNativeBlePlxPackage.h +65 -65
  13. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.cpp +59 -59
  14. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.h +16 -16
  15. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ComponentDescriptors.h +22 -22
  16. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.cpp +18 -18
  17. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.h +19 -19
  18. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.cpp +21 -21
  19. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.h +20 -20
  20. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.cpp +19 -19
  21. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.h +25 -25
  22. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.cpp +18 -18
  23. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.h +22 -22
  24. package/harmony/rn_bleplx/src/main/ets/BleDevice.ts +98 -98
  25. package/harmony/rn_bleplx/src/main/ets/BleModule.ts +1219 -1219
  26. package/harmony/rn_bleplx/src/main/ets/BlePlxInterface.ts +26 -26
  27. package/harmony/rn_bleplx/src/main/ets/BlePlxModule.ts +246 -246
  28. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ets +46 -46
  29. package/harmony/rn_bleplx/src/main/ets/Characteristic.ts +179 -179
  30. package/harmony/rn_bleplx/src/main/ets/CommonConstants.ts +29 -29
  31. package/harmony/rn_bleplx/src/main/ets/Descriptor.ts +143 -143
  32. package/harmony/rn_bleplx/src/main/ets/Service.ts +85 -85
  33. package/harmony/rn_bleplx/src/main/ets/common/BleError.ts +90 -90
  34. package/harmony/rn_bleplx/src/main/ets/common/BleErrorToJsObjectConverter.ts +62 -62
  35. package/harmony/rn_bleplx/src/main/ets/common/BleEvent.ts +32 -32
  36. package/harmony/rn_bleplx/src/main/ets/common/BleUtils.ts +86 -86
  37. package/harmony/rn_bleplx/src/main/ets/common/IdGenerator.ts +49 -49
  38. package/harmony/rn_bleplx/src/main/ets/common/IdGeneratorKey.ts +70 -70
  39. package/harmony/rn_bleplx/src/main/ets/common/InstanceIdGenerator.ts +36 -36
  40. package/harmony/rn_bleplx/src/main/ets/common/Logger.ts +64 -64
  41. package/harmony/rn_bleplx/src/main/ets/common/PermissionHandler.ts +98 -98
  42. package/harmony/rn_bleplx/src/main/ets/common/ServiceFactory.ts +37 -37
  43. package/harmony/rn_bleplx/src/main/ets/generated/components/ts.ts +5 -5
  44. package/harmony/rn_bleplx/src/main/ets/generated/index.ets +5 -5
  45. package/harmony/rn_bleplx/src/main/ets/generated/ts.ts +6 -6
  46. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/BlePlx.ts +100 -100
  47. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/ts.ts +5 -5
  48. package/harmony/rn_bleplx/src/main/module.json5 +6 -6
  49. package/harmony/rn_bleplx/ts.ets +25 -25
  50. package/harmony/rn_bleplx.har +0 -0
  51. package/package.json +185 -185
  52. package/src/BleError.js +555 -555
  53. package/src/BleManager.js +1287 -1287
  54. package/src/BleModule.js +847 -847
  55. package/src/Characteristic.js +166 -166
  56. package/src/Descriptor.js +82 -82
  57. package/src/Device.js +370 -370
  58. package/src/NativeBlePlx.ts +121 -121
  59. package/src/Service.js +188 -188
  60. package/src/TypeDefinition.js +360 -360
  61. package/src/Utils.js +26 -26
  62. package/src/index.d.ts +2113 -2113
  63. package/src/index.js +20 -20
  64. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ts +0 -46
  65. package/harmony/rn_bleplx/ts.ts +0 -26
package/src/index.d.ts CHANGED
@@ -1,2113 +1,2113 @@
1
- declare module 'react-native-ble-plx' {
2
- // TypeDefinition.js *************************************************************************************************
3
-
4
- /**
5
- * [Android only] ConnectionOptions parameter to describe when to call BluetoothGatt.refresh()
6
- */
7
- export type RefreshGattMoment = 'OnConnected'
8
- /**
9
- * Base64 value
10
- */
11
- export type Base64 = string
12
- /**
13
- * Bluetooth UUID
14
- */
15
- export type UUID = string
16
- /**
17
- * Unique identifier for BLE objects.
18
- */
19
- export type Identifier = number
20
- /**
21
- * Bluetooth device id.
22
- */
23
- export type DeviceId = string
24
- /**
25
- * Transaction identifier. All transaction identifiers in numeric form are reserved for internal use.
26
- */
27
- export type TransactionId = string
28
-
29
- /**
30
- * Subscription
31
- * @interface
32
- */
33
- export interface Subscription {
34
- /**
35
- * Removes subscription
36
- * @memberof Subscription
37
- * @ignore
38
- */
39
- remove(): void
40
- }
41
-
42
- /**
43
- * Type of error code mapping table
44
- */
45
- export type BleErrorCodeMessageMapping = { [key in BleErrorCode]: string }
46
-
47
- /**
48
- * Options which can be passed to when creating BLE Manager
49
- */
50
- export interface BleManagerOptions {
51
- /**
52
- * BLE State restoration identifier used to restore state.
53
- * @memberof BleManagerOptions
54
- * @instance
55
- */
56
- restoreStateIdentifier?: string
57
-
58
- /**
59
- * Optional function which is used to properly restore state of your BLE Manager. Callback
60
- * is emitted in the beginning of BleManager creation and optional {@link BleRestoreState}
61
- * is passed. When value is `null` application is launching for the first time, otherwise
62
- * it contains saved state which may be used by developer to continue working with
63
- * connected peripherals.
64
- * @memberof BleManagerOptions
65
- * @instance
66
- */
67
- restoreStateFunction?: (restoredState: BleRestoredState | null) => void
68
-
69
- /**
70
- * Optional mapping of error codes to error messages. Uses {@link BleErrorCodeMessage}
71
- * by default.
72
- *
73
- * To override logging UUIDs or MAC adresses in error messages copy the original object
74
- * and overwrite values of interest to you.
75
- *
76
- * @memberof BleManagerOptions
77
- * @instance
78
- */
79
- errorCodesToMessagesMapping?: BleErrorCodeMessageMapping
80
- }
81
-
82
- /**
83
- * Object representing information about restored BLE state after application relaunch.
84
- */
85
- export interface BleRestoredState {
86
- /**
87
- * List of connected devices after state restoration.
88
- * @type {Array<Device>}
89
- * @instance
90
- * @memberof BleRestoredState
91
- */
92
- connectedPeripherals: Device[]
93
- }
94
-
95
- /**
96
- * Scan mode for Bluetooth LE scan.
97
- */
98
- export enum ScanMode {
99
- /**
100
- * A special Bluetooth LE scan mode. Applications using this scan mode will passively listen for
101
- * other scan results without starting BLE scans themselves.
102
- */
103
- Opportunistic = -1,
104
-
105
- /**
106
- * Perform Bluetooth LE scan in low power mode. This is the default scan mode as it consumes the
107
- * least power. [default value]
108
- */
109
- LowPower = 0,
110
-
111
- /**
112
- * Perform Bluetooth LE scan in balanced power mode. Scan results are returned at a rate that
113
- * provides a good trade-off between scan frequency and power consumption.
114
- */
115
- Balanced = 1,
116
-
117
- /**
118
- * Scan using highest duty cycle. It's recommended to only use this mode when the application is
119
- * running in the foreground.
120
- */
121
- LowLatency = 2
122
- }
123
-
124
- /**
125
- * The enum of BLE match mode.
126
- */
127
- export enum MatchMode {
128
- /**
129
- * Aggressive mode
130
- */
131
- Aggressive = 1,
132
-
133
- /**
134
- * Sticky mode
135
- */
136
- Sticky = 2
137
- }
138
-
139
- /**
140
- * Phy type used during scan.
141
- */
142
- export enum PhyType {
143
- /**
144
- * Use 1M phy for scanning.
145
- */
146
- LE_1M = 1,
147
-
148
- /**
149
- * Use all supported Phys for scanning.
150
- */
151
- LE_All_Supported = 255
152
- }
153
-
154
- /**
155
- * Scan callback type for Bluetooth LE scan.
156
- * @name ScanCallbackType
157
- */
158
- export enum ScanCallbackType {
159
- /**
160
- * Trigger a callback for every Bluetooth advertisement found that matches the filter criteria.
161
- * If no filter is active, all advertisement packets are reported. [default value]
162
- */
163
- AllMatches = 1,
164
-
165
- /**
166
- * A result callback is only triggered for the first advertisement packet received that matches
167
- * the filter criteria.
168
- */
169
- FirstMatch = 2,
170
-
171
- /**
172
- * Receive a callback when advertisements are no longer received from a device that has been
173
- * previously reported by a first match callback.
174
- */
175
- MatchLost = 4
176
- }
177
-
178
- /**
179
- * Options which can be passed to scanning function
180
- * @name ScanOptions
181
- */
182
- export interface ScanOptions {
183
- /**
184
- * By allowing duplicates scanning records are received more frequently [iOS only]
185
- */
186
- allowDuplicates?: boolean
187
- /**
188
- * Scan mode for Bluetooth LE scan [Android and Harmony]
189
- */
190
- scanMode?: ScanMode
191
- /**
192
- * Scan callback type for Bluetooth LE scan [Android only]
193
- */
194
- callbackType?: ScanCallbackType
195
- /**
196
- * Use legacyScan (default true) [Android only]
197
- * https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setLegacy(boolean)
198
- */
199
- legacyScan?: boolean
200
- /**
201
- * Time of delay for reporting the scan result [Harmony only]
202
- */
203
- interval?: number;
204
- /**
205
- * Match mode for Bluetooth LE scan filters hardware match [Harmony only]
206
- */
207
- matchMode?: MatchMode;
208
- /**
209
- * Physical Layer used during scan [Harmony only]
210
- */
211
- phyType?: PhyType;
212
- }
213
-
214
- /**
215
- * Connection specific options to be passed before connection happen. [Not used]
216
- */
217
- export interface ConnectionOptions {
218
- /**
219
- * Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device
220
- * becomes available (true). [Android only]
221
- * @memberof ConnectionOptions
222
- * @instance
223
- */
224
- autoConnect?: boolean
225
-
226
- /**
227
- * Whether MTU size will be negotiated to this value. It is not guaranteed to get it after connection is successful.
228
- *
229
- * @memberof ConnectionOptions
230
- * @instance
231
- */
232
- requestMTU?: number
233
-
234
- /**
235
- * Whether action will be taken to reset services cache. This option may be useful when a peripheral's firmware was
236
- * updated and it's services/characteristics were added/removed/altered. [Android only]
237
- * {@link https://stackoverflow.com/questions/22596951/how-to-programmatically-force-bluetooth-low-energy-service-discovery-on-android}
238
- * @memberof ConnectionOptions
239
- * @instance
240
- */
241
- refreshGatt?: RefreshGattMoment
242
-
243
- /**
244
- * Number of milliseconds after connection is automatically timed out. In case of race condition were connection is
245
- * established right after timeout event, device will be disconnected immediately. Time out may happen earlier then
246
- * specified due to OS specific behavior.
247
- *
248
- * @memberof ConnectionOptions
249
- * @instance
250
- */
251
- timeout?: number
252
- }
253
-
254
- /**
255
- * Device Bluetooth Low Energy state. It's keys are used to check {@link #blemanagerstate} values
256
- * received by {@link BleManager}
257
- */
258
- export enum State {
259
- /**
260
- * The current state of the manager is unknown; an update is imminent.
261
- */
262
- Unknown = 'Unknown',
263
- /**
264
- * The connection with the system service was momentarily lost; an update is imminent.
265
- */
266
- Resetting = 'Resetting',
267
- /**
268
- * The platform does not support Bluetooth low energy.
269
- */
270
- Unsupported = 'Unsupported',
271
- /**
272
- * The app is not authorized to use Bluetooth low energy.
273
- */
274
- Unauthorized = 'Unauthorized',
275
- /**
276
- * Bluetooth is currently powered off.
277
- */
278
- PoweredOff = 'PoweredOff',
279
- /**
280
- * Bluetooth is currently powered on and available to use.
281
- */
282
- PoweredOn = 'PoweredOn'
283
- }
284
-
285
- /**
286
- * Native module logging log level. By default it is set to None.
287
- * @name LogLevel
288
- */
289
- export enum LogLevel {
290
- /**
291
- * Logging in native module is disabled
292
- */
293
- None = 'None',
294
- /**
295
- * All logs in native module are shown
296
- */
297
- Verbose = 'Verbose',
298
- /**
299
- * Only debug logs and of higher importance are shown in native module.
300
- */
301
- Debug = 'Debug',
302
- /**
303
- * Only info logs and of higher importance are shown in native module.
304
- */
305
- Info = 'Info',
306
- /**
307
- * Only warning logs and of higher importance are shown in native module.
308
- */
309
- Warning = 'Warning',
310
- /**
311
- * Only error logs and of higher importance are shown in native module.
312
- */
313
- Error = 'Error'
314
- }
315
-
316
- /**
317
- * Connection priority of BLE link determining the balance between power consumption and data throughput.
318
- * @name ConnectionPriority
319
- */
320
- export enum ConnectionPriority {
321
- /**
322
- * Default, recommended option balanced between power consumption and data throughput.
323
- */
324
- Balanced = 0,
325
- /**
326
- * High priority, low latency connection, which increases transfer speed at the expense of power consumption.
327
- */
328
- High = 1,
329
- /**
330
- * Low power, reduced data rate connection setup.
331
- */
332
- LowPower = 2
333
- }
334
-
335
- // Utils.js **********************************************************************************************************
336
-
337
- /**
338
- * Converts UUID to full 128bit, lowercase format which should be used to compare UUID values.
339
- *
340
- * @param {UUID} uuid 16bit, 32bit or 128bit UUID.
341
- * @returns {UUID} 128bit lowercase UUID.
342
- */
343
- export function fullUUID(uuid: UUID): UUID
344
-
345
- // BleError.js *******************************************************************************************************
346
-
347
- export interface NativeBleError {
348
- errorCode: BleErrorCode
349
- attErrorCode: BleATTErrorCode | null
350
- iosErrorCode: BleIOSErrorCode | null
351
- androidErrorCode: BleAndroidErrorCode | null
352
- reason: string | null
353
-
354
- deviceID?: string
355
- serviceUUID?: string
356
- characteristicUUID?: string
357
- descriptorUUID?: string
358
- internalMessage?: string
359
- }
360
-
361
- /**
362
- * BleError is an error class which is guaranteed to be thrown by all functions of this
363
- * library. It contains additional properties which help to identify problems in
364
- * platform independent way.
365
- */
366
- export class BleError extends Error {
367
- /**
368
- * Platform independent error code. Possible values are defined in {@link BleErrorCode}.
369
- */
370
- errorCode: BleErrorCode
371
-
372
- /**
373
- * Platform independent error code related to ATT errors.
374
- */
375
- attErrorCode: BleATTErrorCode | null
376
-
377
- /**
378
- * iOS specific error code (if not an ATT error).
379
- */
380
- iosErrorCode: BleIOSErrorCode | null
381
-
382
- /**
383
- * Android specific error code (if not an ATT error).
384
- */
385
- androidErrorCode: BleAndroidErrorCode | null
386
-
387
- /**
388
- * Platform specific error message.
389
- */
390
- reason: string | null
391
-
392
- constructor(nativeBleError: NativeBleError | string, errorMessageMapping: BleErrorCodeMessageMapping)
393
- }
394
-
395
- /**
396
- * Platform independent error code map adjusted to this library's use cases.
397
- */
398
- export enum BleErrorCode {
399
- // Implementation specific errors ----------------------------------------------------------------------------------
400
- /**
401
- * This error can be thrown when unexpected error occurred and in most cases it is related to implementation bug.
402
- * Original message is available in {@link #bleerrorreason|reason} property.
403
- */
404
- UnknownError = 0,
405
- /**
406
- * Current promise failed to finish due to BleManager shutdown. It means that user called
407
- * {@link #blemanagerdestroy|manager.destroy()} function before all operations completed.
408
- */
409
- BluetoothManagerDestroyed = 1,
410
- /**
411
- * Promise was explicitly cancelled by a user with {@link #blemanagercanceltransaction|manager.cancelTransaction()}
412
- * function call.
413
- */
414
- OperationCancelled = 2,
415
- /**
416
- * Operation timed out and was cancelled.
417
- */
418
- OperationTimedOut = 3,
419
- /**
420
- * Native module couldn't start operation due to internal state, which doesn't allow to do that.
421
- */
422
- OperationStartFailed = 4,
423
- /**
424
- * Invalid UUIDs or IDs were passed to API call.
425
- */
426
- InvalidIdentifiers = 5,
427
-
428
- // Bluetooth global states -----------------------------------------------------------------------------------------
429
- /**
430
- * Bluetooth is not supported for this particular device. It may happen on iOS simulator for example.
431
- */
432
- BluetoothUnsupported = 100,
433
- /**
434
- * There are no granted permissions which allow to use BLE functionality. On Android it may require
435
- * android.permission.ACCESS_COARSE_LOCATION permission or android.permission.ACCESS_FINE_LOCATION permission.
436
- */
437
- BluetoothUnauthorized = 101,
438
- /**
439
- * BLE is powered off on device. All previous operations and their state is invalidated.
440
- */
441
- BluetoothPoweredOff = 102,
442
- /**
443
- * BLE stack is in unspecified state.
444
- */
445
- BluetoothInUnknownState = 103,
446
- /**
447
- * BLE stack is resetting.
448
- */
449
- BluetoothResetting = 104,
450
- /**
451
- * BLE state change failed.
452
- */
453
- BluetoothStateChangeFailed = 105,
454
-
455
- // Peripheral errors. ----------------------------------------------------------------------------------------------
456
- /**
457
- * Couldn't connect to specified device.
458
- */
459
- DeviceConnectionFailed = 200,
460
- /**
461
- * Device was disconnected.
462
- */
463
- DeviceDisconnected = 201,
464
- /**
465
- * Couldn't read RSSI from device.
466
- */
467
- DeviceRSSIReadFailed = 202,
468
- /**
469
- * Device is already connected. It is not allowed to connect twice to the same device.
470
- */
471
- DeviceAlreadyConnected = 203,
472
- /**
473
- * Couldn't find device with specified ID.
474
- */
475
- DeviceNotFound = 204,
476
- /**
477
- * Operation failed because device has to be connected to perform it.
478
- */
479
- DeviceNotConnected = 205,
480
- /**
481
- * Device could not change MTU value.
482
- */
483
- DeviceMTUChangeFailed = 206,
484
-
485
- // Services --------------------------------------------------------------------------------------------------------
486
- /**
487
- * Couldn't discover services for specified device.
488
- */
489
- ServicesDiscoveryFailed = 300,
490
- /**
491
- * Couldn't discover included services for specified service.
492
- */
493
- IncludedServicesDiscoveryFailed = 301,
494
- /**
495
- * Service with specified ID or UUID couldn't be found. User may need to call
496
- * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
497
- * to cache them.
498
- */
499
- ServiceNotFound = 302,
500
- /**
501
- * Services were not discovered. User may need to call
502
- * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
503
- * to cache them.
504
- */
505
- ServicesNotDiscovered = 303,
506
-
507
- // Characteristics -------------------------------------------------------------------------------------------------
508
- /**
509
- * Couldn't discover characteristics for specified service.
510
- */
511
- CharacteristicsDiscoveryFailed = 400,
512
- /**
513
- * Couldn't write to specified characteristic. Make sure that
514
- * {@link #characteristiciswritablewithresponse|characteristic.isWritableWithResponse}
515
- * or {@link #characteristiciswritablewithoutresponse|characteristic.isWritableWithoutResponse} is set to true.
516
- */
517
- CharacteristicWriteFailed = 401,
518
- /**
519
- * Couldn't read from specified characteristic. Make sure that
520
- * {@link #characteristicisreadable|characteristic.isReadable} is set to true.
521
- */
522
- CharacteristicReadFailed = 402,
523
- /**
524
- * Couldn't set notification or indication for specified characteristic. Make sure that
525
- * {@link #characteristicisnotifiable|characteristic.isNotifiable} or
526
- * {@link #characteristicisindicatable|characteristic.isIndicatable} is set to true.
527
- */
528
- CharacteristicNotifyChangeFailed = 403,
529
- /**
530
- * Characteristic with specified ID or UUID couldn't be found. User may need to call
531
- * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
532
- * to cache them.
533
- */
534
- CharacteristicNotFound = 404,
535
- /**
536
- * Characteristic were not discovered for specified service. User may need to call
537
- * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
538
- * to cache them.
539
- */
540
- CharacteristicsNotDiscovered = 405,
541
- /**
542
- * Invalid Base64 format was passed to characteristic API function call.
543
- */
544
- CharacteristicInvalidDataFormat = 406,
545
-
546
- // Characteristics -------------------------------------------------------------------------------------------------
547
- /**
548
- * Couldn't discover descriptor for specified characteristic.
549
- */
550
- DescriptorsDiscoveryFailed = 500,
551
- /**
552
- * Couldn't write to specified descriptor.
553
- */
554
- DescriptorWriteFailed = 501,
555
- /**
556
- * Couldn't read from specified descriptor.
557
- */
558
- DescriptorReadFailed = 502,
559
- /**
560
- * Couldn't find specified descriptor.
561
- */
562
- DescriptorNotFound = 503,
563
- /**
564
- * Descriptors are not discovered for specified characteristic.
565
- */
566
- DescriptorsNotDiscovered = 504,
567
- /**
568
- * Invalid Base64 format was passed to descriptor API function call.
569
- */
570
- DescriptorInvalidDataFormat = 505,
571
- /**
572
- * Issued a write to a descriptor, which is handled by OS.
573
- */
574
- DescriptorWriteNotAllowed = 506,
575
-
576
- // Scanning errors -------------------------------------------------------------------------------------------------
577
- /**
578
- * Cannot start scanning operation.
579
- */
580
- ScanStartFailed = 600,
581
- /**
582
- * Location services are disabled.
583
- */
584
- LocationServicesDisabled = 601
585
- }
586
-
587
- /**
588
- * Error codes for ATT errors.
589
- * @name BleATTErrorCode
590
- */
591
- export enum BleATTErrorCode {
592
- /**
593
- * The ATT command or request successfully completed.
594
- */
595
- Success = 0,
596
- /**
597
- * The attribute handle is invalid on this device.
598
- */
599
- InvalidHandle = 1,
600
- /**
601
- * The attribute’s value cannot be read.
602
- */
603
- ReadNotPermitted = 2,
604
- /**
605
- * The attribute’s value cannot be written.
606
- */
607
- WriteNotPermitted = 3,
608
- /**
609
- * The attribute Protocol Data Unit (PDU) or “message” is invalid.
610
- */
611
- InvalidPdu = 4,
612
- /**
613
- * The attribute requires authentication before its value can be read or written.
614
- */
615
- InsufficientAuthentication = 5,
616
- /**
617
- * The attribute server does not support the request received by the client.
618
- */
619
- RequestNotSupported = 6,
620
- /**
621
- * The specified offset value was past the end of the attribute’s value.
622
- */
623
- InvalidOffset = 7,
624
- /**
625
- * The attribute requires authorization before its value can be read or written.
626
- */
627
- InsufficientAuthorization = 8,
628
- /**
629
- * The prepare queue is full, because too many prepare write requests have been queued.
630
- */
631
- PrepareQueueFull = 9,
632
- /**
633
- * The attribute is not found within the specified attribute handle range.
634
- */
635
- AttributeNotFound = 10,
636
- /**
637
- * The attribute cannot be read or written using the ATT read blob request.
638
- */
639
- AttributeNotLong = 11,
640
- /**
641
- * The encryption key size used for encrypting this link is insufficient.
642
- */
643
- InsufficientEncryptionKeySize = 12,
644
- /**
645
- * The length of the attribute’s value is invalid for the intended operation.
646
- */
647
- InvalidAttributeValueLength = 13,
648
- /**
649
- * The ATT request has encountered an unlikely error and therefore could not be completed.
650
- */
651
- UnlikelyError = 14,
652
- /**
653
- * The attribute requires encryption before its value can be read or written.
654
- */
655
- InsufficientEncryption = 15,
656
- /**
657
- * The attribute type is not a supported grouping attribute as defined by a higher-layer specification.
658
- */
659
- UnsupportedGroupType = 16,
660
- /**
661
- * Resources are insufficient to complete the ATT request.
662
- */
663
- InsufficientResources = 17
664
-
665
- // Values 0x012 – 0x7F are reserved for future use.
666
- }
667
-
668
- /**
669
- * iOS specific error codes.
670
- * @name BleIOSErrorCode
671
- */
672
- export enum BleIOSErrorCode {
673
- /**
674
- * An unknown error occurred.
675
- */
676
- Unknown = 0,
677
- /**
678
- * The specified parameters are invalid.
679
- */
680
- InvalidParameters = 1,
681
- /**
682
- * The specified attribute handle is invalid.
683
- */
684
- InvalidHandle = 2,
685
- /**
686
- * The device is not currently connected.
687
- */
688
- NotConnected = 3,
689
- /**
690
- * The device has run out of space to complete the intended operation.
691
- */
692
- OutOfSpace = 4,
693
- /**
694
- * The operation is canceled.
695
- */
696
- OperationCancelled = 5,
697
- /**
698
- * The connection timed out.
699
- */
700
- ConnectionTimeout = 6,
701
- /**
702
- * The peripheral disconnected.
703
- */
704
- PeripheralDisconnected = 7,
705
- /**
706
- * The specified UUID is not permitted.
707
- */
708
- UuidNotAllowed = 8,
709
- /**
710
- * The peripheral is already advertising.
711
- */
712
- AlreadyAdvertising = 9,
713
- /**
714
- * The connection failed.
715
- */
716
- ConnectionFailed = 10,
717
- /**
718
- * The device already has the maximum number of connections.
719
- */
720
- ConnectionLimitReached = 11,
721
- /**
722
- * Unknown device.
723
- */
724
- UnknownDevice = 12
725
- }
726
-
727
- /**
728
- * Android specific error codes.
729
- * @name BleAndroidErrorCode
730
- */
731
- export enum BleAndroidErrorCode {
732
- /**
733
- * The device has insufficient resources to complete the intended operation.
734
- */
735
- NoResources = 0x80,
736
- /**
737
- * Internal error occurred which may happen due to implementation error in BLE stack.
738
- */
739
- InternalError = 0x81,
740
- /**
741
- * BLE stack implementation entered illegal state and operation couldn't complete.
742
- */
743
- WrongState = 0x82,
744
- /**
745
- * BLE stack didn't allocate sufficient memory buffer for internal caches.
746
- */
747
- DbFull = 0x83,
748
- /**
749
- * Maximum number of pending operations was exceeded.
750
- */
751
- Busy = 0x84,
752
- /**
753
- * Generic BLE stack error.
754
- */
755
- Error = 0x85,
756
- /**
757
- * Command is already queued up in GATT.
758
- */
759
- CmdStarted = 0x86,
760
- /**
761
- * Illegal parameter was passed to internal BLE stack function.
762
- */
763
- IllegalParameter = 0x87,
764
- /**
765
- * Operation is pending.
766
- */
767
- Pending = 0x88,
768
- /**
769
- * Authorization failed before performing read or write operation.
770
- */
771
- AuthFail = 0x89,
772
- /**
773
- * More cache entries were loaded then expected.
774
- */
775
- More = 0x8a,
776
- /**
777
- * Invalid configuration
778
- */
779
- InvalidCfg = 0x8b,
780
- /**
781
- * GATT service already started.
782
- */
783
- ServiceStarted = 0x8c,
784
- /**
785
- * GATT link is encrypted but prone to man in the middle attacks.
786
- */
787
- EncrypedNoMitm = 0x8d,
788
- /**
789
- * GATT link is not encrypted.
790
- */
791
- NotEncrypted = 0x8e,
792
- /**
793
- * ATT command was sent but channel is congested.
794
- */
795
- Congested = 0x8f
796
- }
797
-
798
- // BleModule.js ******************************************************************************************************
799
-
800
- /**
801
- * Native device object passed from BleModule.
802
- * @private
803
- */
804
- export interface NativeDevice {
805
- /**
806
- * Device identifier: MAC address on Android and UUID on iOS.
807
- * @private
808
- */
809
- id: DeviceId
810
- /**
811
- * Device name if present
812
- * @private
813
- */
814
- name: string | null
815
- /**
816
- * Current Received Signal Strength Indication of device
817
- * @private
818
- */
819
- rssi: number | null
820
- /**
821
- * Current Maximum Transmission Unit for this device. When device is not connected
822
- * default value of 23 is used.
823
- * @private
824
- */
825
- mtu: number
826
-
827
- // Advertisement
828
-
829
- /**
830
- * Device's custom manufacturer data. Its format is defined by manufacturer.
831
- * @private
832
- */
833
- manufacturerData: Base64 | null
834
-
835
- /**
836
- * Raw device scan data. When you have specific advertiser data,
837
- * you can implement your own processing.
838
- * @private
839
- */
840
- rawScanRecord: Base64
841
-
842
- /**
843
- * Map od service UUIDs with associated data.
844
- * @private
845
- */
846
- serviceData: { [uuid: string]: Base64 } | null
847
-
848
- /**
849
- * List of available services visible during scanning.
850
- * @private
851
- */
852
- serviceUUIDs: UUID[] | null
853
-
854
- /**
855
- * User friendly name of device.
856
- * @private
857
- */
858
- localName: string | null
859
-
860
- /**
861
- * Transmission power level of device.
862
- * @private
863
- */
864
- txPowerLevel: number | null
865
-
866
- /**
867
- * List of solicited service UUIDs.
868
- * @private
869
- */
870
- solicitedServiceUUIDs: UUID[] | null
871
-
872
- /**
873
- * Is device connectable.
874
- * @private
875
- */
876
- isConnectable: boolean | null
877
-
878
- /**
879
- * List of overflow service UUIDs.
880
- * @private
881
- */
882
- overflowServiceUUIDs: UUID[] | null
883
- }
884
-
885
- /**
886
- * Native service object passed from BleModule.
887
- * @private
888
- */
889
- export interface NativeService {
890
- /**
891
- * Service unique identifier
892
- * @private
893
- */
894
- id: Identifier
895
- /**
896
- * Service UUID
897
- * @private
898
- */
899
- uuid: UUID
900
- /**
901
- * Device's ID to which service belongs
902
- * @private
903
- */
904
- deviceID: DeviceId
905
- /**
906
- * Value indicating whether the type of service is primary or secondary.
907
- * @private
908
- */
909
- isPrimary: boolean
910
- }
911
-
912
- /**
913
- * Native characteristic object passed from BleModule.
914
- * @private
915
- */
916
- export interface NativeCharacteristic {
917
- /**
918
- * Characteristic unique identifier
919
- * @private
920
- */
921
- id: Identifier
922
- /**
923
- * Characteristic UUID
924
- * @private
925
- */
926
- uuid: UUID
927
- /**
928
- * Service's ID to which characteristic belongs
929
- * @private
930
- */
931
- serviceID: Identifier
932
- /**
933
- * Service's UUID to which characteristic belongs
934
- * @private
935
- */
936
- serviceUUID: UUID
937
- /**
938
- * Device's ID to which characteristic belongs
939
- * @private
940
- */
941
- deviceID: DeviceId
942
- /**
943
- * True if characteristic can be read
944
- * @private
945
- */
946
- isReadable: boolean
947
- /**
948
- * True if characteristic can be written with response
949
- * @private
950
- */
951
- isWritableWithResponse: boolean
952
- /**
953
- * True if characteristic can be written without response
954
- * @private
955
- */
956
- isWritableWithoutResponse: boolean
957
- /**
958
- * True if characteristic can monitor value changes.
959
- * @private
960
- */
961
- isNotifiable: boolean
962
- /**
963
- * True if characteristic is monitoring value changes without ACK.
964
- * @private
965
- */
966
- isNotifying: boolean
967
- /**
968
- * True if characteristic is monitoring value changes with ACK.
969
- * @private
970
- */
971
- isIndicatable: boolean
972
- /**
973
- * Characteristic value if present
974
- * @private
975
- */
976
- value: Base64 | null
977
- }
978
-
979
- /**
980
- * Native descriptor object passed from BleModule.
981
- * @private
982
- */
983
- export interface NativeDescriptor {
984
- /**
985
- * Descriptor unique identifier
986
- * @private
987
- */
988
- id: Identifier
989
- /**
990
- * Descriptor UUID
991
- * @private
992
- */
993
- uuid: UUID
994
- /**
995
- * Characteristic's ID to which descriptor belongs
996
- * @private
997
- */
998
- characteristicID: Identifier
999
- /**
1000
- * Characteristic's UUID to which descriptor belongs
1001
- * @private
1002
- */
1003
- characteristicUUID: UUID
1004
- /**
1005
- * Service's ID to which descriptor belongs
1006
- * @private
1007
- */
1008
- serviceID: Identifier
1009
- /**
1010
- * Service's UUID to which descriptor belongs
1011
- * @private
1012
- */
1013
- serviceUUID: UUID
1014
- /**
1015
- * Device's ID to which descriptor belongs
1016
- * @private
1017
- */
1018
- deviceID: DeviceId
1019
- /**
1020
- * Descriptor value if present
1021
- * @private
1022
- */
1023
- value: Base64 | null
1024
- }
1025
-
1026
- /**
1027
- * Object representing information about restored BLE state after application relaunch.
1028
- * @private
1029
- */
1030
- export interface NativeBleRestoredState {
1031
- /**
1032
- * List of connected devices after state restoration.
1033
- * @type {Array<NativeDevice>}
1034
- * @instance
1035
- * @memberof NativeBleRestoredState
1036
- * @private
1037
- */
1038
- connectedPeripherals: NativeDevice[]
1039
- }
1040
-
1041
- // BleManager.js *****************************************************************************************************
1042
-
1043
- /**
1044
- *
1045
- * BleManager is an entry point for react-native-ble-plx library. It provides all means to discover and work with
1046
- * {@link Device} instances. It should be initialized only once with `new` keyword and method
1047
- * {@link #blemanagerdestroy|destroy()} should be called on its instance when user wants to deallocate all resources.
1048
- *
1049
- * In case you want to properly support Background Mode, you should provide `restoreStateIdentifier` and
1050
- * `restoreStateFunction` in {@link BleManagerOptions}.
1051
- *
1052
- * @example
1053
- * const manager = new BleManager();
1054
- * // ... work with BLE manager ...
1055
- * manager.destroy();
1056
- */
1057
- export class BleManager {
1058
- /**
1059
- * Creates an instance of {@link BleManager}.
1060
- */
1061
- constructor(options?: BleManagerOptions)
1062
-
1063
- /**
1064
- * Destroys {@link BleManager} instance. A new instance needs to be created to continue working with
1065
- * this library. All operations which were in progress completes with
1066
- * @returns {Promise<void>}
1067
- * {@link #bleerrorcodebluetoothmanagerdestroyed|BluetoothManagerDestroyed} error code.
1068
- */
1069
- destroy(): Promise<void>;
1070
-
1071
- // Mark: Common ----------------------------------------------------------------------------------------------------
1072
-
1073
- /**
1074
- * Sets new log level for native module's logging mechanism.
1075
- * @param {LogLevel} logLevel New log level to be set.
1076
- * @returns {Promise<LogLevel>} Current log level.
1077
- */
1078
- setLogLevel(logLevel: LogLevel): Promise<LogLevel>
1079
-
1080
- /**
1081
- * Get current log level for native module's logging mechanism.
1082
- * @returns {Promise<LogLevel>} Current log level.
1083
- */
1084
- logLevel(): Promise<LogLevel>
1085
-
1086
- /**
1087
- * Cancels pending transaction.
1088
- *
1089
- * Few operations such as monitoring characteristic's value changes can be cancelled by a user. Basically every API
1090
- * entry which accepts `transactionId` allows to call `cancelTransaction` function. When cancelled operation is a
1091
- * promise or a callback which registers errors, {@link #bleerror|BleError} with error code
1092
- * {@link #bleerrorcodeoperationcancelled|OperationCancelled} will be emitted in that case. Cancelling transaction
1093
- * which doesn't exist is ignored.
1094
- *
1095
- * @example
1096
- * const transactionId = 'monitor_battery';
1097
- *
1098
- * // Monitor battery notifications
1099
- * manager.monitorCharacteristicForDevice(
1100
- * device.id, '180F', '2A19',
1101
- * (error, characteristic) => {
1102
- * // Handle battery level changes...
1103
- * }, transactionId);
1104
- *
1105
- * // Cancel after specified amount of time
1106
- * setTimeout(() => manager.cancelTransaction(transactionId), 2000);
1107
- *
1108
- * @param {TransactionId} transactionId Id of pending transactions.
1109
- * @returns {Promise<void>}
1110
- */
1111
- cancelTransaction(transactionId: TransactionId): Promise<void>
1112
-
1113
- // Mark: Monitoring state ------------------------------------------------------------------------------------------
1114
-
1115
- /**
1116
- * Enable Bluetooth. This function blocks until BLE is in PoweredOn state. [Android only]
1117
- *
1118
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1119
- * @returns {Promise<BleManager>} Promise completes when state transition was successful.
1120
- */
1121
- enable(transactionId?: TransactionId): Promise<BleManager>
1122
-
1123
- /**
1124
- * Disable Bluetooth. This function blocks until BLE is in PoweredOff state. [Android only]
1125
- *
1126
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1127
- * @returns {Promise<BleManager>} Promise completes when state transition was successful.
1128
- */
1129
- disable(transactionId?: TransactionId): Promise<BleManager>
1130
-
1131
- /**
1132
- * Current, global {@link State} of a {@link BleManager}. All APIs are working only when active state
1133
- * is "PoweredOn".
1134
- *
1135
- * @returns {Promise<State>} Promise which emits current state of BleManager.
1136
- */
1137
- state(): Promise<State>
1138
-
1139
- /**
1140
- * Notifies about {@link State} changes of a {@link BleManager}.
1141
- *
1142
- * @example
1143
- * const subscription = this.manager.onStateChange((state) => {
1144
- * if (state === 'PoweredOn') {
1145
- * this.scanAndConnect();
1146
- * subscription.remove();
1147
- * }
1148
- * }, true);
1149
- *
1150
- * @param {function(newState: State)} listener Callback which emits state changes of BLE Manager.
1151
- * Look at {@link State} for possible values.
1152
- * @param {boolean} [emitCurrentState=false] If true, current state will be emitted as well. Defaults to false.
1153
- *
1154
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1155
- */
1156
- onStateChange(listener: (newState: State) => void, emitCurrentState?: boolean): Subscription
1157
-
1158
- // Mark: Scanning --------------------------------------------------------------------------------------------------
1159
-
1160
- /**
1161
- * Starts device scanning. When previous scan is in progress it will be stopped before executing this command.
1162
- *
1163
- * @param {?Array<UUID>} UUIDs Array of strings containing {@link UUID}s of {@link Service}s which are registered in
1164
- * scanned {@link Device}. If `null` is passed, all available {@link Device}s will be scanned.
1165
- * @param {?ScanOptions} options Optional configuration for scanning operation.
1166
- * @param {function(error?: BleError, scannedDevice: ?Device)} listener Function which will be called for every scanned
1167
- * {@link Device} (devices may be scanned multiple times). It's first argument is potential {@link Error} which is set
1168
- * to non `null` value when scanning failed. You have to start scanning process again if that happens. Second argument
1169
- * is a scanned {@link Device}.
1170
- * @returns {Promise<void>} the promise may be rejected if the operation is impossible to perform.
1171
- */
1172
- startDeviceScan(
1173
- UUIDs: UUID[] | null,
1174
- options: ScanOptions | null,
1175
- listener: (error: BleError | null, scannedDevice: Device | null) => void
1176
- ): Promise<void>
1177
-
1178
- /**
1179
- * Stops {@link Device} scan if in progress.
1180
- * @returns {Promise<void>} the promise may be rejected if the operation is impossible to perform.
1181
- */
1182
- stopDeviceScan(): Promise<void>
1183
-
1184
- /**
1185
- * Request a connection parameter update. This functions may update connection parameters on Android API level 21 or
1186
- * above.
1187
- *
1188
- * @param {DeviceId} deviceIdentifier Device identifier.
1189
- * @param {ConnectionPriority} connectionPriority: Connection priority.
1190
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1191
- * @returns {Promise<Device>} Connected device.
1192
- */
1193
- requestConnectionPriorityForDevice(
1194
- deviceIdentifier: DeviceId,
1195
- connectionPriority: ConnectionPriority,
1196
- transactionId?: TransactionId
1197
- ): Promise<Device>
1198
-
1199
- /**
1200
- * Reads RSSI for connected device.
1201
- *
1202
- * @param {DeviceId} deviceIdentifier Device identifier.
1203
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1204
- * @returns {Promise<Device>} Connected device with updated RSSI value.
1205
- */
1206
- readRSSIForDevice(deviceIdentifier: DeviceId, transactionId?: TransactionId): Promise<Device>
1207
-
1208
- /**
1209
- * Request new MTU value for this device. This function currently is not doing anything
1210
- * on iOS platform as MTU exchange is done automatically. Since Android 14,
1211
- * mtu management has been changed, more information can be found at the link:
1212
- * https://developer.android.com/about/versions/14/behavior-changes-all#mtu-set-to-517
1213
- * @param {DeviceId} deviceIdentifier Device identifier.
1214
- * @param {number} mtu New MTU to negotiate.
1215
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1216
- * @returns {Promise<Device>} Device with updated MTU size. Default value is 23 (517 since Android 14).
1217
- */
1218
- requestMTUForDevice(deviceIdentifier: DeviceId, mtu: number, transactionId?: TransactionId): Promise<Device>
1219
-
1220
- // Mark: Connection management -------------------------------------------------------------------------------------
1221
-
1222
- /**
1223
- * Returns a list of known devices by their identifiers.
1224
- * @param {Array<DeviceId>} deviceIdentifiers List of device identifiers.
1225
- * @returns {Promise<Array<Device>>} List of known devices by their identifiers.
1226
- */
1227
- devices(deviceIdentifiers: Array<DeviceId>): Promise<Device[]>
1228
-
1229
- /**
1230
- * Returns a list of the peripherals (containing any of the specified services) currently connected to the system
1231
- * which have discovered services. Returned devices **may not be connected** to your application. Make sure to check
1232
- * if that's the case with function {@link #blemanagerisdeviceconnected|isDeviceConnected}.
1233
- * @param {Array<UUID>} serviceUUIDs List of service UUIDs. Device must contain at least one of them to be listed.
1234
- * @returns {Promise<Array<Device>>} List of known devices with discovered services as stated in the parameter.
1235
- */
1236
- connectedDevices(serviceUUIDs: Array<UUID>): Promise<Device[]>
1237
-
1238
- // Mark: Connection management -------------------------------------------------------------------------------------
1239
-
1240
- /**
1241
- * Connects to {@link Device} with provided ID.
1242
- *
1243
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1244
- * @param {?ConnectionOptions} options Platform specific options for connection establishment.
1245
- * @returns {Promise<Device>} Connected {@link Device} object if successful.
1246
- */
1247
- connectToDevice(deviceIdentifier: DeviceId, options?: ConnectionOptions): Promise<Device>
1248
-
1249
- /**
1250
- * Disconnects from {@link Device} if it's connected or cancels pending connection.
1251
- *
1252
- * @param {DeviceId} deviceIdentifier {@link Device} identifier to be closed.
1253
- * @returns {Promise<Device>} Returns closed {@link Device} when operation is successful.
1254
- */
1255
- cancelDeviceConnection(deviceIdentifier: DeviceId): Promise<Device>
1256
-
1257
- /**
1258
- * Monitors if {@link Device} was disconnected due to any errors or connection problems.
1259
- *
1260
- * @param {DeviceId} deviceIdentifier {@link Device} identifier to be monitored.
1261
- * @param {function(error?: BleError, device: ?Device)} listener - callback returning error as a reason of disconnection
1262
- * if available and {@link Device} object. If an error is null, that means the connection was terminated by
1263
- * {@link #blemanagercanceldeviceconnection|bleManager.cancelDeviceConnection()} call.
1264
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1265
- */
1266
- onDeviceDisconnected(
1267
- deviceIdentifier: DeviceId,
1268
- listener: (error: BleError | null, device: Device | null) => void
1269
- ): Subscription
1270
-
1271
- /**
1272
- * Check connection state of a {@link Device}.
1273
- *
1274
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1275
- * @returns {Promise<boolean>} Promise which emits `true` if device is connected, and `false` otherwise.
1276
- */
1277
- isDeviceConnected(deviceIdentifier: DeviceId): Promise<boolean>
1278
-
1279
- // Mark: Discovery -------------------------------------------------------------------------------------------------
1280
-
1281
- /**
1282
- * Discovers all {@link Service}s, {@link Characteristic}s and {@link Descriptor}s for {@link Device}.
1283
- *
1284
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1285
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1286
- * @returns {Promise<Device>} Promise which emits {@link Device} object if all available services and
1287
- * characteristics have been discovered.
1288
- */
1289
- discoverAllServicesAndCharacteristicsForDevice(
1290
- deviceIdentifier: DeviceId,
1291
- transactionId?: TransactionId
1292
- ): Promise<Device>
1293
-
1294
- // Mark: Service and characteristic getters ------------------------------------------------------------------------
1295
-
1296
- /**
1297
- * List of discovered {@link Service}s for {@link Device}.
1298
- *
1299
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1300
- * @returns {Promise<Array<Service>>} Promise which emits array of {@link Service} objects which are discovered for a
1301
- * {@link Device}.
1302
- */
1303
- servicesForDevice(deviceIdentifier: DeviceId): Promise<Service[]>
1304
-
1305
- /**
1306
- * List of discovered {@link Characteristic}s for given {@link Device} and {@link Service}.
1307
- *
1308
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1309
- * @param {UUID} serviceUUID {@link Service} UUID.
1310
- * @returns {Promise<Array<Characteristic>>} Promise which emits array of {@link Characteristic} objects which are
1311
- * discovered for a {@link Device} in specified {@link Service}.
1312
- */
1313
- characteristicsForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID): Promise<Characteristic[]>
1314
-
1315
- /**
1316
- * List of discovered {@link Descriptor}s for given {@link Device}, {@link Service} and {@link Characteristic}.
1317
- *
1318
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1319
- * @param {UUID} serviceUUID {@link Service} UUID.
1320
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1321
- * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1322
- * discovered for a {@link Device}, {@link Service} in specified {@link Characteristic}.
1323
- */
1324
- descriptorsForDevice(
1325
- deviceIdentifier: DeviceId,
1326
- serviceUUID: UUID,
1327
- characteristicUUID: UUID
1328
- ): Promise<Array<Descriptor>>
1329
-
1330
- // Mark: Characteristics operations --------------------------------------------------------------------------------
1331
-
1332
- /**
1333
- * Read {@link Characteristic} value.
1334
- *
1335
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1336
- * @param {UUID} serviceUUID {@link Service} UUID.
1337
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1338
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1339
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1340
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1341
- * UUID paths. Latest value of {@link Characteristic} will be stored inside returned object.
1342
- */
1343
- readCharacteristicForDevice(
1344
- deviceIdentifier: DeviceId,
1345
- serviceUUID: UUID,
1346
- characteristicUUID: UUID,
1347
- transactionId?: TransactionId
1348
- ): Promise<Characteristic>
1349
-
1350
- /**
1351
- * Write {@link Characteristic} value with response.
1352
- *
1353
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1354
- * @param {UUID} serviceUUID {@link Service} UUID.
1355
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1356
- * @param {Base64} base64Value Value in Base64 format.
1357
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1358
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1359
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1360
- * UUID paths. Latest value of characteristic may not be stored inside returned object.
1361
- */
1362
- writeCharacteristicWithResponseForDevice(
1363
- deviceIdentifier: DeviceId,
1364
- serviceUUID: UUID,
1365
- characteristicUUID: UUID,
1366
- base64Value: Base64,
1367
- transactionId?: TransactionId
1368
- ): Promise<Characteristic>
1369
-
1370
- /**
1371
- * Write {@link Characteristic} value without response.
1372
- *
1373
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1374
- * @param {UUID} serviceUUID {@link Service} UUID.
1375
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1376
- * @param {Base64} base64Value Value in Base64 format.
1377
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1378
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1379
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1380
- * UUID paths. Latest value of characteristic may not be stored inside returned object.
1381
- */
1382
- writeCharacteristicWithoutResponseForDevice(
1383
- deviceIdentifier: DeviceId,
1384
- serviceUUID: UUID,
1385
- characteristicUUID: UUID,
1386
- base64Value: Base64,
1387
- transactionId?: TransactionId
1388
- ): Promise<Characteristic>
1389
-
1390
- /**
1391
- * Monitor value changes of a {@link Characteristic}. If notifications are enabled they will be used
1392
- * in favour of indications.
1393
- *
1394
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1395
- * @param {UUID} serviceUUID {@link Service} UUID.
1396
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1397
- * @param {function(error?: BleError, characteristic?: Characteristic)} listener - callback which emits
1398
- * {@link Characteristic} objects with modified value for each notification.
1399
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1400
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1401
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1402
- */
1403
- monitorCharacteristicForDevice(
1404
- deviceIdentifier: DeviceId,
1405
- serviceUUID: UUID,
1406
- characteristicUUID: UUID,
1407
- listener: (error: BleError | null, characteristic: Characteristic | null) => void,
1408
- transactionId?: TransactionId
1409
- ): Subscription
1410
-
1411
- // Mark: Descriptors operations ----------------------------------------------------------------------------------
1412
-
1413
- /**
1414
- * Read {@link Descriptor} value.
1415
- *
1416
- * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1417
- * @param {UUID} serviceUUID {@link Service} UUID.
1418
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1419
- * @param {UUID} descriptorUUID {@link Descriptor} UUID.
1420
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1421
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1422
- * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
1423
- * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
1424
- */
1425
- readDescriptorForDevice(
1426
- deviceIdentifier: DeviceId,
1427
- serviceUUID: UUID,
1428
- characteristicUUID: UUID,
1429
- descriptorUUID: UUID,
1430
- transactionId?: string
1431
- ): Promise<Descriptor>
1432
-
1433
- /**
1434
- * Write {@link Descriptor} value.
1435
- *
1436
- * @param {DeviceId} deviceIdentifier Connected device identifier
1437
- * @param {UUID} serviceUUID Service UUID
1438
- * @param {UUID} characteristicUUID Characteristic UUID
1439
- * @param {UUID} descriptorUUID Descriptor UUID
1440
- * @param {Base64} valueBase64 Value to be set coded in Base64
1441
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1442
- * @returns {Promise<Descriptor>} Descriptor which saved passed value
1443
- */
1444
- writeDescriptorForDevice(
1445
- deviceIdentifier: DeviceId,
1446
- serviceUUID: UUID,
1447
- characteristicUUID: UUID,
1448
- descriptorUUID: UUID,
1449
- valueBase64: Base64,
1450
- transactionId?: string
1451
- ): Promise<Descriptor>
1452
- }
1453
-
1454
- // Device.js *********************************************************************************************************
1455
-
1456
- /**
1457
- * Device instance which can be retrieved only by calling
1458
- * {@link #blemanagerstartdevicescan|bleManager.startDeviceScan()}.
1459
- */
1460
- export class Device implements NativeDevice {
1461
- /**
1462
- * Device identifier: MAC address on Android and UUID on iOS.
1463
- */
1464
- id: DeviceId
1465
-
1466
- /**
1467
- * Device name if present
1468
- */
1469
- name: string | null
1470
-
1471
- /**
1472
- * Current Received Signal Strength Indication of device
1473
- */
1474
- rssi: number | null
1475
-
1476
- /**
1477
- * Current Maximum Transmission Unit for this device. When device is not connected
1478
- * default value of 23 is used.
1479
- */
1480
- mtu: number
1481
-
1482
- // Advertisement
1483
-
1484
- /**
1485
- * Device's custom manufacturer data. Its format is defined by manufacturer.
1486
- */
1487
- manufacturerData: Base64 | null
1488
-
1489
- /**
1490
- * Raw device scan data. When you have specific advertiser data,
1491
- * you can implement your own processing.
1492
- */
1493
- rawScanRecord: Base64
1494
-
1495
- /**
1496
- * Map of service UUIDs (as keys) with associated data (as values).
1497
- */
1498
- serviceData: { [uuid: string]: Base64 } | null
1499
-
1500
- /**
1501
- * List of available services visible during scanning.
1502
- */
1503
- serviceUUIDs: UUID[] | null
1504
-
1505
- /**
1506
- * User friendly name of device.
1507
- */
1508
- localName: string | null
1509
-
1510
- /**
1511
- * Transmission power level of device.
1512
- */
1513
- txPowerLevel: number | null
1514
-
1515
- /**
1516
- * List of solicited service UUIDs.
1517
- */
1518
- solicitedServiceUUIDs: UUID[] | null
1519
-
1520
- /**
1521
- * Is device connectable. [iOS only]
1522
- */
1523
- isConnectable: boolean | null
1524
-
1525
- /**
1526
- * List of overflow service UUIDs. [iOS only]
1527
- */
1528
- overflowServiceUUIDs: UUID[] | null
1529
-
1530
- /**
1531
- * Private constructor used to create {@link Device} object.
1532
- *
1533
- * @param {NativeDevice} nativeDevice Native device properties
1534
- * @param {BleManager} manager {@link BleManager} handle
1535
- * @private
1536
- */
1537
- constructor(nativeDevice: NativeDevice, manager: BleManager)
1538
-
1539
- /**
1540
- * {@link #blemanagerrequestconnectionpriorityfordevice|bleManager.requestConnectionPriorityForDevice()} with partially filled arguments.
1541
- *
1542
- * @param {ConnectionPriority} connectionPriority: Connection priority.
1543
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1544
- * @returns {Promise<Device>} Connected device.
1545
- */
1546
- requestConnectionPriority(connectionPriority: ConnectionPriority, transactionId?: TransactionId): Promise<Device>
1547
-
1548
- /**
1549
- * {@link #blemanagerreadrssifordevice|bleManager.readRSSIForDevice()} with partially filled arguments.
1550
- *
1551
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1552
- * @returns {Promise<Device>} This device with updated RSSI value.
1553
- */
1554
- readRSSI(transactionId?: TransactionId): Promise<Device>
1555
-
1556
- /**
1557
- * {@link #blemanagerrequestmtufordevice|bleManager.requestMTUForDevice()} with partially filled arguments.
1558
- *
1559
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1560
- * @returns {Promise<Device>} Device with updated MTU size. Default value is 23.
1561
- */
1562
- requestMTU(mtu: number, transactionId?: TransactionId): Promise<Device>
1563
-
1564
- /**
1565
- * {@link #blemanagerconnecttodevice|bleManager.connectToDevice()} with partially filled arguments.
1566
- *
1567
- * @param {?ConnectionOptions} options Platform specific options for connection establishment. Not used currently.
1568
- * @returns {Promise<Device>} Connected {@link Device} object if successful.
1569
- */
1570
- connect(options?: ConnectionOptions): Promise<Device>
1571
-
1572
- /**
1573
- * {@link #blemanagercanceldeviceconnection|bleManager.cancelDeviceConnection()} with partially filled arguments.
1574
- *
1575
- * @returns {Promise<Device>} Returns closed {@link Device} when operation is successful.
1576
- */
1577
- cancelConnection(): Promise<Device>
1578
-
1579
- /**
1580
- * {@link #blemanagerisdeviceconnected|bleManager.isDeviceConnected()} with partially filled arguments.
1581
- *
1582
- * @returns {Promise<boolean>} Promise which emits `true` if device is connected, and `false` otherwise.
1583
- */
1584
- isConnected(): Promise<boolean>
1585
-
1586
- /**
1587
- * {@link #blemanagerondevicedisconnected|bleManager.onDeviceDisconnected()} with partially filled arguments.
1588
- *
1589
- * @param {function(error: ?BleError, device: Device)} listener callback returning error as a reason of disconnection
1590
- * if available and {@link Device} object. If an error is null, that means the connection was terminated by
1591
- * {@link #blemanagercanceldeviceconnection|bleManager.cancelDeviceConnection()} call.
1592
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1593
- */
1594
- onDisconnected(listener: (error: BleError | null, device: Device) => void): Subscription
1595
-
1596
- /**
1597
- * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|bleManager.discoverAllServicesAndCharacteristicsForDevice()} with partially filled arguments.
1598
- *
1599
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1600
- * @returns {Promise<Device>} Promise which emits {@link Device} object if all available services and
1601
- * characteristics have been discovered.
1602
- */
1603
- discoverAllServicesAndCharacteristics(transactionId?: TransactionId): Promise<Device>
1604
-
1605
- /**
1606
- * {@link #blemanagerservicesfordevice|bleManager.servicesForDevice()} with partially filled arguments.
1607
- *
1608
- * @returns {Promise<Service[]>} Promise which emits array of {@link Service} objects which are discovered by this
1609
- * device.
1610
- */
1611
- services(): Promise<Service[]>
1612
-
1613
- /**
1614
- * {@link #blemanagercharacteristicsfordevice|bleManager.characteristicsForDevice()} with partially filled arguments.
1615
- *
1616
- * @param {UUID} serviceUUID {@link Service} UUID.
1617
- * @returns {Promise<Characteristic[]>} Promise which emits array of {@link Characteristic} objects which are
1618
- * discovered for a {@link Device} in specified {@link Service}.
1619
- */
1620
- characteristicsForService(serviceUUID: string): Promise<Characteristic[]>
1621
-
1622
- /**
1623
- * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
1624
- *
1625
- * @param {UUID} serviceUUID {@link Service} UUID.
1626
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1627
- * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1628
- * discovered for this {@link Characteristic}.
1629
- */
1630
- descriptorsForService(serviceUUID: UUID, characteristicUUID: UUID): Promise<Array<Descriptor>>
1631
-
1632
- /**
1633
- * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
1634
- *
1635
- * @param {UUID} serviceUUID {@link Service} UUID.
1636
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1637
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1638
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1639
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1640
- * UUID paths. Latest value of {@link Characteristic} will be stored inside returned object.
1641
- */
1642
- readCharacteristicForService(
1643
- serviceUUID: UUID,
1644
- characteristicUUID: UUID,
1645
- transactionId?: TransactionId
1646
- ): Promise<Characteristic>
1647
-
1648
- /**
1649
- * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
1650
- *
1651
- * @param {UUID} serviceUUID {@link Service} UUID.
1652
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1653
- * @param {Base64} valueBase64 Value in Base64 format.
1654
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1655
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1656
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1657
- * UUID paths. Latest value of characteristic may not be stored inside returned object.
1658
- */
1659
- writeCharacteristicWithResponseForService(
1660
- serviceUUID: UUID,
1661
- characteristicUUID: UUID,
1662
- valueBase64: Base64,
1663
- transactionId?: TransactionId
1664
- ): Promise<Characteristic>
1665
-
1666
- /**
1667
- * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
1668
- *
1669
- * @param {UUID} serviceUUID {@link Service} UUID.
1670
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1671
- * @param {Base64} valueBase64 Value in Base64 format.
1672
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1673
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1674
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1675
- * UUID paths. Latest value of characteristic may not be stored inside returned object.
1676
- */
1677
- writeCharacteristicWithoutResponseForService(
1678
- serviceUUID: UUID,
1679
- characteristicUUID: UUID,
1680
- valueBase64: Base64,
1681
- transactionId?: TransactionId
1682
- ): Promise<Characteristic>
1683
-
1684
- /**
1685
- * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
1686
- *
1687
- * @param {UUID} serviceUUID {@link Service} UUID.
1688
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1689
- * @param {function(error: ?BleError, characteristic: ?Characteristic)} listener - callback which emits
1690
- * {@link Characteristic} objects with modified value for each notification.
1691
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1692
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1693
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1694
- */
1695
- monitorCharacteristicForService(
1696
- serviceUUID: UUID,
1697
- characteristicUUID: UUID,
1698
- listener: (error: BleError | null, characteristic: Characteristic | null) => void,
1699
- transactionId?: TransactionId
1700
- ): Subscription
1701
-
1702
- /**
1703
- * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
1704
- *
1705
- * @param {UUID} serviceUUID {@link Service} UUID.
1706
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1707
- * @param {UUID} descriptorUUID {@link Descriptor} UUID.
1708
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1709
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1710
- * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
1711
- * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
1712
- */
1713
- readDescriptorForService(
1714
- serviceUUID: UUID,
1715
- characteristicUUID: UUID,
1716
- descriptorUUID: UUID,
1717
- transactionId?: string
1718
- ): Promise<Descriptor>
1719
-
1720
- /**
1721
- * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
1722
- *
1723
- * @param {UUID} serviceUUID {@link Service} UUID.
1724
- * @param {UUID} characteristicUUID Characteristic UUID
1725
- * @param {UUID} descriptorUUID Descriptor UUID
1726
- * @param {Base64} valueBase64 Value to be set coded in Base64
1727
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1728
- * @returns {Promise<Descriptor>} Descriptor which saved passed value.
1729
- */
1730
- writeDescriptorForService(
1731
- serviceUUID: UUID,
1732
- characteristicUUID: UUID,
1733
- descriptorUUID: UUID,
1734
- valueBase64: Base64,
1735
- transactionId?: string
1736
- ): Promise<Descriptor>
1737
- }
1738
-
1739
- // Service.js ********************************************************************************************************
1740
-
1741
- /**
1742
- * Service object.
1743
- */
1744
- export class Service implements NativeService {
1745
- /**
1746
- * Service unique identifier
1747
- */
1748
- id: Identifier
1749
-
1750
- /**
1751
- * Service UUID
1752
- */
1753
- uuid: UUID
1754
-
1755
- /**
1756
- * Device's ID to which service belongs
1757
- */
1758
- deviceID: DeviceId
1759
-
1760
- /**
1761
- * Value indicating whether the type of service is primary or secondary.
1762
- */
1763
- isPrimary: boolean
1764
-
1765
- /**
1766
- * Private constructor used to create {@link Service} object.
1767
- *
1768
- * @param {NativeService} nativeService NativeService properties to be copied.
1769
- * @param {BleManager} manager Current BleManager instance.
1770
- * @private
1771
- * @ignore
1772
- */
1773
- constructor(nativeService: NativeService, manager: BleManager)
1774
-
1775
- /**
1776
- * {@link #blemanagercharacteristicsfordevice|bleManager.characteristicsForDevice()} with partially filled arguments.
1777
- *
1778
- * @returns {Promise<Array<Characteristic>>} Promise which emits array of {@link Characteristic} objects which are
1779
- * discovered for this service.
1780
- */
1781
- characteristics(): Promise<Characteristic[]>
1782
-
1783
- /**
1784
- * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
1785
- *
1786
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1787
- * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1788
- * discovered for this {@link Service} in specified {@link Characteristic}.
1789
- */
1790
- descriptorsForCharacteristic(characteristicUUID: UUID): Promise<Array<Descriptor>>
1791
-
1792
- /**
1793
- * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
1794
- *
1795
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1796
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1797
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1798
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1799
- * UUID path. Latest value of {@link Characteristic} will be stored inside returned object.
1800
- */
1801
- readCharacteristic(characteristicUUID: UUID, transactionId?: string): Promise<Characteristic>
1802
-
1803
- /**
1804
- * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
1805
- *
1806
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1807
- * @param {Base64} valueBase64 Value in Base64 format.
1808
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1809
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1810
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1811
- * UUID path. Latest value of characteristic may not be stored inside returned object.
1812
- */
1813
- writeCharacteristicWithResponse(
1814
- characteristicUUID: UUID,
1815
- valueBase64: Base64,
1816
- transactionId?: string
1817
- ): Promise<Characteristic>
1818
-
1819
- /**
1820
- * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
1821
- *
1822
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1823
- * @param {Base64} valueBase64 Value in Base64 format.
1824
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1825
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1826
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1827
- * UUID path. Latest value of characteristic may not be stored inside returned object.
1828
- */
1829
- writeCharacteristicWithoutResponse(
1830
- characteristicUUID: UUID,
1831
- valueBase64: Base64,
1832
- transactionId?: string
1833
- ): Promise<Characteristic>
1834
-
1835
- /**
1836
- * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
1837
- *
1838
- * @param {UUID} characteristicUUID - {@link Characteristic} UUID.
1839
- * @param {function(error?: BleError, characteristic?: Characteristic)} listener callback which emits
1840
- * {@link Characteristic} objects with modified value for each notification.
1841
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1842
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1843
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1844
- */
1845
- monitorCharacteristic(
1846
- characteristicUUID: UUID,
1847
- listener: (error: BleError | null, characteristic: Characteristic | null) => void,
1848
- transactionId?: string
1849
- ): Subscription
1850
-
1851
- /**
1852
- * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
1853
- *
1854
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1855
- * @param {UUID} descriptorUUID {@link Descriptor} UUID.
1856
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1857
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1858
- * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
1859
- * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
1860
- */
1861
- readDescriptorForCharacteristic(
1862
- characteristicUUID: UUID,
1863
- descriptorUUID: UUID,
1864
- transactionId?: string
1865
- ): Promise<Descriptor>
1866
-
1867
- /**
1868
- * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
1869
- *
1870
- * @param {UUID} characteristicUUID Characteristic UUID
1871
- * @param {UUID} descriptorUUID Descriptor UUID
1872
- * @param {Base64} valueBase64 Value to be set coded in Base64
1873
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1874
- * @returns {Promise<Descriptor>} Descriptor which saved passed value.
1875
- */
1876
- writeDescriptorForCharacteristic(
1877
- characteristicUUID: UUID,
1878
- descriptorUUID: UUID,
1879
- valueBase64: Base64,
1880
- transactionId?: string
1881
- ): Promise<Descriptor>
1882
- }
1883
-
1884
- // Characteristic.js *************************************************************************************************
1885
-
1886
- /**
1887
- * Characteristic object.
1888
- */
1889
- export class Characteristic implements NativeCharacteristic {
1890
- /**
1891
- * Characteristic unique identifier
1892
- */
1893
- id: Identifier
1894
-
1895
- /**
1896
- * Characteristic UUID
1897
- */
1898
- uuid: UUID
1899
-
1900
- /**
1901
- * Service's ID to which characteristic belongs
1902
- */
1903
- serviceID: Identifier
1904
-
1905
- /**
1906
- * Service's UUID to which characteristic belongs
1907
- */
1908
- serviceUUID: UUID
1909
-
1910
- /**
1911
- * Device's ID to which characteristic belongs
1912
- */
1913
- deviceID: DeviceId
1914
-
1915
- /**
1916
- * True if characteristic can be read
1917
- */
1918
- isReadable: boolean
1919
-
1920
- /**
1921
- * True if characteristic can be written with response
1922
- */
1923
- isWritableWithResponse: boolean
1924
-
1925
- /**
1926
- * True if characteristic can be written without response
1927
- */
1928
- isWritableWithoutResponse: boolean
1929
-
1930
- /**
1931
- * True if characteristic can monitor value changes.
1932
- */
1933
- isNotifiable: boolean
1934
-
1935
- /**
1936
- * True if characteristic is monitoring value changes without ACK.
1937
- */
1938
- isNotifying: boolean
1939
-
1940
- /**
1941
- * True if characteristic is monitoring value changes with ACK.
1942
- */
1943
- isIndicatable: boolean
1944
-
1945
- /**
1946
- * Characteristic value if present
1947
- */
1948
- value: Base64 | null
1949
-
1950
- /**
1951
- * Private constructor used to create instance of {@link Characteristic}.
1952
- * @param {NativeCharacteristic} nativeCharacteristic NativeCharacteristic
1953
- * @param {BleManager} manager BleManager
1954
- * @private
1955
- */
1956
- constructor(nativeCharacteristic: NativeCharacteristic, manager: BleManager)
1957
-
1958
- /**
1959
- * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
1960
- *
1961
- * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1962
- * discovered for this {@link Characteristic}.
1963
- */
1964
- descriptors(): Promise<Array<Descriptor>>
1965
-
1966
- /**
1967
- * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
1968
- *
1969
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1970
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1971
- * @returns {Promise<Characteristic>} Promise which emits this {@link Characteristic}. Latest value will be stored
1972
- * inside returned object.
1973
- */
1974
- read(transactionId?: string): Promise<Characteristic>
1975
-
1976
- /**
1977
- * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
1978
- *
1979
- * @param {Base64} valueBase64 Value in Base64 format.
1980
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1981
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1982
- * @returns {Promise<Characteristic>} Promise which emits this {@link Characteristic}. Latest value may
1983
- * not be stored inside returned object.
1984
- */
1985
- writeWithResponse(valueBase64: Base64, transactionId?: string): Promise<Characteristic>
1986
-
1987
- /**
1988
- * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
1989
- *
1990
- * @param {Base64} valueBase64 Value in Base64 format.
1991
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1992
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1993
- * @returns {Promise<Characteristic>} Promise which emits this {@link Characteristic}. Latest value may
1994
- * not be stored inside returned object.
1995
- */
1996
- writeWithoutResponse(valueBase64: Base64, transactionId?: string): Promise<Characteristic>
1997
-
1998
- /**
1999
- * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
2000
- *
2001
- * @param {function(error?: BleError, characteristic?: Characteristic)} listener callback which emits
2002
- * this {@link Characteristic} with modified value for each notification.
2003
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
2004
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
2005
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
2006
- */
2007
- monitor(
2008
- listener: (error: BleError | null, characteristic: Characteristic | null) => void,
2009
- transactionId?: string
2010
- ): Subscription
2011
-
2012
- /**
2013
- * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
2014
- *
2015
- * @param {UUID} descriptorUUID {@link Descriptor} UUID.
2016
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
2017
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
2018
- * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
2019
- * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
2020
- */
2021
- readDescriptor(descriptorUUID: UUID, transactionId?: string): Promise<Descriptor>
2022
-
2023
- /**
2024
- * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
2025
- *
2026
- * @param {UUID} descriptorUUID Descriptor UUID
2027
- * @param {Base64} valueBase64 Value to be set coded in Base64
2028
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
2029
- * @returns {Promise<Descriptor>} Descriptor which saved passed value.
2030
- */
2031
- writeDescriptor(descriptorUUID: UUID, valueBase64: Base64, transactionId?: string): Promise<Descriptor>
2032
- }
2033
-
2034
- // Descriptor.js *************************************************************************************************
2035
-
2036
- /**
2037
- * Descriptor object.
2038
- */
2039
- export class Descriptor implements NativeDescriptor {
2040
- /**
2041
- * Internal BLE Manager handle
2042
- * @private
2043
- */
2044
- _manager: BleManager
2045
-
2046
- /**
2047
- * Descriptor unique identifier
2048
- */
2049
- id: Identifier
2050
-
2051
- /**
2052
- * Descriptor UUID
2053
- */
2054
- uuid: UUID
2055
-
2056
- /**
2057
- * Characteristic's ID to which descriptor belongs
2058
- */
2059
- characteristicID: Identifier
2060
-
2061
- /**
2062
- * Characteristic's UUID to which descriptor belongs
2063
- */
2064
- characteristicUUID: UUID
2065
-
2066
- /**
2067
- * Service's ID to which descriptor belongs
2068
- */
2069
- serviceID: Identifier
2070
-
2071
- /**
2072
- * Service's UUID to which descriptor belongs
2073
- */
2074
- serviceUUID: UUID
2075
-
2076
- /**
2077
- * Device's ID to which descriptor belongs
2078
- */
2079
- deviceID: DeviceId
2080
-
2081
- /**
2082
- * Descriptor value if present
2083
- */
2084
- value: Base64 | null
2085
-
2086
- /**
2087
- * Private constructor used to create instance of {@link Descriptor}.
2088
- * @param {NativeDescriptor} nativeDescriptor NativeDescriptor
2089
- * @param {BleManager} manager BleManager
2090
- * @private
2091
- */
2092
- constructor(nativeDescriptor: NativeDescriptor, manager: BleManager)
2093
-
2094
- /**
2095
- * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
2096
- *
2097
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
2098
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
2099
- * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
2100
- * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
2101
- */
2102
- read(transactionId?: string): Promise<Descriptor>
2103
-
2104
- /**
2105
- * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
2106
- *
2107
- * @param {Base64} valueBase64 Value to be set coded in Base64
2108
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
2109
- * @returns {Promise<Descriptor>} Descriptor which saved passed value.
2110
- */
2111
- write(valueBase64: Base64, transactionId?: string): Promise<Descriptor>
2112
- }
2113
- }
1
+ declare module 'react-native-ble-plx' {
2
+ // TypeDefinition.js *************************************************************************************************
3
+
4
+ /**
5
+ * [Android only] ConnectionOptions parameter to describe when to call BluetoothGatt.refresh()
6
+ */
7
+ export type RefreshGattMoment = 'OnConnected'
8
+ /**
9
+ * Base64 value
10
+ */
11
+ export type Base64 = string
12
+ /**
13
+ * Bluetooth UUID
14
+ */
15
+ export type UUID = string
16
+ /**
17
+ * Unique identifier for BLE objects.
18
+ */
19
+ export type Identifier = number
20
+ /**
21
+ * Bluetooth device id.
22
+ */
23
+ export type DeviceId = string
24
+ /**
25
+ * Transaction identifier. All transaction identifiers in numeric form are reserved for internal use.
26
+ */
27
+ export type TransactionId = string
28
+
29
+ /**
30
+ * Subscription
31
+ * @interface
32
+ */
33
+ export interface Subscription {
34
+ /**
35
+ * Removes subscription
36
+ * @memberof Subscription
37
+ * @ignore
38
+ */
39
+ remove(): void
40
+ }
41
+
42
+ /**
43
+ * Type of error code mapping table
44
+ */
45
+ export type BleErrorCodeMessageMapping = { [key in BleErrorCode]: string }
46
+
47
+ /**
48
+ * Options which can be passed to when creating BLE Manager
49
+ */
50
+ export interface BleManagerOptions {
51
+ /**
52
+ * BLE State restoration identifier used to restore state.
53
+ * @memberof BleManagerOptions
54
+ * @instance
55
+ */
56
+ restoreStateIdentifier?: string
57
+
58
+ /**
59
+ * Optional function which is used to properly restore state of your BLE Manager. Callback
60
+ * is emitted in the beginning of BleManager creation and optional {@link BleRestoreState}
61
+ * is passed. When value is `null` application is launching for the first time, otherwise
62
+ * it contains saved state which may be used by developer to continue working with
63
+ * connected peripherals.
64
+ * @memberof BleManagerOptions
65
+ * @instance
66
+ */
67
+ restoreStateFunction?: (restoredState: BleRestoredState | null) => void
68
+
69
+ /**
70
+ * Optional mapping of error codes to error messages. Uses {@link BleErrorCodeMessage}
71
+ * by default.
72
+ *
73
+ * To override logging UUIDs or MAC adresses in error messages copy the original object
74
+ * and overwrite values of interest to you.
75
+ *
76
+ * @memberof BleManagerOptions
77
+ * @instance
78
+ */
79
+ errorCodesToMessagesMapping?: BleErrorCodeMessageMapping
80
+ }
81
+
82
+ /**
83
+ * Object representing information about restored BLE state after application relaunch.
84
+ */
85
+ export interface BleRestoredState {
86
+ /**
87
+ * List of connected devices after state restoration.
88
+ * @type {Array<Device>}
89
+ * @instance
90
+ * @memberof BleRestoredState
91
+ */
92
+ connectedPeripherals: Device[]
93
+ }
94
+
95
+ /**
96
+ * Scan mode for Bluetooth LE scan.
97
+ */
98
+ export enum ScanMode {
99
+ /**
100
+ * A special Bluetooth LE scan mode. Applications using this scan mode will passively listen for
101
+ * other scan results without starting BLE scans themselves.
102
+ */
103
+ Opportunistic = -1,
104
+
105
+ /**
106
+ * Perform Bluetooth LE scan in low power mode. This is the default scan mode as it consumes the
107
+ * least power. [default value]
108
+ */
109
+ LowPower = 0,
110
+
111
+ /**
112
+ * Perform Bluetooth LE scan in balanced power mode. Scan results are returned at a rate that
113
+ * provides a good trade-off between scan frequency and power consumption.
114
+ */
115
+ Balanced = 1,
116
+
117
+ /**
118
+ * Scan using highest duty cycle. It's recommended to only use this mode when the application is
119
+ * running in the foreground.
120
+ */
121
+ LowLatency = 2
122
+ }
123
+
124
+ /**
125
+ * The enum of BLE match mode.
126
+ */
127
+ export enum MatchMode {
128
+ /**
129
+ * Aggressive mode
130
+ */
131
+ Aggressive = 1,
132
+
133
+ /**
134
+ * Sticky mode
135
+ */
136
+ Sticky = 2
137
+ }
138
+
139
+ /**
140
+ * Phy type used during scan.
141
+ */
142
+ export enum PhyType {
143
+ /**
144
+ * Use 1M phy for scanning.
145
+ */
146
+ LE_1M = 1,
147
+
148
+ /**
149
+ * Use all supported Phys for scanning.
150
+ */
151
+ LE_All_Supported = 255
152
+ }
153
+
154
+ /**
155
+ * Scan callback type for Bluetooth LE scan.
156
+ * @name ScanCallbackType
157
+ */
158
+ export enum ScanCallbackType {
159
+ /**
160
+ * Trigger a callback for every Bluetooth advertisement found that matches the filter criteria.
161
+ * If no filter is active, all advertisement packets are reported. [default value]
162
+ */
163
+ AllMatches = 1,
164
+
165
+ /**
166
+ * A result callback is only triggered for the first advertisement packet received that matches
167
+ * the filter criteria.
168
+ */
169
+ FirstMatch = 2,
170
+
171
+ /**
172
+ * Receive a callback when advertisements are no longer received from a device that has been
173
+ * previously reported by a first match callback.
174
+ */
175
+ MatchLost = 4
176
+ }
177
+
178
+ /**
179
+ * Options which can be passed to scanning function
180
+ * @name ScanOptions
181
+ */
182
+ export interface ScanOptions {
183
+ /**
184
+ * By allowing duplicates scanning records are received more frequently [iOS only]
185
+ */
186
+ allowDuplicates?: boolean
187
+ /**
188
+ * Scan mode for Bluetooth LE scan [Android and Harmony]
189
+ */
190
+ scanMode?: ScanMode
191
+ /**
192
+ * Scan callback type for Bluetooth LE scan [Android only]
193
+ */
194
+ callbackType?: ScanCallbackType
195
+ /**
196
+ * Use legacyScan (default true) [Android only]
197
+ * https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setLegacy(boolean)
198
+ */
199
+ legacyScan?: boolean
200
+ /**
201
+ * Time of delay for reporting the scan result [Harmony only]
202
+ */
203
+ interval?: number;
204
+ /**
205
+ * Match mode for Bluetooth LE scan filters hardware match [Harmony only]
206
+ */
207
+ matchMode?: MatchMode;
208
+ /**
209
+ * Physical Layer used during scan [Harmony only]
210
+ */
211
+ phyType?: PhyType;
212
+ }
213
+
214
+ /**
215
+ * Connection specific options to be passed before connection happen. [Not used]
216
+ */
217
+ export interface ConnectionOptions {
218
+ /**
219
+ * Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device
220
+ * becomes available (true). [Android only]
221
+ * @memberof ConnectionOptions
222
+ * @instance
223
+ */
224
+ autoConnect?: boolean
225
+
226
+ /**
227
+ * Whether MTU size will be negotiated to this value. It is not guaranteed to get it after connection is successful.
228
+ *
229
+ * @memberof ConnectionOptions
230
+ * @instance
231
+ */
232
+ requestMTU?: number
233
+
234
+ /**
235
+ * Whether action will be taken to reset services cache. This option may be useful when a peripheral's firmware was
236
+ * updated and it's services/characteristics were added/removed/altered. [Android only]
237
+ * {@link https://stackoverflow.com/questions/22596951/how-to-programmatically-force-bluetooth-low-energy-service-discovery-on-android}
238
+ * @memberof ConnectionOptions
239
+ * @instance
240
+ */
241
+ refreshGatt?: RefreshGattMoment
242
+
243
+ /**
244
+ * Number of milliseconds after connection is automatically timed out. In case of race condition were connection is
245
+ * established right after timeout event, device will be disconnected immediately. Time out may happen earlier then
246
+ * specified due to OS specific behavior.
247
+ *
248
+ * @memberof ConnectionOptions
249
+ * @instance
250
+ */
251
+ timeout?: number
252
+ }
253
+
254
+ /**
255
+ * Device Bluetooth Low Energy state. It's keys are used to check {@link #blemanagerstate} values
256
+ * received by {@link BleManager}
257
+ */
258
+ export enum State {
259
+ /**
260
+ * The current state of the manager is unknown; an update is imminent.
261
+ */
262
+ Unknown = 'Unknown',
263
+ /**
264
+ * The connection with the system service was momentarily lost; an update is imminent.
265
+ */
266
+ Resetting = 'Resetting',
267
+ /**
268
+ * The platform does not support Bluetooth low energy.
269
+ */
270
+ Unsupported = 'Unsupported',
271
+ /**
272
+ * The app is not authorized to use Bluetooth low energy.
273
+ */
274
+ Unauthorized = 'Unauthorized',
275
+ /**
276
+ * Bluetooth is currently powered off.
277
+ */
278
+ PoweredOff = 'PoweredOff',
279
+ /**
280
+ * Bluetooth is currently powered on and available to use.
281
+ */
282
+ PoweredOn = 'PoweredOn'
283
+ }
284
+
285
+ /**
286
+ * Native module logging log level. By default it is set to None.
287
+ * @name LogLevel
288
+ */
289
+ export enum LogLevel {
290
+ /**
291
+ * Logging in native module is disabled
292
+ */
293
+ None = 'None',
294
+ /**
295
+ * All logs in native module are shown
296
+ */
297
+ Verbose = 'Verbose',
298
+ /**
299
+ * Only debug logs and of higher importance are shown in native module.
300
+ */
301
+ Debug = 'Debug',
302
+ /**
303
+ * Only info logs and of higher importance are shown in native module.
304
+ */
305
+ Info = 'Info',
306
+ /**
307
+ * Only warning logs and of higher importance are shown in native module.
308
+ */
309
+ Warning = 'Warning',
310
+ /**
311
+ * Only error logs and of higher importance are shown in native module.
312
+ */
313
+ Error = 'Error'
314
+ }
315
+
316
+ /**
317
+ * Connection priority of BLE link determining the balance between power consumption and data throughput.
318
+ * @name ConnectionPriority
319
+ */
320
+ export enum ConnectionPriority {
321
+ /**
322
+ * Default, recommended option balanced between power consumption and data throughput.
323
+ */
324
+ Balanced = 0,
325
+ /**
326
+ * High priority, low latency connection, which increases transfer speed at the expense of power consumption.
327
+ */
328
+ High = 1,
329
+ /**
330
+ * Low power, reduced data rate connection setup.
331
+ */
332
+ LowPower = 2
333
+ }
334
+
335
+ // Utils.js **********************************************************************************************************
336
+
337
+ /**
338
+ * Converts UUID to full 128bit, lowercase format which should be used to compare UUID values.
339
+ *
340
+ * @param {UUID} uuid 16bit, 32bit or 128bit UUID.
341
+ * @returns {UUID} 128bit lowercase UUID.
342
+ */
343
+ export function fullUUID(uuid: UUID): UUID
344
+
345
+ // BleError.js *******************************************************************************************************
346
+
347
+ export interface NativeBleError {
348
+ errorCode: BleErrorCode
349
+ attErrorCode: BleATTErrorCode | null
350
+ iosErrorCode: BleIOSErrorCode | null
351
+ androidErrorCode: BleAndroidErrorCode | null
352
+ reason: string | null
353
+
354
+ deviceID?: string
355
+ serviceUUID?: string
356
+ characteristicUUID?: string
357
+ descriptorUUID?: string
358
+ internalMessage?: string
359
+ }
360
+
361
+ /**
362
+ * BleError is an error class which is guaranteed to be thrown by all functions of this
363
+ * library. It contains additional properties which help to identify problems in
364
+ * platform independent way.
365
+ */
366
+ export class BleError extends Error {
367
+ /**
368
+ * Platform independent error code. Possible values are defined in {@link BleErrorCode}.
369
+ */
370
+ errorCode: BleErrorCode
371
+
372
+ /**
373
+ * Platform independent error code related to ATT errors.
374
+ */
375
+ attErrorCode: BleATTErrorCode | null
376
+
377
+ /**
378
+ * iOS specific error code (if not an ATT error).
379
+ */
380
+ iosErrorCode: BleIOSErrorCode | null
381
+
382
+ /**
383
+ * Android specific error code (if not an ATT error).
384
+ */
385
+ androidErrorCode: BleAndroidErrorCode | null
386
+
387
+ /**
388
+ * Platform specific error message.
389
+ */
390
+ reason: string | null
391
+
392
+ constructor(nativeBleError: NativeBleError | string, errorMessageMapping: BleErrorCodeMessageMapping)
393
+ }
394
+
395
+ /**
396
+ * Platform independent error code map adjusted to this library's use cases.
397
+ */
398
+ export enum BleErrorCode {
399
+ // Implementation specific errors ----------------------------------------------------------------------------------
400
+ /**
401
+ * This error can be thrown when unexpected error occurred and in most cases it is related to implementation bug.
402
+ * Original message is available in {@link #bleerrorreason|reason} property.
403
+ */
404
+ UnknownError = 0,
405
+ /**
406
+ * Current promise failed to finish due to BleManager shutdown. It means that user called
407
+ * {@link #blemanagerdestroy|manager.destroy()} function before all operations completed.
408
+ */
409
+ BluetoothManagerDestroyed = 1,
410
+ /**
411
+ * Promise was explicitly cancelled by a user with {@link #blemanagercanceltransaction|manager.cancelTransaction()}
412
+ * function call.
413
+ */
414
+ OperationCancelled = 2,
415
+ /**
416
+ * Operation timed out and was cancelled.
417
+ */
418
+ OperationTimedOut = 3,
419
+ /**
420
+ * Native module couldn't start operation due to internal state, which doesn't allow to do that.
421
+ */
422
+ OperationStartFailed = 4,
423
+ /**
424
+ * Invalid UUIDs or IDs were passed to API call.
425
+ */
426
+ InvalidIdentifiers = 5,
427
+
428
+ // Bluetooth global states -----------------------------------------------------------------------------------------
429
+ /**
430
+ * Bluetooth is not supported for this particular device. It may happen on iOS simulator for example.
431
+ */
432
+ BluetoothUnsupported = 100,
433
+ /**
434
+ * There are no granted permissions which allow to use BLE functionality. On Android it may require
435
+ * android.permission.ACCESS_COARSE_LOCATION permission or android.permission.ACCESS_FINE_LOCATION permission.
436
+ */
437
+ BluetoothUnauthorized = 101,
438
+ /**
439
+ * BLE is powered off on device. All previous operations and their state is invalidated.
440
+ */
441
+ BluetoothPoweredOff = 102,
442
+ /**
443
+ * BLE stack is in unspecified state.
444
+ */
445
+ BluetoothInUnknownState = 103,
446
+ /**
447
+ * BLE stack is resetting.
448
+ */
449
+ BluetoothResetting = 104,
450
+ /**
451
+ * BLE state change failed.
452
+ */
453
+ BluetoothStateChangeFailed = 105,
454
+
455
+ // Peripheral errors. ----------------------------------------------------------------------------------------------
456
+ /**
457
+ * Couldn't connect to specified device.
458
+ */
459
+ DeviceConnectionFailed = 200,
460
+ /**
461
+ * Device was disconnected.
462
+ */
463
+ DeviceDisconnected = 201,
464
+ /**
465
+ * Couldn't read RSSI from device.
466
+ */
467
+ DeviceRSSIReadFailed = 202,
468
+ /**
469
+ * Device is already connected. It is not allowed to connect twice to the same device.
470
+ */
471
+ DeviceAlreadyConnected = 203,
472
+ /**
473
+ * Couldn't find device with specified ID.
474
+ */
475
+ DeviceNotFound = 204,
476
+ /**
477
+ * Operation failed because device has to be connected to perform it.
478
+ */
479
+ DeviceNotConnected = 205,
480
+ /**
481
+ * Device could not change MTU value.
482
+ */
483
+ DeviceMTUChangeFailed = 206,
484
+
485
+ // Services --------------------------------------------------------------------------------------------------------
486
+ /**
487
+ * Couldn't discover services for specified device.
488
+ */
489
+ ServicesDiscoveryFailed = 300,
490
+ /**
491
+ * Couldn't discover included services for specified service.
492
+ */
493
+ IncludedServicesDiscoveryFailed = 301,
494
+ /**
495
+ * Service with specified ID or UUID couldn't be found. User may need to call
496
+ * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
497
+ * to cache them.
498
+ */
499
+ ServiceNotFound = 302,
500
+ /**
501
+ * Services were not discovered. User may need to call
502
+ * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
503
+ * to cache them.
504
+ */
505
+ ServicesNotDiscovered = 303,
506
+
507
+ // Characteristics -------------------------------------------------------------------------------------------------
508
+ /**
509
+ * Couldn't discover characteristics for specified service.
510
+ */
511
+ CharacteristicsDiscoveryFailed = 400,
512
+ /**
513
+ * Couldn't write to specified characteristic. Make sure that
514
+ * {@link #characteristiciswritablewithresponse|characteristic.isWritableWithResponse}
515
+ * or {@link #characteristiciswritablewithoutresponse|characteristic.isWritableWithoutResponse} is set to true.
516
+ */
517
+ CharacteristicWriteFailed = 401,
518
+ /**
519
+ * Couldn't read from specified characteristic. Make sure that
520
+ * {@link #characteristicisreadable|characteristic.isReadable} is set to true.
521
+ */
522
+ CharacteristicReadFailed = 402,
523
+ /**
524
+ * Couldn't set notification or indication for specified characteristic. Make sure that
525
+ * {@link #characteristicisnotifiable|characteristic.isNotifiable} or
526
+ * {@link #characteristicisindicatable|characteristic.isIndicatable} is set to true.
527
+ */
528
+ CharacteristicNotifyChangeFailed = 403,
529
+ /**
530
+ * Characteristic with specified ID or UUID couldn't be found. User may need to call
531
+ * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
532
+ * to cache them.
533
+ */
534
+ CharacteristicNotFound = 404,
535
+ /**
536
+ * Characteristic were not discovered for specified service. User may need to call
537
+ * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
538
+ * to cache them.
539
+ */
540
+ CharacteristicsNotDiscovered = 405,
541
+ /**
542
+ * Invalid Base64 format was passed to characteristic API function call.
543
+ */
544
+ CharacteristicInvalidDataFormat = 406,
545
+
546
+ // Characteristics -------------------------------------------------------------------------------------------------
547
+ /**
548
+ * Couldn't discover descriptor for specified characteristic.
549
+ */
550
+ DescriptorsDiscoveryFailed = 500,
551
+ /**
552
+ * Couldn't write to specified descriptor.
553
+ */
554
+ DescriptorWriteFailed = 501,
555
+ /**
556
+ * Couldn't read from specified descriptor.
557
+ */
558
+ DescriptorReadFailed = 502,
559
+ /**
560
+ * Couldn't find specified descriptor.
561
+ */
562
+ DescriptorNotFound = 503,
563
+ /**
564
+ * Descriptors are not discovered for specified characteristic.
565
+ */
566
+ DescriptorsNotDiscovered = 504,
567
+ /**
568
+ * Invalid Base64 format was passed to descriptor API function call.
569
+ */
570
+ DescriptorInvalidDataFormat = 505,
571
+ /**
572
+ * Issued a write to a descriptor, which is handled by OS.
573
+ */
574
+ DescriptorWriteNotAllowed = 506,
575
+
576
+ // Scanning errors -------------------------------------------------------------------------------------------------
577
+ /**
578
+ * Cannot start scanning operation.
579
+ */
580
+ ScanStartFailed = 600,
581
+ /**
582
+ * Location services are disabled.
583
+ */
584
+ LocationServicesDisabled = 601
585
+ }
586
+
587
+ /**
588
+ * Error codes for ATT errors.
589
+ * @name BleATTErrorCode
590
+ */
591
+ export enum BleATTErrorCode {
592
+ /**
593
+ * The ATT command or request successfully completed.
594
+ */
595
+ Success = 0,
596
+ /**
597
+ * The attribute handle is invalid on this device.
598
+ */
599
+ InvalidHandle = 1,
600
+ /**
601
+ * The attribute’s value cannot be read.
602
+ */
603
+ ReadNotPermitted = 2,
604
+ /**
605
+ * The attribute’s value cannot be written.
606
+ */
607
+ WriteNotPermitted = 3,
608
+ /**
609
+ * The attribute Protocol Data Unit (PDU) or “message” is invalid.
610
+ */
611
+ InvalidPdu = 4,
612
+ /**
613
+ * The attribute requires authentication before its value can be read or written.
614
+ */
615
+ InsufficientAuthentication = 5,
616
+ /**
617
+ * The attribute server does not support the request received by the client.
618
+ */
619
+ RequestNotSupported = 6,
620
+ /**
621
+ * The specified offset value was past the end of the attribute’s value.
622
+ */
623
+ InvalidOffset = 7,
624
+ /**
625
+ * The attribute requires authorization before its value can be read or written.
626
+ */
627
+ InsufficientAuthorization = 8,
628
+ /**
629
+ * The prepare queue is full, because too many prepare write requests have been queued.
630
+ */
631
+ PrepareQueueFull = 9,
632
+ /**
633
+ * The attribute is not found within the specified attribute handle range.
634
+ */
635
+ AttributeNotFound = 10,
636
+ /**
637
+ * The attribute cannot be read or written using the ATT read blob request.
638
+ */
639
+ AttributeNotLong = 11,
640
+ /**
641
+ * The encryption key size used for encrypting this link is insufficient.
642
+ */
643
+ InsufficientEncryptionKeySize = 12,
644
+ /**
645
+ * The length of the attribute’s value is invalid for the intended operation.
646
+ */
647
+ InvalidAttributeValueLength = 13,
648
+ /**
649
+ * The ATT request has encountered an unlikely error and therefore could not be completed.
650
+ */
651
+ UnlikelyError = 14,
652
+ /**
653
+ * The attribute requires encryption before its value can be read or written.
654
+ */
655
+ InsufficientEncryption = 15,
656
+ /**
657
+ * The attribute type is not a supported grouping attribute as defined by a higher-layer specification.
658
+ */
659
+ UnsupportedGroupType = 16,
660
+ /**
661
+ * Resources are insufficient to complete the ATT request.
662
+ */
663
+ InsufficientResources = 17
664
+
665
+ // Values 0x012 – 0x7F are reserved for future use.
666
+ }
667
+
668
+ /**
669
+ * iOS specific error codes.
670
+ * @name BleIOSErrorCode
671
+ */
672
+ export enum BleIOSErrorCode {
673
+ /**
674
+ * An unknown error occurred.
675
+ */
676
+ Unknown = 0,
677
+ /**
678
+ * The specified parameters are invalid.
679
+ */
680
+ InvalidParameters = 1,
681
+ /**
682
+ * The specified attribute handle is invalid.
683
+ */
684
+ InvalidHandle = 2,
685
+ /**
686
+ * The device is not currently connected.
687
+ */
688
+ NotConnected = 3,
689
+ /**
690
+ * The device has run out of space to complete the intended operation.
691
+ */
692
+ OutOfSpace = 4,
693
+ /**
694
+ * The operation is canceled.
695
+ */
696
+ OperationCancelled = 5,
697
+ /**
698
+ * The connection timed out.
699
+ */
700
+ ConnectionTimeout = 6,
701
+ /**
702
+ * The peripheral disconnected.
703
+ */
704
+ PeripheralDisconnected = 7,
705
+ /**
706
+ * The specified UUID is not permitted.
707
+ */
708
+ UuidNotAllowed = 8,
709
+ /**
710
+ * The peripheral is already advertising.
711
+ */
712
+ AlreadyAdvertising = 9,
713
+ /**
714
+ * The connection failed.
715
+ */
716
+ ConnectionFailed = 10,
717
+ /**
718
+ * The device already has the maximum number of connections.
719
+ */
720
+ ConnectionLimitReached = 11,
721
+ /**
722
+ * Unknown device.
723
+ */
724
+ UnknownDevice = 12
725
+ }
726
+
727
+ /**
728
+ * Android specific error codes.
729
+ * @name BleAndroidErrorCode
730
+ */
731
+ export enum BleAndroidErrorCode {
732
+ /**
733
+ * The device has insufficient resources to complete the intended operation.
734
+ */
735
+ NoResources = 0x80,
736
+ /**
737
+ * Internal error occurred which may happen due to implementation error in BLE stack.
738
+ */
739
+ InternalError = 0x81,
740
+ /**
741
+ * BLE stack implementation entered illegal state and operation couldn't complete.
742
+ */
743
+ WrongState = 0x82,
744
+ /**
745
+ * BLE stack didn't allocate sufficient memory buffer for internal caches.
746
+ */
747
+ DbFull = 0x83,
748
+ /**
749
+ * Maximum number of pending operations was exceeded.
750
+ */
751
+ Busy = 0x84,
752
+ /**
753
+ * Generic BLE stack error.
754
+ */
755
+ Error = 0x85,
756
+ /**
757
+ * Command is already queued up in GATT.
758
+ */
759
+ CmdStarted = 0x86,
760
+ /**
761
+ * Illegal parameter was passed to internal BLE stack function.
762
+ */
763
+ IllegalParameter = 0x87,
764
+ /**
765
+ * Operation is pending.
766
+ */
767
+ Pending = 0x88,
768
+ /**
769
+ * Authorization failed before performing read or write operation.
770
+ */
771
+ AuthFail = 0x89,
772
+ /**
773
+ * More cache entries were loaded then expected.
774
+ */
775
+ More = 0x8a,
776
+ /**
777
+ * Invalid configuration
778
+ */
779
+ InvalidCfg = 0x8b,
780
+ /**
781
+ * GATT service already started.
782
+ */
783
+ ServiceStarted = 0x8c,
784
+ /**
785
+ * GATT link is encrypted but prone to man in the middle attacks.
786
+ */
787
+ EncrypedNoMitm = 0x8d,
788
+ /**
789
+ * GATT link is not encrypted.
790
+ */
791
+ NotEncrypted = 0x8e,
792
+ /**
793
+ * ATT command was sent but channel is congested.
794
+ */
795
+ Congested = 0x8f
796
+ }
797
+
798
+ // BleModule.js ******************************************************************************************************
799
+
800
+ /**
801
+ * Native device object passed from BleModule.
802
+ * @private
803
+ */
804
+ export interface NativeDevice {
805
+ /**
806
+ * Device identifier: MAC address on Android and UUID on iOS.
807
+ * @private
808
+ */
809
+ id: DeviceId
810
+ /**
811
+ * Device name if present
812
+ * @private
813
+ */
814
+ name: string | null
815
+ /**
816
+ * Current Received Signal Strength Indication of device
817
+ * @private
818
+ */
819
+ rssi: number | null
820
+ /**
821
+ * Current Maximum Transmission Unit for this device. When device is not connected
822
+ * default value of 23 is used.
823
+ * @private
824
+ */
825
+ mtu: number
826
+
827
+ // Advertisement
828
+
829
+ /**
830
+ * Device's custom manufacturer data. Its format is defined by manufacturer.
831
+ * @private
832
+ */
833
+ manufacturerData: Base64 | null
834
+
835
+ /**
836
+ * Raw device scan data. When you have specific advertiser data,
837
+ * you can implement your own processing.
838
+ * @private
839
+ */
840
+ rawScanRecord: Base64
841
+
842
+ /**
843
+ * Map od service UUIDs with associated data.
844
+ * @private
845
+ */
846
+ serviceData: { [uuid: string]: Base64 } | null
847
+
848
+ /**
849
+ * List of available services visible during scanning.
850
+ * @private
851
+ */
852
+ serviceUUIDs: UUID[] | null
853
+
854
+ /**
855
+ * User friendly name of device.
856
+ * @private
857
+ */
858
+ localName: string | null
859
+
860
+ /**
861
+ * Transmission power level of device.
862
+ * @private
863
+ */
864
+ txPowerLevel: number | null
865
+
866
+ /**
867
+ * List of solicited service UUIDs.
868
+ * @private
869
+ */
870
+ solicitedServiceUUIDs: UUID[] | null
871
+
872
+ /**
873
+ * Is device connectable.
874
+ * @private
875
+ */
876
+ isConnectable: boolean | null
877
+
878
+ /**
879
+ * List of overflow service UUIDs.
880
+ * @private
881
+ */
882
+ overflowServiceUUIDs: UUID[] | null
883
+ }
884
+
885
+ /**
886
+ * Native service object passed from BleModule.
887
+ * @private
888
+ */
889
+ export interface NativeService {
890
+ /**
891
+ * Service unique identifier
892
+ * @private
893
+ */
894
+ id: Identifier
895
+ /**
896
+ * Service UUID
897
+ * @private
898
+ */
899
+ uuid: UUID
900
+ /**
901
+ * Device's ID to which service belongs
902
+ * @private
903
+ */
904
+ deviceID: DeviceId
905
+ /**
906
+ * Value indicating whether the type of service is primary or secondary.
907
+ * @private
908
+ */
909
+ isPrimary: boolean
910
+ }
911
+
912
+ /**
913
+ * Native characteristic object passed from BleModule.
914
+ * @private
915
+ */
916
+ export interface NativeCharacteristic {
917
+ /**
918
+ * Characteristic unique identifier
919
+ * @private
920
+ */
921
+ id: Identifier
922
+ /**
923
+ * Characteristic UUID
924
+ * @private
925
+ */
926
+ uuid: UUID
927
+ /**
928
+ * Service's ID to which characteristic belongs
929
+ * @private
930
+ */
931
+ serviceID: Identifier
932
+ /**
933
+ * Service's UUID to which characteristic belongs
934
+ * @private
935
+ */
936
+ serviceUUID: UUID
937
+ /**
938
+ * Device's ID to which characteristic belongs
939
+ * @private
940
+ */
941
+ deviceID: DeviceId
942
+ /**
943
+ * True if characteristic can be read
944
+ * @private
945
+ */
946
+ isReadable: boolean
947
+ /**
948
+ * True if characteristic can be written with response
949
+ * @private
950
+ */
951
+ isWritableWithResponse: boolean
952
+ /**
953
+ * True if characteristic can be written without response
954
+ * @private
955
+ */
956
+ isWritableWithoutResponse: boolean
957
+ /**
958
+ * True if characteristic can monitor value changes.
959
+ * @private
960
+ */
961
+ isNotifiable: boolean
962
+ /**
963
+ * True if characteristic is monitoring value changes without ACK.
964
+ * @private
965
+ */
966
+ isNotifying: boolean
967
+ /**
968
+ * True if characteristic is monitoring value changes with ACK.
969
+ * @private
970
+ */
971
+ isIndicatable: boolean
972
+ /**
973
+ * Characteristic value if present
974
+ * @private
975
+ */
976
+ value: Base64 | null
977
+ }
978
+
979
+ /**
980
+ * Native descriptor object passed from BleModule.
981
+ * @private
982
+ */
983
+ export interface NativeDescriptor {
984
+ /**
985
+ * Descriptor unique identifier
986
+ * @private
987
+ */
988
+ id: Identifier
989
+ /**
990
+ * Descriptor UUID
991
+ * @private
992
+ */
993
+ uuid: UUID
994
+ /**
995
+ * Characteristic's ID to which descriptor belongs
996
+ * @private
997
+ */
998
+ characteristicID: Identifier
999
+ /**
1000
+ * Characteristic's UUID to which descriptor belongs
1001
+ * @private
1002
+ */
1003
+ characteristicUUID: UUID
1004
+ /**
1005
+ * Service's ID to which descriptor belongs
1006
+ * @private
1007
+ */
1008
+ serviceID: Identifier
1009
+ /**
1010
+ * Service's UUID to which descriptor belongs
1011
+ * @private
1012
+ */
1013
+ serviceUUID: UUID
1014
+ /**
1015
+ * Device's ID to which descriptor belongs
1016
+ * @private
1017
+ */
1018
+ deviceID: DeviceId
1019
+ /**
1020
+ * Descriptor value if present
1021
+ * @private
1022
+ */
1023
+ value: Base64 | null
1024
+ }
1025
+
1026
+ /**
1027
+ * Object representing information about restored BLE state after application relaunch.
1028
+ * @private
1029
+ */
1030
+ export interface NativeBleRestoredState {
1031
+ /**
1032
+ * List of connected devices after state restoration.
1033
+ * @type {Array<NativeDevice>}
1034
+ * @instance
1035
+ * @memberof NativeBleRestoredState
1036
+ * @private
1037
+ */
1038
+ connectedPeripherals: NativeDevice[]
1039
+ }
1040
+
1041
+ // BleManager.js *****************************************************************************************************
1042
+
1043
+ /**
1044
+ *
1045
+ * BleManager is an entry point for react-native-ble-plx library. It provides all means to discover and work with
1046
+ * {@link Device} instances. It should be initialized only once with `new` keyword and method
1047
+ * {@link #blemanagerdestroy|destroy()} should be called on its instance when user wants to deallocate all resources.
1048
+ *
1049
+ * In case you want to properly support Background Mode, you should provide `restoreStateIdentifier` and
1050
+ * `restoreStateFunction` in {@link BleManagerOptions}.
1051
+ *
1052
+ * @example
1053
+ * const manager = new BleManager();
1054
+ * // ... work with BLE manager ...
1055
+ * manager.destroy();
1056
+ */
1057
+ export class BleManager {
1058
+ /**
1059
+ * Creates an instance of {@link BleManager}.
1060
+ */
1061
+ constructor(options?: BleManagerOptions)
1062
+
1063
+ /**
1064
+ * Destroys {@link BleManager} instance. A new instance needs to be created to continue working with
1065
+ * this library. All operations which were in progress completes with
1066
+ * @returns {Promise<void>}
1067
+ * {@link #bleerrorcodebluetoothmanagerdestroyed|BluetoothManagerDestroyed} error code.
1068
+ */
1069
+ destroy(): Promise<void>;
1070
+
1071
+ // Mark: Common ----------------------------------------------------------------------------------------------------
1072
+
1073
+ /**
1074
+ * Sets new log level for native module's logging mechanism.
1075
+ * @param {LogLevel} logLevel New log level to be set.
1076
+ * @returns {Promise<LogLevel>} Current log level.
1077
+ */
1078
+ setLogLevel(logLevel: LogLevel): Promise<LogLevel>
1079
+
1080
+ /**
1081
+ * Get current log level for native module's logging mechanism.
1082
+ * @returns {Promise<LogLevel>} Current log level.
1083
+ */
1084
+ logLevel(): Promise<LogLevel>
1085
+
1086
+ /**
1087
+ * Cancels pending transaction.
1088
+ *
1089
+ * Few operations such as monitoring characteristic's value changes can be cancelled by a user. Basically every API
1090
+ * entry which accepts `transactionId` allows to call `cancelTransaction` function. When cancelled operation is a
1091
+ * promise or a callback which registers errors, {@link #bleerror|BleError} with error code
1092
+ * {@link #bleerrorcodeoperationcancelled|OperationCancelled} will be emitted in that case. Cancelling transaction
1093
+ * which doesn't exist is ignored.
1094
+ *
1095
+ * @example
1096
+ * const transactionId = 'monitor_battery';
1097
+ *
1098
+ * // Monitor battery notifications
1099
+ * manager.monitorCharacteristicForDevice(
1100
+ * device.id, '180F', '2A19',
1101
+ * (error, characteristic) => {
1102
+ * // Handle battery level changes...
1103
+ * }, transactionId);
1104
+ *
1105
+ * // Cancel after specified amount of time
1106
+ * setTimeout(() => manager.cancelTransaction(transactionId), 2000);
1107
+ *
1108
+ * @param {TransactionId} transactionId Id of pending transactions.
1109
+ * @returns {Promise<void>}
1110
+ */
1111
+ cancelTransaction(transactionId: TransactionId): Promise<void>
1112
+
1113
+ // Mark: Monitoring state ------------------------------------------------------------------------------------------
1114
+
1115
+ /**
1116
+ * Enable Bluetooth. This function blocks until BLE is in PoweredOn state. [Android only]
1117
+ *
1118
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1119
+ * @returns {Promise<BleManager>} Promise completes when state transition was successful.
1120
+ */
1121
+ enable(transactionId?: TransactionId): Promise<BleManager>
1122
+
1123
+ /**
1124
+ * Disable Bluetooth. This function blocks until BLE is in PoweredOff state. [Android only]
1125
+ *
1126
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1127
+ * @returns {Promise<BleManager>} Promise completes when state transition was successful.
1128
+ */
1129
+ disable(transactionId?: TransactionId): Promise<BleManager>
1130
+
1131
+ /**
1132
+ * Current, global {@link State} of a {@link BleManager}. All APIs are working only when active state
1133
+ * is "PoweredOn".
1134
+ *
1135
+ * @returns {Promise<State>} Promise which emits current state of BleManager.
1136
+ */
1137
+ state(): Promise<State>
1138
+
1139
+ /**
1140
+ * Notifies about {@link State} changes of a {@link BleManager}.
1141
+ *
1142
+ * @example
1143
+ * const subscription = this.manager.onStateChange((state) => {
1144
+ * if (state === 'PoweredOn') {
1145
+ * this.scanAndConnect();
1146
+ * subscription.remove();
1147
+ * }
1148
+ * }, true);
1149
+ *
1150
+ * @param {function(newState: State)} listener Callback which emits state changes of BLE Manager.
1151
+ * Look at {@link State} for possible values.
1152
+ * @param {boolean} [emitCurrentState=false] If true, current state will be emitted as well. Defaults to false.
1153
+ *
1154
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1155
+ */
1156
+ onStateChange(listener: (newState: State) => void, emitCurrentState?: boolean): Subscription
1157
+
1158
+ // Mark: Scanning --------------------------------------------------------------------------------------------------
1159
+
1160
+ /**
1161
+ * Starts device scanning. When previous scan is in progress it will be stopped before executing this command.
1162
+ *
1163
+ * @param {?Array<UUID>} UUIDs Array of strings containing {@link UUID}s of {@link Service}s which are registered in
1164
+ * scanned {@link Device}. If `null` is passed, all available {@link Device}s will be scanned.
1165
+ * @param {?ScanOptions} options Optional configuration for scanning operation.
1166
+ * @param {function(error?: BleError, scannedDevice: ?Device)} listener Function which will be called for every scanned
1167
+ * {@link Device} (devices may be scanned multiple times). It's first argument is potential {@link Error} which is set
1168
+ * to non `null` value when scanning failed. You have to start scanning process again if that happens. Second argument
1169
+ * is a scanned {@link Device}.
1170
+ * @returns {Promise<void>} the promise may be rejected if the operation is impossible to perform.
1171
+ */
1172
+ startDeviceScan(
1173
+ UUIDs: UUID[] | null,
1174
+ options: ScanOptions | null,
1175
+ listener: (error: BleError | null, scannedDevice: Device | null) => void
1176
+ ): Promise<void>
1177
+
1178
+ /**
1179
+ * Stops {@link Device} scan if in progress.
1180
+ * @returns {Promise<void>} the promise may be rejected if the operation is impossible to perform.
1181
+ */
1182
+ stopDeviceScan(): Promise<void>
1183
+
1184
+ /**
1185
+ * Request a connection parameter update. This functions may update connection parameters on Android API level 21 or
1186
+ * above.
1187
+ *
1188
+ * @param {DeviceId} deviceIdentifier Device identifier.
1189
+ * @param {ConnectionPriority} connectionPriority: Connection priority.
1190
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1191
+ * @returns {Promise<Device>} Connected device.
1192
+ */
1193
+ requestConnectionPriorityForDevice(
1194
+ deviceIdentifier: DeviceId,
1195
+ connectionPriority: ConnectionPriority,
1196
+ transactionId?: TransactionId
1197
+ ): Promise<Device>
1198
+
1199
+ /**
1200
+ * Reads RSSI for connected device.
1201
+ *
1202
+ * @param {DeviceId} deviceIdentifier Device identifier.
1203
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1204
+ * @returns {Promise<Device>} Connected device with updated RSSI value.
1205
+ */
1206
+ readRSSIForDevice(deviceIdentifier: DeviceId, transactionId?: TransactionId): Promise<Device>
1207
+
1208
+ /**
1209
+ * Request new MTU value for this device. This function currently is not doing anything
1210
+ * on iOS platform as MTU exchange is done automatically. Since Android 14,
1211
+ * mtu management has been changed, more information can be found at the link:
1212
+ * https://developer.android.com/about/versions/14/behavior-changes-all#mtu-set-to-517
1213
+ * @param {DeviceId} deviceIdentifier Device identifier.
1214
+ * @param {number} mtu New MTU to negotiate.
1215
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1216
+ * @returns {Promise<Device>} Device with updated MTU size. Default value is 23 (517 since Android 14).
1217
+ */
1218
+ requestMTUForDevice(deviceIdentifier: DeviceId, mtu: number, transactionId?: TransactionId): Promise<Device>
1219
+
1220
+ // Mark: Connection management -------------------------------------------------------------------------------------
1221
+
1222
+ /**
1223
+ * Returns a list of known devices by their identifiers.
1224
+ * @param {Array<DeviceId>} deviceIdentifiers List of device identifiers.
1225
+ * @returns {Promise<Array<Device>>} List of known devices by their identifiers.
1226
+ */
1227
+ devices(deviceIdentifiers: Array<DeviceId>): Promise<Device[]>
1228
+
1229
+ /**
1230
+ * Returns a list of the peripherals (containing any of the specified services) currently connected to the system
1231
+ * which have discovered services. Returned devices **may not be connected** to your application. Make sure to check
1232
+ * if that's the case with function {@link #blemanagerisdeviceconnected|isDeviceConnected}.
1233
+ * @param {Array<UUID>} serviceUUIDs List of service UUIDs. Device must contain at least one of them to be listed.
1234
+ * @returns {Promise<Array<Device>>} List of known devices with discovered services as stated in the parameter.
1235
+ */
1236
+ connectedDevices(serviceUUIDs: Array<UUID>): Promise<Device[]>
1237
+
1238
+ // Mark: Connection management -------------------------------------------------------------------------------------
1239
+
1240
+ /**
1241
+ * Connects to {@link Device} with provided ID.
1242
+ *
1243
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1244
+ * @param {?ConnectionOptions} options Platform specific options for connection establishment.
1245
+ * @returns {Promise<Device>} Connected {@link Device} object if successful.
1246
+ */
1247
+ connectToDevice(deviceIdentifier: DeviceId, options?: ConnectionOptions): Promise<Device>
1248
+
1249
+ /**
1250
+ * Disconnects from {@link Device} if it's connected or cancels pending connection.
1251
+ *
1252
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier to be closed.
1253
+ * @returns {Promise<Device>} Returns closed {@link Device} when operation is successful.
1254
+ */
1255
+ cancelDeviceConnection(deviceIdentifier: DeviceId): Promise<Device>
1256
+
1257
+ /**
1258
+ * Monitors if {@link Device} was disconnected due to any errors or connection problems.
1259
+ *
1260
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier to be monitored.
1261
+ * @param {function(error?: BleError, device: ?Device)} listener - callback returning error as a reason of disconnection
1262
+ * if available and {@link Device} object. If an error is null, that means the connection was terminated by
1263
+ * {@link #blemanagercanceldeviceconnection|bleManager.cancelDeviceConnection()} call.
1264
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1265
+ */
1266
+ onDeviceDisconnected(
1267
+ deviceIdentifier: DeviceId,
1268
+ listener: (error: BleError | null, device: Device | null) => void
1269
+ ): Subscription
1270
+
1271
+ /**
1272
+ * Check connection state of a {@link Device}.
1273
+ *
1274
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1275
+ * @returns {Promise<boolean>} Promise which emits `true` if device is connected, and `false` otherwise.
1276
+ */
1277
+ isDeviceConnected(deviceIdentifier: DeviceId): Promise<boolean>
1278
+
1279
+ // Mark: Discovery -------------------------------------------------------------------------------------------------
1280
+
1281
+ /**
1282
+ * Discovers all {@link Service}s, {@link Characteristic}s and {@link Descriptor}s for {@link Device}.
1283
+ *
1284
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1285
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1286
+ * @returns {Promise<Device>} Promise which emits {@link Device} object if all available services and
1287
+ * characteristics have been discovered.
1288
+ */
1289
+ discoverAllServicesAndCharacteristicsForDevice(
1290
+ deviceIdentifier: DeviceId,
1291
+ transactionId?: TransactionId
1292
+ ): Promise<Device>
1293
+
1294
+ // Mark: Service and characteristic getters ------------------------------------------------------------------------
1295
+
1296
+ /**
1297
+ * List of discovered {@link Service}s for {@link Device}.
1298
+ *
1299
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1300
+ * @returns {Promise<Array<Service>>} Promise which emits array of {@link Service} objects which are discovered for a
1301
+ * {@link Device}.
1302
+ */
1303
+ servicesForDevice(deviceIdentifier: DeviceId): Promise<Service[]>
1304
+
1305
+ /**
1306
+ * List of discovered {@link Characteristic}s for given {@link Device} and {@link Service}.
1307
+ *
1308
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1309
+ * @param {UUID} serviceUUID {@link Service} UUID.
1310
+ * @returns {Promise<Array<Characteristic>>} Promise which emits array of {@link Characteristic} objects which are
1311
+ * discovered for a {@link Device} in specified {@link Service}.
1312
+ */
1313
+ characteristicsForDevice(deviceIdentifier: DeviceId, serviceUUID: UUID): Promise<Characteristic[]>
1314
+
1315
+ /**
1316
+ * List of discovered {@link Descriptor}s for given {@link Device}, {@link Service} and {@link Characteristic}.
1317
+ *
1318
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1319
+ * @param {UUID} serviceUUID {@link Service} UUID.
1320
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1321
+ * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1322
+ * discovered for a {@link Device}, {@link Service} in specified {@link Characteristic}.
1323
+ */
1324
+ descriptorsForDevice(
1325
+ deviceIdentifier: DeviceId,
1326
+ serviceUUID: UUID,
1327
+ characteristicUUID: UUID
1328
+ ): Promise<Array<Descriptor>>
1329
+
1330
+ // Mark: Characteristics operations --------------------------------------------------------------------------------
1331
+
1332
+ /**
1333
+ * Read {@link Characteristic} value.
1334
+ *
1335
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1336
+ * @param {UUID} serviceUUID {@link Service} UUID.
1337
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1338
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1339
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1340
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1341
+ * UUID paths. Latest value of {@link Characteristic} will be stored inside returned object.
1342
+ */
1343
+ readCharacteristicForDevice(
1344
+ deviceIdentifier: DeviceId,
1345
+ serviceUUID: UUID,
1346
+ characteristicUUID: UUID,
1347
+ transactionId?: TransactionId
1348
+ ): Promise<Characteristic>
1349
+
1350
+ /**
1351
+ * Write {@link Characteristic} value with response.
1352
+ *
1353
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1354
+ * @param {UUID} serviceUUID {@link Service} UUID.
1355
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1356
+ * @param {Base64} base64Value Value in Base64 format.
1357
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1358
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1359
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1360
+ * UUID paths. Latest value of characteristic may not be stored inside returned object.
1361
+ */
1362
+ writeCharacteristicWithResponseForDevice(
1363
+ deviceIdentifier: DeviceId,
1364
+ serviceUUID: UUID,
1365
+ characteristicUUID: UUID,
1366
+ base64Value: Base64,
1367
+ transactionId?: TransactionId
1368
+ ): Promise<Characteristic>
1369
+
1370
+ /**
1371
+ * Write {@link Characteristic} value without response.
1372
+ *
1373
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1374
+ * @param {UUID} serviceUUID {@link Service} UUID.
1375
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1376
+ * @param {Base64} base64Value Value in Base64 format.
1377
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1378
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1379
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1380
+ * UUID paths. Latest value of characteristic may not be stored inside returned object.
1381
+ */
1382
+ writeCharacteristicWithoutResponseForDevice(
1383
+ deviceIdentifier: DeviceId,
1384
+ serviceUUID: UUID,
1385
+ characteristicUUID: UUID,
1386
+ base64Value: Base64,
1387
+ transactionId?: TransactionId
1388
+ ): Promise<Characteristic>
1389
+
1390
+ /**
1391
+ * Monitor value changes of a {@link Characteristic}. If notifications are enabled they will be used
1392
+ * in favour of indications.
1393
+ *
1394
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1395
+ * @param {UUID} serviceUUID {@link Service} UUID.
1396
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1397
+ * @param {function(error?: BleError, characteristic?: Characteristic)} listener - callback which emits
1398
+ * {@link Characteristic} objects with modified value for each notification.
1399
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1400
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1401
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1402
+ */
1403
+ monitorCharacteristicForDevice(
1404
+ deviceIdentifier: DeviceId,
1405
+ serviceUUID: UUID,
1406
+ characteristicUUID: UUID,
1407
+ listener: (error: BleError | null, characteristic: Characteristic | null) => void,
1408
+ transactionId?: TransactionId
1409
+ ): Subscription
1410
+
1411
+ // Mark: Descriptors operations ----------------------------------------------------------------------------------
1412
+
1413
+ /**
1414
+ * Read {@link Descriptor} value.
1415
+ *
1416
+ * @param {DeviceId} deviceIdentifier {@link Device} identifier.
1417
+ * @param {UUID} serviceUUID {@link Service} UUID.
1418
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1419
+ * @param {UUID} descriptorUUID {@link Descriptor} UUID.
1420
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1421
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1422
+ * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
1423
+ * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
1424
+ */
1425
+ readDescriptorForDevice(
1426
+ deviceIdentifier: DeviceId,
1427
+ serviceUUID: UUID,
1428
+ characteristicUUID: UUID,
1429
+ descriptorUUID: UUID,
1430
+ transactionId?: string
1431
+ ): Promise<Descriptor>
1432
+
1433
+ /**
1434
+ * Write {@link Descriptor} value.
1435
+ *
1436
+ * @param {DeviceId} deviceIdentifier Connected device identifier
1437
+ * @param {UUID} serviceUUID Service UUID
1438
+ * @param {UUID} characteristicUUID Characteristic UUID
1439
+ * @param {UUID} descriptorUUID Descriptor UUID
1440
+ * @param {Base64} valueBase64 Value to be set coded in Base64
1441
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1442
+ * @returns {Promise<Descriptor>} Descriptor which saved passed value
1443
+ */
1444
+ writeDescriptorForDevice(
1445
+ deviceIdentifier: DeviceId,
1446
+ serviceUUID: UUID,
1447
+ characteristicUUID: UUID,
1448
+ descriptorUUID: UUID,
1449
+ valueBase64: Base64,
1450
+ transactionId?: string
1451
+ ): Promise<Descriptor>
1452
+ }
1453
+
1454
+ // Device.js *********************************************************************************************************
1455
+
1456
+ /**
1457
+ * Device instance which can be retrieved only by calling
1458
+ * {@link #blemanagerstartdevicescan|bleManager.startDeviceScan()}.
1459
+ */
1460
+ export class Device implements NativeDevice {
1461
+ /**
1462
+ * Device identifier: MAC address on Android and UUID on iOS.
1463
+ */
1464
+ id: DeviceId
1465
+
1466
+ /**
1467
+ * Device name if present
1468
+ */
1469
+ name: string | null
1470
+
1471
+ /**
1472
+ * Current Received Signal Strength Indication of device
1473
+ */
1474
+ rssi: number | null
1475
+
1476
+ /**
1477
+ * Current Maximum Transmission Unit for this device. When device is not connected
1478
+ * default value of 23 is used.
1479
+ */
1480
+ mtu: number
1481
+
1482
+ // Advertisement
1483
+
1484
+ /**
1485
+ * Device's custom manufacturer data. Its format is defined by manufacturer.
1486
+ */
1487
+ manufacturerData: Base64 | null
1488
+
1489
+ /**
1490
+ * Raw device scan data. When you have specific advertiser data,
1491
+ * you can implement your own processing.
1492
+ */
1493
+ rawScanRecord: Base64
1494
+
1495
+ /**
1496
+ * Map of service UUIDs (as keys) with associated data (as values).
1497
+ */
1498
+ serviceData: { [uuid: string]: Base64 } | null
1499
+
1500
+ /**
1501
+ * List of available services visible during scanning.
1502
+ */
1503
+ serviceUUIDs: UUID[] | null
1504
+
1505
+ /**
1506
+ * User friendly name of device.
1507
+ */
1508
+ localName: string | null
1509
+
1510
+ /**
1511
+ * Transmission power level of device.
1512
+ */
1513
+ txPowerLevel: number | null
1514
+
1515
+ /**
1516
+ * List of solicited service UUIDs.
1517
+ */
1518
+ solicitedServiceUUIDs: UUID[] | null
1519
+
1520
+ /**
1521
+ * Is device connectable. [iOS only]
1522
+ */
1523
+ isConnectable: boolean | null
1524
+
1525
+ /**
1526
+ * List of overflow service UUIDs. [iOS only]
1527
+ */
1528
+ overflowServiceUUIDs: UUID[] | null
1529
+
1530
+ /**
1531
+ * Private constructor used to create {@link Device} object.
1532
+ *
1533
+ * @param {NativeDevice} nativeDevice Native device properties
1534
+ * @param {BleManager} manager {@link BleManager} handle
1535
+ * @private
1536
+ */
1537
+ constructor(nativeDevice: NativeDevice, manager: BleManager)
1538
+
1539
+ /**
1540
+ * {@link #blemanagerrequestconnectionpriorityfordevice|bleManager.requestConnectionPriorityForDevice()} with partially filled arguments.
1541
+ *
1542
+ * @param {ConnectionPriority} connectionPriority: Connection priority.
1543
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1544
+ * @returns {Promise<Device>} Connected device.
1545
+ */
1546
+ requestConnectionPriority(connectionPriority: ConnectionPriority, transactionId?: TransactionId): Promise<Device>
1547
+
1548
+ /**
1549
+ * {@link #blemanagerreadrssifordevice|bleManager.readRSSIForDevice()} with partially filled arguments.
1550
+ *
1551
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1552
+ * @returns {Promise<Device>} This device with updated RSSI value.
1553
+ */
1554
+ readRSSI(transactionId?: TransactionId): Promise<Device>
1555
+
1556
+ /**
1557
+ * {@link #blemanagerrequestmtufordevice|bleManager.requestMTUForDevice()} with partially filled arguments.
1558
+ *
1559
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation.
1560
+ * @returns {Promise<Device>} Device with updated MTU size. Default value is 23.
1561
+ */
1562
+ requestMTU(mtu: number, transactionId?: TransactionId): Promise<Device>
1563
+
1564
+ /**
1565
+ * {@link #blemanagerconnecttodevice|bleManager.connectToDevice()} with partially filled arguments.
1566
+ *
1567
+ * @param {?ConnectionOptions} options Platform specific options for connection establishment. Not used currently.
1568
+ * @returns {Promise<Device>} Connected {@link Device} object if successful.
1569
+ */
1570
+ connect(options?: ConnectionOptions): Promise<Device>
1571
+
1572
+ /**
1573
+ * {@link #blemanagercanceldeviceconnection|bleManager.cancelDeviceConnection()} with partially filled arguments.
1574
+ *
1575
+ * @returns {Promise<Device>} Returns closed {@link Device} when operation is successful.
1576
+ */
1577
+ cancelConnection(): Promise<Device>
1578
+
1579
+ /**
1580
+ * {@link #blemanagerisdeviceconnected|bleManager.isDeviceConnected()} with partially filled arguments.
1581
+ *
1582
+ * @returns {Promise<boolean>} Promise which emits `true` if device is connected, and `false` otherwise.
1583
+ */
1584
+ isConnected(): Promise<boolean>
1585
+
1586
+ /**
1587
+ * {@link #blemanagerondevicedisconnected|bleManager.onDeviceDisconnected()} with partially filled arguments.
1588
+ *
1589
+ * @param {function(error: ?BleError, device: Device)} listener callback returning error as a reason of disconnection
1590
+ * if available and {@link Device} object. If an error is null, that means the connection was terminated by
1591
+ * {@link #blemanagercanceldeviceconnection|bleManager.cancelDeviceConnection()} call.
1592
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1593
+ */
1594
+ onDisconnected(listener: (error: BleError | null, device: Device) => void): Subscription
1595
+
1596
+ /**
1597
+ * {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|bleManager.discoverAllServicesAndCharacteristicsForDevice()} with partially filled arguments.
1598
+ *
1599
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1600
+ * @returns {Promise<Device>} Promise which emits {@link Device} object if all available services and
1601
+ * characteristics have been discovered.
1602
+ */
1603
+ discoverAllServicesAndCharacteristics(transactionId?: TransactionId): Promise<Device>
1604
+
1605
+ /**
1606
+ * {@link #blemanagerservicesfordevice|bleManager.servicesForDevice()} with partially filled arguments.
1607
+ *
1608
+ * @returns {Promise<Service[]>} Promise which emits array of {@link Service} objects which are discovered by this
1609
+ * device.
1610
+ */
1611
+ services(): Promise<Service[]>
1612
+
1613
+ /**
1614
+ * {@link #blemanagercharacteristicsfordevice|bleManager.characteristicsForDevice()} with partially filled arguments.
1615
+ *
1616
+ * @param {UUID} serviceUUID {@link Service} UUID.
1617
+ * @returns {Promise<Characteristic[]>} Promise which emits array of {@link Characteristic} objects which are
1618
+ * discovered for a {@link Device} in specified {@link Service}.
1619
+ */
1620
+ characteristicsForService(serviceUUID: string): Promise<Characteristic[]>
1621
+
1622
+ /**
1623
+ * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
1624
+ *
1625
+ * @param {UUID} serviceUUID {@link Service} UUID.
1626
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1627
+ * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1628
+ * discovered for this {@link Characteristic}.
1629
+ */
1630
+ descriptorsForService(serviceUUID: UUID, characteristicUUID: UUID): Promise<Array<Descriptor>>
1631
+
1632
+ /**
1633
+ * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
1634
+ *
1635
+ * @param {UUID} serviceUUID {@link Service} UUID.
1636
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1637
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1638
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1639
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1640
+ * UUID paths. Latest value of {@link Characteristic} will be stored inside returned object.
1641
+ */
1642
+ readCharacteristicForService(
1643
+ serviceUUID: UUID,
1644
+ characteristicUUID: UUID,
1645
+ transactionId?: TransactionId
1646
+ ): Promise<Characteristic>
1647
+
1648
+ /**
1649
+ * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
1650
+ *
1651
+ * @param {UUID} serviceUUID {@link Service} UUID.
1652
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1653
+ * @param {Base64} valueBase64 Value in Base64 format.
1654
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1655
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1656
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1657
+ * UUID paths. Latest value of characteristic may not be stored inside returned object.
1658
+ */
1659
+ writeCharacteristicWithResponseForService(
1660
+ serviceUUID: UUID,
1661
+ characteristicUUID: UUID,
1662
+ valueBase64: Base64,
1663
+ transactionId?: TransactionId
1664
+ ): Promise<Characteristic>
1665
+
1666
+ /**
1667
+ * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
1668
+ *
1669
+ * @param {UUID} serviceUUID {@link Service} UUID.
1670
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1671
+ * @param {Base64} valueBase64 Value in Base64 format.
1672
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1673
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1674
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1675
+ * UUID paths. Latest value of characteristic may not be stored inside returned object.
1676
+ */
1677
+ writeCharacteristicWithoutResponseForService(
1678
+ serviceUUID: UUID,
1679
+ characteristicUUID: UUID,
1680
+ valueBase64: Base64,
1681
+ transactionId?: TransactionId
1682
+ ): Promise<Characteristic>
1683
+
1684
+ /**
1685
+ * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
1686
+ *
1687
+ * @param {UUID} serviceUUID {@link Service} UUID.
1688
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1689
+ * @param {function(error: ?BleError, characteristic: ?Characteristic)} listener - callback which emits
1690
+ * {@link Characteristic} objects with modified value for each notification.
1691
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1692
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1693
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1694
+ */
1695
+ monitorCharacteristicForService(
1696
+ serviceUUID: UUID,
1697
+ characteristicUUID: UUID,
1698
+ listener: (error: BleError | null, characteristic: Characteristic | null) => void,
1699
+ transactionId?: TransactionId
1700
+ ): Subscription
1701
+
1702
+ /**
1703
+ * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
1704
+ *
1705
+ * @param {UUID} serviceUUID {@link Service} UUID.
1706
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1707
+ * @param {UUID} descriptorUUID {@link Descriptor} UUID.
1708
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1709
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1710
+ * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
1711
+ * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
1712
+ */
1713
+ readDescriptorForService(
1714
+ serviceUUID: UUID,
1715
+ characteristicUUID: UUID,
1716
+ descriptorUUID: UUID,
1717
+ transactionId?: string
1718
+ ): Promise<Descriptor>
1719
+
1720
+ /**
1721
+ * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
1722
+ *
1723
+ * @param {UUID} serviceUUID {@link Service} UUID.
1724
+ * @param {UUID} characteristicUUID Characteristic UUID
1725
+ * @param {UUID} descriptorUUID Descriptor UUID
1726
+ * @param {Base64} valueBase64 Value to be set coded in Base64
1727
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1728
+ * @returns {Promise<Descriptor>} Descriptor which saved passed value.
1729
+ */
1730
+ writeDescriptorForService(
1731
+ serviceUUID: UUID,
1732
+ characteristicUUID: UUID,
1733
+ descriptorUUID: UUID,
1734
+ valueBase64: Base64,
1735
+ transactionId?: string
1736
+ ): Promise<Descriptor>
1737
+ }
1738
+
1739
+ // Service.js ********************************************************************************************************
1740
+
1741
+ /**
1742
+ * Service object.
1743
+ */
1744
+ export class Service implements NativeService {
1745
+ /**
1746
+ * Service unique identifier
1747
+ */
1748
+ id: Identifier
1749
+
1750
+ /**
1751
+ * Service UUID
1752
+ */
1753
+ uuid: UUID
1754
+
1755
+ /**
1756
+ * Device's ID to which service belongs
1757
+ */
1758
+ deviceID: DeviceId
1759
+
1760
+ /**
1761
+ * Value indicating whether the type of service is primary or secondary.
1762
+ */
1763
+ isPrimary: boolean
1764
+
1765
+ /**
1766
+ * Private constructor used to create {@link Service} object.
1767
+ *
1768
+ * @param {NativeService} nativeService NativeService properties to be copied.
1769
+ * @param {BleManager} manager Current BleManager instance.
1770
+ * @private
1771
+ * @ignore
1772
+ */
1773
+ constructor(nativeService: NativeService, manager: BleManager)
1774
+
1775
+ /**
1776
+ * {@link #blemanagercharacteristicsfordevice|bleManager.characteristicsForDevice()} with partially filled arguments.
1777
+ *
1778
+ * @returns {Promise<Array<Characteristic>>} Promise which emits array of {@link Characteristic} objects which are
1779
+ * discovered for this service.
1780
+ */
1781
+ characteristics(): Promise<Characteristic[]>
1782
+
1783
+ /**
1784
+ * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
1785
+ *
1786
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1787
+ * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1788
+ * discovered for this {@link Service} in specified {@link Characteristic}.
1789
+ */
1790
+ descriptorsForCharacteristic(characteristicUUID: UUID): Promise<Array<Descriptor>>
1791
+
1792
+ /**
1793
+ * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
1794
+ *
1795
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1796
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1797
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1798
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1799
+ * UUID path. Latest value of {@link Characteristic} will be stored inside returned object.
1800
+ */
1801
+ readCharacteristic(characteristicUUID: UUID, transactionId?: string): Promise<Characteristic>
1802
+
1803
+ /**
1804
+ * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
1805
+ *
1806
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1807
+ * @param {Base64} valueBase64 Value in Base64 format.
1808
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1809
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1810
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1811
+ * UUID path. Latest value of characteristic may not be stored inside returned object.
1812
+ */
1813
+ writeCharacteristicWithResponse(
1814
+ characteristicUUID: UUID,
1815
+ valueBase64: Base64,
1816
+ transactionId?: string
1817
+ ): Promise<Characteristic>
1818
+
1819
+ /**
1820
+ * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
1821
+ *
1822
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1823
+ * @param {Base64} valueBase64 Value in Base64 format.
1824
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1825
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1826
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
1827
+ * UUID path. Latest value of characteristic may not be stored inside returned object.
1828
+ */
1829
+ writeCharacteristicWithoutResponse(
1830
+ characteristicUUID: UUID,
1831
+ valueBase64: Base64,
1832
+ transactionId?: string
1833
+ ): Promise<Characteristic>
1834
+
1835
+ /**
1836
+ * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
1837
+ *
1838
+ * @param {UUID} characteristicUUID - {@link Characteristic} UUID.
1839
+ * @param {function(error?: BleError, characteristic?: Characteristic)} listener callback which emits
1840
+ * {@link Characteristic} objects with modified value for each notification.
1841
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1842
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1843
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
1844
+ */
1845
+ monitorCharacteristic(
1846
+ characteristicUUID: UUID,
1847
+ listener: (error: BleError | null, characteristic: Characteristic | null) => void,
1848
+ transactionId?: string
1849
+ ): Subscription
1850
+
1851
+ /**
1852
+ * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
1853
+ *
1854
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
1855
+ * @param {UUID} descriptorUUID {@link Descriptor} UUID.
1856
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1857
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
1858
+ * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
1859
+ * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
1860
+ */
1861
+ readDescriptorForCharacteristic(
1862
+ characteristicUUID: UUID,
1863
+ descriptorUUID: UUID,
1864
+ transactionId?: string
1865
+ ): Promise<Descriptor>
1866
+
1867
+ /**
1868
+ * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
1869
+ *
1870
+ * @param {UUID} characteristicUUID Characteristic UUID
1871
+ * @param {UUID} descriptorUUID Descriptor UUID
1872
+ * @param {Base64} valueBase64 Value to be set coded in Base64
1873
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
1874
+ * @returns {Promise<Descriptor>} Descriptor which saved passed value.
1875
+ */
1876
+ writeDescriptorForCharacteristic(
1877
+ characteristicUUID: UUID,
1878
+ descriptorUUID: UUID,
1879
+ valueBase64: Base64,
1880
+ transactionId?: string
1881
+ ): Promise<Descriptor>
1882
+ }
1883
+
1884
+ // Characteristic.js *************************************************************************************************
1885
+
1886
+ /**
1887
+ * Characteristic object.
1888
+ */
1889
+ export class Characteristic implements NativeCharacteristic {
1890
+ /**
1891
+ * Characteristic unique identifier
1892
+ */
1893
+ id: Identifier
1894
+
1895
+ /**
1896
+ * Characteristic UUID
1897
+ */
1898
+ uuid: UUID
1899
+
1900
+ /**
1901
+ * Service's ID to which characteristic belongs
1902
+ */
1903
+ serviceID: Identifier
1904
+
1905
+ /**
1906
+ * Service's UUID to which characteristic belongs
1907
+ */
1908
+ serviceUUID: UUID
1909
+
1910
+ /**
1911
+ * Device's ID to which characteristic belongs
1912
+ */
1913
+ deviceID: DeviceId
1914
+
1915
+ /**
1916
+ * True if characteristic can be read
1917
+ */
1918
+ isReadable: boolean
1919
+
1920
+ /**
1921
+ * True if characteristic can be written with response
1922
+ */
1923
+ isWritableWithResponse: boolean
1924
+
1925
+ /**
1926
+ * True if characteristic can be written without response
1927
+ */
1928
+ isWritableWithoutResponse: boolean
1929
+
1930
+ /**
1931
+ * True if characteristic can monitor value changes.
1932
+ */
1933
+ isNotifiable: boolean
1934
+
1935
+ /**
1936
+ * True if characteristic is monitoring value changes without ACK.
1937
+ */
1938
+ isNotifying: boolean
1939
+
1940
+ /**
1941
+ * True if characteristic is monitoring value changes with ACK.
1942
+ */
1943
+ isIndicatable: boolean
1944
+
1945
+ /**
1946
+ * Characteristic value if present
1947
+ */
1948
+ value: Base64 | null
1949
+
1950
+ /**
1951
+ * Private constructor used to create instance of {@link Characteristic}.
1952
+ * @param {NativeCharacteristic} nativeCharacteristic NativeCharacteristic
1953
+ * @param {BleManager} manager BleManager
1954
+ * @private
1955
+ */
1956
+ constructor(nativeCharacteristic: NativeCharacteristic, manager: BleManager)
1957
+
1958
+ /**
1959
+ * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
1960
+ *
1961
+ * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
1962
+ * discovered for this {@link Characteristic}.
1963
+ */
1964
+ descriptors(): Promise<Array<Descriptor>>
1965
+
1966
+ /**
1967
+ * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
1968
+ *
1969
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1970
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1971
+ * @returns {Promise<Characteristic>} Promise which emits this {@link Characteristic}. Latest value will be stored
1972
+ * inside returned object.
1973
+ */
1974
+ read(transactionId?: string): Promise<Characteristic>
1975
+
1976
+ /**
1977
+ * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
1978
+ *
1979
+ * @param {Base64} valueBase64 Value in Base64 format.
1980
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1981
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1982
+ * @returns {Promise<Characteristic>} Promise which emits this {@link Characteristic}. Latest value may
1983
+ * not be stored inside returned object.
1984
+ */
1985
+ writeWithResponse(valueBase64: Base64, transactionId?: string): Promise<Characteristic>
1986
+
1987
+ /**
1988
+ * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
1989
+ *
1990
+ * @param {Base64} valueBase64 Value in Base64 format.
1991
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
1992
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
1993
+ * @returns {Promise<Characteristic>} Promise which emits this {@link Characteristic}. Latest value may
1994
+ * not be stored inside returned object.
1995
+ */
1996
+ writeWithoutResponse(valueBase64: Base64, transactionId?: string): Promise<Characteristic>
1997
+
1998
+ /**
1999
+ * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
2000
+ *
2001
+ * @param {function(error?: BleError, characteristic?: Characteristic)} listener callback which emits
2002
+ * this {@link Characteristic} with modified value for each notification.
2003
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
2004
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
2005
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
2006
+ */
2007
+ monitor(
2008
+ listener: (error: BleError | null, characteristic: Characteristic | null) => void,
2009
+ transactionId?: string
2010
+ ): Subscription
2011
+
2012
+ /**
2013
+ * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
2014
+ *
2015
+ * @param {UUID} descriptorUUID {@link Descriptor} UUID.
2016
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
2017
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
2018
+ * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
2019
+ * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
2020
+ */
2021
+ readDescriptor(descriptorUUID: UUID, transactionId?: string): Promise<Descriptor>
2022
+
2023
+ /**
2024
+ * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
2025
+ *
2026
+ * @param {UUID} descriptorUUID Descriptor UUID
2027
+ * @param {Base64} valueBase64 Value to be set coded in Base64
2028
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
2029
+ * @returns {Promise<Descriptor>} Descriptor which saved passed value.
2030
+ */
2031
+ writeDescriptor(descriptorUUID: UUID, valueBase64: Base64, transactionId?: string): Promise<Descriptor>
2032
+ }
2033
+
2034
+ // Descriptor.js *************************************************************************************************
2035
+
2036
+ /**
2037
+ * Descriptor object.
2038
+ */
2039
+ export class Descriptor implements NativeDescriptor {
2040
+ /**
2041
+ * Internal BLE Manager handle
2042
+ * @private
2043
+ */
2044
+ _manager: BleManager
2045
+
2046
+ /**
2047
+ * Descriptor unique identifier
2048
+ */
2049
+ id: Identifier
2050
+
2051
+ /**
2052
+ * Descriptor UUID
2053
+ */
2054
+ uuid: UUID
2055
+
2056
+ /**
2057
+ * Characteristic's ID to which descriptor belongs
2058
+ */
2059
+ characteristicID: Identifier
2060
+
2061
+ /**
2062
+ * Characteristic's UUID to which descriptor belongs
2063
+ */
2064
+ characteristicUUID: UUID
2065
+
2066
+ /**
2067
+ * Service's ID to which descriptor belongs
2068
+ */
2069
+ serviceID: Identifier
2070
+
2071
+ /**
2072
+ * Service's UUID to which descriptor belongs
2073
+ */
2074
+ serviceUUID: UUID
2075
+
2076
+ /**
2077
+ * Device's ID to which descriptor belongs
2078
+ */
2079
+ deviceID: DeviceId
2080
+
2081
+ /**
2082
+ * Descriptor value if present
2083
+ */
2084
+ value: Base64 | null
2085
+
2086
+ /**
2087
+ * Private constructor used to create instance of {@link Descriptor}.
2088
+ * @param {NativeDescriptor} nativeDescriptor NativeDescriptor
2089
+ * @param {BleManager} manager BleManager
2090
+ * @private
2091
+ */
2092
+ constructor(nativeDescriptor: NativeDescriptor, manager: BleManager)
2093
+
2094
+ /**
2095
+ * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
2096
+ *
2097
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
2098
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
2099
+ * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
2100
+ * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
2101
+ */
2102
+ read(transactionId?: string): Promise<Descriptor>
2103
+
2104
+ /**
2105
+ * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
2106
+ *
2107
+ * @param {Base64} valueBase64 Value to be set coded in Base64
2108
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
2109
+ * @returns {Promise<Descriptor>} Descriptor which saved passed value.
2110
+ */
2111
+ write(valueBase64: Base64, transactionId?: string): Promise<Descriptor>
2112
+ }
2113
+ }