@onekeyfe/hd-transport-react-native 1.2.3-alpha.5 → 1.2.3-alpha.6
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/bleNativeDisconnect.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -51
- package/dist/subscribeBleOn.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/bleNativeDisconnect.test.ts +0 -21
- package/src/__tests__/connectTimeout.test.ts +0 -38
- package/src/__tests__/enumerate.test.ts +1 -36
- package/src/bleNativeDisconnect.ts +1 -2
- package/src/index.ts +13 -17
- package/src/subscribeBleOn.ts +10 -26
- package/src/__tests__/subscribeBleOn.test.ts +0 -111
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bleNativeDisconnect.d.ts","sourceRoot":"","sources":["../src/bleNativeDisconnect.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,0BAA0B,UAAW,OAAO,KAAG,
|
|
1
|
+
{"version":3,"file":"bleNativeDisconnect.d.ts","sourceRoot":"","sources":["../src/bleNativeDisconnect.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,0BAA0B,UAAW,OAAO,KAAG,OAU3D,CAAC;AAEF,eAAO,MAAM,4BAA4B,UAAW,OAAO,UAU1D,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AAgChC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC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OAAO,CAAC,wBAAwB;IA0ChC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA+B1B,OAAO,CAAC,eAAe;IAkEvB,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YAmHd,0BAA0B;YAsB1B,iCAAiC;YAoDjC,eAAe;YAsBf,eAAe;IA4B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,qBAAqB;YAOf,mBAAmB;YAiBnB,qBAAqB;YAmErB,oBAAoB;YAgCpB,cAAc;YAmFd,iCAAiC;IAsB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IAsBjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAmD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -213,42 +213,22 @@ const timer = process.env.NODE_ENV === 'development'
|
|
|
213
213
|
|
|
214
214
|
const subscribeBleOn = (bleManager, ms = 1000) => new Promise((resolve, reject) => {
|
|
215
215
|
let done = false;
|
|
216
|
-
let cancelTimeout = () => undefined;
|
|
217
|
-
let removeSubscription = () => undefined;
|
|
218
|
-
const finish = (error) => {
|
|
219
|
-
if (done)
|
|
220
|
-
return;
|
|
221
|
-
done = true;
|
|
222
|
-
cancelTimeout();
|
|
223
|
-
removeSubscription();
|
|
224
|
-
if (error)
|
|
225
|
-
reject(error);
|
|
226
|
-
else
|
|
227
|
-
resolve();
|
|
228
|
-
};
|
|
229
216
|
const subscription = bleManager.onStateChange(state => {
|
|
230
217
|
if (state === 'PoweredOn') {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
finish(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported));
|
|
238
|
-
}
|
|
239
|
-
else if (state === 'Unauthorized') {
|
|
240
|
-
finish(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
|
|
218
|
+
if (done)
|
|
219
|
+
return;
|
|
220
|
+
clearTimeout();
|
|
221
|
+
done = true;
|
|
222
|
+
subscription.remove();
|
|
223
|
+
resolve();
|
|
241
224
|
}
|
|
242
225
|
}, true);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
finish(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleScanError));
|
|
250
|
-
}, ms);
|
|
251
|
-
}
|
|
226
|
+
const clearTimeout = timer.timeout(() => {
|
|
227
|
+
if (done)
|
|
228
|
+
return;
|
|
229
|
+
subscription.remove();
|
|
230
|
+
reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
|
|
231
|
+
}, ms);
|
|
252
232
|
});
|
|
253
233
|
|
|
254
234
|
const BLE_PLX_DEVICE_DISCONNECTED = 201;
|
|
@@ -262,8 +242,7 @@ const isNativeBleDisconnectError = (error) => {
|
|
|
262
242
|
}
|
|
263
243
|
const nativeError = error;
|
|
264
244
|
return (nativeError.errorCode === BLE_PLX_DEVICE_DISCONNECTED ||
|
|
265
|
-
nativeError.iosErrorCode === IOS_PERIPHERAL_DISCONNECTED
|
|
266
|
-
nativeErrorText$1(nativeError).toLowerCase().includes('was disconnected'));
|
|
245
|
+
nativeError.iosErrorCode === IOS_PERIPHERAL_DISCONNECTED);
|
|
267
246
|
};
|
|
268
247
|
const toBleDisconnectHardwareError = (error) => {
|
|
269
248
|
if ((error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.BleDeviceDisconnected) {
|
|
@@ -566,7 +545,7 @@ const resolveNegotiatedMtu = (device, cancelTransaction) => shouldRefreshNegotia
|
|
|
566
545
|
? requestNegotiatedMtu(device, 'connected', 0, cancelTransaction)
|
|
567
546
|
: Promise.resolve({ device, timedOut: false });
|
|
568
547
|
function remapError(error) {
|
|
569
|
-
var _a
|
|
548
|
+
var _a;
|
|
570
549
|
if (error instanceof reactNativeBlePlx.BleError) {
|
|
571
550
|
if (isNativeBleStaleBondError(error)) {
|
|
572
551
|
throw toBleStaleBondHardwareError(error);
|
|
@@ -575,13 +554,12 @@ function remapError(error) {
|
|
|
575
554
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceBondError);
|
|
576
555
|
}
|
|
577
556
|
}
|
|
578
|
-
if (
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
if (error instanceof Error && ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('not found'))) {
|
|
557
|
+
if (error instanceof Error &&
|
|
558
|
+
error.message &&
|
|
559
|
+
(error.message.includes('was disconnected') || error.message.includes('not found'))) {
|
|
582
560
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
583
561
|
}
|
|
584
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (
|
|
562
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_a = error.reason) !== null && _a !== void 0 ? _a : error);
|
|
585
563
|
}
|
|
586
564
|
class ReactNativeBleTransport {
|
|
587
565
|
constructor(options) {
|
|
@@ -927,11 +905,8 @@ class ReactNativeBleTransport {
|
|
|
927
905
|
var _a, _b;
|
|
928
906
|
if (error) {
|
|
929
907
|
Log === null || Log === void 0 ? void 0 : Log.debug('ble scan error: ', error);
|
|
930
|
-
if (
|
|
931
|
-
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.
|
|
932
|
-
}
|
|
933
|
-
else if (error.errorCode === reactNativeBlePlx.BleErrorCode.BluetoothUnsupported) {
|
|
934
|
-
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleUnsupported));
|
|
908
|
+
if ([reactNativeBlePlx.BleErrorCode.BluetoothPoweredOff, reactNativeBlePlx.BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {
|
|
909
|
+
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
|
|
935
910
|
}
|
|
936
911
|
else if (error.errorCode === reactNativeBlePlx.BleErrorCode.BluetoothUnauthorized) {
|
|
937
912
|
finishScan(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationError));
|
|
@@ -2063,12 +2038,6 @@ class ReactNativeBleTransport {
|
|
|
2063
2038
|
throw this.createWedgedBleSetupError();
|
|
2064
2039
|
}
|
|
2065
2040
|
}
|
|
2066
|
-
if (isNativeBleStaleBondError(error) || hdShared.isBleStaleBondHardwareError(error)) {
|
|
2067
|
-
throw toBleStaleBondHardwareError(error);
|
|
2068
|
-
}
|
|
2069
|
-
if (isNativeBleDisconnectError(error)) {
|
|
2070
|
-
throw toBleDisconnectHardwareError(error);
|
|
2071
|
-
}
|
|
2072
2041
|
if (reactNative.Platform.OS === 'android' && isMissingGattShapeError(error)) {
|
|
2073
2042
|
this.androidGattCacheRefreshes.add(uuid);
|
|
2074
2043
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribeBleOn.d.ts","sourceRoot":"","sources":["../src/subscribeBleOn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAgB,aAAa,kBAAc,QAAQ,IAAI,
|
|
1
|
+
{"version":3,"file":"subscribeBleOn.d.ts","sourceRoot":"","sources":["../src/subscribeBleOn.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAgB,aAAa,kBAAc,QAAQ,IAAI,CAmB9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.3-alpha.
|
|
3
|
+
"version": "1.2.3-alpha.6",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-core": "1.2.3-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.3-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.3-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.3-alpha.6",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.3-alpha.6",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.3-alpha.6",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "0.1.6",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "80a130479ef3ca8479cfb9041d80097ae43d2574"
|
|
30
30
|
}
|
|
@@ -30,25 +30,4 @@ describe('native BLE disconnect mapping', () => {
|
|
|
30
30
|
})
|
|
31
31
|
).toBe(false);
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
test('recognizes the unstructured ble-plx disconnect observed during GATT discovery', () => {
|
|
35
|
-
const nativeError = {
|
|
36
|
-
errorCode: 0,
|
|
37
|
-
message: 'BleError: Device stalled-connect-device was disconnected',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
expect(isNativeBleDisconnectError(nativeError)).toBe(true);
|
|
41
|
-
expect(toBleDisconnectHardwareError(nativeError)).toMatchObject({
|
|
42
|
-
errorCode: HardwareErrorCode.BleDeviceDisconnected,
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('does not infer a disconnect from an unrelated discovery failure', () => {
|
|
47
|
-
expect(
|
|
48
|
-
isNativeBleDisconnectError({
|
|
49
|
-
errorCode: 0,
|
|
50
|
-
message: 'Known OneKey service UUID not found',
|
|
51
|
-
})
|
|
52
|
-
).toBe(false);
|
|
53
|
-
});
|
|
54
33
|
});
|
|
@@ -623,44 +623,6 @@ describe('BLE connect timeout', () => {
|
|
|
623
623
|
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
624
624
|
});
|
|
625
625
|
|
|
626
|
-
test.each([
|
|
627
|
-
{
|
|
628
|
-
nativeFields: { errorCode: BleErrorCode.DeviceDisconnected, iosErrorCode: 14 },
|
|
629
|
-
reason: 'Peer removed pairing information',
|
|
630
|
-
errorCode: HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
631
|
-
},
|
|
632
|
-
{
|
|
633
|
-
nativeFields: { errorCode: 0, attErrorCode: 5 },
|
|
634
|
-
reason: 'GATT_INSUF_AUTHENTICATION',
|
|
635
|
-
errorCode: HardwareErrorCode.BleDeviceBondError,
|
|
636
|
-
},
|
|
637
|
-
])(
|
|
638
|
-
'maps a stale bond during GATT discovery to canonical error $errorCode',
|
|
639
|
-
async ({ nativeFields, reason, errorCode }) => {
|
|
640
|
-
const { transport, device } = createHarness(() => Promise.resolve());
|
|
641
|
-
const nativeError = Object.assign(new Error(reason), nativeFields, { reason });
|
|
642
|
-
device.discoverAllServicesAndCharacteristics.mockRejectedValueOnce(nativeError);
|
|
643
|
-
|
|
644
|
-
await expect(
|
|
645
|
-
(transport as any).resolveCharacteristicsWithTimeout(UUID, device)
|
|
646
|
-
).rejects.toMatchObject({ errorCode });
|
|
647
|
-
}
|
|
648
|
-
);
|
|
649
|
-
|
|
650
|
-
test('normalizes an unstructured GATT disconnect instead of leaking an unknown error', async () => {
|
|
651
|
-
const { transport, device } = createHarness(() => Promise.resolve());
|
|
652
|
-
const nativeError = Object.assign(new Error(`BleError: Device ${UUID} was disconnected`), {
|
|
653
|
-
errorCode: 0,
|
|
654
|
-
});
|
|
655
|
-
device.discoverAllServicesAndCharacteristics.mockRejectedValueOnce(nativeError);
|
|
656
|
-
|
|
657
|
-
await expect(
|
|
658
|
-
(transport as any).resolveCharacteristicsWithTimeout(UUID, device)
|
|
659
|
-
).rejects.toMatchObject({
|
|
660
|
-
errorCode: HardwareErrorCode.BleDeviceDisconnected,
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
|
|
664
626
|
test('a successful GATT retry clears the timeout budget before an abandoned call settles', async () => {
|
|
665
627
|
const { transport, device, bleManager } = createHarness(() => Promise.resolve());
|
|
666
628
|
let resolveAbandonedDiscovery: (() => void) | undefined;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
|
|
3
|
-
import { BleErrorCode } from 'react-native-ble-plx';
|
|
4
|
-
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
5
|
-
|
|
6
3
|
import { getConnectedDeviceIds } from '../BleManager';
|
|
7
4
|
import ReactNativeBleTransport from '../index';
|
|
8
5
|
|
|
@@ -17,14 +14,7 @@ jest.mock(
|
|
|
17
14
|
|
|
18
15
|
jest.mock('react-native-ble-plx', () => ({
|
|
19
16
|
BleError: class BleError extends Error {},
|
|
20
|
-
BleErrorCode: {
|
|
21
|
-
BluetoothUnsupported: 100,
|
|
22
|
-
BluetoothUnauthorized: 101,
|
|
23
|
-
BluetoothPoweredOff: 102,
|
|
24
|
-
BluetoothInUnknownState: 103,
|
|
25
|
-
ScanStartFailed: 600,
|
|
26
|
-
LocationServicesDisabled: 601,
|
|
27
|
-
},
|
|
17
|
+
BleErrorCode: {},
|
|
28
18
|
BleManager: jest.fn(),
|
|
29
19
|
ScanMode: { LowLatency: 2 },
|
|
30
20
|
}));
|
|
@@ -41,31 +31,6 @@ jest.mock('../subscribeBleOn', () => ({
|
|
|
41
31
|
|
|
42
32
|
const ONEKEY_SERVICE_UUID = '00000001-0000-1000-8000-00805f9b34fb';
|
|
43
33
|
|
|
44
|
-
describe('ReactNativeBleTransport scan error mapping', () => {
|
|
45
|
-
test.each([
|
|
46
|
-
[BleErrorCode.BluetoothPoweredOff, HardwareErrorCode.BlePoweredOff],
|
|
47
|
-
[BleErrorCode.BluetoothUnsupported, HardwareErrorCode.BleUnsupported],
|
|
48
|
-
[BleErrorCode.BluetoothInUnknownState, HardwareErrorCode.BleScanError],
|
|
49
|
-
[BleErrorCode.BluetoothUnauthorized, HardwareErrorCode.BleLocationError],
|
|
50
|
-
])('maps native BLE error %s to hardware error %s', async (nativeCode, errorCode) => {
|
|
51
|
-
jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([]);
|
|
52
|
-
const blePlxManager = {
|
|
53
|
-
startDeviceScan: jest.fn((_serviceUUIDs, _options, listener) => {
|
|
54
|
-
queueMicrotask(() => {
|
|
55
|
-
listener({ errorCode: nativeCode, reason: 'native scan failure' }, null);
|
|
56
|
-
});
|
|
57
|
-
}),
|
|
58
|
-
stopDeviceScan: jest.fn(() => Promise.resolve()),
|
|
59
|
-
};
|
|
60
|
-
const transport = new ReactNativeBleTransport({ scanTimeout: 10_000 });
|
|
61
|
-
transport.blePlxManager = blePlxManager as never;
|
|
62
|
-
transport.init({ debug: jest.fn(), error: jest.fn() }, new EventEmitter());
|
|
63
|
-
|
|
64
|
-
await expect(transport.enumerate()).rejects.toMatchObject({ errorCode });
|
|
65
|
-
expect(blePlxManager.stopDeviceScan).toHaveBeenCalledTimes(1);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
34
|
describe('ReactNativeBleTransport iOS discovery', () => {
|
|
70
35
|
test('keeps a bonded Pro2 communication peripheral after Find My changes its name', async () => {
|
|
71
36
|
jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([
|
|
@@ -23,8 +23,7 @@ export const isNativeBleDisconnectError = (error: unknown): boolean => {
|
|
|
23
23
|
const nativeError = error as NativeBleErrorFields;
|
|
24
24
|
return (
|
|
25
25
|
nativeError.errorCode === BLE_PLX_DEVICE_DISCONNECTED ||
|
|
26
|
-
nativeError.iosErrorCode === IOS_PERIPHERAL_DISCONNECTED
|
|
27
|
-
nativeErrorText(nativeError).toLowerCase().includes('was disconnected')
|
|
26
|
+
nativeError.iosErrorCode === IOS_PERIPHERAL_DISCONNECTED
|
|
28
27
|
);
|
|
29
28
|
};
|
|
30
29
|
|
package/src/index.ts
CHANGED
|
@@ -175,8 +175,8 @@ const shouldRethrowProtocolProbeError = (error: unknown): boolean => {
|
|
|
175
175
|
const code = (error as { errorCode?: unknown })?.errorCode;
|
|
176
176
|
// Bonding and GATT failures are not evidence of a protocol mismatch. Preserve
|
|
177
177
|
// them instead of probing another protocol on an unusable connection.
|
|
178
|
-
// Native PLX disconnects (errorCode 201 / iOS 7
|
|
179
|
-
//
|
|
178
|
+
// Native PLX disconnects (errorCode 201 / iOS 7) must match before they are
|
|
179
|
+
// mapped: Protocol V2 writes rethrow them unchanged unless normalized first.
|
|
180
180
|
return (
|
|
181
181
|
isBleStaleBondHardwareError(error) ||
|
|
182
182
|
isNativeBleDisconnectError(error) ||
|
|
@@ -460,11 +460,11 @@ function remapError(error: IOBleErrorRemap) {
|
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
if (
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
463
|
+
if (
|
|
464
|
+
error instanceof Error &&
|
|
465
|
+
error.message &&
|
|
466
|
+
(error.message.includes('was disconnected') || error.message.includes('not found'))
|
|
467
|
+
) {
|
|
468
468
|
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected);
|
|
469
469
|
}
|
|
470
470
|
|
|
@@ -910,10 +910,12 @@ export default class ReactNativeBleTransport {
|
|
|
910
910
|
(error, device) => {
|
|
911
911
|
if (error) {
|
|
912
912
|
Log?.debug('ble scan error: ', error);
|
|
913
|
-
if (
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
913
|
+
if (
|
|
914
|
+
[BleErrorCode.BluetoothPoweredOff, BleErrorCode.BluetoothInUnknownState].includes(
|
|
915
|
+
error.errorCode
|
|
916
|
+
)
|
|
917
|
+
) {
|
|
918
|
+
finishScan(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
|
|
917
919
|
} else if (error.errorCode === BleErrorCode.BluetoothUnauthorized) {
|
|
918
920
|
finishScan(ERRORS.TypedError(HardwareErrorCode.BleLocationError));
|
|
919
921
|
} else if (error.errorCode === BleErrorCode.LocationServicesDisabled) {
|
|
@@ -2341,12 +2343,6 @@ export default class ReactNativeBleTransport {
|
|
|
2341
2343
|
throw this.createWedgedBleSetupError();
|
|
2342
2344
|
}
|
|
2343
2345
|
}
|
|
2344
|
-
if (isNativeBleStaleBondError(error) || isBleStaleBondHardwareError(error)) {
|
|
2345
|
-
throw toBleStaleBondHardwareError(error);
|
|
2346
|
-
}
|
|
2347
|
-
if (isNativeBleDisconnectError(error)) {
|
|
2348
|
-
throw toBleDisconnectHardwareError(error);
|
|
2349
|
-
}
|
|
2350
2346
|
if (Platform.OS === 'android' && isMissingGattShapeError(error)) {
|
|
2351
2347
|
this.androidGattCacheRefreshes.add(uuid);
|
|
2352
2348
|
}
|
package/src/subscribeBleOn.ts
CHANGED
|
@@ -7,36 +7,20 @@ import type { BlePlxManager } from './types';
|
|
|
7
7
|
export const subscribeBleOn = (bleManager: BlePlxManager, ms = 1000): Promise<void> =>
|
|
8
8
|
new Promise((resolve, reject) => {
|
|
9
9
|
let done = false;
|
|
10
|
-
let cancelTimeout: () => void = () => undefined;
|
|
11
|
-
let removeSubscription: () => void = () => undefined;
|
|
12
|
-
|
|
13
|
-
const finish = (error?: Error) => {
|
|
14
|
-
if (done) return;
|
|
15
|
-
done = true;
|
|
16
|
-
cancelTimeout();
|
|
17
|
-
removeSubscription();
|
|
18
|
-
if (error) reject(error);
|
|
19
|
-
else resolve();
|
|
20
|
-
};
|
|
21
10
|
|
|
22
11
|
const subscription = bleManager.onStateChange(state => {
|
|
23
12
|
if (state === 'PoweredOn') {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} else if (state === 'Unauthorized') {
|
|
30
|
-
finish(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
|
|
13
|
+
if (done) return;
|
|
14
|
+
clearTimeout();
|
|
15
|
+
done = true;
|
|
16
|
+
subscription.remove();
|
|
17
|
+
resolve();
|
|
31
18
|
}
|
|
32
19
|
}, true);
|
|
33
|
-
removeSubscription = () => subscription.remove();
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, ms);
|
|
41
|
-
}
|
|
21
|
+
const clearTimeout = timer.timeout(() => {
|
|
22
|
+
if (done) return;
|
|
23
|
+
subscription.remove();
|
|
24
|
+
reject(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
|
|
25
|
+
}, ms);
|
|
42
26
|
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
-
|
|
3
|
-
import { subscribeBleOn } from '../subscribeBleOn';
|
|
4
|
-
|
|
5
|
-
import type { BlePlxManager } from '../types';
|
|
6
|
-
|
|
7
|
-
type BleState = Parameters<Parameters<BlePlxManager['onStateChange']>[0]>[0];
|
|
8
|
-
|
|
9
|
-
const createBleManager = () => {
|
|
10
|
-
let stateListener: ((state: BleState) => void) | undefined;
|
|
11
|
-
const remove = jest.fn();
|
|
12
|
-
const bleManager = {
|
|
13
|
-
onStateChange: jest.fn(listener => {
|
|
14
|
-
stateListener = listener;
|
|
15
|
-
return { remove };
|
|
16
|
-
}),
|
|
17
|
-
} as unknown as BlePlxManager;
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
bleManager,
|
|
21
|
-
emitState: (state: BleState) => stateListener?.(state),
|
|
22
|
-
remove,
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
describe('subscribeBleOn', () => {
|
|
27
|
-
beforeAll(() => {
|
|
28
|
-
jest.useFakeTimers({ doNotFake: ['performance'] });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
afterAll(() => {
|
|
32
|
-
jest.useRealTimers();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
afterEach(() => {
|
|
36
|
-
jest.clearAllTimers();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('resolves when Bluetooth is powered on', async () => {
|
|
40
|
-
const { bleManager, emitState, remove } = createBleManager();
|
|
41
|
-
const result = subscribeBleOn(bleManager);
|
|
42
|
-
|
|
43
|
-
emitState('PoweredOn');
|
|
44
|
-
|
|
45
|
-
await expect(result).resolves.toBeUndefined();
|
|
46
|
-
expect(remove).toHaveBeenCalledTimes(1);
|
|
47
|
-
expect(jest.getTimerCount()).toBe(0);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('cleans up when the current state is emitted synchronously', async () => {
|
|
51
|
-
const remove = jest.fn();
|
|
52
|
-
const bleManager = {
|
|
53
|
-
onStateChange: jest.fn(listener => {
|
|
54
|
-
listener('PoweredOn');
|
|
55
|
-
return { remove };
|
|
56
|
-
}),
|
|
57
|
-
} as unknown as BlePlxManager;
|
|
58
|
-
|
|
59
|
-
await expect(subscribeBleOn(bleManager)).resolves.toBeUndefined();
|
|
60
|
-
expect(remove).toHaveBeenCalledTimes(1);
|
|
61
|
-
expect(jest.getTimerCount()).toBe(0);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test.each([
|
|
65
|
-
['PoweredOff', HardwareErrorCode.BlePoweredOff],
|
|
66
|
-
['Unsupported', HardwareErrorCode.BleUnsupported],
|
|
67
|
-
['Unauthorized', HardwareErrorCode.BlePermissionError],
|
|
68
|
-
] as const)('maps %s to hardware error %s', async (state, errorCode) => {
|
|
69
|
-
const { bleManager, emitState, remove } = createBleManager();
|
|
70
|
-
const result = subscribeBleOn(bleManager);
|
|
71
|
-
const rejection = expect(result).rejects.toMatchObject({ errorCode });
|
|
72
|
-
|
|
73
|
-
emitState(state);
|
|
74
|
-
|
|
75
|
-
await rejection;
|
|
76
|
-
expect(remove).toHaveBeenCalledTimes(1);
|
|
77
|
-
expect(jest.getTimerCount()).toBe(0);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('settles only once when terminal states repeat', async () => {
|
|
81
|
-
const { bleManager, emitState, remove } = createBleManager();
|
|
82
|
-
const result = subscribeBleOn(bleManager);
|
|
83
|
-
const rejection = expect(result).rejects.toMatchObject({
|
|
84
|
-
errorCode: HardwareErrorCode.BlePoweredOff,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
emitState('PoweredOff');
|
|
88
|
-
emitState('PoweredOn');
|
|
89
|
-
|
|
90
|
-
await rejection;
|
|
91
|
-
expect(remove).toHaveBeenCalledTimes(1);
|
|
92
|
-
expect(jest.getTimerCount()).toBe(0);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test.each(['Unknown', 'Resetting'] as const)(
|
|
96
|
-
'reports %s as a scan error if no stable state arrives before timeout',
|
|
97
|
-
async state => {
|
|
98
|
-
const { bleManager, emitState, remove } = createBleManager();
|
|
99
|
-
const result = subscribeBleOn(bleManager, 1000);
|
|
100
|
-
const rejection = expect(result).rejects.toMatchObject({
|
|
101
|
-
errorCode: HardwareErrorCode.BleScanError,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
emitState(state);
|
|
105
|
-
jest.advanceTimersByTime(1000);
|
|
106
|
-
|
|
107
|
-
await rejection;
|
|
108
|
-
expect(remove).toHaveBeenCalledTimes(1);
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
});
|