@onekeyfe/hd-transport-react-native 1.2.0-alpha.60 → 1.2.0-alpha.61
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.map +1 -1
- package/dist/index.js +27 -1
- package/package.json +5 -5
- package/src/__tests__/protocolV2Link.test.ts +13 -0
- package/src/index.ts +28 -1
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,EAIL,UAAU,IAAI,aAAa,EAE5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAEhB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAG1B,MAAM,wBAAwB,CAAC;AAoBhC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAK1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAiBjE,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;IAChC,mBAAmB,EAAE,cAAc,CAAC;IACpC,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,EAE5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAEhB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAG1B,MAAM,wBAAwB,CAAC;AAo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EAAE,OAAO,CAAC;IAIjE,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YA+BlB,cAAc;IA2M5B,IAAI;IAIE,UAAU,CAAC,OAAO,EAAE,MAAM;IA8EhC,MAAM;IASN,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;YAMZ,cAAc;YA4Ed,iCAAiC;YAoDjC,eAAe;YAkBf,eAAe;IAwB7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;YAiBnB,qBAAqB;YA0CrB,oBAAoB;YAwCpB,cAAc;IAoC5B,OAAO,CAAC,uBAAuB;IA4C/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -230,6 +230,32 @@ const IOS_PROTOCOL_V2_CONTROL_WRITE_DELAY_MS = 5;
|
|
|
230
230
|
const ANDROID_FIRMWARE_UPLOAD_PACKET_LENGTH = 192;
|
|
231
231
|
const FIRMWARE_UPLOAD_WRITE_PACKET_CAPACITY = reactNative.Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_FIRMWARE_UPLOAD_PACKET_LENGTH;
|
|
232
232
|
const ANDROID_GATT_CONGESTED_STATUS = 143;
|
|
233
|
+
const isAsciiWhitespace = (code) => code === 0x09 ||
|
|
234
|
+
code === 0x0a ||
|
|
235
|
+
code === 0x0b ||
|
|
236
|
+
code === 0x0c ||
|
|
237
|
+
code === 0x0d ||
|
|
238
|
+
code === 0x20;
|
|
239
|
+
const hasGattCongestedStatus = (text) => {
|
|
240
|
+
let searchFrom = 0;
|
|
241
|
+
while (searchFrom < text.length) {
|
|
242
|
+
const statusIndex = text.indexOf('status', searchFrom);
|
|
243
|
+
if (statusIndex < 0)
|
|
244
|
+
return false;
|
|
245
|
+
let cursor = statusIndex + 'status'.length;
|
|
246
|
+
while (cursor < text.length && isAsciiWhitespace(text.charCodeAt(cursor)))
|
|
247
|
+
cursor += 1;
|
|
248
|
+
if (text[cursor] === ':' || text[cursor] === '=') {
|
|
249
|
+
cursor += 1;
|
|
250
|
+
while (cursor < text.length && isAsciiWhitespace(text.charCodeAt(cursor)))
|
|
251
|
+
cursor += 1;
|
|
252
|
+
}
|
|
253
|
+
if (text.startsWith(String(ANDROID_GATT_CONGESTED_STATUS), cursor))
|
|
254
|
+
return true;
|
|
255
|
+
searchFrom = statusIndex + 'status'.length;
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
};
|
|
233
259
|
const delay = (ms) => new Promise(resolve => {
|
|
234
260
|
setTimeout(resolve, ms);
|
|
235
261
|
});
|
|
@@ -244,7 +270,7 @@ const getFirmwareUploadWriteRetryType = (error) => {
|
|
|
244
270
|
const text = [bleWriteError.reason, bleWriteError.message, bleWriteError.name]
|
|
245
271
|
.filter(value => typeof value === 'string')
|
|
246
272
|
.join(' ');
|
|
247
|
-
return
|
|
273
|
+
return text.includes('GATT_CONGESTED') || hasGattCongestedStatus(text) ? 'congested' : null;
|
|
248
274
|
};
|
|
249
275
|
const resolveFirmwareUploadRetryDelay = (attempt, baseDelayMs = 200, maxDelayMs = 1200) => Math.min(baseDelayMs * Math.pow(2, attempt), maxDelayMs);
|
|
250
276
|
const PROTOCOL_PROBE_TIMEOUT_MS = 1000;
|
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.61",
|
|
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.61",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.61",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.61",
|
|
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": "19c6dc68cec2250bab703e802209ec7be586521d"
|
|
30
30
|
}
|
|
@@ -290,6 +290,19 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
290
290
|
).toBeNull();
|
|
291
291
|
});
|
|
292
292
|
|
|
293
|
+
test.each(['status 143', 'status:143', 'status = 143', 'GATT_CONGESTED'])(
|
|
294
|
+
'classifies %s as transient GATT congestion',
|
|
295
|
+
message => {
|
|
296
|
+
expect(getFirmwareUploadWriteRetryType({ message })).toBe('congested');
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
test('handles long uncontrolled status messages without a backtracking regular expression', () => {
|
|
301
|
+
const message = `status${' '.repeat(100_000)}142`;
|
|
302
|
+
|
|
303
|
+
expect(getFirmwareUploadWriteRetryType({ message })).toBeNull();
|
|
304
|
+
});
|
|
305
|
+
|
|
293
306
|
test('keeps another device reader when releasing a device with an active V1 call', async () => {
|
|
294
307
|
const transport = new ReactNativeBleTransport({ scanTimeout: 1 }) as any;
|
|
295
308
|
const activeV1Call = createDeferred<string>();
|
package/src/index.ts
CHANGED
|
@@ -73,6 +73,33 @@ type ResolvedBleCharacteristics = {
|
|
|
73
73
|
notifyCharacteristic: Characteristic;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
const isAsciiWhitespace = (code: number) =>
|
|
77
|
+
code === 0x09 ||
|
|
78
|
+
code === 0x0a ||
|
|
79
|
+
code === 0x0b ||
|
|
80
|
+
code === 0x0c ||
|
|
81
|
+
code === 0x0d ||
|
|
82
|
+
code === 0x20;
|
|
83
|
+
|
|
84
|
+
const hasGattCongestedStatus = (text: string) => {
|
|
85
|
+
let searchFrom = 0;
|
|
86
|
+
while (searchFrom < text.length) {
|
|
87
|
+
const statusIndex = text.indexOf('status', searchFrom);
|
|
88
|
+
if (statusIndex < 0) return false;
|
|
89
|
+
|
|
90
|
+
let cursor = statusIndex + 'status'.length;
|
|
91
|
+
while (cursor < text.length && isAsciiWhitespace(text.charCodeAt(cursor))) cursor += 1;
|
|
92
|
+
if (text[cursor] === ':' || text[cursor] === '=') {
|
|
93
|
+
cursor += 1;
|
|
94
|
+
while (cursor < text.length && isAsciiWhitespace(text.charCodeAt(cursor))) cursor += 1;
|
|
95
|
+
}
|
|
96
|
+
if (text.startsWith(String(ANDROID_GATT_CONGESTED_STATUS), cursor)) return true;
|
|
97
|
+
|
|
98
|
+
searchFrom = statusIndex + 'status'.length;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
};
|
|
102
|
+
|
|
76
103
|
const delay = (ms: number) =>
|
|
77
104
|
new Promise<void>(resolve => {
|
|
78
105
|
setTimeout(resolve, ms);
|
|
@@ -101,7 +128,7 @@ export const getFirmwareUploadWriteRetryType = (
|
|
|
101
128
|
const text = [bleWriteError.reason, bleWriteError.message, bleWriteError.name]
|
|
102
129
|
.filter(value => typeof value === 'string')
|
|
103
130
|
.join(' ');
|
|
104
|
-
return
|
|
131
|
+
return text.includes('GATT_CONGESTED') || hasGattCongestedStatus(text) ? 'congested' : null;
|
|
105
132
|
};
|
|
106
133
|
|
|
107
134
|
const resolveFirmwareUploadRetryDelay = (attempt: number, baseDelayMs = 200, maxDelayMs = 1200) =>
|