@onekeyfe/hd-core 0.1.59 → 0.2.0
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/dist/core/index.d.ts.map +1 -1
- package/dist/index.js +23 -2
- package/package.json +4 -4
- package/src/core/index.ts +24 -3
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqBlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AA2BxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBA+PjD,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqBlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AA2BxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBA+PjD,CAAC;AAqMF,eAAO,MAAM,MAAM,0CAkBlB,CAAC;AA8IF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA8CxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAIzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAmBnE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16347,6 +16347,26 @@ function initDeviceForBle(method) {
|
|
|
16347
16347
|
device.deviceConnector = _connector;
|
|
16348
16348
|
return device;
|
|
16349
16349
|
}
|
|
16350
|
+
let bleTimeoutRetry = 0;
|
|
16351
|
+
function connectDeviceForBle(method, device) {
|
|
16352
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16353
|
+
try {
|
|
16354
|
+
yield device.acquire();
|
|
16355
|
+
yield device.initialize(parseInitOptions(method));
|
|
16356
|
+
}
|
|
16357
|
+
catch (err) {
|
|
16358
|
+
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError && bleTimeoutRetry <= 5) {
|
|
16359
|
+
bleTimeoutRetry += 1;
|
|
16360
|
+
Log.debug(`Bletooth connect timeout and will retry, retry count: ${bleTimeoutRetry}`);
|
|
16361
|
+
yield wait(3000);
|
|
16362
|
+
yield connectDeviceForBle(method, device);
|
|
16363
|
+
}
|
|
16364
|
+
else {
|
|
16365
|
+
throw err;
|
|
16366
|
+
}
|
|
16367
|
+
}
|
|
16368
|
+
});
|
|
16369
|
+
}
|
|
16350
16370
|
const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16351
16371
|
let tryCount = 0;
|
|
16352
16372
|
const MAX_RETRY_COUNT = (method.payload && method.payload.retryCount) || 5;
|
|
@@ -16397,8 +16417,8 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
|
|
|
16397
16417
|
clearTimeout(timer);
|
|
16398
16418
|
}
|
|
16399
16419
|
if (env === 'react-native') {
|
|
16400
|
-
|
|
16401
|
-
yield
|
|
16420
|
+
bleTimeoutRetry = 0;
|
|
16421
|
+
yield connectDeviceForBle(method, device);
|
|
16402
16422
|
}
|
|
16403
16423
|
resolve(device);
|
|
16404
16424
|
return;
|
|
@@ -16412,6 +16432,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
|
|
|
16412
16432
|
hdShared.HardwareErrorCode.BleLocationServicesDisabled,
|
|
16413
16433
|
hdShared.HardwareErrorCode.BleDeviceNotBonded,
|
|
16414
16434
|
hdShared.HardwareErrorCode.BleCharacteristicNotifyError,
|
|
16435
|
+
hdShared.HardwareErrorCode.BleTimeoutError,
|
|
16415
16436
|
hdShared.HardwareErrorCode.BleWriteCharacteristicError,
|
|
16416
16437
|
hdShared.HardwareErrorCode.BleAlreadyConnected,
|
|
16417
16438
|
hdShared.HardwareErrorCode.FirmwareUpdateLimitOneDevice,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@onekeyfe/hd-shared": "^0.
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.
|
|
27
|
+
"@onekeyfe/hd-shared": "^0.2.0",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.2.0",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"bignumber.js": "^9.0.2",
|
|
31
31
|
"jszip": "^3.10.1",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"@types/parse-uri": "^1.0.0",
|
|
41
41
|
"@types/semver": "^7.3.9"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "7d63bbcdd05b277e361b8f6ed52c9c59973c40fa"
|
|
44
44
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { DeviceList } from '../device/DeviceList';
|
|
|
19
19
|
import { DevicePool } from '../device/DevicePool';
|
|
20
20
|
import { findMethod } from '../api/utils';
|
|
21
21
|
import { DataManager } from '../data-manager';
|
|
22
|
-
import { enableLog, getLogger, LoggerNames, setLoggerPostMessage } from '../utils';
|
|
22
|
+
import { enableLog, getLogger, LoggerNames, setLoggerPostMessage, wait } from '../utils';
|
|
23
23
|
import {
|
|
24
24
|
CoreMessage,
|
|
25
25
|
createResponseMessage,
|
|
@@ -387,6 +387,26 @@ function initDeviceForBle(method: BaseMethod) {
|
|
|
387
387
|
return device;
|
|
388
388
|
}
|
|
389
389
|
|
|
390
|
+
/**
|
|
391
|
+
* If the Bluetooth connection times out, retry 6 times
|
|
392
|
+
*/
|
|
393
|
+
let bleTimeoutRetry = 0;
|
|
394
|
+
async function connectDeviceForBle(method: BaseMethod, device: Device) {
|
|
395
|
+
try {
|
|
396
|
+
await device.acquire();
|
|
397
|
+
await device.initialize(parseInitOptions(method));
|
|
398
|
+
} catch (err) {
|
|
399
|
+
if (err.errorCode === HardwareErrorCode.BleTimeoutError && bleTimeoutRetry <= 5) {
|
|
400
|
+
bleTimeoutRetry += 1;
|
|
401
|
+
Log.debug(`Bletooth connect timeout and will retry, retry count: ${bleTimeoutRetry}`);
|
|
402
|
+
await wait(3000);
|
|
403
|
+
await connectDeviceForBle(method, device);
|
|
404
|
+
} else {
|
|
405
|
+
throw err;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
390
410
|
type IPollFn<T> = (time?: number) => T;
|
|
391
411
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
392
412
|
const ensureConnected = async (method: BaseMethod, pollingId: number) => {
|
|
@@ -455,8 +475,8 @@ const ensureConnected = async (method: BaseMethod, pollingId: number) => {
|
|
|
455
475
|
* Bluetooth should call initialize here
|
|
456
476
|
*/
|
|
457
477
|
if (env === 'react-native') {
|
|
458
|
-
|
|
459
|
-
await
|
|
478
|
+
bleTimeoutRetry = 0;
|
|
479
|
+
await connectDeviceForBle(method, device);
|
|
460
480
|
}
|
|
461
481
|
resolve(device);
|
|
462
482
|
return;
|
|
@@ -470,6 +490,7 @@ const ensureConnected = async (method: BaseMethod, pollingId: number) => {
|
|
|
470
490
|
HardwareErrorCode.BleLocationServicesDisabled,
|
|
471
491
|
HardwareErrorCode.BleDeviceNotBonded,
|
|
472
492
|
HardwareErrorCode.BleCharacteristicNotifyError,
|
|
493
|
+
HardwareErrorCode.BleTimeoutError,
|
|
473
494
|
HardwareErrorCode.BleWriteCharacteristicError,
|
|
474
495
|
HardwareErrorCode.BleAlreadyConnected,
|
|
475
496
|
HardwareErrorCode.FirmwareUpdateLimitOneDevice,
|