@react-native-ohos/react-native-ble-plx 3.5.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.OpenSource +11 -0
- package/README.md +9 -0
- package/app.plugin.js +1 -0
- package/harmony/rn_bleplx/BuildProfile.ets +9 -0
- package/harmony/rn_bleplx/build-profile.json5 +8 -0
- package/harmony/rn_bleplx/hvigorfile.ts +6 -0
- package/harmony/rn_bleplx/index.ets +5 -0
- package/harmony/rn_bleplx/obfuscation-rules.txt +18 -0
- package/harmony/rn_bleplx/oh-package.json5 +13 -0
- package/harmony/rn_bleplx/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/rn_bleplx/src/main/cpp/generated/BlePlx.cpp +64 -0
- package/harmony/rn_bleplx/src/main/cpp/generated/BlePlx.h +21 -0
- package/harmony/rn_bleplx/src/main/cpp/generated/BlePlxRNOHGeneratedPackage.h +76 -0
- package/harmony/rn_bleplx/src/main/ets/BleDevice.ts +79 -0
- package/harmony/rn_bleplx/src/main/ets/BleModule.ts +1208 -0
- package/harmony/rn_bleplx/src/main/ets/BlePlxInterface.ts +7 -0
- package/harmony/rn_bleplx/src/main/ets/BlePlxModule.ts +226 -0
- package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ts +26 -0
- package/harmony/rn_bleplx/src/main/ets/Characteristic.ts +159 -0
- package/harmony/rn_bleplx/src/main/ets/CommonConstants.ts +10 -0
- package/harmony/rn_bleplx/src/main/ets/Descriptor.ts +123 -0
- package/harmony/rn_bleplx/src/main/ets/Service.ts +65 -0
- package/harmony/rn_bleplx/src/main/ets/common/BleError.ts +70 -0
- package/harmony/rn_bleplx/src/main/ets/common/BleErrorToJsObjectConverter.ts +43 -0
- package/harmony/rn_bleplx/src/main/ets/common/BleEvent.ts +13 -0
- package/harmony/rn_bleplx/src/main/ets/common/BleUtils.ts +66 -0
- package/harmony/rn_bleplx/src/main/ets/common/IdGenerator.ts +29 -0
- package/harmony/rn_bleplx/src/main/ets/common/IdGeneratorKey.ts +50 -0
- package/harmony/rn_bleplx/src/main/ets/common/InstanceIdGenerator.ts +17 -0
- package/harmony/rn_bleplx/src/main/ets/common/Logger.ts +64 -0
- package/harmony/rn_bleplx/src/main/ets/common/PermissionHandler.ts +78 -0
- package/harmony/rn_bleplx/src/main/ets/common/ServiceFactory.ts +17 -0
- package/harmony/rn_bleplx/src/main/ets/generated/components/ts.ts +8 -0
- package/harmony/rn_bleplx/src/main/ets/generated/index.ets +8 -0
- package/harmony/rn_bleplx/src/main/ets/generated/ts.ts +9 -0
- package/harmony/rn_bleplx/src/main/ets/generated/turboModules/BlePlx.ts +105 -0
- package/harmony/rn_bleplx/src/main/ets/generated/turboModules/ts.ts +8 -0
- package/harmony/rn_bleplx/src/main/module.json5 +7 -0
- package/harmony/rn_bleplx/ts.ts +6 -0
- package/harmony/rn_bleplx.har +0 -0
- package/package.json +181 -0
- package/src/BleError.js +555 -0
- package/src/BleManager.js +1324 -0
- package/src/BleModule.js +857 -0
- package/src/Characteristic.js +180 -0
- package/src/Descriptor.js +83 -0
- package/src/Device.js +378 -0
- package/src/NativeBlePlx.ts +101 -0
- package/src/Service.js +204 -0
- package/src/TypeDefinition.js +365 -0
- package/src/Utils.js +29 -0
- package/src/index.d.ts +2126 -0
- package/src/index.js +20 -0
package/src/BleError.js
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { fillStringWithArguments } from './Utils'
|
|
3
|
+
import type { BleErrorCodeMessageMapping } from './TypeDefinition'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* BleError is an error class which is guaranteed to be thrown by all functions of this
|
|
7
|
+
* library. It contains additional properties which help to identify problems in
|
|
8
|
+
* platform independent way.
|
|
9
|
+
*/
|
|
10
|
+
export class BleError extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Platform independent error code. Possible values are defined in {@link BleErrorCode}.
|
|
13
|
+
*/
|
|
14
|
+
errorCode: $Values<typeof BleErrorCode>
|
|
15
|
+
/**
|
|
16
|
+
* Platform independent error code related to ATT errors.
|
|
17
|
+
*/
|
|
18
|
+
attErrorCode: ?$Values<typeof BleATTErrorCode>
|
|
19
|
+
/**
|
|
20
|
+
* iOS specific error code (if not an ATT error).
|
|
21
|
+
*/
|
|
22
|
+
iosErrorCode: ?$Values<typeof BleIOSErrorCode>
|
|
23
|
+
/**
|
|
24
|
+
* Android specific error code (if not an ATT error).
|
|
25
|
+
*/
|
|
26
|
+
androidErrorCode: ?$Values<typeof BleAndroidErrorCode>
|
|
27
|
+
/**
|
|
28
|
+
* Platform specific error message.
|
|
29
|
+
*/
|
|
30
|
+
reason: ?string
|
|
31
|
+
|
|
32
|
+
constructor(nativeBleError: NativeBleError | string, errorMessageMapping: BleErrorCodeMessageMapping) {
|
|
33
|
+
super()
|
|
34
|
+
this.message = errorMessageMapping[BleErrorCode.UnknownError]
|
|
35
|
+
if (typeof nativeBleError === 'string') {
|
|
36
|
+
this.errorCode = BleErrorCode.UnknownError
|
|
37
|
+
this.attErrorCode = null
|
|
38
|
+
this.iosErrorCode = null
|
|
39
|
+
this.androidErrorCode = null
|
|
40
|
+
this.reason = nativeBleError
|
|
41
|
+
} else {
|
|
42
|
+
const message = errorMessageMapping[nativeBleError.errorCode]
|
|
43
|
+
if (message) {
|
|
44
|
+
this.message = fillStringWithArguments(message, nativeBleError)
|
|
45
|
+
}
|
|
46
|
+
this.errorCode = nativeBleError.errorCode
|
|
47
|
+
this.attErrorCode = nativeBleError.attErrorCode
|
|
48
|
+
this.iosErrorCode = nativeBleError.iosErrorCode
|
|
49
|
+
this.androidErrorCode = nativeBleError.androidErrorCode
|
|
50
|
+
this.reason = nativeBleError.reason
|
|
51
|
+
}
|
|
52
|
+
this.name = 'BleError'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function parseBleError(errorMessage: string, errorMessageMapping: BleErrorCodeMessageMapping): BleError {
|
|
57
|
+
let bleError: BleError
|
|
58
|
+
const errorMapping = errorMessageMapping ? errorMessageMapping : BleErrorCodeMessage
|
|
59
|
+
try {
|
|
60
|
+
const nativeBleError = JSON.parse(errorMessage)
|
|
61
|
+
bleError = new BleError(nativeBleError, errorMapping)
|
|
62
|
+
} catch (parseError) {
|
|
63
|
+
bleError = new BleError(errorMessage, errorMapping)
|
|
64
|
+
}
|
|
65
|
+
return bleError
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Platform independent error code map adjusted to this library's use cases.
|
|
70
|
+
*/
|
|
71
|
+
export const BleErrorCode = {
|
|
72
|
+
// Implementation specific errors ------------------------------------------------------------------------------------
|
|
73
|
+
/**
|
|
74
|
+
* This error can be thrown when unexpected error occurred and in most cases it is related to implementation bug.
|
|
75
|
+
* Original message is available in {@link #bleerrorreason|reason} property.
|
|
76
|
+
*/
|
|
77
|
+
UnknownError: 0,
|
|
78
|
+
/**
|
|
79
|
+
* Current promise failed to finish due to BleManager shutdown. It means that user called
|
|
80
|
+
* {@link #blemanagerdestroy|manager.destroy()} function before all operations completed.
|
|
81
|
+
*/
|
|
82
|
+
BluetoothManagerDestroyed: 1,
|
|
83
|
+
/**
|
|
84
|
+
* Promise was explicitly cancelled by a user with {@link #blemanagercanceltransaction|manager.cancelTransaction()}
|
|
85
|
+
* function call.
|
|
86
|
+
*/
|
|
87
|
+
OperationCancelled: 2,
|
|
88
|
+
/**
|
|
89
|
+
* Operation timed out and was cancelled.
|
|
90
|
+
*/
|
|
91
|
+
OperationTimedOut: 3,
|
|
92
|
+
/**
|
|
93
|
+
* Native module couldn't start operation due to internal state, which doesn't allow to do that.
|
|
94
|
+
*/
|
|
95
|
+
OperationStartFailed: 4,
|
|
96
|
+
/**
|
|
97
|
+
* Invalid UUIDs or IDs were passed to API call.
|
|
98
|
+
*/
|
|
99
|
+
InvalidIdentifiers: 5,
|
|
100
|
+
|
|
101
|
+
// Bluetooth global states -------------------------------------------------------------------------------------------
|
|
102
|
+
/**
|
|
103
|
+
* Bluetooth is not supported for this particular device. It may happen on iOS simulator for example.
|
|
104
|
+
*/
|
|
105
|
+
BluetoothUnsupported: 100,
|
|
106
|
+
/**
|
|
107
|
+
* There are no granted permissions which allow to use BLE functionality. On Android it may require
|
|
108
|
+
* android.permission.ACCESS_COARSE_LOCATION permission or android.permission.ACCESS_FINE_LOCATION permission.
|
|
109
|
+
*/
|
|
110
|
+
BluetoothUnauthorized: 101,
|
|
111
|
+
/**
|
|
112
|
+
* BLE is powered off on device. All previous operations and their state is invalidated.
|
|
113
|
+
*/
|
|
114
|
+
BluetoothPoweredOff: 102,
|
|
115
|
+
/**
|
|
116
|
+
* BLE stack is in unspecified state.
|
|
117
|
+
*/
|
|
118
|
+
BluetoothInUnknownState: 103,
|
|
119
|
+
/**
|
|
120
|
+
* BLE stack is resetting.
|
|
121
|
+
*/
|
|
122
|
+
BluetoothResetting: 104,
|
|
123
|
+
/**
|
|
124
|
+
* BLE state change failed.
|
|
125
|
+
*/
|
|
126
|
+
BluetoothStateChangeFailed: 105,
|
|
127
|
+
|
|
128
|
+
// Peripheral errors. ------------------------------------------------------------------------------------------------
|
|
129
|
+
/**
|
|
130
|
+
* Couldn't connect to specified device.
|
|
131
|
+
*/
|
|
132
|
+
DeviceConnectionFailed: 200,
|
|
133
|
+
/**
|
|
134
|
+
* Device was disconnected.
|
|
135
|
+
*/
|
|
136
|
+
DeviceDisconnected: 201,
|
|
137
|
+
/**
|
|
138
|
+
* Couldn't read RSSI from device.
|
|
139
|
+
*/
|
|
140
|
+
DeviceRSSIReadFailed: 202,
|
|
141
|
+
/**
|
|
142
|
+
* Device is already connected. It is not allowed to connect twice to the same device.
|
|
143
|
+
*/
|
|
144
|
+
DeviceAlreadyConnected: 203,
|
|
145
|
+
/**
|
|
146
|
+
* Couldn't find device with specified ID.
|
|
147
|
+
*/
|
|
148
|
+
DeviceNotFound: 204,
|
|
149
|
+
/**
|
|
150
|
+
* Operation failed because device has to be connected to perform it.
|
|
151
|
+
*/
|
|
152
|
+
DeviceNotConnected: 205,
|
|
153
|
+
/**
|
|
154
|
+
* Device could not change MTU value.
|
|
155
|
+
*/
|
|
156
|
+
DeviceMTUChangeFailed: 206,
|
|
157
|
+
|
|
158
|
+
// Services ----------------------------------------------------------------------------------------------------------
|
|
159
|
+
/**
|
|
160
|
+
* Couldn't discover services for specified device.
|
|
161
|
+
*/
|
|
162
|
+
ServicesDiscoveryFailed: 300,
|
|
163
|
+
/**
|
|
164
|
+
* Couldn't discover included services for specified service.
|
|
165
|
+
*/
|
|
166
|
+
IncludedServicesDiscoveryFailed: 301,
|
|
167
|
+
/**
|
|
168
|
+
* Service with specified ID or UUID couldn't be found. User may need to call
|
|
169
|
+
* {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
|
|
170
|
+
* to cache them.
|
|
171
|
+
*/
|
|
172
|
+
ServiceNotFound: 302,
|
|
173
|
+
/**
|
|
174
|
+
* Services were not discovered. User may need to call
|
|
175
|
+
* {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
|
|
176
|
+
* to cache them.
|
|
177
|
+
*/
|
|
178
|
+
ServicesNotDiscovered: 303,
|
|
179
|
+
|
|
180
|
+
// Characteristics ---------------------------------------------------------------------------------------------------
|
|
181
|
+
/**
|
|
182
|
+
* Couldn't discover characteristics for specified service.
|
|
183
|
+
*/
|
|
184
|
+
CharacteristicsDiscoveryFailed: 400,
|
|
185
|
+
/**
|
|
186
|
+
* Couldn't write to specified characteristic. Make sure that
|
|
187
|
+
* {@link #characteristiciswritablewithresponse|characteristic.isWritableWithResponse}
|
|
188
|
+
* or {@link #characteristiciswritablewithoutresponse|characteristic.isWritableWithoutResponse} is set to true.
|
|
189
|
+
*/
|
|
190
|
+
CharacteristicWriteFailed: 401,
|
|
191
|
+
/**
|
|
192
|
+
* Couldn't read from specified characteristic. Make sure that
|
|
193
|
+
* {@link #characteristicisreadable|characteristic.isReadable} is set to true.
|
|
194
|
+
*/
|
|
195
|
+
CharacteristicReadFailed: 402,
|
|
196
|
+
/**
|
|
197
|
+
* Couldn't set notification or indication for specified characteristic. Make sure that
|
|
198
|
+
* {@link #characteristicisnotifiable|characteristic.isNotifiable} or
|
|
199
|
+
* {@link #characteristicisindicatable|characteristic.isIndicatable} is set to true.
|
|
200
|
+
*/
|
|
201
|
+
CharacteristicNotifyChangeFailed: 403,
|
|
202
|
+
/**
|
|
203
|
+
* Characteristic with specified ID or UUID couldn't be found. User may need to call
|
|
204
|
+
* {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
|
|
205
|
+
* to cache them.
|
|
206
|
+
*/
|
|
207
|
+
CharacteristicNotFound: 404,
|
|
208
|
+
/**
|
|
209
|
+
* Characteristic were not discovered for specified service. User may need to call
|
|
210
|
+
* {@link #blemanagerdiscoverallservicesandcharacteristicsfordevice|manager.discoverAllServicesAndCharacteristicsForDevice}
|
|
211
|
+
* to cache them.
|
|
212
|
+
*/
|
|
213
|
+
CharacteristicsNotDiscovered: 405,
|
|
214
|
+
/**
|
|
215
|
+
* Invalid Base64 format was passed to characteristic API function call.
|
|
216
|
+
*/
|
|
217
|
+
CharacteristicInvalidDataFormat: 406,
|
|
218
|
+
|
|
219
|
+
// Characteristics ---------------------------------------------------------------------------------------------------
|
|
220
|
+
/**
|
|
221
|
+
* Couldn't discover descriptor for specified characteristic.
|
|
222
|
+
*/
|
|
223
|
+
DescriptorsDiscoveryFailed: 500,
|
|
224
|
+
/**
|
|
225
|
+
* Couldn't write to specified descriptor.
|
|
226
|
+
*/
|
|
227
|
+
DescriptorWriteFailed: 501,
|
|
228
|
+
/**
|
|
229
|
+
* Couldn't read from specified descriptor.
|
|
230
|
+
*/
|
|
231
|
+
DescriptorReadFailed: 502,
|
|
232
|
+
/**
|
|
233
|
+
* Couldn't find specified descriptor.
|
|
234
|
+
*/
|
|
235
|
+
DescriptorNotFound: 503,
|
|
236
|
+
/**
|
|
237
|
+
* Descriptors are not discovered for specified characteristic.
|
|
238
|
+
*/
|
|
239
|
+
DescriptorsNotDiscovered: 504,
|
|
240
|
+
/**
|
|
241
|
+
* Invalid Base64 format was passed to descriptor API function call.
|
|
242
|
+
*/
|
|
243
|
+
DescriptorInvalidDataFormat: 505,
|
|
244
|
+
/**
|
|
245
|
+
* Issued a write to a descriptor, which is handled by OS.
|
|
246
|
+
*/
|
|
247
|
+
DescriptorWriteNotAllowed: 506,
|
|
248
|
+
|
|
249
|
+
// Scanning errors ---------------------------------------------------------------------------------------------------
|
|
250
|
+
/**
|
|
251
|
+
* Cannot start scanning operation.
|
|
252
|
+
*/
|
|
253
|
+
ScanStartFailed: 600,
|
|
254
|
+
/**
|
|
255
|
+
* Location services are disabled.
|
|
256
|
+
*/
|
|
257
|
+
LocationServicesDisabled: 601
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Mapping of error codes to error messages
|
|
262
|
+
* @name BleErrorCodeMessage
|
|
263
|
+
*/
|
|
264
|
+
export const BleErrorCodeMessage: BleErrorCodeMessageMapping = {
|
|
265
|
+
// Implementation specific errors
|
|
266
|
+
[BleErrorCode.UnknownError]: 'Unknown error occurred. This is probably a bug! Check reason property.',
|
|
267
|
+
[BleErrorCode.BluetoothManagerDestroyed]: 'BleManager was destroyed',
|
|
268
|
+
[BleErrorCode.OperationCancelled]: 'Operation was cancelled',
|
|
269
|
+
[BleErrorCode.OperationTimedOut]: 'Operation timed out',
|
|
270
|
+
[BleErrorCode.OperationStartFailed]: 'Operation was rejected',
|
|
271
|
+
[BleErrorCode.InvalidIdentifiers]: 'Invalid UUIDs or IDs were passed: {internalMessage}',
|
|
272
|
+
|
|
273
|
+
// Bluetooth global states
|
|
274
|
+
[BleErrorCode.BluetoothUnsupported]: 'BluetoothLE is unsupported on this device',
|
|
275
|
+
[BleErrorCode.BluetoothUnauthorized]: 'Device is not authorized to use BluetoothLE',
|
|
276
|
+
[BleErrorCode.BluetoothPoweredOff]: 'BluetoothLE is powered off',
|
|
277
|
+
[BleErrorCode.BluetoothInUnknownState]: 'BluetoothLE is in unknown state',
|
|
278
|
+
[BleErrorCode.BluetoothResetting]: 'BluetoothLE is resetting',
|
|
279
|
+
[BleErrorCode.BluetoothStateChangeFailed]: 'Bluetooth state change failed',
|
|
280
|
+
|
|
281
|
+
// Peripheral errors.
|
|
282
|
+
[BleErrorCode.DeviceConnectionFailed]: 'Device {deviceID} connection failed',
|
|
283
|
+
[BleErrorCode.DeviceDisconnected]: 'Device {deviceID} was disconnected',
|
|
284
|
+
[BleErrorCode.DeviceRSSIReadFailed]: 'RSSI read failed for device {deviceID}',
|
|
285
|
+
[BleErrorCode.DeviceAlreadyConnected]: 'Device {deviceID} is already connected',
|
|
286
|
+
[BleErrorCode.DeviceNotFound]: 'Device {deviceID} not found',
|
|
287
|
+
[BleErrorCode.DeviceNotConnected]: 'Device {deviceID} is not connected',
|
|
288
|
+
[BleErrorCode.DeviceMTUChangeFailed]: 'Device {deviceID} could not change MTU size',
|
|
289
|
+
|
|
290
|
+
// Services
|
|
291
|
+
[BleErrorCode.ServicesDiscoveryFailed]: 'Services discovery failed for device {deviceID}',
|
|
292
|
+
[BleErrorCode.IncludedServicesDiscoveryFailed]:
|
|
293
|
+
'Included services discovery failed for device {deviceID} and service: {serviceUUID}',
|
|
294
|
+
[BleErrorCode.ServiceNotFound]: 'Service {serviceUUID} for device {deviceID} not found',
|
|
295
|
+
[BleErrorCode.ServicesNotDiscovered]: 'Services not discovered for device {deviceID}',
|
|
296
|
+
|
|
297
|
+
// Characteristics
|
|
298
|
+
[BleErrorCode.CharacteristicsDiscoveryFailed]:
|
|
299
|
+
'Characteristic discovery failed for device {deviceID} and service {serviceUUID}',
|
|
300
|
+
[BleErrorCode.CharacteristicWriteFailed]:
|
|
301
|
+
'Characteristic {characteristicUUID} write failed for device {deviceID} and service {serviceUUID}',
|
|
302
|
+
[BleErrorCode.CharacteristicReadFailed]:
|
|
303
|
+
'Characteristic {characteristicUUID} read failed for device {deviceID} and service {serviceUUID}',
|
|
304
|
+
[BleErrorCode.CharacteristicNotifyChangeFailed]:
|
|
305
|
+
'Characteristic {characteristicUUID} notify change failed for device {deviceID} and service {serviceUUID}',
|
|
306
|
+
[BleErrorCode.CharacteristicNotFound]: 'Characteristic {characteristicUUID} not found',
|
|
307
|
+
[BleErrorCode.CharacteristicsNotDiscovered]:
|
|
308
|
+
'Characteristics not discovered for device {deviceID} and service {serviceUUID}',
|
|
309
|
+
[BleErrorCode.CharacteristicInvalidDataFormat]:
|
|
310
|
+
'Cannot write to characteristic {characteristicUUID} with invalid data format: {internalMessage}',
|
|
311
|
+
|
|
312
|
+
// Descriptors
|
|
313
|
+
[BleErrorCode.DescriptorsDiscoveryFailed]:
|
|
314
|
+
'Descriptor {descriptorUUID} discovery failed for device {deviceID}, service {serviceUUID} and characteristic {characteristicUUID}',
|
|
315
|
+
[BleErrorCode.DescriptorWriteFailed]:
|
|
316
|
+
'Descriptor {descriptorUUID} write failed for device {deviceID}, service {serviceUUID} and characteristic {characteristicUUID}',
|
|
317
|
+
[BleErrorCode.DescriptorReadFailed]:
|
|
318
|
+
'Descriptor {descriptorUUID} read failed for device {deviceID}, service {serviceUUID} and characteristic {characteristicUUID}',
|
|
319
|
+
[BleErrorCode.DescriptorNotFound]: 'Descriptor {descriptorUUID} not found',
|
|
320
|
+
[BleErrorCode.DescriptorsNotDiscovered]:
|
|
321
|
+
'Descriptors not discovered for device {deviceID}, service {serviceUUID} and characteristic {characteristicUUID}',
|
|
322
|
+
[BleErrorCode.DescriptorInvalidDataFormat]:
|
|
323
|
+
'Cannot write to descriptor {descriptorUUID} with invalid data format: {internalMessage}',
|
|
324
|
+
[BleErrorCode.DescriptorWriteNotAllowed]:
|
|
325
|
+
"Cannot write to descriptor {descriptorUUID}. It's not allowed by iOS and therefore forbidden on Android as well.",
|
|
326
|
+
|
|
327
|
+
// Scanning
|
|
328
|
+
[BleErrorCode.ScanStartFailed]: 'Cannot start scanning operation',
|
|
329
|
+
[BleErrorCode.LocationServicesDisabled]: 'Location services are disabled'
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Error codes for ATT errors.
|
|
334
|
+
* @name BleATTErrorCode
|
|
335
|
+
*/
|
|
336
|
+
export const BleATTErrorCode = {
|
|
337
|
+
/**
|
|
338
|
+
* The ATT command or request successfully completed.
|
|
339
|
+
*/
|
|
340
|
+
Success: 0,
|
|
341
|
+
/**
|
|
342
|
+
* The attribute handle is invalid on this device.
|
|
343
|
+
*/
|
|
344
|
+
InvalidHandle: 1,
|
|
345
|
+
/**
|
|
346
|
+
* The attribute’s value cannot be read.
|
|
347
|
+
*/
|
|
348
|
+
ReadNotPermitted: 2,
|
|
349
|
+
/**
|
|
350
|
+
* The attribute’s value cannot be written.
|
|
351
|
+
*/
|
|
352
|
+
WriteNotPermitted: 3,
|
|
353
|
+
/**
|
|
354
|
+
* The attribute Protocol Data Unit (PDU) or “message” is invalid.
|
|
355
|
+
*/
|
|
356
|
+
InvalidPdu: 4,
|
|
357
|
+
/**
|
|
358
|
+
* The attribute requires authentication before its value can be read or written.
|
|
359
|
+
*/
|
|
360
|
+
InsufficientAuthentication: 5,
|
|
361
|
+
/**
|
|
362
|
+
* The attribute server does not support the request received by the client.
|
|
363
|
+
*/
|
|
364
|
+
RequestNotSupported: 6,
|
|
365
|
+
/**
|
|
366
|
+
* The specified offset value was past the end of the attribute’s value.
|
|
367
|
+
*/
|
|
368
|
+
InvalidOffset: 7,
|
|
369
|
+
/**
|
|
370
|
+
* The attribute requires authorization before its value can be read or written.
|
|
371
|
+
*/
|
|
372
|
+
InsufficientAuthorization: 8,
|
|
373
|
+
/**
|
|
374
|
+
* The prepare queue is full, because too many prepare write requests have been queued.
|
|
375
|
+
*/
|
|
376
|
+
PrepareQueueFull: 9,
|
|
377
|
+
/**
|
|
378
|
+
* The attribute is not found within the specified attribute handle range.
|
|
379
|
+
*/
|
|
380
|
+
AttributeNotFound: 10,
|
|
381
|
+
/**
|
|
382
|
+
* The attribute cannot be read or written using the ATT read blob request.
|
|
383
|
+
*/
|
|
384
|
+
AttributeNotLong: 11,
|
|
385
|
+
/**
|
|
386
|
+
* The encryption key size used for encrypting this link is insufficient.
|
|
387
|
+
*/
|
|
388
|
+
InsufficientEncryptionKeySize: 12,
|
|
389
|
+
/**
|
|
390
|
+
* The length of the attribute’s value is invalid for the intended operation.
|
|
391
|
+
*/
|
|
392
|
+
InvalidAttributeValueLength: 13,
|
|
393
|
+
/**
|
|
394
|
+
* The ATT request has encountered an unlikely error and therefore could not be completed.
|
|
395
|
+
*/
|
|
396
|
+
UnlikelyError: 14,
|
|
397
|
+
/**
|
|
398
|
+
* The attribute requires encryption before its value can be read or written.
|
|
399
|
+
*/
|
|
400
|
+
InsufficientEncryption: 15,
|
|
401
|
+
/**
|
|
402
|
+
* The attribute type is not a supported grouping attribute as defined by a higher-layer specification.
|
|
403
|
+
*/
|
|
404
|
+
UnsupportedGroupType: 16,
|
|
405
|
+
/**
|
|
406
|
+
* Resources are insufficient to complete the ATT request.
|
|
407
|
+
*/
|
|
408
|
+
InsufficientResources: 17
|
|
409
|
+
|
|
410
|
+
// Values 0x012 – 0x7F are reserved for future use.
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* iOS specific error codes.
|
|
415
|
+
* @name BleIOSErrorCode
|
|
416
|
+
*/
|
|
417
|
+
export const BleIOSErrorCode = {
|
|
418
|
+
/**
|
|
419
|
+
* An unknown error occurred.
|
|
420
|
+
*/
|
|
421
|
+
Unknown: 0,
|
|
422
|
+
/**
|
|
423
|
+
* The specified parameters are invalid.
|
|
424
|
+
*/
|
|
425
|
+
InvalidParameters: 1,
|
|
426
|
+
/**
|
|
427
|
+
* The specified attribute handle is invalid.
|
|
428
|
+
*/
|
|
429
|
+
InvalidHandle: 2,
|
|
430
|
+
/**
|
|
431
|
+
* The device is not currently connected.
|
|
432
|
+
*/
|
|
433
|
+
NotConnected: 3,
|
|
434
|
+
/**
|
|
435
|
+
* The device has run out of space to complete the intended operation.
|
|
436
|
+
*/
|
|
437
|
+
OutOfSpace: 4,
|
|
438
|
+
/**
|
|
439
|
+
* The operation is canceled.
|
|
440
|
+
*/
|
|
441
|
+
OperationCancelled: 5,
|
|
442
|
+
/**
|
|
443
|
+
* The connection timed out.
|
|
444
|
+
*/
|
|
445
|
+
ConnectionTimeout: 6,
|
|
446
|
+
/**
|
|
447
|
+
* The peripheral disconnected.
|
|
448
|
+
*/
|
|
449
|
+
PeripheralDisconnected: 7,
|
|
450
|
+
/**
|
|
451
|
+
* The specified UUID is not permitted.
|
|
452
|
+
*/
|
|
453
|
+
UuidNotAllowed: 8,
|
|
454
|
+
/**
|
|
455
|
+
* The peripheral is already advertising.
|
|
456
|
+
*/
|
|
457
|
+
AlreadyAdvertising: 9,
|
|
458
|
+
/**
|
|
459
|
+
* The connection failed.
|
|
460
|
+
*/
|
|
461
|
+
ConnectionFailed: 10,
|
|
462
|
+
/**
|
|
463
|
+
* The device already has the maximum number of connections.
|
|
464
|
+
*/
|
|
465
|
+
ConnectionLimitReached: 11,
|
|
466
|
+
/**
|
|
467
|
+
* Unknown device.
|
|
468
|
+
*/
|
|
469
|
+
UnknownDevice: 12
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Android specific error codes.
|
|
474
|
+
* @name BleAndroidErrorCode
|
|
475
|
+
*/
|
|
476
|
+
export const BleAndroidErrorCode = {
|
|
477
|
+
/**
|
|
478
|
+
* The device has insufficient resources to complete the intended operation.
|
|
479
|
+
*/
|
|
480
|
+
NoResources: 0x80,
|
|
481
|
+
/**
|
|
482
|
+
* Internal error occurred which may happen due to implementation error in BLE stack.
|
|
483
|
+
*/
|
|
484
|
+
InternalError: 0x81,
|
|
485
|
+
/**
|
|
486
|
+
* BLE stack implementation entered illegal state and operation couldn't complete.
|
|
487
|
+
*/
|
|
488
|
+
WrongState: 0x82,
|
|
489
|
+
/**
|
|
490
|
+
* BLE stack didn't allocate sufficient memory buffer for internal caches.
|
|
491
|
+
*/
|
|
492
|
+
DbFull: 0x83,
|
|
493
|
+
/**
|
|
494
|
+
* Maximum number of pending operations was exceeded.
|
|
495
|
+
*/
|
|
496
|
+
Busy: 0x84,
|
|
497
|
+
/**
|
|
498
|
+
* Generic BLE stack error.
|
|
499
|
+
*/
|
|
500
|
+
Error: 0x85,
|
|
501
|
+
/**
|
|
502
|
+
* Command is already queued up in GATT.
|
|
503
|
+
*/
|
|
504
|
+
CmdStarted: 0x86,
|
|
505
|
+
/**
|
|
506
|
+
* Illegal parameter was passed to internal BLE stack function.
|
|
507
|
+
*/
|
|
508
|
+
IllegalParameter: 0x87,
|
|
509
|
+
/**
|
|
510
|
+
* Operation is pending.
|
|
511
|
+
*/
|
|
512
|
+
Pending: 0x88,
|
|
513
|
+
/**
|
|
514
|
+
* Authorization failed before performing read or write operation.
|
|
515
|
+
*/
|
|
516
|
+
AuthFail: 0x89,
|
|
517
|
+
/**
|
|
518
|
+
* More cache entries were loaded then expected.
|
|
519
|
+
*/
|
|
520
|
+
More: 0x8a,
|
|
521
|
+
/**
|
|
522
|
+
* Invalid configuration
|
|
523
|
+
*/
|
|
524
|
+
InvalidCfg: 0x8b,
|
|
525
|
+
/**
|
|
526
|
+
* GATT service already started.
|
|
527
|
+
*/
|
|
528
|
+
ServiceStarted: 0x8c,
|
|
529
|
+
/**
|
|
530
|
+
* GATT link is encrypted but prone to man in the middle attacks.
|
|
531
|
+
*/
|
|
532
|
+
EncrypedNoMitm: 0x8d,
|
|
533
|
+
/**
|
|
534
|
+
* GATT link is not encrypted.
|
|
535
|
+
*/
|
|
536
|
+
NotEncrypted: 0x8e,
|
|
537
|
+
/**
|
|
538
|
+
* ATT command was sent but channel is congested.
|
|
539
|
+
*/
|
|
540
|
+
Congested: 0x8f
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export interface NativeBleError {
|
|
544
|
+
errorCode: $Values<typeof BleErrorCode>;
|
|
545
|
+
attErrorCode: ?$Values<typeof BleATTErrorCode>;
|
|
546
|
+
iosErrorCode: ?$Values<typeof BleIOSErrorCode>;
|
|
547
|
+
androidErrorCode: ?$Values<typeof BleAndroidErrorCode>;
|
|
548
|
+
reason: ?string;
|
|
549
|
+
|
|
550
|
+
deviceID?: string;
|
|
551
|
+
serviceUUID?: string;
|
|
552
|
+
characteristicUUID?: string;
|
|
553
|
+
descriptorUUID?: string;
|
|
554
|
+
internalMessage?: string;
|
|
555
|
+
}
|