@onekeyfe/hd-transport-react-native 1.2.0-alpha.75 → 1.2.0-alpha.76
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 +88 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +298 -44
- package/jest.config.js +5 -0
- package/package.json +5 -5
- package/src/BleTransport.ts +9 -6
- package/src/__tests__/BleTransport.test.ts +24 -3
- package/src/__tests__/connectTimeout.test.ts +280 -0
- package/src/__tests__/protocolReprobe.test.ts +132 -0
- package/src/__tests__/protocolV1SchemaFixture.ts +39 -0
- package/src/__tests__/protocolV2Link.test.ts +35 -5
- package/src/__tests__/staleCallTimeout.test.ts +210 -0
- package/src/__tests__/writePacketTimeout.test.ts +305 -0
- package/src/index.ts +449 -39
|
@@ -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
|
|
|
@@ -35,6 +44,17 @@ type ResolvedBleCharacteristics = {
|
|
|
35
44
|
notifyCharacteristic: Characteristic;
|
|
36
45
|
};
|
|
37
46
|
declare const getFirmwareUploadWriteRetryType: (error: unknown) => FirmwareUploadWriteRetryType | null;
|
|
47
|
+
/**
|
|
48
|
+
* Per-packet write budget. iOS only resolves writeWithoutResponse once CoreBluetooth
|
|
49
|
+
* reports the peripheral ready again; a peripheral wedged by its own firmware reboot
|
|
50
|
+
* stops reporting ready while staying connected, so the write promise never settles.
|
|
51
|
+
* Response timeouts cannot cover that — they are armed after the writes complete —
|
|
52
|
+
* and an unbounded write leaves the whole transport unusable until the process dies.
|
|
53
|
+
* A healthy packet completes in milliseconds, so this only fires on a dead link.
|
|
54
|
+
*/
|
|
55
|
+
declare const BLE_WRITE_PACKET_TIMEOUT_MS = 10000;
|
|
56
|
+
/** Consecutive wedged writes on one device before the BLE manager itself is recreated. */
|
|
57
|
+
declare const BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
38
58
|
type ProtocolV2BleTuning = {
|
|
39
59
|
iosPacketLength?: number;
|
|
40
60
|
androidPacketLength?: number;
|
|
@@ -45,6 +65,31 @@ declare function getProtocolV2BleTuning(): {
|
|
|
45
65
|
iosPacketLength: number;
|
|
46
66
|
androidPacketLength: number;
|
|
47
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* JS backstop for connect. The native adapter applies its own 3s budget, but it
|
|
70
|
+
* schedules that timeout on its serial queue, so a busy queue (e.g. right after a
|
|
71
|
+
* firmware install tears the link down) can leave the promise unsettled — observed
|
|
72
|
+
* blocking a reconnect for 61s until the app-level timeout. Healthy connects finish
|
|
73
|
+
* inside the native budget, so this only fires when the native timeout did not.
|
|
74
|
+
*/
|
|
75
|
+
declare const BLE_CONNECT_TIMEOUT_MS: number;
|
|
76
|
+
/**
|
|
77
|
+
* Service discovery and characteristic resolution run after connect() succeeds, but
|
|
78
|
+
* CoreBluetooth schedules them on the same serial queue. If that queue is wedged by a
|
|
79
|
+
* device reboot, these calls can remain pending forever unless they have their own
|
|
80
|
+
* budget.
|
|
81
|
+
*/
|
|
82
|
+
declare const BLE_GATT_SETUP_TIMEOUT_MS = 10000;
|
|
83
|
+
/**
|
|
84
|
+
* How many times a known device may fail its own protocol before we probe the others
|
|
85
|
+
* again. Reconnect polling during a device reboot repeats this every few seconds, and
|
|
86
|
+
* probing Protocol V2 costs a 10s Ping timeout, so paying it on every attempt for a
|
|
87
|
+
* device we just spoke V1 to dominates the wait. A firmware update can legitimately
|
|
88
|
+
* change a device's protocol, so the shortcut has to expire rather than stick.
|
|
89
|
+
*/
|
|
90
|
+
declare const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
|
|
91
|
+
/** BLE setup timeouts since the last successful setup before the manager is recreated. */
|
|
92
|
+
declare const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
48
93
|
type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
49
94
|
declare class ReactNativeBleTransport {
|
|
50
95
|
blePlxManager: BleManager | undefined;
|
|
@@ -61,7 +106,22 @@ declare class ReactNativeBleTransport {
|
|
|
61
106
|
firmwareUploadWriteRecoveryIds: Set<string>;
|
|
62
107
|
/** Per-device protocol type detected by active wire-level probe after connect. */
|
|
63
108
|
private deviceProtocol;
|
|
109
|
+
/**
|
|
110
|
+
* Protocol a probe is currently trying, before the device has confirmed it. Calls
|
|
111
|
+
* must route with it, but acquire() must not treat it as a detected protocol: a
|
|
112
|
+
* probe that never answers would otherwise leave the reuse fast path handing out a
|
|
113
|
+
* transport that was never validated.
|
|
114
|
+
*/
|
|
115
|
+
private probingProtocols;
|
|
116
|
+
/** Consecutive write timeouts per device; reset by any write that completes. */
|
|
117
|
+
private writeTimeoutCounts;
|
|
118
|
+
/** BLE setup timeouts per device since the last complete characteristic resolution. */
|
|
119
|
+
private connectionSetupTimeoutCounts;
|
|
64
120
|
private deviceProtocolHints;
|
|
121
|
+
/** Protocol this device actually answered on, kept across reconnects of one session. */
|
|
122
|
+
private sessionProtocols;
|
|
123
|
+
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
124
|
+
private protocolReprobeFailures;
|
|
65
125
|
private protocolV2Assemblers;
|
|
66
126
|
private protocolV2FrameQueues;
|
|
67
127
|
private protocolV2FramePromises;
|
|
@@ -102,10 +162,37 @@ declare class ReactNativeBleTransport {
|
|
|
102
162
|
stop(): void;
|
|
103
163
|
disconnect(session: string): Promise<void>;
|
|
104
164
|
cancel(): void;
|
|
165
|
+
/** Run a native connect under the JS backstop budget. */
|
|
166
|
+
private connectWithTimeout;
|
|
167
|
+
/** Resolve the complete GATT shape under a budget so acquire() always settles. */
|
|
168
|
+
private resolveCharacteristicsWithTimeout;
|
|
169
|
+
/**
|
|
170
|
+
* Give up on a BLE setup operation the native layer did not settle. The abandoned
|
|
171
|
+
* operation still owns native connection/GATT state that can poison the next attempt,
|
|
172
|
+
* so it is cleared here without awaiting the same queue that stopped responding.
|
|
173
|
+
*/
|
|
174
|
+
private abandonStalledConnection;
|
|
105
175
|
private getCachedTransport;
|
|
176
|
+
/**
|
|
177
|
+
* Write one packet under a bounded budget. A write that never settles means the
|
|
178
|
+
* peripheral is wedged even though the GATT link still reports connected, so the
|
|
179
|
+
* link is torn down: releasing JS state alone would leave the poisoned peripheral
|
|
180
|
+
* cached and every later call would hang on it again.
|
|
181
|
+
*/
|
|
182
|
+
private writeBlePacket;
|
|
183
|
+
/**
|
|
184
|
+
* Drop a link whose writes stopped completing. The JS state is purged synchronously
|
|
185
|
+
* so the next acquire() cannot reuse the dead transport, while the native teardown is
|
|
186
|
+
* intentionally NOT awaited: it talks to the very layer that just stopped settling
|
|
187
|
+
* promises, so awaiting it could hang exactly like the write it is recovering from.
|
|
188
|
+
*/
|
|
189
|
+
private tearDownWedgedLink;
|
|
190
|
+
private resetPlxManager;
|
|
106
191
|
private createProtocolMismatchError;
|
|
107
192
|
private createProtocolDetectionError;
|
|
108
193
|
private clearProbeProtocol;
|
|
194
|
+
/** Protocol to route a call with: confirmed if known, otherwise the one being probed. */
|
|
195
|
+
private getActiveProtocol;
|
|
109
196
|
private detectProtocol;
|
|
110
197
|
private resetProbeStateAfterProtocolProbe;
|
|
111
198
|
private probeProtocolV1;
|
|
@@ -128,4 +215,4 @@ declare class ReactNativeBleTransport {
|
|
|
128
215
|
getProtocolType(path: string): ProtocolType | undefined;
|
|
129
216
|
}
|
|
130
217
|
|
|
131
|
-
export { IOneKeyDevice, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
|
218
|
+
export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, PROTOCOL_REPROBE_FALLBACK_ATTEMPTS, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
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,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA2BhC,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;AAgBjE,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;IAChC,mBAAmB,EAAE,cAAc,CAAC;IACpC,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC;AAkCF,eAAO,MAAM,+BAA+B,UACnC,OAAO,KACb,4BAA4B,GAAG,IAsBjC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,M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