@react-native-ohos/react-native-ble-plx 3.2.1-rc.1 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +202 -202
  2. package/README.OpenSource +10 -10
  3. package/README.md +9 -9
  4. package/app.plugin.js +1 -1
  5. package/harmony/rn_bleplx/build-profile.json5 +7 -7
  6. package/harmony/rn_bleplx/hvigorfile.ts +1 -1
  7. package/harmony/rn_bleplx/index.ets +26 -26
  8. package/harmony/rn_bleplx/obfuscation-rules.txt +17 -17
  9. package/harmony/rn_bleplx/oh-package.json5 +13 -13
  10. package/harmony/rn_bleplx/src/main/cpp/BlePlxPackage.h +36 -36
  11. package/harmony/rn_bleplx/src/main/cpp/CMakeLists.txt +9 -9
  12. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/BaseReactNativeBlePlxPackage.h +65 -65
  13. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.cpp +59 -59
  14. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.h +16 -16
  15. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ComponentDescriptors.h +22 -22
  16. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.cpp +18 -18
  17. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.h +19 -19
  18. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.cpp +21 -21
  19. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.h +20 -20
  20. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.cpp +19 -19
  21. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.h +25 -25
  22. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.cpp +18 -18
  23. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.h +22 -22
  24. package/harmony/rn_bleplx/src/main/ets/BleDevice.ts +98 -98
  25. package/harmony/rn_bleplx/src/main/ets/BleModule.ts +1219 -1219
  26. package/harmony/rn_bleplx/src/main/ets/BlePlxInterface.ts +26 -26
  27. package/harmony/rn_bleplx/src/main/ets/BlePlxModule.ts +246 -246
  28. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ets +46 -46
  29. package/harmony/rn_bleplx/src/main/ets/Characteristic.ts +179 -179
  30. package/harmony/rn_bleplx/src/main/ets/CommonConstants.ts +29 -29
  31. package/harmony/rn_bleplx/src/main/ets/Descriptor.ts +143 -143
  32. package/harmony/rn_bleplx/src/main/ets/Service.ts +85 -85
  33. package/harmony/rn_bleplx/src/main/ets/common/BleError.ts +90 -90
  34. package/harmony/rn_bleplx/src/main/ets/common/BleErrorToJsObjectConverter.ts +62 -62
  35. package/harmony/rn_bleplx/src/main/ets/common/BleEvent.ts +32 -32
  36. package/harmony/rn_bleplx/src/main/ets/common/BleUtils.ts +86 -86
  37. package/harmony/rn_bleplx/src/main/ets/common/IdGenerator.ts +49 -49
  38. package/harmony/rn_bleplx/src/main/ets/common/IdGeneratorKey.ts +70 -70
  39. package/harmony/rn_bleplx/src/main/ets/common/InstanceIdGenerator.ts +36 -36
  40. package/harmony/rn_bleplx/src/main/ets/common/Logger.ts +64 -64
  41. package/harmony/rn_bleplx/src/main/ets/common/PermissionHandler.ts +98 -98
  42. package/harmony/rn_bleplx/src/main/ets/common/ServiceFactory.ts +37 -37
  43. package/harmony/rn_bleplx/src/main/ets/generated/components/ts.ts +5 -5
  44. package/harmony/rn_bleplx/src/main/ets/generated/index.ets +5 -5
  45. package/harmony/rn_bleplx/src/main/ets/generated/ts.ts +6 -6
  46. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/BlePlx.ts +100 -100
  47. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/ts.ts +5 -5
  48. package/harmony/rn_bleplx/src/main/module.json5 +6 -6
  49. package/harmony/rn_bleplx/ts.ets +25 -25
  50. package/harmony/rn_bleplx.har +0 -0
  51. package/package.json +185 -185
  52. package/src/BleError.js +555 -555
  53. package/src/BleManager.js +1287 -1287
  54. package/src/BleModule.js +847 -847
  55. package/src/Characteristic.js +166 -166
  56. package/src/Descriptor.js +82 -82
  57. package/src/Device.js +370 -370
  58. package/src/NativeBlePlx.ts +121 -121
  59. package/src/Service.js +188 -188
  60. package/src/TypeDefinition.js +360 -360
  61. package/src/Utils.js +26 -26
  62. package/src/index.d.ts +2113 -2113
  63. package/src/index.js +20 -20
  64. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ts +0 -46
  65. package/harmony/rn_bleplx/ts.ts +0 -26
