@onekeyfe/hd-transport-react-native 1.2.0-alpha.72 → 1.2.0-alpha.74
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BleTransport.d.ts","sourceRoot":"","sources":["../src/BleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,IAAI,SAA6B;IAEjC,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B,mBAAmB,EAAE,cAAc,CAAC;IAEpC,oBAAoB,EAAE,cAAc,CAAC;IAErC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAElC,sBAAsB,CAAC,EAAE,YAAY,CAAC;IAEtC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,YAAY,CAAC,EAAE,MAAM,CAAC;gBAGpB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,cAAc,EACnC,oBAAoB,EAAE,cAAc;IAiBhC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,15 @@ declare class BleTransport {
|
|
|
16
16
|
notifyTransactionId?: string;
|
|
17
17
|
monitorToken?: number;
|
|
18
18
|
constructor(device: Device, writeCharacteristic: Characteristic, notifyCharacteristic: Characteristic);
|
|
19
|
+
/**
|
|
20
|
+
* Bulk-transfer write (Protocol V1 FirmwareUpload / EmmcFileWrite only).
|
|
21
|
+
*
|
|
22
|
+
* Must stay writeWithoutResponse on every platform. writeWithResponse serialises
|
|
23
|
+
* each packet into its own connection-interval round trip, which on iOS turned a
|
|
24
|
+
* 1.7MB firmware upload (~13.5k packets) into a >10 minute transfer that never
|
|
25
|
+
* finished before the app-level timeout. Protocol V2 and ordinary V1 control
|
|
26
|
+
* messages pick their write type separately and are unaffected by this method.
|
|
27
|
+
*/
|
|
19
28
|
writeWithRetry(data: string): Promise<void>;
|
|
20
29
|
}
|
|
21
30
|
|
package/dist/index.js
CHANGED
|
@@ -216,10 +216,6 @@ class BleTransport {
|
|
|
216
216
|
}
|
|
217
217
|
writeWithRetry(data) {
|
|
218
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
if (reactNative.Platform.OS === 'ios' && this.writeCharacteristic.isWritableWithResponse) {
|
|
220
|
-
yield this.writeCharacteristic.writeWithResponse(data);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
219
|
yield this.writeCharacteristic.writeWithoutResponse(data);
|
|
224
220
|
});
|
|
225
221
|
}
|
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.74",
|
|
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.74",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.74",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.74",
|
|
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": "4b263fb8e60a3286d9ad12d6b3bce3b0f8d023ce"
|
|
30
30
|
}
|
package/src/BleTransport.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
|
|
3
1
|
import type { Characteristic, Device, Subscription } from 'react-native-ble-plx';
|
|
4
2
|
|
|
5
3
|
export default class BleTransport {
|
|
@@ -34,11 +32,16 @@ export default class BleTransport {
|
|
|
34
32
|
this.notifyCharacteristic = notifyCharacteristic;
|
|
35
33
|
}
|
|
36
34
|
|
|
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
|
+
*/
|
|
37
44
|
async writeWithRetry(data: string): Promise<void> {
|
|
38
|
-
if (Platform.OS === 'ios' && this.writeCharacteristic.isWritableWithResponse) {
|
|
39
|
-
await this.writeCharacteristic.writeWithResponse(data);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
45
|
await this.writeCharacteristic.writeWithoutResponse(data);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -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.resolve()),
|
|
42
|
+
writeWithoutResponse: jest.fn(() => Promise.reject(error)),
|
|
43
43
|
};
|
|
44
44
|
const device = {
|
|
45
45
|
id: 'classic-id',
|
|
@@ -50,10 +50,31 @@ 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.writeWithoutResponse).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
|
+
|
|
57
78
|
test('keeps Android Protocol V1 writes on writeWithoutResponse', async () => {
|
|
58
79
|
Platform.OS = 'android';
|
|
59
80
|
const writeCharacteristic = {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { BleErrorCode } from 'react-native-ble-plx';
|
|
3
|
-
|
|
4
3
|
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
5
4
|
|
|
6
5
|
import ReactNativeBleTransport, {
|
|
7
|
-
BLE_CONNECT_TIMEOUT_MS,
|
|
8
6
|
BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD,
|
|
7
|
+
BLE_CONNECT_TIMEOUT_MS,
|
|
9
8
|
BLE_GATT_SETUP_TIMEOUT_MS,
|
|
10
9
|
} from '../index';
|
|
11
10
|
import protocolV1Schema from './protocolV1SchemaFixture';
|