@onekeyfe/hd-transport-react-native 0.1.34 → 0.1.37

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAavC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmBjE,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,WAAW,SAAQ;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;gBAEX,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY;IAKvC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IAsET,OAAO,CAAC,KAAK,EAAE,eAAe;;;IA4KpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IA4D/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAcpB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE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AmFpE,IAAI;IAIJ,MAAM;CAOP"}
package/dist/index.js CHANGED
@@ -232,6 +232,9 @@ class ReactNativeBleTransport {
232
232
  else if (error.errorCode === reactNativeBlePlx.BleErrorCode.BluetoothUnauthorized) {
233
233
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationError));
234
234
  }
235
+ else if (error.errorCode === reactNativeBlePlx.BleErrorCode.ScanStartFailed) {
236
+ timer.timeout(() => { }, this.scanTimeout);
237
+ }
235
238
  else {
236
239
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleScanError, (_a = error.reason) !== null && _a !== void 0 ? _a : ''));
237
240
  }
@@ -303,8 +306,12 @@ class ReactNativeBleTransport {
303
306
  if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
304
307
  e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
305
308
  connectOptions = {};
306
- device = yield blePlxManager.connectToDevice(uuid);
307
309
  this.Log.debug('first try to reconnect without params');
310
+ device = yield blePlxManager.connectToDevice(uuid);
311
+ }
312
+ else if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
313
+ this.Log.debug('device already connected');
314
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleAlreadyConnected);
308
315
  }
309
316
  else {
310
317
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_a = e.reason) !== null && _a !== void 0 ? _a : e);
@@ -324,8 +331,18 @@ class ReactNativeBleTransport {
324
331
  if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
325
332
  e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
326
333
  connectOptions = {};
327
- yield device.connect();
328
334
  this.Log.debug('second try to reconnect without params');
335
+ try {
336
+ yield device.connect();
337
+ }
338
+ catch (e) {
339
+ this.Log.debug('last try to reconnect error: ', e);
340
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
341
+ this.Log.debug('last try to reconnect');
342
+ yield device.cancelConnection();
343
+ yield device.connect();
344
+ }
345
+ }
329
346
  }
330
347
  else {
331
348
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_b = e.reason) !== null && _b !== void 0 ? _b : e);
@@ -355,6 +372,13 @@ class ReactNativeBleTransport {
355
372
  }
356
373
  }
357
374
  if (!infos) {
375
+ try {
376
+ this.Log.debug('cancel connection when service not found');
377
+ yield device.cancelConnection();
378
+ }
379
+ catch (e) {
380
+ this.Log.debug('cancel connection error when service not found: ', e.message || e.reason);
381
+ }
358
382
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound);
359
383
  }
360
384
  const { serviceUuid, writeUuid, notifyUuid } = infos;
@@ -451,15 +475,13 @@ class ReactNativeBleTransport {
451
475
  };
452
476
  }