@@ -1,121 +1,121 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (C) 2023 Huawei Device Co., Ltd.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
26
- import { TurboModuleRegistry } from 'react-native';
27
-
28
- export interface Spec extends TurboModule {
29
-
30
- // NativeModule methods
31
-
32
- addListener(eventName: string): void;
33
-
34
- removeListeners(count: number): void;
35
-
36
- createClient(restoreStateIdentifier?: string): void;
37
-
38
- destroyClient(): Promise<void>;
39
-
40
- cancelTransaction(transactionId: string): Promise<void>;
41
-
42
- setLogLevel(logLevel: string): Promise<Object>;
43
-
44
- logLevel(): Promise<Object>;
45
-
46
- enable(transactionId: string): Promise<void>;
47
-
48
- disable(transactionId: string): Promise<void>;
49
-
50
- state(): Promise<Object>;
51
-
52
- startDeviceScan(filteredUUIDs?: Array<string>, options?: Object): Promise<void>;
53
-
54
- stopDeviceScan(): Promise<void>;
55
-
56
- requestConnectionPriorityForDevice(deviceId: string, connectionPriority: number, transactionId: string): Promise<Object>;
57
-
58
- readRSSIForDevice(deviceId: string, transactionId: string): Promise<Object>;
59
-
60
- requestMTUForDevice(deviceId: string, mtu: number, transactionId: string): Promise<Object>;
61
-
62
- devices(deviceIdentifiers: Array<string>): Promise<Array<Object>>;
63
-
64
- connectedDevices(serviceUUIDs: Array<string>): Promise<Array<Object>>;
65
-
66
- connectToDevice(deviceId: string, options?: Object): Promise<Object>;
67
-
68
- cancelDeviceConnection(deviceId: string): Promise<Object>;
69
-
70
- isDeviceConnected(deviceId: string): Promise<boolean>;
71
-
72
- discoverAllServicesAndCharacteristicsForDevice(deviceId: string, transactionId: string): Promise<Object>;
73
-
74
- servicesForDevice(deviceId: string): Promise<Array<Object>>;
75
-
76
- characteristicsForDevice(deviceId: string, serviceUUID: string): Promise<Array<Object>>;
77
-
78
- characteristicsForService(serviceIdentifier: number): Promise<Array<Object>>;
79
-
80
- descriptorsForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string): Promise<Array<Object>>; //Object-->NativeDescriptor
81
-
82
- descriptorsForService(serviceIdentifier: number, characteristicUUID: string): Promise<Array<Object>>; //Object-->NativeDescriptor
83
-
84
- descriptorsForCharacteristic(characteristicIdentifier: number): Promise<Array<Object>>; //Object-->NativeDescriptor
85
-
86
- readCharacteristicForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
87
-
88
- readCharacteristicForService(serviceIdentifier: number, characteristicUUID: string, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
89
-
90
- readCharacteristic(characteristicIdentifer: number, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
91
-
92
- writeCharacteristicForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, valueBase64: string, response: boolean, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
93
-
94
- writeCharacteristicForService(serviceIdentifier: number, characteristicUUID: string, valueBase64: string, response: boolean, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
95
-
96
- writeCharacteristic(characteristicIdentifier: number, valueBase64: string, response: boolean, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
97
-
98
- monitorCharacteristicForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, transactionId: string): Promise<void>;
99
-
100
- monitorCharacteristicForService(serviceIdentifier: number, characteristicUUID: string, transactionId: string): Promise<void>;
101
-
102
- monitorCharacteristic(characteristicIdentifier: number, transactionId: string): Promise<void>;
103
-
104
- readDescriptorForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, descriptorUUID: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
105
-
106
- readDescriptorForService(serviceIdentifier: number, characteristicUUID: string, descriptorUUID: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
107
-
108
- readDescriptorForCharacteristic(characteristicIdentifier: number, descriptorUUID: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
109
-
110
- readDescriptor(descriptorIdentifier: number, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
111
-
112
- writeDescriptorForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, descriptorUUID: string, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
113
-
114
- writeDescriptorForService(serviceIdentifier: number, characteristicUUID: string, descriptorUUID: string, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
115
-
116
- writeDescriptorForCharacteristic(characteristicIdentifier: number, descriptorUUID: string, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
117
-
118
- writeDescriptor(descriptorIdentifier: number, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
119
- }
120
-
121
- export default TurboModuleRegistry.getEnforcing<Spec>('BlePlx');
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
26
+ import { TurboModuleRegistry } from 'react-native';
27
+
28
+ export interface Spec extends TurboModule {
29
+
30
+ // NativeModule methods
31
+
32
+ addListener(eventName: string): void;
33
+
34
+ removeListeners(count: number): void;
35
+
36
+ createClient(restoreStateIdentifier?: string): void;
37
+
38
+ destroyClient(): Promise<void>;
39
+
40
+ cancelTransaction(transactionId: string): Promise<void>;
41
+
42
+ setLogLevel(logLevel: string): Promise<Object>;
43
+
44
+ logLevel(): Promise<Object>;
45
+
46
+ enable(transactionId: string): Promise<void>;
47
+
48
+ disable(transactionId: string): Promise<void>;
49
+
50
+ state(): Promise<Object>;
51
+
52
+ startDeviceScan(filteredUUIDs?: Array<string>, options?: Object): Promise<void>;
53
+
54
+ stopDeviceScan(): Promise<void>;
55
+
56
+ requestConnectionPriorityForDevice(deviceId: string, connectionPriority: number, transactionId: string): Promise<Object>;
57
+
58
+ readRSSIForDevice(deviceId: string, transactionId: string): Promise<Object>;
59
+
60
+ requestMTUForDevice(deviceId: string, mtu: number, transactionId: string): Promise<Object>;
61
+
62
+ devices(deviceIdentifiers: Array<string>): Promise<Array<Object>>;
63
+
64
+ connectedDevices(serviceUUIDs: Array<string>): Promise<Array<Object>>;
65
+
66
+ connectToDevice(deviceId: string, options?: Object): Promise<Object>;
67
+
68
+ cancelDeviceConnection(deviceId: string): Promise<Object>;
69
+
70
+ isDeviceConnected(deviceId: string): Promise<boolean>;
71
+
72
+ discoverAllServicesAndCharacteristicsForDevice(deviceId: string, transactionId: string): Promise<Object>;
73
+
74
+ servicesForDevice(deviceId: string): Promise<Array<Object>>;
75
+
76
+ characteristicsForDevice(deviceId: string, serviceUUID: string): Promise<Array<Object>>;
77
+
78
+ characteristicsForService(serviceIdentifier: number): Promise<Array<Object>>;
79
+
80
+ descriptorsForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string): Promise<Array<Object>>; //Object-->NativeDescriptor
81
+
82
+ descriptorsForService(serviceIdentifier: number, characteristicUUID: string): Promise<Array<Object>>; //Object-->NativeDescriptor
83
+
84
+ descriptorsForCharacteristic(characteristicIdentifier: number): Promise<Array<Object>>; //Object-->NativeDescriptor
85
+
86
+ readCharacteristicForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
87
+
88
+ readCharacteristicForService(serviceIdentifier: number, characteristicUUID: string, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
89
+
90
+ readCharacteristic(characteristicIdentifer: number, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
91
+
92
+ writeCharacteristicForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, valueBase64: string, response: boolean, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
93
+
94
+ writeCharacteristicForService(serviceIdentifier: number, characteristicUUID: string, valueBase64: string, response: boolean, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
95
+
96
+ writeCharacteristic(characteristicIdentifier: number, valueBase64: string, response: boolean, transactionId: string): Promise<Object>; //Object-->NativeCharacteristic
97
+
98
+ monitorCharacteristicForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, transactionId: string): Promise<void>;
99
+
100
+ monitorCharacteristicForService(serviceIdentifier: number, characteristicUUID: string, transactionId: string): Promise<void>;
101
+
102
+ monitorCharacteristic(characteristicIdentifier: number, transactionId: string): Promise<void>;
103
+
104
+ readDescriptorForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, descriptorUUID: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
105
+
106
+ readDescriptorForService(serviceIdentifier: number, characteristicUUID: string, descriptorUUID: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
107
+
108
+ readDescriptorForCharacteristic(characteristicIdentifier: number, descriptorUUID: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
109
+
110
+ readDescriptor(descriptorIdentifier: number, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
111
+
112
+ writeDescriptorForDevice(deviceId: string, serviceUUID: string, characteristicUUID: string, descriptorUUID: string, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
113
+
114
+ writeDescriptorForService(serviceIdentifier: number, characteristicUUID: string, descriptorUUID: string, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
115
+
116
+ writeDescriptorForCharacteristic(characteristicIdentifier: number, descriptorUUID: string, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
117
+
118
+ writeDescriptor(descriptorIdentifier: number, valueBase64: string, transactionId: string): Promise<Object>; //Object-->NativeDescriptor
119
+ }
120
+
121
+ export default TurboModuleRegistry.getEnforcing<Spec>('BlePlx');
package/src/Service.js CHANGED
@@ -1,188 +1,188 @@
1
- // @flow
2
- 'use strict'
3
-
4
- import type { BleManager } from './BleManager'
5
- import type { BleError } from './BleError'
6
- import type { Characteristic } from './Characteristic'
7
- import type { Descriptor } from './Descriptor'
8
- import type { NativeService } from './BleModule'
9
- import type { DeviceId, Identifier, Base64, UUID, Subscription, TransactionId } from './TypeDefinition'
10
-
11
- /**
12
- * Service object.
13
- */
14
- export class Service implements NativeService {
15
- /**
16
- * Internal BLE Manager handle
17
- * @private
18
- */
19
- _manager: BleManager
20
- /**
21
- * Service unique identifier
22
- */
23
- id: Identifier
24
- /**
25
- * Service UUID
26
- */
27
- uuid: UUID
28
- /**
29
- * Device's ID to which service belongs
30
- */
31
- deviceID: DeviceId
32
- /**
33
- * Value indicating whether the type of service is primary or secondary.
34
- */
35
- isPrimary: boolean
36
-
37
- /**
38
- * Private constructor used to create {@link Service} object.
39
- *
40
- * @param {NativeService} nativeService NativeService properties to be copied.
41
- * @param {BleManager} manager Current BleManager instance.
42
- * @private
43
- * @ignore
44
- */
45
- constructor(nativeService: NativeService, manager: BleManager) {
46
- Object.assign(this, nativeService, { _manager: manager })
47
- }
48
-
49
- /**
50
- * {@link #blemanagercharacteristicsfordevice|bleManager.characteristicsForDevice()} with partially filled arguments.
51
- *
52
- * @returns {Promise<Array<Characteristic>>} Promise which emits array of {@link Characteristic} objects which are
53
- * discovered for this service.
54
- */
55
- characteristics(): Promise<Array<Characteristic>> {
56
- return this._manager._characteristicsForService(this.id)
57
- }
58
-
59
- /**
60
- * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
61
- *
62
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
63
- * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
64
- * discovered for this {@link Service} in specified {@link Characteristic}.
65
- */
66
- descriptorsForCharacteristic(characteristicUUID: UUID): Promise<Array<Descriptor>> {
67
- return this._manager._descriptorsForService(this.id, characteristicUUID)
68
- }
69
-
70
- /**
71
- * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
72
- *
73
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
74
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
75
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
76
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
77
- * UUID path. Latest value of {@link Characteristic} will be stored inside returned object.
78
- */
79
- readCharacteristic(characteristicUUID: UUID, transactionId: ?TransactionId): Promise<Characteristic> {
80
- return this._manager._readCharacteristicForService(this.id, characteristicUUID, transactionId)
81
- }
82
-
83
- /**
84
- * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
85
- *
86
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
87
- * @param {Base64} valueBase64 Value in Base64 format.
88
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
89
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
90
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
91
- * UUID path. Latest value of characteristic may not be stored inside returned object.
92
- */
93
- writeCharacteristicWithResponse(
94
- characteristicUUID: UUID,
95
- valueBase64: Base64,
96
- transactionId: ?TransactionId
97
- ): Promise<Characteristic> {
98
- return this._manager._writeCharacteristicWithResponseForService(
99
- this.id,
100
- characteristicUUID,
101
- valueBase64,
102
- transactionId
103
- )
104
- }
105
-
106
- /**
107
- * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
108
- *
109
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
110
- * @param {Base64} valueBase64 Value in Base64 format.
111
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
112
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
113
- * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
114
- * UUID path. Latest value of characteristic may not be stored inside returned object.
115
- */
116
- writeCharacteristicWithoutResponse(
117
- characteristicUUID: UUID,
118
- valueBase64: Base64,
119
- transactionId: ?TransactionId
120
- ): Promise<Characteristic> {
121
- return this._manager._writeCharacteristicWithoutResponseForService(
122
- this.id,
123
- characteristicUUID,
124
- valueBase64,
125
- transactionId
126
- )
127
- }
128
-
129
- /**
130
- * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
131
- *
132
- * @param {UUID} characteristicUUID - {@link Characteristic} UUID.
133
- * @param {function(error: ?BleError, characteristic: ?Characteristic)} listener callback which emits
134
- * {@link Characteristic} objects with modified value for each notification.
135
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
136
- * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
137
- * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
138
- */
139
- monitorCharacteristic(
140
- characteristicUUID: UUID,
141
- listener: (error: ?BleError, characteristic: ?Characteristic) => void,
142
- transactionId: ?TransactionId
143
- ): Subscription {
144
- return this._manager._monitorCharacteristicForService(this.id, characteristicUUID, listener, transactionId)
145
- }
146
-
147
- /**
148
- * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
149
- *
150
- * @param {UUID} characteristicUUID {@link Characteristic} UUID.
151
- * @param {UUID} descriptorUUID {@link Descriptor} UUID.
152
- * @param {?TransactionId} transactionId optional `transactionId` which can be used in
153
- * {@link #blemanagercanceltransaction|cancelTransaction()} function.
154
- * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
155
- * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
156
- */
157
- async readDescriptorForCharacteristic(
158
- characteristicUUID: UUID,
159
- descriptorUUID: UUID,
160
- transactionId: ?TransactionId
161
- ): Promise<Descriptor> {
162
- return this._manager._readDescriptorForService(this.id, characteristicUUID, descriptorUUID, transactionId)
163
- }
164
-
165
- /**
166
- * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
167
- *
168
- * @param {UUID} characteristicUUID Characteristic UUID
169
- * @param {UUID} descriptorUUID Descriptor UUID
170
- * @param {Base64} valueBase64 Value to be set coded in Base64
171
- * @param {?TransactionId} transactionId Transaction handle used to cancel operation
172
- * @returns {Promise<Descriptor>} Descriptor which saved passed value.
173
- */
174
- async writeDescriptorForCharacteristic(
175
- characteristicUUID: UUID,
176
- descriptorUUID: UUID,
177
- valueBase64: Base64,
178
- transactionId: ?TransactionId
179
- ): Promise<Descriptor> {
180
- return this._manager._writeDescriptorForService(
181
- this.id,
182
- characteristicUUID,
183
- descriptorUUID,
184
- valueBase64,
185
- transactionId
186
- )
187
- }
188
- }
1
+ // @flow
2
+ 'use strict'
3
+
4
+ import type { BleManager } from './BleManager'
5
+ import type { BleError } from './BleError'
6
+ import type { Characteristic } from './Characteristic'
7
+ import type { Descriptor } from './Descriptor'
8
+ import type { NativeService } from './BleModule'
9
+ import type { DeviceId, Identifier, Base64, UUID, Subscription, TransactionId } from './TypeDefinition'
10
+
11
+ /**
12
+ * Service object.
13
+ */
14
+ export class Service implements NativeService {
15
+ /**
16
+ * Internal BLE Manager handle
17
+ * @private
18
+ */
19
+ _manager: BleManager
20
+ /**
21
+ * Service unique identifier
22
+ */
23
+ id: Identifier
24
+ /**
25
+ * Service UUID
26
+ */
27
+ uuid: UUID
28
+ /**
29
+ * Device's ID to which service belongs
30
+ */
31
+ deviceID: DeviceId
32
+ /**
33
+ * Value indicating whether the type of service is primary or secondary.
34
+ */
35
+ isPrimary: boolean
36
+
37
+ /**
38
+ * Private constructor used to create {@link Service} object.
39
+ *
40
+ * @param {NativeService} nativeService NativeService properties to be copied.
41
+ * @param {BleManager} manager Current BleManager instance.
42
+ * @private
43
+ * @ignore
44
+ */
45
+ constructor(nativeService: NativeService, manager: BleManager) {
46
+ Object.assign(this, nativeService, { _manager: manager })
47
+ }
48
+
49
+ /**
50
+ * {@link #blemanagercharacteristicsfordevice|bleManager.characteristicsForDevice()} with partially filled arguments.
51
+ *
52
+ * @returns {Promise<Array<Characteristic>>} Promise which emits array of {@link Characteristic} objects which are
53
+ * discovered for this service.
54
+ */
55
+ characteristics(): Promise<Array<Characteristic>> {
56
+ return this._manager._characteristicsForService(this.id)
57
+ }
58
+
59
+ /**
60
+ * {@link #blemanagerdescriptorsfordevice|bleManager.descriptorsForDevice()} with partially filled arguments.
61
+ *
62
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
63
+ * @returns {Promise<Array<Descriptor>>} Promise which emits array of {@link Descriptor} objects which are
64
+ * discovered for this {@link Service} in specified {@link Characteristic}.
65
+ */
66
+ descriptorsForCharacteristic(characteristicUUID: UUID): Promise<Array<Descriptor>> {
67
+ return this._manager._descriptorsForService(this.id, characteristicUUID)
68
+ }
69
+
70
+ /**
71
+ * {@link #blemanagerreadcharacteristicfordevice|bleManager.readCharacteristicForDevice()} with partially filled arguments.
72
+ *
73
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
74
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
75
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
76
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
77
+ * UUID path. Latest value of {@link Characteristic} will be stored inside returned object.
78
+ */
79
+ readCharacteristic(characteristicUUID: UUID, transactionId: ?TransactionId): Promise<Characteristic> {
80
+ return this._manager._readCharacteristicForService(this.id, characteristicUUID, transactionId)
81
+ }
82
+
83
+ /**
84
+ * {@link #blemanagerwritecharacteristicwithresponsefordevice|bleManager.writeCharacteristicWithResponseForDevice()} with partially filled arguments.
85
+ *
86
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
87
+ * @param {Base64} valueBase64 Value in Base64 format.
88
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
89
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
90
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
91
+ * UUID path. Latest value of characteristic may not be stored inside returned object.
92
+ */
93
+ writeCharacteristicWithResponse(
94
+ characteristicUUID: UUID,
95
+ valueBase64: Base64,
96
+ transactionId: ?TransactionId
97
+ ): Promise<Characteristic> {
98
+ return this._manager._writeCharacteristicWithResponseForService(
99
+ this.id,
100
+ characteristicUUID,
101
+ valueBase64,
102
+ transactionId
103
+ )
104
+ }
105
+
106
+ /**
107
+ * {@link #blemanagerwritecharacteristicwithoutresponsefordevice|bleManager.writeCharacteristicWithoutResponseForDevice()} with partially filled arguments.
108
+ *
109
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
110
+ * @param {Base64} valueBase64 Value in Base64 format.
111
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
112
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
113
+ * @returns {Promise<Characteristic>} Promise which emits first {@link Characteristic} object matching specified
114
+ * UUID path. Latest value of characteristic may not be stored inside returned object.
115
+ */
116
+ writeCharacteristicWithoutResponse(
117
+ characteristicUUID: UUID,
118
+ valueBase64: Base64,
119
+ transactionId: ?TransactionId
120
+ ): Promise<Characteristic> {
121
+ return this._manager._writeCharacteristicWithoutResponseForService(
122
+ this.id,
123
+ characteristicUUID,
124
+ valueBase64,
125
+ transactionId
126
+ )
127
+ }
128
+
129
+ /**
130
+ * {@link #blemanagermonitorcharacteristicfordevice|bleManager.monitorCharacteristicForDevice()} with partially filled arguments.
131
+ *
132
+ * @param {UUID} characteristicUUID - {@link Characteristic} UUID.
133
+ * @param {function(error: ?BleError, characteristic: ?Characteristic)} listener callback which emits
134
+ * {@link Characteristic} objects with modified value for each notification.
135
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
136
+ * {@link #blemanagercanceltransaction|bleManager.cancelTransaction()} function.
137
+ * @returns {Subscription} Subscription on which `remove()` function can be called to unsubscribe.
138
+ */
139
+ monitorCharacteristic(
140
+ characteristicUUID: UUID,
141
+ listener: (error: ?BleError, characteristic: ?Characteristic) => void,
142
+ transactionId: ?TransactionId
143
+ ): Subscription {
144
+ return this._manager._monitorCharacteristicForService(this.id, characteristicUUID, listener, transactionId)
145
+ }
146
+
147
+ /**
148
+ * {@link #blemanagerreaddescriptorfordevice|bleManager.readDescriptorForDevice()} with partially filled arguments.
149
+ *
150
+ * @param {UUID} characteristicUUID {@link Characteristic} UUID.
151
+ * @param {UUID} descriptorUUID {@link Descriptor} UUID.
152
+ * @param {?TransactionId} transactionId optional `transactionId` which can be used in
153
+ * {@link #blemanagercanceltransaction|cancelTransaction()} function.
154
+ * @returns {Promise<Descriptor>} Promise which emits first {@link Descriptor} object matching specified
155
+ * UUID paths. Latest value of {@link Descriptor} will be stored inside returned object.
156
+ */
157
+ async readDescriptorForCharacteristic(
158
+ characteristicUUID: UUID,
159
+ descriptorUUID: UUID,
160
+ transactionId: ?TransactionId
161
+ ): Promise<Descriptor> {
162
+ return this._manager._readDescriptorForService(this.id, characteristicUUID, descriptorUUID, transactionId)
163
+ }
164
+
165
+ /**
166
+ * {@link #blemanagerwritedescriptorfordevice|bleManager.writeDescriptorForDevice()} with partially filled arguments.
167
+ *
168
+ * @param {UUID} characteristicUUID Characteristic UUID
169
+ * @param {UUID} descriptorUUID Descriptor UUID
170
+ * @param {Base64} valueBase64 Value to be set coded in Base64
171
+ * @param {?TransactionId} transactionId Transaction handle used to cancel operation
172
+ * @returns {Promise<Descriptor>} Descriptor which saved passed value.
173
+ */
174
+ async writeDescriptorForCharacteristic(
175
+ characteristicUUID: UUID,
176
+ descriptorUUID: UUID,
177
+ valueBase64: Base64,
178
+ transactionId: ?TransactionId
179
+ ): Promise<Descriptor> {
180
+ return this._manager._writeDescriptorForService(
181
+ this.id,
182
+ characteristicUUID,
183
+ descriptorUUID,
184
+ valueBase64,
185
+ transactionId
186
+ )
187
+ }
188
+ }