@onekeyfe/hd-transport-react-native 1.2.0-alpha.74 → 1.2.0-alpha.75
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/BleTransport.d.ts.map +1 -1
- package/dist/index.d.ts +1 -88
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -298
- package/jest.config.js +0 -5
- package/package.json +5 -5
- package/src/BleTransport.ts +6 -9
- package/src/__tests__/BleTransport.test.ts +3 -24
- package/src/__tests__/protocolV2Link.test.ts +5 -35
- package/src/index.ts +39 -449
- package/src/__tests__/connectTimeout.test.ts +0 -280
- package/src/__tests__/protocolReprobe.test.ts +0 -132
- package/src/__tests__/protocolV1SchemaFixture.ts +0 -39
- package/src/__tests__/staleCallTimeout.test.ts +0 -210
- package/src/__tests__/writePacketTimeout.test.ts +0 -305
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.75",
|
|
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.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.75",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.75",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.75",
|
|
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": "a9b3ab1cb53f87121ababb2b0ce45789be8fe5ad"
|
|
30
30
|
}
|
package/src/BleTransport.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
1
3
|
import type { Characteristic, Device, Subscription } from 'react-native-ble-plx';
|
|
2
4
|
|
|
3
5
|
export default class BleTransport {
|
|
@@ -32,16 +34,11 @@ export default class BleTransport {
|
|
|
32
34
|
this.notifyCharacteristic = notifyCharacteristic;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
/**
|
|
36
|
-
* Bulk-transfer write (Protocol V1 FirmwareUpload / EmmcFileWrite only).
|
|
37
|
-
*
|
|
38
|
-
* Must stay writeWithoutResponse on every platform. writeWithResponse serialises
|
|
39
|
-
* each packet into its own connection-interval round trip, which on iOS turned a
|
|
40
|
-
* 1.7MB firmware upload (~13.5k packets) into a >10 minute transfer that never
|
|
41
|
-
* finished before the app-level timeout. Protocol V2 and ordinary V1 control
|
|
42
|
-
* messages pick their write type separately and are unaffected by this method.
|
|
43
|
-
*/
|
|
44
37
|
async writeWithRetry(data: string): Promise<void> {
|
|
38
|
+
if (Platform.OS === 'ios' && this.writeCharacteristic.isWritableWithResponse) {
|
|
39
|
+
await this.writeCharacteristic.writeWithResponse(data);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
45
42
|
await this.writeCharacteristic.writeWithoutResponse(data);
|
|
46
43
|
}
|
|
47
44
|
}
|
|
@@ -38,8 +38,8 @@ describe('BleTransport side-effecting writes', () => {
|
|
|
38
38
|
});
|
|
39
39
|
const writeCharacteristic = {
|
|
40
40
|
isWritableWithResponse: true,
|
|
41
|
-
writeWithResponse: jest.fn(() => Promise.
|
|
42
|
-
writeWithoutResponse: jest.fn(() => Promise.
|
|
41
|
+
writeWithResponse: jest.fn(() => Promise.reject(error)),
|
|
42
|
+
writeWithoutResponse: jest.fn(() => Promise.resolve()),
|
|
43
43
|
};
|
|
44
44
|
const device = {
|
|
45
45
|
id: 'classic-id',
|
|
@@ -50,31 +50,10 @@ describe('BleTransport side-effecting writes', () => {
|
|
|
50
50
|
|
|
51
51
|
await expect(transport.writeWithRetry('payload')).rejects.toBe(error);
|
|
52
52
|
|
|
53
|
-
expect(writeCharacteristic.
|
|
53
|
+
expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(1);
|
|
54
54
|
expect(device.connect).not.toHaveBeenCalled();
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
test('keeps iOS bulk transfer on writeWithoutResponse even when the characteristic supports responses', async () => {
|
|
58
|
-
// writeWithResponse serialises every packet into its own connection-interval
|
|
59
|
-
// round trip. On a ~1.7MB firmware (~13.5k packets) that stalled the upload past
|
|
60
|
-
// the 600s app-level timeout, so bulk transfer must never opt into it.
|
|
61
|
-
const writeCharacteristic = {
|
|
62
|
-
isWritableWithResponse: true,
|
|
63
|
-
writeWithResponse: jest.fn(() => Promise.resolve()),
|
|
64
|
-
writeWithoutResponse: jest.fn(() => Promise.resolve()),
|
|
65
|
-
};
|
|
66
|
-
const transport = new BleTransport(
|
|
67
|
-
{ id: 'classic-id' } as any,
|
|
68
|
-
writeCharacteristic as any,
|
|
69
|
-
{} as any
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
await transport.writeWithRetry('payload');
|
|
73
|
-
|
|
74
|
-
expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
|
|
75
|
-
expect(writeCharacteristic.writeWithoutResponse).toHaveBeenCalledWith('payload');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
57
|
test('keeps Android Protocol V1 writes on writeWithoutResponse', async () => {
|
|
79
58
|
Platform.OS = 'android';
|
|
80
59
|
const writeCharacteristic = {
|
|
@@ -7,7 +7,6 @@ import transportPackage, {
|
|
|
7
7
|
import { HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
|
|
8
8
|
|
|
9
9
|
import ReactNativeBleTransport, {
|
|
10
|
-
BLE_WRITE_PACKET_TIMEOUT_MS,
|
|
11
10
|
configureProtocolV2BleTuning,
|
|
12
11
|
getFirmwareUploadWriteRetryType,
|
|
13
12
|
resetProtocolV2BleTuning,
|
|
@@ -756,7 +755,6 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
756
755
|
|
|
757
756
|
await expect(
|
|
758
757
|
transport.writeProtocolV2Packet(
|
|
759
|
-
'test-device',
|
|
760
758
|
{
|
|
761
759
|
writeCharacteristic: {
|
|
762
760
|
isWritableWithResponse: true,
|
|
@@ -791,19 +789,9 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
791
789
|
const setTimeoutSpy = jest.spyOn(global, 'setTimeout');
|
|
792
790
|
|
|
793
791
|
try {
|
|
794
|
-
|
|
795
|
-
'test-device',
|
|
796
|
-
bleTransport,
|
|
797
|
-
new Uint8Array(10),
|
|
798
|
-
context,
|
|
799
|
-
jest.fn()
|
|
800
|
-
);
|
|
792
|
+
await transport.writeProtocolV2Frame(bleTransport, new Uint8Array(10), context, jest.fn());
|
|
801
793
|
|
|
802
|
-
|
|
803
|
-
// The only scheduled timer is the per-packet BLE write watchdog: no pacing delay.
|
|
804
|
-
expect(setTimeoutSpy.mock.calls.map(([, timeout]) => timeout)).toEqual([
|
|
805
|
-
BLE_WRITE_PACKET_TIMEOUT_MS,
|
|
806
|
-
]);
|
|
794
|
+
expect(setTimeoutSpy).not.toHaveBeenCalled();
|
|
807
795
|
expect(writeWithoutResponse).toHaveBeenCalledTimes(1);
|
|
808
796
|
} finally {
|
|
809
797
|
setTimeoutSpy.mockRestore();
|
|
@@ -867,7 +855,6 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
867
855
|
configureProtocolV2BleTuning({ iosPacketLength: 20 });
|
|
868
856
|
|
|
869
857
|
await transport.writeProtocolV2Frame(
|
|
870
|
-
'device-uuid',
|
|
871
858
|
bleTransport,
|
|
872
859
|
new Uint8Array(30),
|
|
873
860
|
context,
|
|
@@ -899,13 +886,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
899
886
|
configureProtocolV2BleTuning({ iosPacketLength: 20 });
|
|
900
887
|
|
|
901
888
|
await expect(
|
|
902
|
-
transport.writeProtocolV2Frame(
|
|
903
|
-
'device-uuid',
|
|
904
|
-
bleTransport,
|
|
905
|
-
new Uint8Array(30),
|
|
906
|
-
context,
|
|
907
|
-
jest.fn()
|
|
908
|
-
)
|
|
889
|
+
transport.writeProtocolV2Frame(bleTransport, new Uint8Array(30), context, jest.fn())
|
|
909
890
|
).rejects.toMatchObject({ errorCode: 205 });
|
|
910
891
|
expect(writeWithoutResponse).toHaveBeenCalledTimes(1);
|
|
911
892
|
});
|
|
@@ -927,21 +908,10 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
927
908
|
const setTimeoutSpy = jest.spyOn(global, 'setTimeout');
|
|
928
909
|
|
|
929
910
|
try {
|
|
930
|
-
await transport.writeProtocolV2Frame(
|
|
931
|
-
'test-device',
|
|
932
|
-
bleTransport,
|
|
933
|
-
new Uint8Array(600),
|
|
934
|
-
context,
|
|
935
|
-
jest.fn()
|
|
936
|
-
);
|
|
911
|
+
await transport.writeProtocolV2Frame(bleTransport, new Uint8Array(600), context, jest.fn());
|
|
937
912
|
|
|
938
913
|
expect(writeWithoutResponse).toHaveBeenCalledTimes(3);
|
|
939
|
-
|
|
940
|
-
expect(setTimeoutSpy.mock.calls.map(([, timeout]) => timeout)).toEqual([
|
|
941
|
-
BLE_WRITE_PACKET_TIMEOUT_MS,
|
|
942
|
-
BLE_WRITE_PACKET_TIMEOUT_MS,
|
|
943
|
-
BLE_WRITE_PACKET_TIMEOUT_MS,
|
|
944
|
-
]);
|
|
914
|
+
expect(setTimeoutSpy).not.toHaveBeenCalled();
|
|
945
915
|
} finally {
|
|
946
916
|
setTimeoutSpy.mockRestore();
|
|
947
917
|
}
|