@react-native-ohos/react-native-ble-plx 3.2.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.
Files changed (65) hide show
  1. package/LICENSE +202 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +9 -0
  4. package/app.plugin.js +1 -0
  5. package/harmony/rn_bleplx/build-profile.json5 +8 -0
  6. package/harmony/rn_bleplx/hvigorfile.ts +2 -0
  7. package/harmony/rn_bleplx/index.ets +27 -0
  8. package/harmony/rn_bleplx/obfuscation-rules.txt +18 -0
  9. package/harmony/rn_bleplx/oh-package.json5 +13 -0
  10. package/harmony/rn_bleplx/src/main/cpp/BlePlxPackage.h +36 -0
  11. package/harmony/rn_bleplx/src/main/cpp/CMakeLists.txt +9 -0
  12. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/BaseReactNativeBlePlxPackage.h +65 -0
  13. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.cpp +59 -0
  14. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.h +16 -0
  15. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ComponentDescriptors.h +22 -0
  16. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.cpp +18 -0
  17. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.h +19 -0
  18. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.cpp +21 -0
  19. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.h +20 -0
  20. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.cpp +19 -0
  21. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.h +25 -0
  22. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.cpp +18 -0
  23. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.h +23 -0
  24. package/harmony/rn_bleplx/src/main/ets/BleDevice.ts +99 -0
  25. package/harmony/rn_bleplx/src/main/ets/BleModule.ts +1219 -0
  26. package/harmony/rn_bleplx/src/main/ets/BlePlxInterface.ts +27 -0
  27. package/harmony/rn_bleplx/src/main/ets/BlePlxModule.ts +246 -0
  28. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ets +47 -0
  29. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ts +46 -0
  30. package/harmony/rn_bleplx/src/main/ets/Characteristic.ts +179 -0
  31. package/harmony/rn_bleplx/src/main/ets/CommonConstants.ts +30 -0
  32. package/harmony/rn_bleplx/src/main/ets/Descriptor.ts +143 -0
  33. package/harmony/rn_bleplx/src/main/ets/Service.ts +85 -0
  34. package/harmony/rn_bleplx/src/main/ets/common/BleError.ts +90 -0
  35. package/harmony/rn_bleplx/src/main/ets/common/BleErrorToJsObjectConverter.ts +63 -0
  36. package/harmony/rn_bleplx/src/main/ets/common/BleEvent.ts +33 -0
  37. package/harmony/rn_bleplx/src/main/ets/common/BleUtils.ts +86 -0
  38. package/harmony/rn_bleplx/src/main/ets/common/IdGenerator.ts +49 -0
  39. package/harmony/rn_bleplx/src/main/ets/common/IdGeneratorKey.ts +70 -0
  40. package/harmony/rn_bleplx/src/main/ets/common/InstanceIdGenerator.ts +37 -0
  41. package/harmony/rn_bleplx/src/main/ets/common/Logger.ts +64 -0
  42. package/harmony/rn_bleplx/src/main/ets/common/PermissionHandler.ts +98 -0
  43. package/harmony/rn_bleplx/src/main/ets/common/ServiceFactory.ts +37 -0
  44. package/harmony/rn_bleplx/src/main/ets/generated/components/ts.ts +5 -0
  45. package/harmony/rn_bleplx/src/main/ets/generated/index.ets +5 -0
  46. package/harmony/rn_bleplx/src/main/ets/generated/ts.ts +6 -0
  47. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/BlePlx.ts +100 -0
  48. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/ts.ts +5 -0
  49. package/harmony/rn_bleplx/src/main/module.json5 +7 -0
  50. package/harmony/rn_bleplx/ts.ets +26 -0
  51. package/harmony/rn_bleplx/ts.ts +26 -0
  52. package/harmony/rn_bleplx.har +0 -0
  53. package/package.json +185 -0
  54. package/src/BleError.js +555 -0
  55. package/src/BleManager.js +1287 -0
  56. package/src/BleModule.js +847 -0
  57. package/src/Characteristic.js +166 -0
  58. package/src/Descriptor.js +82 -0
  59. package/src/Device.js +370 -0
  60. package/src/NativeBlePlx.ts +121 -0
  61. package/src/Service.js +188 -0
  62. package/src/TypeDefinition.js +360 -0
  63. package/src/Utils.js +26 -0
  64. package/src/index.d.ts +2113 -0
  65. package/src/index.js +20 -0