453
477
  release(uuid) {
454
- var _a, _b;
478
+ var _a;
455
479
  return __awaiter(this, void 0, void 0, function* () {
456
480
  const transport = transportCache[uuid];
457
481
  if (transport) {
458
482
  delete transportCache[uuid];
459
483
  (_a = transport.nofitySubscription) === null || _a === void 0 ? void 0 : _a.call(transport);
460
- if (reactNative.Platform.OS === 'android') {
461
- yield ((_b = this.blePlxManager) === null || _b === void 0 ? void 0 : _b.cancelDeviceConnection(uuid));
462
- }
484
+ if (reactNative.Platform.OS === 'android') ;
463
485
  }
464
486
  return Promise.resolve(true);
465
487
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "0.1.34",
3
+ "version": "0.1.37",
4
4
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -20,10 +20,10 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-shared": "^0.1.34",
24
- "@onekeyfe/hd-transport": "^0.1.34",
23
+ "@onekeyfe/hd-shared": "^0.1.37",
24
+ "@onekeyfe/hd-transport": "^0.1.37",
25
25
  "react-native-ble-manager": "^8.1.0",
26
26
  "react-native-ble-plx": "^2.0.3"
27
27
  },
28
- "gitHead": "6da875e815d27f3573e4c7578c57c245a24bba8c"
28
+ "gitHead": "c7aaa0d4af5ade4c9e07229f142ed85ee14db096"
29
29
  }
package/src/index.ts CHANGED
@@ -120,6 +120,11 @@ export default class ReactNativeBleTransport {
120
120
  reject(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
121
121
  } else if (error.errorCode === BleErrorCode.BluetoothUnauthorized) {
122
122
  reject(ERRORS.TypedError(HardwareErrorCode.BleLocationError));
123
+ } else if (error.errorCode === BleErrorCode.ScanStartFailed) {
124
+ // Android Bluetooth will report an error when the search frequency is too fast,
125
+ // then nothing is processed and an empty array of devices is returned.
126
+ // Then the next search will be back to normal
127
+ timer.timeout(() => {}, this.scanTimeout);
123
128
  } else {
124
129
  reject(ERRORS.TypedError(HardwareErrorCode.BleScanError, error.reason ?? ''));
125
130
  }
@@ -128,13 +133,11 @@ export default class ReactNativeBleTransport {
128
133
 
129
134
  if (isOnekeyDevice(device?.name ?? null, device?.id)) {
130
135
  this.Log.debug('search device start ======================');
131
-
132
136
  const { name, localName, id } = device ?? {};
133
137
  this.Log.debug(
134
138
  `device name: ${name ?? ''}\nlocalName: ${localName ?? ''}\nid: ${id ?? ''}`
135
139
  );
136
140
  addDevice(device as unknown as Device);
137
-
138
141
  this.Log.debug('search device end ======================\n');
139
142
  }
140
143
  }
@@ -209,8 +212,11 @@ export default class ReactNativeBleTransport {
209
212
  e.errorCode === BleErrorCode.OperationCancelled
210
213
  ) {
211
214
  connectOptions = {};
212
- device = await blePlxManager.connectToDevice(uuid);
213
215
  this.Log.debug('first try to reconnect without params');
216
+ device = await blePlxManager.connectToDevice(uuid);
217
+ } else if (e.errorCode === BleErrorCode.DeviceAlreadyConnected) {
218
+ this.Log.debug('device already connected');
219
+ throw ERRORS.TypedError(HardwareErrorCode.BleAlreadyConnected);
214
220
  } else {
215
221
  throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, e.reason ?? e);
216
222
  }
@@ -233,8 +239,19 @@ export default class ReactNativeBleTransport {
233
239
  e.errorCode === BleErrorCode.OperationCancelled
234
240
  ) {
235
241
  connectOptions = {};
236
- await device.connect();
237
242
  this.Log.debug('second try to reconnect without params');
243
+ try {
244
+ await device.connect();
245
+ } catch (e) {
246
+ this.Log.debug('last try to reconnect error: ', e);
247
+ // last try to reconnect device if this issue exists
248
+ // https://github.com/dotintent/react-native-ble-plx/issues/426
249
+ if (e.errorCode === BleErrorCode.OperationCancelled) {
250
+ this.Log.debug('last try to reconnect');
251
+ await device.cancelConnection();
252
+ await device.connect();
253
+ }
254
+ }
238
255
  } else {
239
256
  throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, e.reason ?? e);
240
257
  }
@@ -267,6 +284,12 @@ export default class ReactNativeBleTransport {
267
284
  }
268
285
 
269
286
  if (!infos) {
287
+ try {
288
+ this.Log.debug('cancel connection when service not found');
289
+ await device.cancelConnection();
290
+ } catch (e) {
291
+ this.Log.debug('cancel connection error when service not found: ', e.message || e.reason);
292
+ }
270
293
  throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound);
271
294
  }
272
295
 
@@ -398,8 +421,9 @@ export default class ReactNativeBleTransport {
398
421
  if (transport) {
399
422
  delete transportCache[uuid];
400
423
  transport.nofitySubscription?.();
424
+ // Temporary close the Android disconnect after each request
401
425
  if (Platform.OS === 'android') {
402
- await this.blePlxManager?.cancelDeviceConnection(uuid);
426
+ // await this.blePlxManager?.cancelDeviceConnection(uuid);
403
427
  }
404
428
  }
405
429