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