@onekeyfe/hd-transport-react-native 1.2.4-alpha.0 → 1.2.4-alpha.1
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/bleIosStaleBond.d.ts +16 -0
- package/dist/bleIosStaleBond.d.ts.map +1 -0
- package/dist/index.d.ts +7 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +102 -139
- package/package.json +5 -5
- package/src/__tests__/iosPeerTermination.test.ts +303 -0
- package/src/__tests__/protocolReprobe.test.ts +1 -116
- package/src/bleIosStaleBond.ts +92 -0
- package/src/index.ts +54 -184
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const IOS_PEER_TERMINATION_LINK_WINDOW_MS = 10000;
|
|
2
|
+
export declare const IOS_PEER_TERMINATION_REPEAT_WINDOW_MS = 60000;
|
|
3
|
+
export declare const isIosPeerTerminationError: (error: unknown) => boolean;
|
|
4
|
+
export declare class IosPeerTerminationTracker {
|
|
5
|
+
private linkStartedAt;
|
|
6
|
+
private terminatedAt;
|
|
7
|
+
private evidenceAt;
|
|
8
|
+
attemptStarted(deviceId: string): void;
|
|
9
|
+
linkStarted(deviceId: string): void;
|
|
10
|
+
note(deviceId: string, error: unknown): void;
|
|
11
|
+
linkProven(deviceId: string): void;
|
|
12
|
+
forget(deviceId: string): void;
|
|
13
|
+
attemptFailed(deviceId: string): boolean;
|
|
14
|
+
reset(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=bleIosStaleBond.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bleIosStaleBond.d.ts","sourceRoot":"","sources":["../src/bleIosStaleBond.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,mCAAmC,QAAS,CAAC;AAE1D,eAAO,MAAM,qCAAqC,QAAS,CAAC;AAE5D,eAAO,MAAM,yBAAyB,UAAW,OAAO,KAAG,OAE9B,CAAC;AAE9B,qBAAa,yBAAyB;IAEpC,OAAO,CAAC,aAAa,CAA6B;IAGlD,OAAO,CAAC,YAAY,CAA6B;IAGjD,OAAO,CAAC,UAAU,CAA6B;IAE/C,cAAc,CAAC,QAAQ,EAAE,MAAM;IAK/B,WAAW,CAAC,QAAQ,EAAE,MAAM;IAM5B,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAMrC,UAAU,CAAC,QAAQ,EAAE,MAAM;IAI3B,MAAM,CAAC,QAAQ,EAAE,MAAM;IAOvB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAuBxC,KAAK;CAKN"}
|
package/dist/index.d.ts
CHANGED
|
@@ -165,13 +165,6 @@ declare class ReactNativeBleTransport {
|
|
|
165
165
|
private protocolReprobeFailures;
|
|
166
166
|
/** Endpoints whose last detection got no answer; 'woken' once their Initialize wake is spent. */
|
|
167
167
|
private silentDetections;
|
|
168
|
-
/**
|
|
169
|
-
* iOS can report a reset Pro2 as a generic peripheral disconnect instead of
|
|
170
|
-
* CBErrorPeerRemovedPairingInformation. Keep that first probe failure across
|
|
171
|
-
* the automatic cold reconnect and require a second failed probe before
|
|
172
|
-
* classifying the OS bond as invalid.
|
|
173
|
-
*/
|
|
174
|
-
private iosProbeDisconnectEvidence;
|
|
175
168
|
/** Android endpoints whose cached GATT table is suspect; the next connect refreshes it. */
|
|
176
169
|
private androidGattCacheRefreshes;
|
|
177
170
|
/**
|
|
@@ -182,6 +175,8 @@ declare class ReactNativeBleTransport {
|
|
|
182
175
|
private staleBondErrors;
|
|
183
176
|
/** When the current Android link attempt began; bounds which key-missing signals apply. */
|
|
184
177
|
private androidLinkStartedAt;
|
|
178
|
+
/** iOS acquire attempts whose new link the peer ended; two in a row mean a stale bond. */
|
|
179
|
+
private iosPeerTermination;
|
|
185
180
|
/** Strict or previously confirmed V2 target while acquire installs notifications. */
|
|
186
181
|
private acquiringProtocolV2;
|
|
187
182
|
private protocolV2Assemblers;
|
|
@@ -233,6 +228,11 @@ declare class ReactNativeBleTransport {
|
|
|
233
228
|
* connect is re-read as an invalid bond when that signal belongs to the same attempt.
|
|
234
229
|
*/
|
|
235
230
|
private resolveAndroidBondInvalid;
|
|
231
|
+
/**
|
|
232
|
+
* iPhones that do not report a lost bond only show the device ending each new link. One such
|
|
233
|
+
* attempt keeps its error so Core retries; the second in a row is the stale bond.
|
|
234
|
+
*/
|
|
235
|
+
private resolveIosBondInvalid;
|
|
236
236
|
/**
|
|
237
237
|
* Android 16+ encrypts a bonded link on its own right after connecting. Subscribing to
|
|
238
238
|
* notifications before that finishes gets the CCCD write rejected, and the framework's retry
|
|
@@ -286,9 +286,6 @@ declare class ReactNativeBleTransport {
|
|
|
286
286
|
private resetPlxManager;
|
|
287
287
|
private createProtocolMismatchError;
|
|
288
288
|
private createProtocolDetectionError;
|
|
289
|
-
private rememberIosProbeDisconnect;
|
|
290
|
-
private getIosProbeDisconnectEvidence;
|
|
291
|
-
private confirmIosProbeDisconnect;
|
|
292
289
|
private clearProbeProtocol;
|
|
293
290
|
/** Protocol to route a call with: confirmed if known, otherwise the one being probed. */
|
|
294
291
|
private getActiveProtocol;
|
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,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAA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B/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IAsBjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAmD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -494,6 +494,63 @@ const waitForAndroidLinkEncryption = ({ deviceId, linkStartedAt, resultTimeoutMs
|
|
|
494
494
|
});
|
|
495
495
|
};
|
|
496
496
|
|
|
497
|
+
const IOS_PERIPHERAL_DISCONNECTED$1 = 7;
|
|
498
|
+
const IOS_PEER_TERMINATION_LINK_WINDOW_MS = 10000;
|
|
499
|
+
const IOS_PEER_TERMINATION_REPEAT_WINDOW_MS = 60000;
|
|
500
|
+
const isIosPeerTerminationError = (error) => (error === null || error === void 0 ? void 0 : error.iosErrorCode) ===
|
|
501
|
+
IOS_PERIPHERAL_DISCONNECTED$1;
|
|
502
|
+
class IosPeerTerminationTracker {
|
|
503
|
+
constructor() {
|
|
504
|
+
this.linkStartedAt = new Map();
|
|
505
|
+
this.terminatedAt = new Map();
|
|
506
|
+
this.evidenceAt = new Map();
|
|
507
|
+
}
|
|
508
|
+
attemptStarted(deviceId) {
|
|
509
|
+
this.linkStartedAt.delete(deviceId);
|
|
510
|
+
this.terminatedAt.delete(deviceId);
|
|
511
|
+
}
|
|
512
|
+
linkStarted(deviceId) {
|
|
513
|
+
this.linkStartedAt.set(deviceId, Date.now());
|
|
514
|
+
this.terminatedAt.delete(deviceId);
|
|
515
|
+
}
|
|
516
|
+
note(deviceId, error) {
|
|
517
|
+
if (!isIosPeerTerminationError(error))
|
|
518
|
+
return;
|
|
519
|
+
if (!this.terminatedAt.has(deviceId))
|
|
520
|
+
this.terminatedAt.set(deviceId, Date.now());
|
|
521
|
+
}
|
|
522
|
+
linkProven(deviceId) {
|
|
523
|
+
this.forget(deviceId);
|
|
524
|
+
}
|
|
525
|
+
forget(deviceId) {
|
|
526
|
+
this.linkStartedAt.delete(deviceId);
|
|
527
|
+
this.terminatedAt.delete(deviceId);
|
|
528
|
+
this.evidenceAt.delete(deviceId);
|
|
529
|
+
}
|
|
530
|
+
attemptFailed(deviceId) {
|
|
531
|
+
const startedAt = this.linkStartedAt.get(deviceId);
|
|
532
|
+
const terminatedAt = this.terminatedAt.get(deviceId);
|
|
533
|
+
const previous = this.evidenceAt.get(deviceId);
|
|
534
|
+
this.forget(deviceId);
|
|
535
|
+
if (startedAt === undefined ||
|
|
536
|
+
terminatedAt === undefined ||
|
|
537
|
+
terminatedAt - startedAt > IOS_PEER_TERMINATION_LINK_WINDOW_MS) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
if (previous !== undefined &&
|
|
541
|
+
terminatedAt - previous <= IOS_PEER_TERMINATION_REPEAT_WINDOW_MS) {
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
this.evidenceAt.set(deviceId, terminatedAt);
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
reset() {
|
|
548
|
+
this.linkStartedAt.clear();
|
|
549
|
+
this.terminatedAt.clear();
|
|
550
|
+
this.evidenceAt.clear();
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
497
554
|
const BLE_PLX_DEVICE_DISCONNECTED = 201;
|
|
498
555
|
const IOS_PERIPHERAL_DISCONNECTED = 7;
|
|
499
556
|
const nativeErrorText$1 = (error) => [error.reason, error.message]
|
|
@@ -661,33 +718,6 @@ const isAndroidLinkLossError = (error) => {
|
|
|
661
718
|
code === hdShared.HardwareErrorCode.BleCharacteristicNotifyError ||
|
|
662
719
|
code === hdShared.HardwareErrorCode.BleConnectedError);
|
|
663
720
|
};
|
|
664
|
-
const logIosBleBondDiagnostic = (phase, error, outcome) => {
|
|
665
|
-
if (reactNative.Platform.OS !== 'ios')
|
|
666
|
-
return;
|
|
667
|
-
const nativeError = (error !== null && error !== void 0 ? error : {});
|
|
668
|
-
const scalar = (value) => typeof value === 'string' || typeof value === 'number' ? value : undefined;
|
|
669
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport][BleBondDiagnostic] probe error', {
|
|
670
|
-
phase,
|
|
671
|
-
outcome,
|
|
672
|
-
errorName: scalar(nativeError.name),
|
|
673
|
-
errorCode: scalar(nativeError.errorCode),
|
|
674
|
-
attErrorCode: scalar(nativeError.attErrorCode),
|
|
675
|
-
iosErrorCode: scalar(nativeError.iosErrorCode),
|
|
676
|
-
androidErrorCode: scalar(nativeError.androidErrorCode),
|
|
677
|
-
nativeStaleBond: isNativeBleStaleBondError(error),
|
|
678
|
-
hardwareStaleBond: hdShared.isBleStaleBondHardwareError(error),
|
|
679
|
-
nativeDisconnect: isNativeBleDisconnectError(error),
|
|
680
|
-
});
|
|
681
|
-
};
|
|
682
|
-
const IOS_PROBE_DISCONNECT_EVIDENCE_TTL_MS = 5 * 60000;
|
|
683
|
-
const isIosProbeDisconnectError = (error) => {
|
|
684
|
-
if (reactNative.Platform.OS !== 'ios')
|
|
685
|
-
return false;
|
|
686
|
-
const code = error === null || error === void 0 ? void 0 : error.errorCode;
|
|
687
|
-
return (isNativeBleDisconnectError(error) ||
|
|
688
|
-
code === hdShared.HardwareErrorCode.BleDeviceNotBonded ||
|
|
689
|
-
code === hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
690
|
-
};
|
|
691
721
|
const BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
|
|
692
722
|
const DEVICE_SCAN_TIMEOUT_MS = 3000;
|
|
693
723
|
const IOS_NOTIFY_READY_DELAY_MS = 150;
|
|
@@ -883,10 +913,10 @@ class ReactNativeBleTransport {
|
|
|
883
913
|
this.confirmedProtocolV2 = new Set();
|
|
884
914
|
this.protocolReprobeFailures = new Map();
|
|
885
915
|
this.silentDetections = new Map();
|
|
886
|
-
this.iosProbeDisconnectEvidence = new Map();
|
|
887
916
|
this.androidGattCacheRefreshes = new Set();
|
|
888
917
|
this.staleBondErrors = new Map();
|
|
889
918
|
this.androidLinkStartedAt = new Map();
|
|
919
|
+
this.iosPeerTermination = new IosPeerTerminationTracker();
|
|
890
920
|
this.acquiringProtocolV2 = new Set();
|
|
891
921
|
this.protocolV2Assemblers = new Map();
|
|
892
922
|
this.protocolV2FrameQueues = new Map();
|
|
@@ -1329,7 +1359,7 @@ class ReactNativeBleTransport {
|
|
|
1329
1359
|
return yield this.acquireUnlocked(input);
|
|
1330
1360
|
}
|
|
1331
1361
|
catch (error) {
|
|
1332
|
-
throw yield this.resolveAndroidBondInvalid(uuid, error);
|
|
1362
|
+
throw this.resolveIosBondInvalid(input, yield this.resolveAndroidBondInvalid(uuid, error));
|
|
1333
1363
|
}
|
|
1334
1364
|
}));
|
|
1335
1365
|
});
|
|
@@ -1340,6 +1370,7 @@ class ReactNativeBleTransport {
|
|
|
1340
1370
|
if (this.stopped)
|
|
1341
1371
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1342
1372
|
const { uuid, forceCleanRunPromise, expectedProtocol, skipProtocolProbe } = input;
|
|
1373
|
+
this.iosPeerTermination.attemptStarted(uuid);
|
|
1343
1374
|
const shouldMapProtocolV2StaleBond = expectedProtocol
|
|
1344
1375
|
? expectedProtocol === 'V2'
|
|
1345
1376
|
: this.confirmedProtocolV2.has(uuid);
|
|
@@ -1633,6 +1664,7 @@ class ReactNativeBleTransport {
|
|
|
1633
1664
|
}));
|
|
1634
1665
|
if (this.stopped)
|
|
1635
1666
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1667
|
+
this.iosPeerTermination.linkProven(uuid);
|
|
1636
1668
|
const currentTransport = transportCache[uuid];
|
|
1637
1669
|
if (!currentTransport) {
|
|
1638
1670
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
|
|
@@ -1659,6 +1691,8 @@ class ReactNativeBleTransport {
|
|
|
1659
1691
|
var _a, _b, _c, _d, _e, _f;
|
|
1660
1692
|
const isCurrentMonitor = this.monitorTokens.get(uuid) === monitorToken;
|
|
1661
1693
|
if (error) {
|
|
1694
|
+
if (isCurrentMonitor)
|
|
1695
|
+
this.iosPeerTermination.note(uuid, error);
|
|
1662
1696
|
Log === null || Log === void 0 ? void 0 : Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
|
|
1663
1697
|
if (this.firmwareUploadWriteRecoveryIds.has(uuid)) {
|
|
1664
1698
|
Log === null || Log === void 0 ? void 0 : Log.debug('notify error ignored during FirmwareUpload write recovery: ', uuid);
|
|
@@ -1877,6 +1911,24 @@ class ReactNativeBleTransport {
|
|
|
1877
1911
|
});
|
|
1878
1912
|
});
|
|
1879
1913
|
}
|
|
1914
|
+
resolveIosBondInvalid(input, error) {
|
|
1915
|
+
if (reactNative.Platform.OS !== 'ios')
|
|
1916
|
+
return error;
|
|
1917
|
+
const { uuid, skipProtocolProbe } = input;
|
|
1918
|
+
if (skipProtocolProbe || hdShared.isBleStaleBondHardwareError(error)) {
|
|
1919
|
+
this.iosPeerTermination.forget(uuid);
|
|
1920
|
+
return error;
|
|
1921
|
+
}
|
|
1922
|
+
if (!this.iosPeerTermination.attemptFailed(uuid))
|
|
1923
|
+
return error;
|
|
1924
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] iOS peer ended two new links in a row, bond is invalid:', {
|
|
1925
|
+
connectIdSuffix: uuid.slice(-8),
|
|
1926
|
+
});
|
|
1927
|
+
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleBondInvalid, undefined, {
|
|
1928
|
+
phase: 'connect',
|
|
1929
|
+
reason: 'peer_disconnected',
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1880
1932
|
waitForAndroidLinkSecurity(uuid) {
|
|
1881
1933
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1882
1934
|
const linkStartedAt = this.androidLinkStartedAt.get(uuid);
|
|
@@ -2116,9 +2168,9 @@ class ReactNativeBleTransport {
|
|
|
2116
2168
|
this.androidPriorityResetTimers.clear();
|
|
2117
2169
|
this.androidHighPriorityDevices.clear();
|
|
2118
2170
|
this.androidLinkStartedAt.clear();
|
|
2171
|
+
this.iosPeerTermination.reset();
|
|
2119
2172
|
stopBleKeyMissingTracking();
|
|
2120
2173
|
stopBleEncryptionTracking();
|
|
2121
|
-
this.iosProbeDisconnectEvidence.clear();
|
|
2122
2174
|
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
2123
2175
|
(_a = this.runPromise) === null || _a === void 0 ? void 0 : _a.reject(error);
|
|
2124
2176
|
this.runPromise = null;
|
|
@@ -2372,6 +2424,7 @@ class ReactNativeBleTransport {
|
|
|
2372
2424
|
}),
|
|
2373
2425
|
]);
|
|
2374
2426
|
succeeded = true;
|
|
2427
|
+
this.iosPeerTermination.linkStarted(uuid);
|
|
2375
2428
|
return result;
|
|
2376
2429
|
}
|
|
2377
2430
|
catch (error) {
|
|
@@ -2418,6 +2471,10 @@ class ReactNativeBleTransport {
|
|
|
2418
2471
|
return result;
|
|
2419
2472
|
}
|
|
2420
2473
|
catch (error) {
|
|
2474
|
+
this.iosPeerTermination.note(uuid, error);
|
|
2475
|
+
if (reactNative.Platform.OS === 'ios' && isNativeBleStaleBondError(error)) {
|
|
2476
|
+
throw toBleStaleBondHardwareError(error);
|
|
2477
|
+
}
|
|
2421
2478
|
if (timedOut || isNativeOperationTimeoutError(error)) {
|
|
2422
2479
|
const resetManager = this.abandonStalledConnection(uuid, timedOut ? 'gatt-backstop' : 'gatt-native');
|
|
2423
2480
|
if (resetManager) {
|
|
@@ -2496,6 +2553,7 @@ class ReactNativeBleTransport {
|
|
|
2496
2553
|
this.writeTimeoutCounts.delete(uuid);
|
|
2497
2554
|
}
|
|
2498
2555
|
catch (error) {
|
|
2556
|
+
this.iosPeerTermination.note(uuid, error);
|
|
2499
2557
|
if (timedOut) {
|
|
2500
2558
|
if (isCurrentOwner && !isCurrentOwner()) {
|
|
2501
2559
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] stale BLE write timed out, link kept:', uuid);
|
|
@@ -2604,50 +2662,6 @@ class ReactNativeBleTransport {
|
|
|
2604
2662
|
createProtocolDetectionError() {
|
|
2605
2663
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
|
|
2606
2664
|
}
|
|
2607
|
-
rememberIosProbeDisconnect(uuid, phase, error) {
|
|
2608
|
-
if (!isIosProbeDisconnectError(error))
|
|
2609
|
-
return undefined;
|
|
2610
|
-
const previous = this.getIosProbeDisconnectEvidence(uuid);
|
|
2611
|
-
const errorCode = error === null || error === void 0 ? void 0 : error.errorCode;
|
|
2612
|
-
const evidence = Object.assign(Object.assign({ phase }, (typeof errorCode === 'string' || typeof errorCode === 'number' ? { errorCode } : {})), { recordedAt: Date.now() });
|
|
2613
|
-
this.iosProbeDisconnectEvidence.set(uuid, evidence);
|
|
2614
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport][BleBondDiagnostic] probe disconnect recorded', {
|
|
2615
|
-
phase,
|
|
2616
|
-
errorCode: evidence.errorCode,
|
|
2617
|
-
repeated: Boolean(previous),
|
|
2618
|
-
});
|
|
2619
|
-
if (!previous)
|
|
2620
|
-
return undefined;
|
|
2621
|
-
return this.confirmIosProbeDisconnect(uuid, 'repeated-probe-disconnect');
|
|
2622
|
-
}
|
|
2623
|
-
getIosProbeDisconnectEvidence(uuid) {
|
|
2624
|
-
const evidence = this.iosProbeDisconnectEvidence.get(uuid);
|
|
2625
|
-
if (!evidence)
|
|
2626
|
-
return undefined;
|
|
2627
|
-
const ageMs = Date.now() - evidence.recordedAt;
|
|
2628
|
-
if (ageMs <= IOS_PROBE_DISCONNECT_EVIDENCE_TTL_MS)
|
|
2629
|
-
return evidence;
|
|
2630
|
-
this.iosProbeDisconnectEvidence.delete(uuid);
|
|
2631
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport][BleBondDiagnostic] probe disconnect expired', {
|
|
2632
|
-
triggerPhase: evidence.phase,
|
|
2633
|
-
triggerErrorCode: evidence.errorCode,
|
|
2634
|
-
ageMs,
|
|
2635
|
-
});
|
|
2636
|
-
return undefined;
|
|
2637
|
-
}
|
|
2638
|
-
confirmIosProbeDisconnect(uuid, confirmation) {
|
|
2639
|
-
const evidence = this.getIosProbeDisconnectEvidence(uuid);
|
|
2640
|
-
if (!evidence)
|
|
2641
|
-
return undefined;
|
|
2642
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport][BleBondDiagnostic] stale bond confirmed', {
|
|
2643
|
-
confirmation,
|
|
2644
|
-
triggerPhase: evidence.phase,
|
|
2645
|
-
triggerErrorCode: evidence.errorCode,
|
|
2646
|
-
evidenceAgeMs: Date.now() - evidence.recordedAt,
|
|
2647
|
-
finalErrorCode: hdShared.HardwareErrorCode.BleBondInvalid,
|
|
2648
|
-
});
|
|
2649
|
-
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleBondInvalid);
|
|
2650
|
-
}
|
|
2651
2665
|
clearProbeProtocol(uuid, protocol) {
|
|
2652
2666
|
if (this.probingProtocols.get(uuid) === protocol) {
|
|
2653
2667
|
this.probingProtocols.delete(uuid);
|
|
@@ -2661,10 +2675,9 @@ class ReactNativeBleTransport {
|
|
|
2661
2675
|
return (_a = this.deviceProtocol.get(uuid)) !== null && _a !== void 0 ? _a : this.probingProtocols.get(uuid);
|
|
2662
2676
|
}
|
|
2663
2677
|
detectProtocol(uuid, expectedProtocol, protocolHint, rebuildTransport) {
|
|
2664
|
-
var _a
|
|
2678
|
+
var _a;
|
|
2665
2679
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2666
2680
|
if (expectedProtocol === 'V1') {
|
|
2667
|
-
this.iosProbeDisconnectEvidence.delete(uuid);
|
|
2668
2681
|
this.deviceProtocol.set(uuid, 'V1');
|
|
2669
2682
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected', {
|
|
2670
2683
|
deviceId: uuid,
|
|
@@ -2678,7 +2691,6 @@ class ReactNativeBleTransport {
|
|
|
2678
2691
|
}
|
|
2679
2692
|
if (expectedProtocol === 'V2') {
|
|
2680
2693
|
if (yield this.probeProtocolV2(uuid)) {
|
|
2681
|
-
this.iosProbeDisconnectEvidence.delete(uuid);
|
|
2682
2694
|
this.deviceProtocol.set(uuid, 'V2');
|
|
2683
2695
|
this.sessionProtocols.set(uuid, 'V2');
|
|
2684
2696
|
this.confirmedProtocolV2.add(uuid);
|
|
@@ -2689,19 +2701,6 @@ class ReactNativeBleTransport {
|
|
|
2689
2701
|
});
|
|
2690
2702
|
return 'V2';
|
|
2691
2703
|
}
|
|
2692
|
-
const staleBondError = this.confirmIosProbeDisconnect(uuid, 'follow-up-no-response');
|
|
2693
|
-
if (reactNative.Platform.OS === 'ios') {
|
|
2694
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport][BleBondDiagnostic] protocol detection ended', {
|
|
2695
|
-
outcome: 'expected-v2-no-response',
|
|
2696
|
-
expectedProtocol,
|
|
2697
|
-
protocolHint: protocolHint !== null && protocolHint !== void 0 ? protocolHint : 'none',
|
|
2698
|
-
finalErrorCode: staleBondError
|
|
2699
|
-
? hdShared.HardwareErrorCode.BleBondInvalid
|
|
2700
|
-
: hdShared.HardwareErrorCode.RuntimeError,
|
|
2701
|
-
});
|
|
2702
|
-
}
|
|
2703
|
-
if (staleBondError)
|
|
2704
|
-
throw staleBondError;
|
|
2705
2704
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
2706
2705
|
}
|
|
2707
2706
|
const sessionProtocol = this.sessionProtocols.get(uuid);
|
|
@@ -2725,7 +2724,6 @@ class ReactNativeBleTransport {
|
|
|
2725
2724
|
}
|
|
2726
2725
|
const detected = protocol === 'V1' ? yield this.probeProtocolV1(uuid) : yield this.probeProtocolV2(uuid);
|
|
2727
2726
|
if (detected) {
|
|
2728
|
-
this.iosProbeDisconnectEvidence.delete(uuid);
|
|
2729
2727
|
this.deviceProtocol.set(uuid, protocol);
|
|
2730
2728
|
this.sessionProtocols.set(uuid, protocol);
|
|
2731
2729
|
if (protocol === 'V2') {
|
|
@@ -2751,26 +2749,6 @@ class ReactNativeBleTransport {
|
|
|
2751
2749
|
}
|
|
2752
2750
|
this.deviceProtocol.delete(uuid);
|
|
2753
2751
|
this.probingProtocols.delete(uuid);
|
|
2754
|
-
const staleBondError = this.confirmIosProbeDisconnect(uuid, 'follow-up-no-response');
|
|
2755
|
-
if (reactNative.Platform.OS === 'ios') {
|
|
2756
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport][BleBondDiagnostic] protocol detection ended', {
|
|
2757
|
-
outcome: 'all-probes-no-response',
|
|
2758
|
-
expectedProtocol: expectedProtocol !== null && expectedProtocol !== void 0 ? expectedProtocol : 'none',
|
|
2759
|
-
protocolHint: protocolHint !== null && protocolHint !== void 0 ? protocolHint : 'none',
|
|
2760
|
-
sessionProtocol: sessionProtocol !== null && sessionProtocol !== void 0 ? sessionProtocol : 'none',
|
|
2761
|
-
probeOrder: probeOrder.join(','),
|
|
2762
|
-
trustSessionProtocol,
|
|
2763
|
-
reprobeFailures,
|
|
2764
|
-
transportCached: Boolean(transportCache[uuid]),
|
|
2765
|
-
notifyActive: Boolean((_b = transportCache[uuid]) === null || _b === void 0 ? void 0 : _b.notifySubscription),
|
|
2766
|
-
staleBondRecorded: this.iosProbeDisconnectEvidence.has(uuid),
|
|
2767
|
-
finalErrorCode: staleBondError
|
|
2768
|
-
? hdShared.HardwareErrorCode.BleBondInvalid
|
|
2769
|
-
: hdShared.HardwareErrorCode.BleTimeoutError,
|
|
2770
|
-
});
|
|
2771
|
-
}
|
|
2772
|
-
if (staleBondError)
|
|
2773
|
-
throw staleBondError;
|
|
2774
2752
|
throw this.createProtocolDetectionError();
|
|
2775
2753
|
});
|
|
2776
2754
|
}
|
|
@@ -2854,12 +2832,7 @@ class ReactNativeBleTransport {
|
|
|
2854
2832
|
catch (error) {
|
|
2855
2833
|
this.clearProbeProtocol(uuid, 'V1');
|
|
2856
2834
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V1 GetFeatures probe failed:', error);
|
|
2857
|
-
|
|
2858
|
-
const staleBondError = this.rememberIosProbeDisconnect(uuid, 'protocol-v1-get-features', error);
|
|
2859
|
-
logIosBleBondDiagnostic('protocol-v1-get-features', error, shouldRethrow ? 'rethrow' : 'fallback');
|
|
2860
|
-
if (staleBondError)
|
|
2861
|
-
throw staleBondError;
|
|
2862
|
-
if (shouldRethrow) {
|
|
2835
|
+
if (shouldRethrowProtocolProbeError(error)) {
|
|
2863
2836
|
throw error;
|
|
2864
2837
|
}
|
|
2865
2838
|
return false;
|
|
@@ -2875,28 +2848,18 @@ class ReactNativeBleTransport {
|
|
|
2875
2848
|
this.probingProtocols.set(uuid, 'V2');
|
|
2876
2849
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
2877
2850
|
this.throwIfStaleBondError(uuid);
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
shouldRethrow: shouldRethrowProtocolProbeError,
|
|
2891
|
-
});
|
|
2892
|
-
}
|
|
2893
|
-
catch (error) {
|
|
2894
|
-
const staleBondError = this.rememberIosProbeDisconnect(uuid, 'protocol-v2-ping', error);
|
|
2895
|
-
logIosBleBondDiagnostic('protocol-v2-ping', error, 'rethrow');
|
|
2896
|
-
if (staleBondError)
|
|
2897
|
-
throw staleBondError;
|
|
2898
|
-
throw error;
|
|
2899
|
-
}
|
|
2851
|
+
const detected = yield transport.probeProtocolV2({
|
|
2852
|
+
call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
|
|
2853
|
+
timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
|
|
2854
|
+
logger: Log,
|
|
2855
|
+
logPrefix: 'ProtocolV2 RN-BLE',
|
|
2856
|
+
onProbeFailed: () => {
|
|
2857
|
+
var _a;
|
|
2858
|
+
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
2859
|
+
this.resetProtocolV2Frames(uuid);
|
|
2860
|
+
},
|
|
2861
|
+
shouldRethrow: shouldRethrowProtocolProbeError,
|
|
2862
|
+
});
|
|
2900
2863
|
if (!detected) {
|
|
2901
2864
|
this.clearProbeProtocol(uuid, 'V2');
|
|
2902
2865
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.4-alpha.
|
|
3
|
+
"version": "1.2.4-alpha.1",
|
|
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.4-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.4-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.4-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.4-alpha.1",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.4-alpha.1",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.4-alpha.1",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "0.1.9",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "711c2e0c33c1316257fce02bc01e7c9bbdd8ce48"
|
|
30
30
|
}
|