@@ -0,0 +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');
package/src/Service.js ADDED
@@ -0,0 +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
+ }
@@ -0,0 +1,360 @@
1
+ // @flow
2
+ 'use strict'
3
+
4
+ import type { Device } from './Device'
5
+ import { BleErrorCode } from './BleError'
6
+
7
+ /**
8
+ * Bluetooth device id.
9
+ */
10
+ export type DeviceId = string
11
+
12
+ /**
13
+ * Unique identifier for BLE objects.
14
+ */
15
+ export type Identifier = number
16
+
17
+ /**
18
+ * Bluetooth UUID
19
+ */
20
+ export type UUID = string
21
+
22
+ /**
23
+ * Base64 value
24
+ */
25
+ export type Base64 = string
26
+
27
+ /**
28
+ * Transaction identifier. All transaction identifiers in numeric form are reserved for internal use.
29
+ */
30
+ export type TransactionId = string
31
+
32
+ /**
33
+ * [Android only] ConnectionOptions parameter to describe when to call BluetoothGatt.refresh()
34
+ */
35
+ export type RefreshGattMoment = 'OnConnected'
36
+
37
+ /**
38
+ * Subscription
39
+ * @interface
40
+ */
41
+ export interface Subscription {
42
+ /**
43
+ * Removes subscription
44
+ * @memberof Subscription
45
+ * @ignore
46
+ */
47
+ remove(): void;
48
+ }
49
+
50
+ /**
51
+ * Type of error code mapping table
52
+ */
53
+ export type BleErrorCodeMessageMapping = { [$Values < typeof BleErrorCode >]: string }
54
+
55
+ /**
56
+ * Options which can be passed to when creating BLE Manager
57
+ */
58
+ export interface BleManagerOptions {
59
+ /**
60
+ * BLE State restoration identifier used to restore state.
61
+ * @memberof BleManagerOptions
62
+ * @instance
63
+ */
64
+ restoreStateIdentifier?: string;
65
+
66
+ /**
67
+ * Optional function which is used to properly restore state of your BLE Manager. Callback
68
+ * is emitted in the beginning of BleManager creation and optional {@link BleRestoreState}
69
+ * is passed. When value is `null` application is launching for the first time, otherwise
70
+ * it contains saved state which may be used by developer to continue working with
71
+ * connected peripherals.
72
+ * @memberof BleManagerOptions
73
+ * @instance
74
+ */
75
+ restoreStateFunction?: (restoredState: ?BleRestoredState) => void;
76
+
77
+ /**
78
+ * Optional mapping of error codes to error messages. Uses {@link BleErrorCodeMessage}
79
+ * by default.
80
+ *
81
+ * To override logging UUIDs or MAC adresses in error messages copy the original object
82
+ * and overwrite values of interest to you.
83
+ *
84
+ * @memberof BleManagerOptions
85
+ * @instance
86
+ */
87
+ errorCodesToMessagesMapping?: BleErrorCodeMessageMapping;
88
+ }
89
+
90
+ /**
91
+ * Object representing information about restored BLE state after application relaunch.
92
+ */
93
+ export interface BleRestoredState {
94
+ /**
95
+ * List of connected devices after state restoration.
96
+ * @type {Array<Device>}
97
+ * @instance
98
+ * @memberof BleRestoredState
99
+ */
100
+ connectedPeripherals: Array<Device>;
101
+ }
102
+
103
+ /**
104
+ * Scan mode for Bluetooth LE scan.
105
+ */
106
+ export const ScanMode = {
107
+ /**
108
+ * A special Bluetooth LE scan mode. Applications using this scan mode will passively listen for
109
+ * other scan results without starting BLE scans themselves. [Android only]
110
+ */
111
+ Opportunistic: -1,
112
+
113
+ /**
114
+ * Perform Bluetooth LE scan in low power mode. This is the default scan mode as it consumes the
115
+ * least power. [Android and Harmony] [default value]
116
+ */
117
+ LowPower: 0,
118
+
119
+ /**
120
+ * Perform Bluetooth LE scan in balanced power mode. Scan results are returned at a rate that
121
+ * provides a good trade-off between scan frequency and power consumption. [Android and Harmony]
122
+ */
123
+ Balanced: 1,
124
+
125
+ /**
126
+ * Scan using highest duty cycle. It's recommended to only use this mode when the application is
127
+ * running in the foreground. [Android and Harmony]
128
+ */
129
+ LowLatency: 2
130
+ }
131
+
132
+ /**
133
+ * The enum of BLE match mode.
134
+ */
135
+ export const MatchMode = {
136
+ /**
137
+ * Aggressive mode
138
+ */
139
+ Aggressive: 1,
140
+
141
+ /**
142
+ * Sticky mode
143
+ */
144
+ Sticky: 2
145
+ }
146
+
147
+ /**
148
+ * Phy type used during scan.
149
+ */
150
+ export const PhyType = {
151
+ /**
152
+ * Use 1M phy for scanning.
153
+ */
154
+ LE_1M: 1,
155
+
156
+ /**
157
+ * Use all supported Phys for scanning.
158
+ */
159
+ LE_All_Supported: 255
160
+ }
161
+
162
+ /**
163
+ * Scan callback type for Bluetooth LE scan.
164
+ * @name ScanCallbackType
165
+ */
166
+ export const ScanCallbackType = {
167
+ /**
168
+ * Trigger a callback for every Bluetooth advertisement found that matches the filter criteria.
169
+ * If no filter is active, all advertisement packets are reported. [default value]
170
+ */
171
+ AllMatches: 1,
172
+
173
+ /**
174
+ * A result callback is only triggered for the first advertisement packet received that matches
175
+ * the filter criteria.
176
+ */
177
+ FirstMatch: 2,
178
+
179
+ /**
180
+ * Receive a callback when advertisements are no longer received from a device that has been
181
+ * previously reported by a first match callback.
182
+ */
183
+ MatchLost: 4
184
+ }
185
+
186
+ /**
187
+ * Options which can be passed to scanning function
188
+ * @name ScanOptions
189
+ */
190
+ export interface ScanOptions {
191
+ /**
192
+ * By allowing duplicates scanning records are received more frequently [iOS only]
193
+ * @memberof ScanOptions
194
+ * @instance
195
+ */
196
+ allowDuplicates?: boolean;
197
+
198
+ /**
199
+ * Scan mode for Bluetooth LE scan [Android and Harmony]
200
+ * @memberof ScanOptions
201
+ * @instance
202
+ */
203
+ scanMode?: $Values<typeof ScanMode>;
204
+
205
+ /**
206
+ * Scan callback type for Bluetooth LE scan [Android only]
207
+ * @memberof ScanOptions
208
+ * @instance
209
+ */
210
+ callbackType?: $Values<typeof ScanCallbackType>;
211
+ /**
212
+ * Use legacyScan (default true) [Android only]
213
+ * https://developer.android.com/reference/android/bluetooth/le/ScanSettings.Builder#setLegacy(boolean)
214
+ * @memberof ScanOptions
215
+ * @instance
216
+ */
217
+ legacyScan?: boolean;
218
+
219
+ /**
220
+ * Time of delay for reporting the scan result [Harmony only]
221
+ * @memberof ScanOptions
222
+ * @instance
223
+ */
224
+ interval?: number;
225
+
226
+ /**
227
+ * Match mode for Bluetooth LE scan filters hardware match [Harmony only]
228
+ * @memberof ScanOptions
229
+ * @instance
230
+ */
231
+ matchMode?: $Values<typeof MatchMode>;
232
+
233
+ /**
234
+ * Physical Layer used during scan [Harmony only]
235
+ * @memberof ScanOptions
236
+ * @instance
237
+ */
238
+ phyType?: $Values<typeof PhyType>;
239
+ }
240
+
241
+ /**
242
+ * Connection specific options to be passed before connection happen. [Not used]
243
+ */
244
+ export interface ConnectionOptions {
245
+ /**
246
+ * Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device
247
+ * becomes available (true). [Android only]
248
+ * @memberof ConnectionOptions
249
+ * @instance
250
+ */
251
+ autoConnect?: boolean;
252
+
253
+ /**
254
+ * Whether MTU size will be negotiated to this value. It is not guaranteed to get it after connection is successful.
255
+ *
256
+ * @memberof ConnectionOptions
257
+ * @instance
258
+ */
259
+ requestMTU?: number;
260
+
261
+ /**
262
+ * Whether action will be taken to reset services cache. This option may be useful when a peripheral's firmware was
263
+ * updated and it's services/characteristics were added/removed/altered. [Android only]
264
+ * {@link https://stackoverflow.com/questions/22596951/how-to-programmatically-force-bluetooth-low-energy-service-discovery-on-android}
265
+ * @memberof ConnectionOptions
266
+ * @instance
267
+ */
268
+ refreshGatt?: RefreshGattMoment;
269
+
270
+ /**
271
+ * Number of milliseconds after connection is automatically timed out. In case of race condition were connection is
272
+ * established right after timeout event, device will be disconnected immediately. Time out may happen earlier then
273
+ * specified due to OS specific behavior.
274
+ *
275
+ * @memberof ConnectionOptions
276
+ * @instance
277
+ */
278
+ timeout?: number;
279
+ }
280
+
281
+ /**
282
+ * Device Bluetooth Low Energy state. It's keys are used to check {@link #blemanagerstate} values
283
+ * received by {@link BleManager}
284
+ */
285
+ export const State = {
286
+ /**
287
+ * The current state of the manager is unknown; an update is imminent.
288
+ */
289
+ Unknown: 'Unknown',
290
+ /**
291
+ * The connection with the system service was momentarily lost; an update is imminent.
292
+ */
293
+ Resetting: 'Resetting',
294
+ /**
295
+ * The platform does not support Bluetooth low energy.
296
+ */
297
+ Unsupported: 'Unsupported',
298
+ /**
299
+ * The app is not authorized to use Bluetooth low energy.
300
+ */
301
+ Unauthorized: 'Unauthorized',
302
+ /**
303
+ * Bluetooth is currently powered off.
304
+ */
305
+ PoweredOff: 'PoweredOff',
306
+ /**
307
+ * Bluetooth is currently powered on and available to use.
308
+ */
309
+ PoweredOn: 'PoweredOn'
310
+ }
311
+
312
+ /**
313
+ * Native module logging log level. By default it is set to None.
314
+ * @name LogLevel
315
+ */
316
+ export const LogLevel = {
317
+ /**
318
+ * Logging in native module is disabled
319
+ */
320
+ None: 'None',
321
+ /**
322
+ * All logs in native module are shown
323
+ */
324
+ Verbose: 'Verbose',
325
+ /**
326
+ * Only debug logs and of higher importance are shown in native module.
327
+ */
328
+ Debug: 'Debug',
329
+ /**
330
+ * Only info logs and of higher importance are shown in native module.
331
+ */
332
+ Info: 'Info',
333
+ /**
334
+ * Only warning logs and of higher importance are shown in native module.
335
+ */
336
+ Warning: 'Warning',
337
+ /**
338
+ * Only error logs and of higher importance are shown in native module.
339
+ */
340
+ Error: 'Error'
341
+ }
342
+
343
+ /**
344
+ * Connection priority of BLE link determining the balance between power consumption and data throughput.
345
+ * @name ConnectionPriority
346
+ */
347
+ export const ConnectionPriority = {
348
+ /**
349
+ * Default, recommended option balanced between power consumption and data throughput.
350
+ */
351
+ Balanced: 0,
352
+ /**
353
+ * High priority, low latency connection, which increases transfer speed at the expense of power consumption.
354
+ */
355
+ High: 1,
356
+ /**
357
+ * Low power, reduced data rate connection setup.
358
+ */
359
+ LowPower: 2
360
+ }
package/src/Utils.js ADDED
@@ -0,0 +1,26 @@
1
+ // @flow
2
+ 'use strict'
3
+
4
+ import type { UUID } from './TypeDefinition'
5
+
6
+ /**
7
+ * Converts UUID to full 128bit, lowercase format which should be used to compare UUID values.
8
+ *
9
+ * @param {UUID} uuid 16bit, 32bit or 128bit UUID.
10
+ * @returns {UUID} 128bit lowercase UUID.
11
+ */
12
+ export function fullUUID(uuid: UUID): UUID {
13
+ if (uuid.length === 4) {
14
+ return '0000' + uuid.toLowerCase() + '-0000-1000-8000-00805f9b34fb'
15
+ }
16
+ if (uuid.length === 8) {
17
+ return uuid.toLowerCase() + '-0000-1000-8000-00805f9b34fb'
18
+ }
19
+ return uuid.toLowerCase()
20
+ }
21
+
22
+ export function fillStringWithArguments(value: string, object: Object): string {
23
+ return value.replace(/\{([^}]+)\}/g, function (_, arg: string) {
24
+ return object[arg] || '?'
25
+ })
26
+ }