@onekeyfe/hd-transport-react-native 1.2.2-alpha.119 → 1.2.2-alpha.120
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/index.d.ts +1 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -265
- package/package.json +5 -5
- package/src/__tests__/connectTimeout.test.ts +1 -85
- package/src/__tests__/protocolV2Link.test.ts +25 -600
- package/src/index.ts +67 -366
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
3
|
+
"version": "1.2.2-alpha.120",
|
|
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.2-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.2-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.2-alpha.120",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.2-alpha.120",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.2-alpha.120",
|
|
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": "26958fa2be6aa34a07f42403fb7022d2785e70b9"
|
|
30
30
|
}
|
|
@@ -6,8 +6,6 @@ import { ERRORS, HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
|
|
|
6
6
|
|
|
7
7
|
import { onDeviceBondState } from '../BleManager';
|
|
8
8
|
import ReactNativeBleTransport, {
|
|
9
|
-
ANDROID_LINK_DROP_QUIET_MS,
|
|
10
|
-
ANDROID_MTU_EXCHANGE_TIMEOUT_MS,
|
|
11
9
|
BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD,
|
|
12
10
|
BLE_CONNECT_TIMEOUT_MS,
|
|
13
11
|
BLE_GATT_SETUP_TIMEOUT_MS,
|
|
@@ -448,7 +446,7 @@ describe('BLE connect timeout', () => {
|
|
|
448
446
|
const nativeOperation = createDeferred<typeof device>();
|
|
449
447
|
const nativeDisconnect = createDeferred<void>();
|
|
450
448
|
const requestMtu = jest.fn(() => Promise.resolve(device));
|
|
451
|
-
Object.assign(device, { mtu:
|
|
449
|
+
Object.assign(device, { mtu: 247, requestMTU: requestMtu });
|
|
452
450
|
device.isConnected.mockResolvedValue(true);
|
|
453
451
|
if (stage === 'connect') device.isConnected.mockResolvedValueOnce(false);
|
|
454
452
|
if (stage === 'mtu') requestMtu.mockImplementationOnce(() => nativeOperation.promise);
|
|
@@ -610,19 +608,6 @@ describe('BLE connect timeout', () => {
|
|
|
610
608
|
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
611
609
|
});
|
|
612
610
|
|
|
613
|
-
test('a native GATT timeout abandons the native connection', async () => {
|
|
614
|
-
const { transport, device, bleManager } = createHarness(() => Promise.resolve());
|
|
615
|
-
const nativeTimeout = Object.assign(new Error('Operation timed out'), {
|
|
616
|
-
errorCode: BleErrorCode.OperationTimedOut,
|
|
617
|
-
});
|
|
618
|
-
device.discoverAllServicesAndCharacteristics.mockRejectedValueOnce(nativeTimeout);
|
|
619
|
-
|
|
620
|
-
await expect((transport as any).resolveCharacteristicsWithTimeout(UUID, device)).rejects.toBe(
|
|
621
|
-
nativeTimeout
|
|
622
|
-
);
|
|
623
|
-
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
624
|
-
});
|
|
625
|
-
|
|
626
611
|
test('a successful GATT retry clears the timeout budget before an abandoned call settles', async () => {
|
|
627
612
|
const { transport, device, bleManager } = createHarness(() => Promise.resolve());
|
|
628
613
|
let resolveAbandonedDiscovery: (() => void) | undefined;
|
|
@@ -655,73 +640,4 @@ describe('BLE connect timeout', () => {
|
|
|
655
640
|
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledTimes(1);
|
|
656
641
|
expect((transport as any).connectionSetupTimeoutCounts.has(UUID)).toBe(false);
|
|
657
642
|
});
|
|
658
|
-
|
|
659
|
-
test('holds an unusable link past the idle timer', async () => {
|
|
660
|
-
Object.assign(Platform, { OS: 'android' });
|
|
661
|
-
const { transport, device, bleManager } = createHarness(() => Promise.resolve(device));
|
|
662
|
-
device.isConnected.mockResolvedValue(true);
|
|
663
|
-
Object.assign(device, { mtu: 23, requestMTU: jest.fn(() => new Promise(() => {})) });
|
|
664
|
-
let settled: Error | undefined;
|
|
665
|
-
const acquire = transport.acquire({ uuid: UUID, expectedProtocol: 'V1' }).catch(error => {
|
|
666
|
-
settled = error;
|
|
667
|
-
});
|
|
668
|
-
await flush();
|
|
669
|
-
await flush();
|
|
670
|
-
expect(device.requestMTU).toHaveBeenCalledTimes(1);
|
|
671
|
-
|
|
672
|
-
jest.advanceTimersByTime(ANDROID_MTU_EXCHANGE_TIMEOUT_MS);
|
|
673
|
-
await flush();
|
|
674
|
-
await flush();
|
|
675
|
-
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
676
|
-
|
|
677
|
-
jest.advanceTimersByTime(4000);
|
|
678
|
-
await flush();
|
|
679
|
-
await flush();
|
|
680
|
-
expect(settled).toBeUndefined();
|
|
681
|
-
|
|
682
|
-
await advanceUntil(() => !!settled, ANDROID_LINK_DROP_QUIET_MS);
|
|
683
|
-
await acquire;
|
|
684
|
-
expect(settled).toMatchObject({ errorCode: HardwareErrorCode.BleConnectedError });
|
|
685
|
-
expect(device.discoverAllServicesAndCharacteristics).not.toHaveBeenCalled();
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
test('a slow but successful MTU exchange completes inside the bound', async () => {
|
|
689
|
-
Object.assign(Platform, { OS: 'android' });
|
|
690
|
-
const { transport, device } = createHarness(() => Promise.resolve(device));
|
|
691
|
-
device.isConnected.mockResolvedValue(true);
|
|
692
|
-
const negotiated = { ...device, mtu: 247 };
|
|
693
|
-
Object.assign(device, {
|
|
694
|
-
mtu: 23,
|
|
695
|
-
// A cold cache makes the stack discover first; the exchange then completes late.
|
|
696
|
-
requestMTU: jest.fn(
|
|
697
|
-
() =>
|
|
698
|
-
new Promise(resolve => {
|
|
699
|
-
setTimeout(() => resolve(negotiated), 10_000);
|
|
700
|
-
})
|
|
701
|
-
),
|
|
702
|
-
});
|
|
703
|
-
const [, notifyCharacteristic] = await device.characteristicsForService();
|
|
704
|
-
Object.assign(notifyCharacteristic, { monitor: jest.fn(() => ({ remove: jest.fn() })) });
|
|
705
|
-
let result: unknown;
|
|
706
|
-
let failure: Error | undefined;
|
|
707
|
-
const acquire = transport.acquire({ uuid: UUID, expectedProtocol: 'V1' }).then(
|
|
708
|
-
value => {
|
|
709
|
-
result = value;
|
|
710
|
-
},
|
|
711
|
-
error => {
|
|
712
|
-
failure = error;
|
|
713
|
-
}
|
|
714
|
-
);
|
|
715
|
-
await flush();
|
|
716
|
-
await flush();
|
|
717
|
-
expect(device.discoverAllServicesAndCharacteristics).not.toHaveBeenCalled();
|
|
718
|
-
|
|
719
|
-
jest.advanceTimersByTime(10_000);
|
|
720
|
-
await advanceUntil(() => result !== undefined || failure !== undefined, 5000);
|
|
721
|
-
await acquire;
|
|
722
|
-
expect(failure).toBeUndefined();
|
|
723
|
-
expect(result).toEqual({ uuid: UUID, protocolType: 'V1' });
|
|
724
|
-
expect(device.discoverAllServicesAndCharacteristics).toHaveBeenCalledTimes(1);
|
|
725
|
-
await transport.release(UUID, true);
|
|
726
|
-
});
|
|
727
643
|
});
|