@onekeyfe/hd-transport-react-native 1.2.0-alpha.56 → 1.2.0-alpha.62
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 +59 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +245 -84
- package/jest.config.js +5 -0
- package/package.json +5 -5
- package/src/BleTransport.ts +1 -1
- package/src/__tests__/BleTransport.test.ts +2 -2
- package/src/__tests__/connectTimeout.test.ts +192 -0
- package/src/__tests__/protocolV2Link.test.ts +41 -241
- package/src/__tests__/staleCallTimeout.test.ts +211 -0
- package/src/__tests__/writePacketTimeout.test.ts +306 -0
- package/src/index.ts +357 -83
- package/src/__tests__/enumerate.test.ts +0 -132
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,17 @@ type ResolvedBleCharacteristics = {
|
|
|
35
35
|
notifyCharacteristic: Characteristic;
|
|
36
36
|
};
|
|
37
37
|
declare const getFirmwareUploadWriteRetryType: (error: unknown) => FirmwareUploadWriteRetryType | null;
|
|
38
|
+
/**
|
|
39
|
+
* Per-packet write budget. iOS only resolves writeWithoutResponse once CoreBluetooth
|
|
40
|
+
* reports the peripheral ready again; a peripheral wedged by its own firmware reboot
|
|
41
|
+
* stops reporting ready while staying connected, so the write promise never settles.
|
|
42
|
+
* Response timeouts cannot cover that — they are armed after the writes complete —
|
|
43
|
+
* and an unbounded write leaves the whole transport unusable until the process dies.
|
|
44
|
+
* A healthy packet completes in milliseconds, so this only fires on a dead link.
|
|
45
|
+
*/
|
|
46
|
+
declare const BLE_WRITE_PACKET_TIMEOUT_MS = 10000;
|
|
47
|
+
/** Consecutive wedged writes on one device before the BLE manager itself is recreated. */
|
|
48
|
+
declare const BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
38
49
|
type ProtocolV2BleTuning = {
|
|
39
50
|
iosPacketLength?: number;
|
|
40
51
|
androidPacketLength?: number;
|
|
@@ -45,6 +56,16 @@ declare function getProtocolV2BleTuning(): {
|
|
|
45
56
|
iosPacketLength: number;
|
|
46
57
|
androidPacketLength: number;
|
|
47
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* JS backstop for connect. The native adapter applies its own 3s budget, but it
|
|
61
|
+
* schedules that timeout on its serial queue, so a busy queue (e.g. right after a
|
|
62
|
+
* firmware install tears the link down) can leave the promise unsettled — observed
|
|
63
|
+
* blocking a reconnect for 61s until the app-level timeout. Healthy connects finish
|
|
64
|
+
* inside the native budget, so this only fires when the native timeout did not.
|
|
65
|
+
*/
|
|
66
|
+
declare const BLE_CONNECT_TIMEOUT_MS: number;
|
|
67
|
+
/** Consecutive connect timeouts on one device before the BLE manager itself is recreated. */
|
|
68
|
+
declare const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
48
69
|
type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
|
|
49
70
|
declare class ReactNativeBleTransport {
|
|
50
71
|
blePlxManager: BleManager | undefined;
|
|
@@ -61,6 +82,17 @@ declare class ReactNativeBleTransport {
|
|
|
61
82
|
firmwareUploadWriteRecoveryIds: Set<string>;
|
|
62
83
|
/** Per-device protocol type detected by active wire-level probe after connect. */
|
|
63
84
|
private deviceProtocol;
|
|
85
|
+
/**
|
|
86
|
+
* Protocol a probe is currently trying, before the device has confirmed it. Calls
|
|
87
|
+
* must route with it, but acquire() must not treat it as a detected protocol: a
|
|
88
|
+
* probe that never answers would otherwise leave the reuse fast path handing out a
|
|
89
|
+
* transport that was never validated.
|
|
90
|
+
*/
|
|
91
|
+
private probingProtocols;
|
|
92
|
+
/** Consecutive write timeouts per device; reset by any write that completes. */
|
|
93
|
+
private writeTimeoutCounts;
|
|
94
|
+
/** Consecutive connect timeouts per device; reset by any connect that settles. */
|
|
95
|
+
private connectTimeoutCounts;
|
|
64
96
|
private deviceProtocolHints;
|
|
65
97
|
private protocolV2Assemblers;
|
|
66
98
|
private protocolV2FrameQueues;
|
|
@@ -99,10 +131,36 @@ declare class ReactNativeBleTransport {
|
|
|
99
131
|
stop(): void;
|
|
100
132
|
disconnect(session: string): Promise<void>;
|
|
101
133
|
cancel(): void;
|
|
134
|
+
/** Run a native connect under the JS backstop budget. */
|
|
135
|
+
private connectWithTimeout;
|
|
136
|
+
/**
|
|
137
|
+
* Give up on a connect the native layer never settled. The abandoned attempt still
|
|
138
|
+
* holds a native "connecting" entry that would cancel the NEXT attempt out from under
|
|
139
|
+
* itself, so it is cleared here — fire and forget, because that call talks to the very
|
|
140
|
+
* queue that just stopped responding.
|
|
141
|
+
*/
|
|
142
|
+
private abandonStalledConnect;
|
|
102
143
|
private getCachedTransport;
|
|
144
|
+
/**
|
|
145
|
+
* Write one packet under a bounded budget. A write that never settles means the
|
|
146
|
+
* peripheral is wedged even though the GATT link still reports connected, so the
|
|
147
|
+
* link is torn down: releasing JS state alone would leave the poisoned peripheral
|
|
148
|
+
* cached and every later call would hang on it again.
|
|
149
|
+
*/
|
|
150
|
+
private writeBlePacket;
|
|
151
|
+
/**
|
|
152
|
+
* Drop a link whose writes stopped completing. The JS state is purged synchronously
|
|
153
|
+
* so the next acquire() cannot reuse the dead transport, while the native teardown is
|
|
154
|
+
* intentionally NOT awaited: it talks to the very layer that just stopped settling
|
|
155
|
+
* promises, so awaiting it could hang exactly like the write it is recovering from.
|
|
156
|
+
*/
|
|
157
|
+
private tearDownWedgedLink;
|
|
158
|
+
private resetPlxManager;
|
|
103
159
|
private createProtocolMismatchError;
|
|
104
160
|
private createProtocolDetectionError;
|
|
105
161
|
private clearProbeProtocol;
|
|
162
|
+
/** Protocol to route a call with: confirmed if known, otherwise the one being probed. */
|
|
163
|
+
private getActiveProtocol;
|
|
106
164
|
private detectProtocol;
|
|
107
165
|
private resetProbeStateAfterProtocolProbe;
|
|
108
166
|
private probeProtocolV1;
|
|
@@ -120,4 +178,4 @@ declare class ReactNativeBleTransport {
|
|
|
120
178
|
getProtocolType(path: string): ProtocolType | undefined;
|
|
121
179
|
}
|
|
122
180
|
|
|
123
|
-
export { IOneKeyDevice, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
|
|
181
|
+
export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, 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,EAE5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAEhB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAG1B,MAAM,wBAAwB,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;AAmBhC,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,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