@onekeyfe/hd-transport-react-native 0.1.21 → 0.1.24

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.
@@ -17,4 +17,5 @@ export declare const getBondedDevices: () => Promise<{
17
17
  id: string;
18
18
  name: string | undefined;
19
19
  }[]>;
20
+ export declare const refreshCache: (peripheralId: string) => Promise<void>;
20
21
  //# sourceMappingURL=BleManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,YAEhC,CAAC;AAOF,eAAO,MAAM,qBAAqB,iBAAwB,MAAM,EAAE;;;;;;;;IAMjE,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;IAM5B,CAAC"}
1
+ {"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,YAEhC,CAAC;AAOF,eAAO,MAAM,qBAAqB,iBAAwB,MAAM,EAAE;;;;;;;;IAMjE,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;IAM5B,CAAC;AAEF,eAAO,MAAM,YAAY,iBAAwB,MAAM,kBAStD,CAAC"}
@@ -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;AAa1F,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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CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;gBAEE,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG;IAIhB,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IAsET,OAAO,CAAC,KAAK,EAAE,eAAe;;;IAiKpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IA4D/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAcpB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAkFpE,IAAI;IAIJ,MAAM;CAOP"}
package/dist/index.js CHANGED
@@ -167,7 +167,7 @@ class BleTransport {
167
167
  const { check, buildBuffers, receiveOne, parseConfigure } = transport__default["default"];
168
168
  const transportCache = {};
169
169
  let connectOptions = {
170
- requestMTU: 512,
170
+ requestMTU: 256,
171
171
  timeout: 3000,
172
172
  };
173
173
  const tryToGetConfiguration = (device) => {
@@ -303,6 +303,7 @@ class ReactNativeBleTransport {
303
303
  e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
304
304
  connectOptions = {};
305
305
  device = yield blePlxManager.connectToDevice(uuid);
306
+ this.Log.debug('first try to reconnect without params');
306
307
  }
307
308
  else {
308
309
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_a = e.reason) !== null && _a !== void 0 ? _a : e);
@@ -318,11 +319,12 @@ class ReactNativeBleTransport {
318
319
  yield device.connect(connectOptions);
319
320
  }
320
321
  catch (e) {
321
- this.Log.debug('try to connect to device has error: ', e);
322
+ this.Log.debug('not connected, try to connect to device has error: ', e);
322
323
  if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
323
324
  e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
324
325
  connectOptions = {};
325
326
  yield device.connect();
327
+ this.Log.debug('second try to reconnect without params');
326
328
  }
327
329
  else {
328
330
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_b = e.reason) !== null && _b !== void 0 ? _b : e);
@@ -500,11 +502,14 @@ class ReactNativeBleTransport {
500
502
  yield transport.writeCharacteristic.writeWithoutResponse(outData);
501
503
  }
502
504
  catch (e) {
505
+ this.Log.debug('writeCharacteristic write error: ', e);
506
+ this.runPromise = null;
503
507
  if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceDisconnected) {
504
508
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded);
505
509
  }
506
- this.runPromise = null;
507
- this.Log.debug('writeCharacteristic write error: ', e);
510
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.OperationStartFailed) {
511
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, e.reason);
512
+ }
508
513
  return;
509
514
  }
510
515
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "0.1.21",
3
+ "version": "0.1.24",
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.21",
24
- "@onekeyfe/hd-transport": "^0.1.21",
23
+ "@onekeyfe/hd-shared": "^0.1.24",
24
+ "@onekeyfe/hd-transport": "^0.1.24",
25
25
  "react-native-ble-manager": "^8.1.0",
26
26
  "react-native-ble-plx": "^2.0.3"
27
27
  },
28
- "gitHead": "807593129b0b2e55dc2beeb7b824494ec8cb07ad"
28
+ "gitHead": "20197605d771616de3dbc47013494b60bc0dbd2d"
29
29
  }
package/src/BleManager.ts CHANGED
@@ -24,3 +24,14 @@ export const getBondedDevices = async () => {
24
24
  return { id, name, ...advertising };
25
25
  });
26
26
  };
27
+
28
+ export const refreshCache = async (peripheralId: string) => {
29
+ try {
30
+ await BleManager.connect(peripheralId);
31
+ await BleManager.refreshCache(peripheralId);
32
+ await BleManager.disconnect(peripheralId, true);
33
+ console.log('refreshCache success');
34
+ } catch (error) {
35
+ console.log('refreshCache error: ', error);
36
+ }
37
+ };
package/src/index.ts CHANGED
@@ -29,7 +29,7 @@ const { check, buildBuffers, receiveOne, parseConfigure } = transport;
29
29
  const transportCache: Record<string, any> = {};
30
30
 
31
31
  let connectOptions: Record<string, unknown> = {
32
- requestMTU: 512,
32
+ requestMTU: 256,
33
33
  timeout: 3000,
34
34
  };
35
35
 
@@ -206,6 +206,7 @@ export default class ReactNativeBleTransport {
206
206
  ) {
207
207
  connectOptions = {};
208
208
  device = await blePlxManager.connectToDevice(uuid);
209
+ this.Log.debug('first try to reconnect without params');
209
210
  } else {
210
211
  throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, e.reason ?? e);
211
212
  }
@@ -222,13 +223,14 @@ export default class ReactNativeBleTransport {
222
223
  try {
223
224
  await device.connect(connectOptions);
224
225
  } catch (e) {
225
- this.Log.debug('try to connect to device has error: ', e);
226
+ this.Log.debug('not connected, try to connect to device has error: ', e);
226
227
  if (
227
228
  e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||
228
229
  e.errorCode === BleErrorCode.OperationCancelled
229
230
  ) {
230
231
  connectOptions = {};
231
232
  await device.connect();
233
+ this.Log.debug('second try to reconnect without params');
232
234
  } else {
233
235
  throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, e.reason ?? e);
234
236
  }
@@ -440,11 +442,14 @@ export default class ReactNativeBleTransport {
440
442
  try {
441
443
  await transport.writeCharacteristic.writeWithoutResponse(outData);
442
444
  } catch (e) {
445
+ this.Log.debug('writeCharacteristic write error: ', e);
446
+ this.runPromise = null;
443
447
  if (e.errorCode === BleErrorCode.DeviceDisconnected) {
444
448
  throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded);
445
449
  }
446
- this.runPromise = null;
447
- this.Log.debug('writeCharacteristic write error: ', e);
450
+ if (e.errorCode === BleErrorCode.OperationStartFailed) {
451
+ throw ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError, e.reason);
452
+ }
448
453
  return;
449
454
  }
450
455
  }