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