forked from dotintent/react-native-ble-plx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Descriptor.js
82 lines (77 loc) · 2.44 KB
/
Descriptor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// @flow
'use strict'
import type { BleManager } from './BleManager'
import type { NativeDescriptor } from './BleModule'
import type { DeviceId, Identifier, UUID, TransactionId, Base64 } from './TypeDefinition'
/**
* Descriptor object.
*/
export class Descriptor implements NativeDescriptor {
/**
* Internal BLE Manager handle
* @private
*/
_manager: BleManager
/**
* Descriptor unique identifier
*/
id: Identifier
/**
* Descriptor UUID
*/
uuid: UUID
/**
* Characteristic's ID to which descriptor belongs
*/
characteristicID: Identifier
/**
* Characteristic's UUID to which descriptor belongs
*/
characteristicUUID: UUID
/**
* Service's ID to which descriptor belongs
*/
serviceID: Identifier
/**
* Service's UUID to which descriptor belongs
*/
serviceUUID: UUID
/**
* Device's ID to which descriptor belongs
*/
deviceID: DeviceId
/**
* Descriptor value if present
*/
value: ?Base64
/**
* Private constructor used to create instance of {@link Descriptor}.
* @param {NativeDescriptor} nativeDescriptor NativeDescriptor
* @param {BleManager} manager BleManager
* @private
*/
constructor(nativeDescriptor: NativeDescriptor, manager: BleManager) {
Object.assign(this, nativeDescriptor, { _manager: manager })
}
/**
* {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
*
* @param {?TransactionId} transactionId optional `transactionId` which can be used in
* {@link #blemanagercanceltransaction|cancelTransaction()} function.
* @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
* UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
*/
async read(transactionId: ?TransactionId): Promise<Descriptor> {
return this._manager._readDescriptor(this.id, transactionId)
}
/**
* {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
*
* @param {Base64} valueBase64 Value to be set coded in Base64
* @param {?TransactionId} transactionId Transaction handle used to cancel operation
* @returns {Promise<Descriptor>} Descriptor which saved passed value.
*/
async write(valueBase64: Base64, transactionId: ?TransactionId): Promise<Descriptor> {
return this._manager._writeDescriptor(this.id, valueBase64, transactionId)
}
}