@onekeyfe/hd-transport-react-native 0.1.35 → 0.1.38

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;IAyET,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
@@ -306,8 +306,12 @@ class ReactNativeBleTransport {
306
306
  if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
307
307
  e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
308
308
  connectOptions = {};
309
- device = yield blePlxManager.connectToDevice(uuid);
310
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);
311
315
  }
312
316
  else {
313
317
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_a = e.reason) !== null && _a !== void 0 ? _a : e);
@@ -327,8 +331,18 @@ class ReactNativeBleTransport {
327
331
  if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
328
332
  e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
329
333
  connectOptions = {};
330
- yield device.connect();
331
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
+ }
332
346
  }
333
347
  else {
334
348
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_b = e.reason) !== null && _b !== void 0 ? _b : e);
@@ -358,6 +372,13 @@ class ReactNativeBleTransport {
358
372
  }
359
373
  }
360
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
+ }
361
382
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound);
362
383
  }
363
384
  const { serviceUuid, writeUuid, notifyUuid } = infos;
@@ -454,15 +475,13 @@ class ReactNativeBleTransport {
454
475
  };
455
476
  }
456
477
  release(uuid) {
457
- var _a, _b;
478
+ var _a;
458
479
  return __awaiter(this, void 0, void 0, function* () {
459
480
  const transport = transportCache[uuid];
460
481
  if (transport) {
461
482
  delete transportCache[uuid];
462
483
  (_a = transport.nofitySubscription) === null || _a === void 0 ? void 0 : _a.call(transport);
463
- if (reactNative.Platform.OS === 'android') {
464
- yield ((_b = this.blePlxManager) === null || _b === void 0 ? void 0 : _b.cancelDeviceConnection(uuid));
465
- }
484
+ if (reactNative.Platform.OS === 'android') ;
466
485
  }
467
486
  return Promise.resolve(true);
468
487
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "0.1.35",
3
+ "version": "0.1.38",
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.35",
24
- "@onekeyfe/hd-transport": "^0.1.35",
23
+ "@onekeyfe/hd-shared": "^0.1.38",
24
+ "@onekeyfe/hd-transport": "^0.1.38",
25
25
  "react-native-ble-manager": "^8.1.0",
26
26
  "react-native-ble-plx": "^2.0.3"
27
27
  },
28
- "gitHead": "8ad01282e959a37412b4f5de6bfe0ca248cf27e3"
28
+ "gitHead": "5828c78b10fca8604e158ef425a8c7314ece2bbf"
29
29
  }
package/src/index.ts CHANGED
@@ -212,8 +212,11 @@ export default class ReactNativeBleTransport {
212
212
  e.errorCode === BleErrorCode.OperationCancelled
213
213
  ) {
214
214
  connectOptions = {};
215
- device = await blePlxManager.connectToDevice(uuid);
216
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);
217
220
  } else {
218
221
  throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, e.reason ?? e);
219
222
  }
@@ -236,8 +239,19 @@ export default class ReactNativeBleTransport {
236
239
  e.errorCode === BleErrorCode.OperationCancelled
237
240
  ) {
238
241
  connectOptions = {};
239
- await device.connect();
240
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
+ }
241
255
  } else {
242
256
  throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, e.reason ?? e);
243
257
  }
@@ -270,6 +284,12 @@ export default class ReactNativeBleTransport {
270
284
  }
271
285
 
272
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
+ }
273
293
  throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound);
274
294
  }
275
295
 
@@ -401,8 +421,9 @@ export default class ReactNativeBleTransport {
401
421
  if (transport) {
402
422
  delete transportCache[uuid];
403
423
  transport.nofitySubscription?.();
424
+ // Temporary close the Android disconnect after each request
404
425
  if (Platform.OS === 'android') {
405
- await this.blePlxManager?.cancelDeviceConnection(uuid);
426
+ // await this.blePlxManager?.cancelDeviceConnection(uuid);
406
427
  }
407
428
  }
408
429