@onekeyfe/hd-transport-react-native 1.2.2-alpha.119 → 1.2.2-alpha.120
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 +1 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -265
- package/package.json +5 -5
- package/src/__tests__/connectTimeout.test.ts +1 -85
- package/src/__tests__/protocolV2Link.test.ts +25 -600
- package/src/index.ts +67 -366
package/dist/index.d.ts
CHANGED
|
@@ -74,16 +74,6 @@ declare function getProtocolV2BleTuning(): {
|
|
|
74
74
|
iosPacketLength: number;
|
|
75
75
|
androidPacketLength: number;
|
|
76
76
|
};
|
|
77
|
-
/**
|
|
78
|
-
* With no cached GATT table the stack runs its own discovery (up to ~8s) before the MTU
|
|
79
|
-
* exchange, so the bound sits above that; a stuck exchange never completes.
|
|
80
|
-
*/
|
|
81
|
-
declare const ANDROID_MTU_EXCHANGE_TIMEOUT_MS = 12000;
|
|
82
|
-
/**
|
|
83
|
-
* Android keeps an LE link, with per-link ATT state such as a pending MTU exchange, for its
|
|
84
|
-
* 4s GATT link idle timer after the last client closes; a reconnect inside it reuses the link.
|
|
85
|
-
*/
|
|
86
|
-
declare const ANDROID_LINK_DROP_QUIET_MS = 5000;
|
|
87
77
|
/**
|
|
88
78
|
* JS backstop for connect. The native adapter applies its own 3s budget, but it
|
|
89
79
|
* schedules that timeout on its serial queue, so a busy queue (e.g. right after a
|
|
@@ -145,10 +135,6 @@ declare class ReactNativeBleTransport {
|
|
|
145
135
|
private confirmedProtocolV2;
|
|
146
136
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
147
137
|
private protocolReprobeFailures;
|
|
148
|
-
/** Endpoints whose last detection got no answer; 'woken' once their Initialize wake is spent. */
|
|
149
|
-
private silentDetections;
|
|
150
|
-
/** Android endpoints whose cached GATT table is suspect; the next connect refreshes it. */
|
|
151
|
-
private androidGattCacheRefreshes;
|
|
152
138
|
/**
|
|
153
139
|
* Native encryption/pairing failures seen before Protocol V2 probe starts.
|
|
154
140
|
* Pro2/Neo GATT connect can succeed on a stale iOS bond; the CCCD write then
|
|
@@ -208,13 +194,6 @@ declare class ReactNativeBleTransport {
|
|
|
208
194
|
private runBestEffortNativeOperation;
|
|
209
195
|
private runLifecycleOperation;
|
|
210
196
|
cancel(): Promise<void>;
|
|
211
|
-
/**
|
|
212
|
-
* Android: request the MTU with nothing queued ahead and never close the client while it is
|
|
213
|
-
* outstanding; a link that times out or stays at MTU 23 is dropped.
|
|
214
|
-
*/
|
|
215
|
-
private negotiateAndroidMtu;
|
|
216
|
-
/** Close the client and wait out the link idle timer so the next connect gets a fresh link. */
|
|
217
|
-
private dropAndroidLink;
|
|
218
197
|
/** Run a native connect under the JS backstop budget. */
|
|
219
198
|
private connectWithTimeout;
|
|
220
199
|
/** Resolve the complete GATT shape under a budget so acquire() always settles. */
|
|
@@ -249,13 +228,6 @@ declare class ReactNativeBleTransport {
|
|
|
249
228
|
/** Protocol to route a call with: confirmed if known, otherwise the one being probed. */
|
|
250
229
|
private getActiveProtocol;
|
|
251
230
|
private detectProtocol;
|
|
252
|
-
/**
|
|
253
|
-
* A sleeping Classic drops GetFeatures/Ping and only leaves its screensaver on Initialize, which
|
|
254
|
-
* resets the wallet session, so it is sent once after a fully silent detection. The firmware does
|
|
255
|
-
* not reliably answer it, so its timeout must not drop the link. It only runs when V1 is probed
|
|
256
|
-
* first, so a late reply lands on the V1 probe rather than on a V2 one.
|
|
257
|
-
*/
|
|
258
|
-
private wakeSilentProtocolV1Device;
|
|
259
231
|
private resetProbeStateAfterProtocolProbe;
|
|
260
232
|
private probeProtocolV1;
|
|
261
233
|
private probeProtocolV2;
|
|
@@ -279,4 +251,4 @@ declare class ReactNativeBleTransport {
|
|
|
279
251
|
getProtocolType(path: string): ProtocolType | undefined;
|
|
280
252
|
}
|
|
281
253
|
|
|
282
|
-
export {
|
|
254
|
+
export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_NATIVE_TEARDOWN_TIMEOUT_MS, BLE_SETUP_WEDGED_MESSAGE, 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,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;AAgChC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,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;AAEjE,KAAK,8BAA8B,GAAG,eAAe,GAAG;IAMtD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAkBF,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,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AQ9B,OAAO,CAAC,qBAAqB;YAOf,mBAAmB;YAiBnB,qBAAqB;YAmErB,oBAAoB;YAgCpB,cAAc;YAmFd,iCAAiC;IAiB/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
|
@@ -420,10 +420,10 @@ function getDeviceDisplayName(device) {
|
|
|
420
420
|
}
|
|
421
421
|
const IOS_REQUEST_MTU = 247;
|
|
422
422
|
const ANDROID_REQUEST_MTU = 517;
|
|
423
|
+
const BLE_MTU_REFRESH_RETRY_DELAY_MS = 200;
|
|
423
424
|
const ANDROID_HIGH_PRIORITY_IDLE_MS = 1000;
|
|
424
425
|
const getRequestedBleMtu = () => reactNative.Platform.OS === 'android' ? ANDROID_REQUEST_MTU : IOS_REQUEST_MTU;
|
|
425
426
|
const BLE_NATIVE_CONNECT_TIMEOUT_MS = 3000;
|
|
426
|
-
const BLE_MTU_REQUEST_TIMEOUT_MS = BLE_NATIVE_CONNECT_TIMEOUT_MS;
|
|
427
427
|
const connectOptions = {
|
|
428
428
|
requestMTU: getRequestedBleMtu(),
|
|
429
429
|
timeout: BLE_NATIVE_CONNECT_TIMEOUT_MS,
|
|
@@ -432,29 +432,6 @@ const connectOptions = {
|
|
|
432
432
|
const fallbackConnectOptions = {
|
|
433
433
|
timeout: BLE_NATIVE_CONNECT_TIMEOUT_MS,
|
|
434
434
|
};
|
|
435
|
-
const androidRefreshGattConnectOptions = {
|
|
436
|
-
timeout: BLE_NATIVE_CONNECT_TIMEOUT_MS,
|
|
437
|
-
refreshGatt: 'OnConnected',
|
|
438
|
-
};
|
|
439
|
-
const ANDROID_MTU_EXCHANGE_TIMEOUT_MS = 12000;
|
|
440
|
-
const ANDROID_LINK_DROP_QUIET_MS = 5000;
|
|
441
|
-
const ANDROID_LINK_DROP_POLL_MS = 250;
|
|
442
|
-
const isKnownDefaultMtu = (mtu) => typeof mtu === 'number' && Number.isFinite(mtu) && mtu <= 23;
|
|
443
|
-
const isMissingGattShapeError = (error) => {
|
|
444
|
-
const code = error === null || error === void 0 ? void 0 : error.errorCode;
|
|
445
|
-
const message = error === null || error === void 0 ? void 0 : error.message;
|
|
446
|
-
return (code === hdShared.HardwareErrorCode.BleServiceNotFound ||
|
|
447
|
-
code === hdShared.HardwareErrorCode.BleCharacteristicNotFound ||
|
|
448
|
-
(typeof message === 'string' &&
|
|
449
|
-
(message.includes('BLECharacteristicNotFound') ||
|
|
450
|
-
message.includes('BLECharacteristicNotWritable') ||
|
|
451
|
-
message.includes('BLECharacteristicNotNotifiable'))));
|
|
452
|
-
};
|
|
453
|
-
const isStaleGattTableNotifyReason = (reason) => !!reason &&
|
|
454
|
-
(reason.includes('Cannot write client characteristic config descriptor') ||
|
|
455
|
-
reason.includes('Cannot find client characteristic config descriptor') ||
|
|
456
|
-
reason.includes('The handle is invalid') ||
|
|
457
|
-
reason.includes('Writing is not permitted'));
|
|
458
435
|
const BLE_CONNECT_TIMEOUT_MS = BLE_NATIVE_CONNECT_TIMEOUT_MS * 2 + 2000;
|
|
459
436
|
const BLE_GATT_SETUP_TIMEOUT_MS = 10000;
|
|
460
437
|
const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
|
|
@@ -469,11 +446,6 @@ const isWedgedBleSetupError = (error) => (error === null || error === void 0 ? v
|
|
|
469
446
|
error.message.startsWith(BLE_SETUP_WEDGED_MESSAGE);
|
|
470
447
|
const shouldRethrowBleSetupError = (error) => isConnectTimeoutError(error) || isWedgedBleSetupError(error);
|
|
471
448
|
const isNativeOperationTimeoutError = (error) => (error === null || error === void 0 ? void 0 : error.errorCode) === reactNativeBlePlx.BleErrorCode.OperationTimedOut;
|
|
472
|
-
const isMtuOrCancelledConnectError = (error) => {
|
|
473
|
-
const errorCode = error === null || error === void 0 ? void 0 : error.errorCode;
|
|
474
|
-
return (errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
475
|
-
errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled);
|
|
476
|
-
};
|
|
477
449
|
const tryToGetConfiguration = (device) => {
|
|
478
450
|
if (!device || !device.serviceUUIDs)
|
|
479
451
|
return null;
|
|
@@ -485,65 +457,25 @@ const tryToGetConfiguration = (device) => {
|
|
|
485
457
|
return null;
|
|
486
458
|
return infos;
|
|
487
459
|
};
|
|
488
|
-
const requestNegotiatedMtu = (device, stage, attempt
|
|
460
|
+
const requestNegotiatedMtu = (device, stage, attempt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
489
461
|
if (reactNative.Platform.OS !== 'ios' && reactNative.Platform.OS !== 'android')
|
|
490
|
-
return
|
|
491
|
-
const transactionId = `${device.id}:mtu:${stage}:${attempt}:${Date.now()}`;
|
|
492
|
-
let timeoutId;
|
|
493
|
-
let timedOut = false;
|
|
462
|
+
return device;
|
|
494
463
|
try {
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
const mtuDevice = yield Promise.race([
|
|
498
|
-
request,
|
|
499
|
-
new Promise((_, reject) => {
|
|
500
|
-
timeoutId = setTimeout(() => {
|
|
501
|
-
timedOut = true;
|
|
502
|
-
reject(new Error(`BLE MTU request timeout after ${BLE_MTU_REQUEST_TIMEOUT_MS}ms`));
|
|
503
|
-
}, BLE_MTU_REQUEST_TIMEOUT_MS);
|
|
504
|
-
}),
|
|
505
|
-
]);
|
|
506
|
-
return { device: mtuDevice, timedOut: false };
|
|
464
|
+
const mtuDevice = yield device.requestMTU(getRequestedBleMtu());
|
|
465
|
+
return mtuDevice;
|
|
507
466
|
}
|
|
508
467
|
catch (error) {
|
|
509
|
-
if (timedOut && cancelTransaction) {
|
|
510
|
-
try {
|
|
511
|
-
Promise.resolve(cancelTransaction(transactionId)).catch(cancelError => {
|
|
512
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] MTU cancellation failed', {
|
|
513
|
-
platform: reactNative.Platform.OS,
|
|
514
|
-
stage,
|
|
515
|
-
attempt,
|
|
516
|
-
error: cancelError instanceof Error ? cancelError.message : String(cancelError),
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
catch (cancelError) {
|
|
521
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] MTU cancellation failed', {
|
|
522
|
-
platform: reactNative.Platform.OS,
|
|
523
|
-
stage,
|
|
524
|
-
attempt,
|
|
525
|
-
error: cancelError instanceof Error ? cancelError.message : String(cancelError),
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
468
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] MTU refresh failed, continuing with current value', {
|
|
530
469
|
platform: reactNative.Platform.OS,
|
|
531
470
|
stage,
|
|
532
471
|
attempt,
|
|
533
472
|
actual: device.mtu,
|
|
534
|
-
timedOut,
|
|
535
473
|
error: error instanceof Error ? error.message : String(error),
|
|
536
474
|
});
|
|
537
|
-
return
|
|
538
|
-
}
|
|
539
|
-
finally {
|
|
540
|
-
if (timeoutId)
|
|
541
|
-
clearTimeout(timeoutId);
|
|
475
|
+
return device;
|
|
542
476
|
}
|
|
543
477
|
});
|
|
544
|
-
const resolveNegotiatedMtu = (device
|
|
545
|
-
? requestNegotiatedMtu(device, 'connected', 0, cancelTransaction)
|
|
546
|
-
: Promise.resolve({ device, timedOut: false });
|
|
478
|
+
const resolveNegotiatedMtu = (device) => requestNegotiatedMtu(device, 'connected', 0);
|
|
547
479
|
function remapError(error) {
|
|
548
480
|
var _a;
|
|
549
481
|
if (error instanceof reactNativeBlePlx.BleError) {
|
|
@@ -580,8 +512,6 @@ class ReactNativeBleTransport {
|
|
|
580
512
|
this.sessionProtocols = new Map();
|
|
581
513
|
this.confirmedProtocolV2 = new Set();
|
|
582
514
|
this.protocolReprobeFailures = new Map();
|
|
583
|
-
this.silentDetections = new Map();
|
|
584
|
-
this.androidGattCacheRefreshes = new Set();
|
|
585
515
|
this.staleBondErrors = new Map();
|
|
586
516
|
this.acquiringProtocolV2 = new Set();
|
|
587
517
|
this.protocolV2Assemblers = new Map();
|
|
@@ -1000,12 +930,38 @@ class ReactNativeBleTransport {
|
|
|
1000
930
|
else if (reactNative.Platform.OS === 'android') {
|
|
1001
931
|
yield delay(ANDROID_NOTIFY_READY_DELAY_MS);
|
|
1002
932
|
}
|
|
933
|
+
if (this.stopped)
|
|
934
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
935
|
+
const initialMtu = transport$1.mtuSize;
|
|
936
|
+
let refreshAttempts = 0;
|
|
937
|
+
if ((reactNative.Platform.OS === 'ios' || reactNative.Platform.OS === 'android') &&
|
|
938
|
+
shouldRefreshNegotiatedMtu(transport$1.mtuSize)) {
|
|
939
|
+
refreshAttempts += 1;
|
|
940
|
+
let refreshedDevice = yield requestNegotiatedMtu(transport$1.device, 'servicesAndNotifyReady', 1);
|
|
941
|
+
if (this.stopped)
|
|
942
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
943
|
+
transport$1.device = refreshedDevice;
|
|
944
|
+
transport$1.mtuSize =
|
|
945
|
+
typeof refreshedDevice.mtu === 'number' ? refreshedDevice.mtu : transport$1.mtuSize;
|
|
946
|
+
if (shouldRefreshNegotiatedMtu(transport$1.mtuSize)) {
|
|
947
|
+
yield delay(BLE_MTU_REFRESH_RETRY_DELAY_MS);
|
|
948
|
+
if (this.stopped)
|
|
949
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
950
|
+
refreshAttempts += 1;
|
|
951
|
+
refreshedDevice = yield requestNegotiatedMtu(transport$1.device, 'servicesAndNotifyReady', 2);
|
|
952
|
+
transport$1.device = refreshedDevice;
|
|
953
|
+
transport$1.mtuSize =
|
|
954
|
+
typeof refreshedDevice.mtu === 'number' ? refreshedDevice.mtu : transport$1.mtuSize;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
1003
957
|
if (this.stopped)
|
|
1004
958
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1005
959
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE MTU ready', {
|
|
1006
960
|
platform: reactNative.Platform.OS,
|
|
1007
961
|
requested: getRequestedBleMtu(),
|
|
962
|
+
initial: initialMtu,
|
|
1008
963
|
actual: transport$1.mtuSize,
|
|
964
|
+
refreshAttempts,
|
|
1009
965
|
});
|
|
1010
966
|
return transport$1;
|
|
1011
967
|
});
|
|
@@ -1055,9 +1011,7 @@ class ReactNativeBleTransport {
|
|
|
1055
1011
|
const isCachedDeviceConnected = yield cachedTransport.device
|
|
1056
1012
|
.isConnected()
|
|
1057
1013
|
.catch(() => false);
|
|
1058
|
-
const isCachedAndroidLinkUsable = reactNative.Platform.OS !== 'android' || !this.androidGattCacheRefreshes.has(uuid);
|
|
1059
1014
|
if (isCachedDeviceConnected &&
|
|
1060
|
-
isCachedAndroidLinkUsable &&
|
|
1061
1015
|
cachedProtocol &&
|
|
1062
1016
|
(!expectedProtocol || cachedProtocol === expectedProtocol)) {
|
|
1063
1017
|
if (this.stopped)
|
|
@@ -1070,15 +1024,6 @@ class ReactNativeBleTransport {
|
|
|
1070
1024
|
}
|
|
1071
1025
|
}
|
|
1072
1026
|
let device = null;
|
|
1073
|
-
const isAndroid = reactNative.Platform.OS === 'android';
|
|
1074
|
-
const refreshAndroidGattCache = isAndroid && (!!skipProtocolProbe || this.androidGattCacheRefreshes.has(uuid));
|
|
1075
|
-
let nativeConnectOptions = connectOptions;
|
|
1076
|
-
if (isAndroid) {
|
|
1077
|
-
nativeConnectOptions = refreshAndroidGattCache
|
|
1078
|
-
? androidRefreshGattConnectOptions
|
|
1079
|
-
: fallbackConnectOptions;
|
|
1080
|
-
}
|
|
1081
|
-
let androidRefreshConnectRan = false;
|
|
1082
1027
|
if (forceCleanRunPromise && this.runPromise) {
|
|
1083
1028
|
const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
|
|
1084
1029
|
this.runPromise.reject(error);
|
|
@@ -1087,7 +1032,6 @@ class ReactNativeBleTransport {
|
|
|
1087
1032
|
Log === null || Log === void 0 ? void 0 : Log.debug('Force clean Bluetooth run promise, forceCleanRunPromise: ', forceCleanRunPromise);
|
|
1088
1033
|
}
|
|
1089
1034
|
const blePlxManager = yield this.getPlxManager();
|
|
1090
|
-
let skipPostConnectMtu = false;
|
|
1091
1035
|
try {
|
|
1092
1036
|
yield subscribeBleOn(blePlxManager);
|
|
1093
1037
|
}
|
|
@@ -1129,16 +1073,15 @@ class ReactNativeBleTransport {
|
|
|
1129
1073
|
if (!device) {
|
|
1130
1074
|
Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device: ', uuid);
|
|
1131
1075
|
try {
|
|
1132
|
-
device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid,
|
|
1133
|
-
androidRefreshConnectRan = refreshAndroidGattCache;
|
|
1076
|
+
device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, connectOptions));
|
|
1134
1077
|
}
|
|
1135
1078
|
catch (e) {
|
|
1136
1079
|
Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device has error: ', e);
|
|
1137
1080
|
if (shouldRethrowBleSetupError(e)) {
|
|
1138
1081
|
throw e;
|
|
1139
1082
|
}
|
|
1140
|
-
if (
|
|
1141
|
-
|
|
1083
|
+
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
1084
|
+
e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
1142
1085
|
Log === null || Log === void 0 ? void 0 : Log.debug('first try to reconnect without params');
|
|
1143
1086
|
device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, fallbackConnectOptions));
|
|
1144
1087
|
}
|
|
@@ -1154,27 +1097,19 @@ class ReactNativeBleTransport {
|
|
|
1154
1097
|
if (!device) {
|
|
1155
1098
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'unable to connect to device');
|
|
1156
1099
|
}
|
|
1157
|
-
if (refreshAndroidGattCache &&
|
|
1158
|
-
!androidRefreshConnectRan &&
|
|
1159
|
-
(yield device.isConnected().catch(() => false))) {
|
|
1160
|
-
yield this.dropAndroidLink(uuid, blePlxManager, device, 'gatt cache refresh');
|
|
1161
|
-
if (this.stopped)
|
|
1162
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1163
|
-
}
|
|
1164
1100
|
if (!(yield device.isConnected())) {
|
|
1165
1101
|
Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device: ', uuid);
|
|
1166
1102
|
const disconnectedDevice = device;
|
|
1167
1103
|
try {
|
|
1168
|
-
device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(
|
|
1169
|
-
androidRefreshConnectRan = refreshAndroidGattCache;
|
|
1104
|
+
device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(connectOptions));
|
|
1170
1105
|
}
|
|
1171
1106
|
catch (e) {
|
|
1172
1107
|
Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device has error: ', e);
|
|
1173
1108
|
if (shouldRethrowBleSetupError(e)) {
|
|
1174
1109
|
throw e;
|
|
1175
1110
|
}
|
|
1176
|
-
if (
|
|
1177
|
-
|
|
1111
|
+
if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
|
|
1112
|
+
e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
1178
1113
|
Log === null || Log === void 0 ? void 0 : Log.debug('second try to reconnect without params');
|
|
1179
1114
|
try {
|
|
1180
1115
|
device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
|
|
@@ -1210,54 +1145,11 @@ class ReactNativeBleTransport {
|
|
|
1210
1145
|
}
|
|
1211
1146
|
if (this.stopped)
|
|
1212
1147
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1213
|
-
|
|
1214
|
-
if (isAndroid) {
|
|
1215
|
-
if (refreshAndroidGattCache) {
|
|
1216
|
-
characteristics = yield this.resolveCharacteristicsWithTimeout(uuid, device);
|
|
1217
|
-
if (androidRefreshConnectRan)
|
|
1218
|
-
this.androidGattCacheRefreshes.delete(uuid);
|
|
1219
|
-
if (this.stopped)
|
|
1220
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1221
|
-
}
|
|
1222
|
-
device = yield this.negotiateAndroidMtu(uuid, blePlxManager, device);
|
|
1223
|
-
}
|
|
1224
|
-
else if (!skipPostConnectMtu) {
|
|
1225
|
-
const mtuResult = yield resolveNegotiatedMtu(device, transactionId => blePlxManager.cancelTransaction(transactionId));
|
|
1226
|
-
device = mtuResult.device;
|
|
1227
|
-
if (mtuResult.timedOut) {
|
|
1228
|
-
if (this.stopped)
|
|
1229
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1230
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] post-connect MTU timed out, reconnecting without requesting MTU');
|
|
1231
|
-
const timedOutDevice = device;
|
|
1232
|
-
let mtuTeardownSettled = false;
|
|
1233
|
-
yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
|
|
1234
|
-
yield this.runBestEffortNativeOperation('mtu timeout: cancel device connection', () => timedOutDevice.cancelConnection());
|
|
1235
|
-
mtuTeardownSettled = true;
|
|
1236
|
-
}));
|
|
1237
|
-
if (this.stopped)
|
|
1238
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1239
|
-
if (!mtuTeardownSettled || this.blePlxManager !== blePlxManager) {
|
|
1240
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'BLE MTU cleanup timed out');
|
|
1241
|
-
}
|
|
1242
|
-
try {
|
|
1243
|
-
device = yield this.connectWithTimeout(uuid, () => timedOutDevice.connect(fallbackConnectOptions));
|
|
1244
|
-
}
|
|
1245
|
-
catch (error) {
|
|
1246
|
-
if (shouldRethrowBleSetupError(error))
|
|
1247
|
-
throw error;
|
|
1248
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
|
|
1249
|
-
device = timedOutDevice;
|
|
1250
|
-
}
|
|
1251
|
-
else {
|
|
1252
|
-
remapError(error);
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1148
|
+
device = yield resolveNegotiatedMtu(device);
|
|
1257
1149
|
if (this.stopped)
|
|
1258
1150
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1259
1151
|
const acquiredDevice = device;
|
|
1260
|
-
const { writeCharacteristic, notifyCharacteristic } =
|
|
1152
|
+
const { writeCharacteristic, notifyCharacteristic } = yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice);
|
|
1261
1153
|
if (this.stopped)
|
|
1262
1154
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1263
1155
|
const protocolHint = expectedProtocol
|
|
@@ -1324,7 +1216,7 @@ class ReactNativeBleTransport {
|
|
|
1324
1216
|
let bufferLength = 0;
|
|
1325
1217
|
let buffer$1 = [];
|
|
1326
1218
|
const subscription = characteristic.monitor((error, c) => {
|
|
1327
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1219
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
1328
1220
|
const isCurrentMonitor = this.monitorTokens.get(uuid) === monitorToken;
|
|
1329
1221
|
if (error) {
|
|
1330
1222
|
Log === null || Log === void 0 ? void 0 : Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
|
|
@@ -1341,16 +1233,16 @@ class ReactNativeBleTransport {
|
|
|
1341
1233
|
this.rememberStaleBondError(uuid, toBleStaleBondHardwareError(error));
|
|
1342
1234
|
return;
|
|
1343
1235
|
}
|
|
1344
|
-
if (reactNative.Platform.OS === 'android' && isStaleGattTableNotifyReason(error.reason)) {
|
|
1345
|
-
this.androidGattCacheRefreshes.add(uuid);
|
|
1346
|
-
}
|
|
1347
1236
|
if (this.getActiveProtocol(uuid) === 'V2') {
|
|
1348
1237
|
let errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
|
|
1349
1238
|
if ((_a = error.reason) === null || _a === void 0 ? void 0 : _a.includes('The connection has timed out unexpectedly')) {
|
|
1350
1239
|
errorCode = hdShared.HardwareErrorCode.BleTimeoutError;
|
|
1351
1240
|
}
|
|
1352
|
-
else if (
|
|
1353
|
-
((
|
|
1241
|
+
else if (((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('Cannot write client characteristic config descriptor')) ||
|
|
1242
|
+
((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('Cannot find client characteristic config descriptor')) ||
|
|
1243
|
+
((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('The handle is invalid')) ||
|
|
1244
|
+
((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('Writing is not permitted')) ||
|
|
1245
|
+
((_f = error.reason) === null || _f === void 0 ? void 0 : _f.includes('notify change failed for device'))) {
|
|
1354
1246
|
errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure;
|
|
1355
1247
|
}
|
|
1356
1248
|
this.rejectProtocolV2Frames(uuid, hdShared.ERRORS.TypedError(errorCode));
|
|
@@ -1358,11 +1250,14 @@ class ReactNativeBleTransport {
|
|
|
1358
1250
|
}
|
|
1359
1251
|
if (this.runPromise && this.runPromiseDeviceId === uuid) {
|
|
1360
1252
|
let ERROR = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
|
|
1361
|
-
if ((
|
|
1253
|
+
if ((_g = error.reason) === null || _g === void 0 ? void 0 : _g.includes('The connection has timed out unexpectedly')) {
|
|
1362
1254
|
ERROR = hdShared.HardwareErrorCode.BleTimeoutError;
|
|
1363
1255
|
}
|
|
1364
|
-
if (
|
|
1365
|
-
((
|
|
1256
|
+
if (((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('Cannot write client characteristic config descriptor')) ||
|
|
1257
|
+
((_j = error.reason) === null || _j === void 0 ? void 0 : _j.includes('Cannot find client characteristic config descriptor')) ||
|
|
1258
|
+
((_k = error.reason) === null || _k === void 0 ? void 0 : _k.includes('The handle is invalid')) ||
|
|
1259
|
+
((_l = error.reason) === null || _l === void 0 ? void 0 : _l.includes('Writing is not permitted')) ||
|
|
1260
|
+
((_m = error.reason) === null || _m === void 0 ? void 0 : _m.includes('notify change failed for device'))) {
|
|
1366
1261
|
const notifyError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure);
|
|
1367
1262
|
this.runPromise.reject(notifyError);
|
|
1368
1263
|
Log === null || Log === void 0 ? void 0 : Log.debug(`${hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`);
|
|
@@ -1404,7 +1299,7 @@ class ReactNativeBleTransport {
|
|
|
1404
1299
|
bufferLength = 0;
|
|
1405
1300
|
buffer$1 = [];
|
|
1406
1301
|
if (this.runPromiseDeviceId === uuid) {
|
|
1407
|
-
(
|
|
1302
|
+
(_o = this.runPromise) === null || _o === void 0 ? void 0 : _o.resolve(value.toString('hex'));
|
|
1408
1303
|
}
|
|
1409
1304
|
}
|
|
1410
1305
|
}
|
|
@@ -1415,7 +1310,7 @@ class ReactNativeBleTransport {
|
|
|
1415
1310
|
this.rejectProtocolV2Frames(uuid, notifyError);
|
|
1416
1311
|
}
|
|
1417
1312
|
else if (this.runPromiseDeviceId === uuid) {
|
|
1418
|
-
(
|
|
1313
|
+
(_p = this.runPromise) === null || _p === void 0 ? void 0 : _p.reject(notifyError);
|
|
1419
1314
|
}
|
|
1420
1315
|
}
|
|
1421
1316
|
}, notifyTransactionId);
|
|
@@ -1691,14 +1586,13 @@ class ReactNativeBleTransport {
|
|
|
1691
1586
|
return check.call(jsonData);
|
|
1692
1587
|
}
|
|
1693
1588
|
catch (e) {
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
if (isProbeTimeout) {
|
|
1697
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(`[ReactNativeBleTransport] Protocol V1 ${name} probe call failed:`, e);
|
|
1589
|
+
if (name === 'GetFeatures' && (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS) {
|
|
1590
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V1 GetFeatures probe call failed:', e);
|
|
1698
1591
|
}
|
|
1699
1592
|
else {
|
|
1700
1593
|
Log === null || Log === void 0 ? void 0 : Log.error('call error: ', e);
|
|
1701
1594
|
}
|
|
1595
|
+
const isProbeTimeout = name === 'GetFeatures' && (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS;
|
|
1702
1596
|
const isStaleCall = this.runPromise !== runPromise;
|
|
1703
1597
|
if (!isProbeTimeout &&
|
|
1704
1598
|
!isStaleCall &&
|
|
@@ -1899,72 +1793,6 @@ class ReactNativeBleTransport {
|
|
|
1899
1793
|
}
|
|
1900
1794
|
});
|
|
1901
1795
|
}
|
|
1902
|
-
negotiateAndroidMtu(uuid, manager, device) {
|
|
1903
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1904
|
-
if (!shouldRefreshNegotiatedMtu(device.mtu))
|
|
1905
|
-
return device;
|
|
1906
|
-
const startedAt = Date.now();
|
|
1907
|
-
let timer;
|
|
1908
|
-
let timedOut = false;
|
|
1909
|
-
let negotiated = device;
|
|
1910
|
-
let failure;
|
|
1911
|
-
try {
|
|
1912
|
-
negotiated = yield Promise.race([
|
|
1913
|
-
device.requestMTU(ANDROID_REQUEST_MTU, `${device.id}:mtu:connected:0:${startedAt}`),
|
|
1914
|
-
new Promise((_, reject) => {
|
|
1915
|
-
timer = setTimeout(() => {
|
|
1916
|
-
timedOut = true;
|
|
1917
|
-
reject(new Error(`BLE MTU exchange timeout after ${ANDROID_MTU_EXCHANGE_TIMEOUT_MS}ms`));
|
|
1918
|
-
}, ANDROID_MTU_EXCHANGE_TIMEOUT_MS);
|
|
1919
|
-
}),
|
|
1920
|
-
]);
|
|
1921
|
-
}
|
|
1922
|
-
catch (error) {
|
|
1923
|
-
failure = error instanceof Error ? error.message : String(error);
|
|
1924
|
-
}
|
|
1925
|
-
finally {
|
|
1926
|
-
if (timer)
|
|
1927
|
-
clearTimeout(timer);
|
|
1928
|
-
}
|
|
1929
|
-
Log === null || Log === void 0 ? void 0 : Log.debug(`[ReactNativeBleTransport] BLE MTU exchange ${failure ? 'failed' : 'completed'}`, {
|
|
1930
|
-
connectIdSuffix: uuid.slice(-8),
|
|
1931
|
-
elapsedMs: Date.now() - startedAt,
|
|
1932
|
-
timedOut,
|
|
1933
|
-
actual: negotiated.mtu,
|
|
1934
|
-
error: failure,
|
|
1935
|
-
});
|
|
1936
|
-
if (this.stopped)
|
|
1937
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
|
|
1938
|
-
if (!timedOut && !isKnownDefaultMtu(negotiated.mtu))
|
|
1939
|
-
return negotiated;
|
|
1940
|
-
const resetManager = this.abandonStalledConnection(uuid, timedOut ? 'mtu-backstop' : 'mtu-default');
|
|
1941
|
-
yield this.dropAndroidLink(uuid, manager, negotiated, timedOut ? 'mtu exchange timeout' : 'default mtu');
|
|
1942
|
-
if (resetManager)
|
|
1943
|
-
throw this.createWedgedBleSetupError();
|
|
1944
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, timedOut
|
|
1945
|
-
? 'BLE MTU exchange did not complete, reconnecting on a fresh link'
|
|
1946
|
-
: `BLE link stayed at the default MTU ${negotiated.mtu}, reconnecting on a fresh link`);
|
|
1947
|
-
});
|
|
1948
|
-
}
|
|
1949
|
-
dropAndroidLink(uuid, manager, device, reason) {
|
|
1950
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1951
|
-
yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
|
|
1952
|
-
yield Promise.all([
|
|
1953
|
-
this.runBestEffortNativeOperation(`${reason}: cancel manager connection`, () => manager.cancelDeviceConnection(uuid)),
|
|
1954
|
-
this.runBestEffortNativeOperation(`${reason}: cancel device connection`, () => device.cancelConnection()),
|
|
1955
|
-
]);
|
|
1956
|
-
}));
|
|
1957
|
-
const startedAt = Date.now();
|
|
1958
|
-
while (!this.stopped && Date.now() - startedAt < ANDROID_LINK_DROP_QUIET_MS) {
|
|
1959
|
-
yield delay(ANDROID_LINK_DROP_POLL_MS);
|
|
1960
|
-
}
|
|
1961
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Android BLE link drop', {
|
|
1962
|
-
connectIdSuffix: uuid.slice(-8),
|
|
1963
|
-
reason,
|
|
1964
|
-
stopped: this.stopped,
|
|
1965
|
-
});
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
1796
|
connectWithTimeout(uuid, connect) {
|
|
1969
1797
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1970
1798
|
if (this.stopped)
|
|
@@ -2038,9 +1866,6 @@ class ReactNativeBleTransport {
|
|
|
2038
1866
|
throw this.createWedgedBleSetupError();
|
|
2039
1867
|
}
|
|
2040
1868
|
}
|
|
2041
|
-
if (reactNative.Platform.OS === 'android' && isMissingGattShapeError(error)) {
|
|
2042
|
-
this.androidGattCacheRefreshes.add(uuid);
|
|
2043
|
-
}
|
|
2044
1869
|
throw error;
|
|
2045
1870
|
}
|
|
2046
1871
|
finally {
|
|
@@ -2192,7 +2017,6 @@ class ReactNativeBleTransport {
|
|
|
2192
2017
|
this.acquiringProtocolV2.clear();
|
|
2193
2018
|
this.sessionProtocols.clear();
|
|
2194
2019
|
this.protocolReprobeFailures.clear();
|
|
2195
|
-
this.silentDetections.clear();
|
|
2196
2020
|
this.writeTimeoutCounts.clear();
|
|
2197
2021
|
this.connectionSetupTimeoutCounts.clear();
|
|
2198
2022
|
this.monitorTokens.clear();
|
|
@@ -2266,7 +2090,6 @@ class ReactNativeBleTransport {
|
|
|
2266
2090
|
!protocolHint &&
|
|
2267
2091
|
reprobeFailures < PROTOCOL_REPROBE_FALLBACK_ATTEMPTS;
|
|
2268
2092
|
const probeOrder = trustSessionProtocol ? [sessionProtocol] : fullProbeOrder;
|
|
2269
|
-
yield this.wakeSilentProtocolV1Device(uuid, probeOrder);
|
|
2270
2093
|
for (let i = 0; i < probeOrder.length; i += 1) {
|
|
2271
2094
|
const protocol = probeOrder[i];
|
|
2272
2095
|
if (i > 0) {
|
|
@@ -2286,7 +2109,6 @@ class ReactNativeBleTransport {
|
|
|
2286
2109
|
this.confirmedProtocolV2.add(uuid);
|
|
2287
2110
|
}
|
|
2288
2111
|
this.protocolReprobeFailures.delete(uuid);
|
|
2289
|
-
this.silentDetections.delete(uuid);
|
|
2290
2112
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
2291
2113
|
deviceId: uuid,
|
|
2292
2114
|
protocol,
|
|
@@ -2295,8 +2117,6 @@ class ReactNativeBleTransport {
|
|
|
2295
2117
|
return protocol;
|
|
2296
2118
|
}
|
|
2297
2119
|
}
|
|
2298
|
-
if (!this.silentDetections.has(uuid))
|
|
2299
|
-
this.silentDetections.set(uuid, 'silent');
|
|
2300
2120
|
if (trustSessionProtocol) {
|
|
2301
2121
|
this.protocolReprobeFailures.set(uuid, reprobeFailures + 1);
|
|
2302
2122
|
}
|
|
@@ -2308,30 +2128,6 @@ class ReactNativeBleTransport {
|
|
|
2308
2128
|
throw this.createProtocolDetectionError();
|
|
2309
2129
|
});
|
|
2310
2130
|
}
|
|
2311
|
-
wakeSilentProtocolV1Device(uuid, probeOrder) {
|
|
2312
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2313
|
-
if (reactNative.Platform.OS !== 'android' ||
|
|
2314
|
-
probeOrder[0] !== 'V1' ||
|
|
2315
|
-
this.silentDetections.get(uuid) !== 'silent') {
|
|
2316
|
-
return;
|
|
2317
|
-
}
|
|
2318
|
-
this.silentDetections.set(uuid, 'woken');
|
|
2319
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] sending Protocol V1 Initialize wake', {
|
|
2320
|
-
connectIdSuffix: uuid.slice(-8),
|
|
2321
|
-
});
|
|
2322
|
-
try {
|
|
2323
|
-
this.probingProtocols.set(uuid, 'V1');
|
|
2324
|
-
yield this.callProtocolV1(uuid, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS });
|
|
2325
|
-
}
|
|
2326
|
-
catch (error) {
|
|
2327
|
-
if (shouldRethrowProtocolProbeError(error))
|
|
2328
|
-
throw error;
|
|
2329
|
-
}
|
|
2330
|
-
finally {
|
|
2331
|
-
this.clearProbeProtocol(uuid, 'V1');
|
|
2332
|
-
}
|
|
2333
|
-
});
|
|
2334
|
-
}
|
|
2335
2131
|
resetProbeStateAfterProtocolProbe(uuid, protocol) {
|
|
2336
2132
|
var _a, _b, _c;
|
|
2337
2133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2649,7 +2445,7 @@ class ReactNativeBleTransport {
|
|
|
2649
2445
|
const transport = this.getCachedTransport(uuid);
|
|
2650
2446
|
if (!shouldRefreshNegotiatedMtu(transport.mtuSize))
|
|
2651
2447
|
return;
|
|
2652
|
-
const
|
|
2448
|
+
const refreshedDevice = yield requestNegotiatedMtu(transport.device, 'highThroughput', 1);
|
|
2653
2449
|
transport.device = refreshedDevice;
|
|
2654
2450
|
transport.mtuSize =
|
|
2655
2451
|
typeof refreshedDevice.mtu === 'number' ? refreshedDevice.mtu : transport.mtuSize;
|
|
@@ -2766,8 +2562,6 @@ class ReactNativeBleTransport {
|
|
|
2766
2562
|
}
|
|
2767
2563
|
}
|
|
2768
2564
|
|
|
2769
|
-
exports.ANDROID_LINK_DROP_QUIET_MS = ANDROID_LINK_DROP_QUIET_MS;
|
|
2770
|
-
exports.ANDROID_MTU_EXCHANGE_TIMEOUT_MS = ANDROID_MTU_EXCHANGE_TIMEOUT_MS;
|
|
2771
2565
|
exports.BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD;
|
|
2772
2566
|
exports.BLE_CONNECT_TIMEOUT_MS = BLE_CONNECT_TIMEOUT_MS;
|
|
2773
2567
|
exports.BLE_GATT_SETUP_TIMEOUT_MS = BLE_GATT_SETUP_TIMEOUT_MS;
|