@onekeyfe/hd-transport-react-native 1.2.11-alpha.4 → 1.2.11-alpha.6

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.js CHANGED
@@ -71,7 +71,6 @@ const bondFailureReasons = {
71
71
  9: 'removed',
72
72
  };
73
73
  const getConnectedDeviceIds = (serviceUuids) => BleUtils.getConnectedPeripherals(serviceUuids);
74
- const getBondedDevices = () => BleUtils.getBondedPeripherals();
75
74
  const pairDevice = (macAddress) => BleUtils.pairDevice(macAddress);
76
75
  const SYSTEM_BONDING_RESTART_WINDOW_MS = 1500;
77
76
  const createBondFailureError = (bondState) => {
@@ -297,22 +296,6 @@ const toBleDisconnectHardwareError = (error) => {
297
296
  return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected, nativeErrorText(nativeError) || undefined);
298
297
  };
299
298
 
300
- const IOS_PEER_REMOVED_PAIRING_INFORMATION = 14;
301
- const isIosPeerRemovedPairingInformation = (error) => {
302
- if (!error || typeof error !== 'object') {
303
- return false;
304
- }
305
- return error.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION;
306
- };
307
- const toIosStaleBondError = (error) => {
308
- const nativeError = (error !== null && error !== void 0 ? error : {});
309
- const nativeErrorMessage = [nativeError.reason, nativeError.message]
310
- .filter((value) => typeof value === 'string')
311
- .join(' ')
312
- .slice(0, 240);
313
- return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation, hdShared.HardwareErrorCodeMessage[hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation], Object.assign({ phase: 'connect', reason: 'peer_removed_pairing_information' }, (nativeErrorMessage ? { nativeErrorMessage } : {})));
314
- };
315
-
316
299
  const isHeaderChunk = (chunk) => {
317
300
  if (chunk.length < 9)
318
301
  return false;
@@ -342,7 +325,7 @@ class BleTransport {
342
325
 
343
326
  var _a;
344
327
  const transport = (_a = transportModule__default["default"].default) !== null && _a !== void 0 ? _a : transportModule__default["default"];
345
- const { check, ProtocolV1, parseConfigure } = transport;
328
+ const { check, ProtocolV1, parseTransportConfigure } = transport;
346
329
  const Log = bleLogger;
347
330
  const transportCache = {};
348
331
  let bleManagerResetPromise;
@@ -382,16 +365,6 @@ const hasGattCongestedStatus = (text) => {
382
365
  const delay = (ms) => new Promise(resolve => {
383
366
  setTimeout(resolve, ms);
384
367
  });
385
- const ANDROID_BOND_ATTEMPTS = 3;
386
- const ANDROID_BOND_RETRY_DELAY_MS = 300;
387
- const normalizeBleMac = (id) => (id !== null && id !== void 0 ? id : '').replace(/[\s:-]/g, '').toUpperCase();
388
- const findBondedDevice = (macAddress) => __awaiter(void 0, void 0, void 0, function* () {
389
- const target = normalizeBleMac(macAddress);
390
- if (!target)
391
- return false;
392
- const bonded = yield getBondedDevices();
393
- return bonded.some(device => normalizeBleMac(device.id) === target);
394
- });
395
368
  const getFirmwareUploadWriteRetryType = (error) => {
396
369
  if (!error || typeof error !== 'object')
397
370
  return null;
@@ -419,11 +392,8 @@ const shouldRethrowProtocolProbeError = (error) => {
419
392
  const code = error === null || error === void 0 ? void 0 : error.errorCode;
420
393
  return (isNativeBleDisconnectError(error) ||
421
394
  code === hdShared.HardwareErrorCode.BleDeviceNotBonded ||
422
- code === hdShared.HardwareErrorCode.BleDeviceBondError ||
423
395
  code === hdShared.HardwareErrorCode.BleDeviceBondedCanceled ||
424
- code === hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation ||
425
396
  code === hdShared.HardwareErrorCode.BleDeviceDisconnected ||
426
- code === hdShared.HardwareErrorCode.BleBondInvalid ||
427
397
  code === hdShared.HardwareErrorCode.BleCharacteristicNotifyError ||
428
398
  code === hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure ||
429
399
  code === hdShared.HardwareErrorCode.BleWriteCharacteristicError);
@@ -623,9 +593,6 @@ const isStaleGattTableNotifyReason = (reason) => !!reason &&
623
593
  reason.includes('The handle is invalid') ||
624
594
  reason.includes('Writing is not permitted'));
625
595
  const BLE_CONNECT_TIMEOUT_MS = BLE_NATIVE_CONNECT_TIMEOUT_MS * 2 + 2000;
626
- const IOS_PRESENT_DEVICE_CONNECT_TIMEOUT_MS = 8000;
627
- const IOS_PRESENT_DEVICE_WINDOW_MS = 15000;
628
- const IOS_PRESENT_DEVICE_CONNECT_BACKSTOP_MS = IOS_PRESENT_DEVICE_CONNECT_TIMEOUT_MS + (BLE_CONNECT_TIMEOUT_MS - BLE_NATIVE_CONNECT_TIMEOUT_MS);
629
596
  const BLE_GATT_SETUP_TIMEOUT_MS = 10000;
630
597
  const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
631
598
  const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
@@ -716,9 +683,6 @@ const resolveNegotiatedMtu = (device, cancelTransaction) => shouldRefreshNegotia
716
683
  : Promise.resolve({ device, timedOut: false });
717
684
  function remapError(error) {
718
685
  var _a, _b;
719
- if (reactNative.Platform.OS === 'ios' && isIosPeerRemovedPairingInformation(error)) {
720
- throw toIosStaleBondError(error);
721
- }
722
686
  if (isNativeBleDisconnectError(error)) {
723
687
  throw toBleDisconnectHardwareError(error);
724
688
  }
@@ -733,8 +697,7 @@ class ReactNativeBleTransport {
733
697
  this.name = 'ReactNativeBleTransport';
734
698
  this.configured = false;
735
699
  this.stopped = false;
736
- this.activeBondControllers = new Map();
737
- this.iosLastAdvertisedAt = new Map();
700
+ this.bondAbortController = new AbortController();
738
701
  this.scanTimeout = DEVICE_SCAN_TIMEOUT_MS;
739
702
  this.runPromise = null;
740
703
  this.runPromiseDeviceId = null;
@@ -749,7 +712,6 @@ class ReactNativeBleTransport {
749
712
  this.protocolReprobeFailures = new Map();
750
713
  this.silentDetections = new Map();
751
714
  this.androidGattCacheRefreshes = new Set();
752
- this.knownBondedDevices = new Set();
753
715
  this.protocolV2Assemblers = new Map();
754
716
  this.protocolV2FrameQueues = new Map();
755
717
  this.protocolV2FramePromises = new Map();
@@ -801,7 +763,7 @@ class ReactNativeBleTransport {
801
763
  this.emitter = emitter;
802
764
  }
803
765
  configure(signedData) {
804
- const messages = parseConfigure(signedData);
766
+ const messages = parseTransportConfigure(signedData);
805
767
  this.configured = true;
806
768
  this._messages = messages;
807
769
  }
@@ -811,7 +773,7 @@ class ReactNativeBleTransport {
811
773
  return;
812
774
  }
813
775
  const isReconfiguration = this.protocolV2SchemaConfiguration !== undefined;
814
- this._messagesV2 = parseConfigure(signedData);
776
+ this._messagesV2 = parseTransportConfigure(signedData);
815
777
  this.protocolV2SchemaConfiguration = configuration;
816
778
  if (isReconfiguration) {
817
779
  this.protocolV2Links
@@ -1134,8 +1096,6 @@ class ReactNativeBleTransport {
1134
1096
  }, error => Log === null || Log === void 0 ? void 0 : Log.debug('search connected peripheral failed:', error));
1135
1097
  const addDevice = (device) => {
1136
1098
  var _a;
1137
- if (reactNative.Platform.OS === 'ios')
1138
- this.iosLastAdvertisedAt.set(device.id, Date.now());
1139
1099
  if (!finished && deviceList.every(d => d.id !== device.id)) {
1140
1100
  firstDeviceMs !== null && firstDeviceMs !== void 0 ? firstDeviceMs : (firstDeviceMs = Date.now() - scanStartedAt);
1141
1101
  const displayName = (_a = getDeviceDisplayName(device)) !== null && _a !== void 0 ? _a : 'Unknown BLE Device';
@@ -1197,412 +1157,297 @@ class ReactNativeBleTransport {
1197
1157
  return this.runLifecycleOperation(uuid, () => this.acquireUnlocked(input));
1198
1158
  });
1199
1159
  }
1200
- createBondAbortController(uuid) {
1201
- const controller = new AbortController();
1202
- let controllers = this.activeBondControllers.get(uuid);
1203
- if (!controllers) {
1204
- controllers = new Set();
1205
- this.activeBondControllers.set(uuid, controllers);
1206
- }
1207
- controllers.add(controller);
1208
- return controller;
1209
- }
1210
- releaseBondAbortController(uuid, controller) {
1211
- const controllers = this.activeBondControllers.get(uuid);
1212
- if (!controllers)
1213
- return;
1214
- controllers.delete(controller);
1215
- if (controllers.size === 0) {
1216
- this.activeBondControllers.delete(uuid);
1217
- }
1218
- }
1219
- abortActiveBonding(uuid) {
1220
- var _a;
1221
- if (uuid !== undefined) {
1222
- (_a = this.activeBondControllers.get(uuid)) === null || _a === void 0 ? void 0 : _a.forEach(controller => controller.abort());
1223
- return;
1224
- }
1225
- this.activeBondControllers.forEach(controllers => {
1226
- controllers.forEach(controller => controller.abort());
1227
- });
1228
- }
1229
- throwIfBondingStopped(signal) {
1230
- if (this.stopped || (signal === null || signal === void 0 ? void 0 : signal.aborted)) {
1231
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1232
- }
1233
- }
1234
- delayUnlessBondingStopped(ms, signal) {
1235
- return new Promise((resolve, reject) => {
1236
- if (this.stopped || (signal === null || signal === void 0 ? void 0 : signal.aborted)) {
1237
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected));
1238
- return;
1239
- }
1240
- const onAbort = () => {
1241
- clearTimeout(timeout);
1242
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected));
1243
- };
1244
- const timeout = setTimeout(() => {
1245
- signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
1246
- if (this.stopped || (signal === null || signal === void 0 ? void 0 : signal.aborted)) {
1247
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected));
1248
- return;
1249
- }
1250
- resolve();
1251
- }, ms);
1252
- signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
1253
- });
1254
- }
1255
- ensureAndroidBond(uuid, acquireSignal) {
1256
- return __awaiter(this, void 0, void 0, function* () {
1257
- const localController = acquireSignal ? undefined : this.createBondAbortController(uuid);
1258
- const signal = acquireSignal !== null && acquireSignal !== void 0 ? acquireSignal : localController === null || localController === void 0 ? void 0 : localController.signal;
1259
- try {
1260
- this.throwIfBondingStopped(signal);
1261
- const key = normalizeBleMac(uuid);
1262
- try {
1263
- const bonded = yield findBondedDevice(uuid);
1264
- this.throwIfBondingStopped(signal);
1265
- if (bonded) {
1266
- this.knownBondedDevices.add(key);
1267
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Android device already bonded, skipping createBond:', uuid);
1268
- return;
1269
- }
1270
- }
1271
- catch (error) {
1272
- this.throwIfBondingStopped(signal);
1273
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Android bonded list query failed, using pairDevice:', {
1274
- uuid,
1275
- error: error instanceof Error ? error.message : String(error),
1276
- });
1277
- }
1278
- for (let attempt = 0; attempt < ANDROID_BOND_ATTEMPTS; attempt += 1) {
1279
- this.throwIfBondingStopped(signal);
1280
- let bondState;
1281
- try {
1282
- bondState = yield pairDevice(uuid);
1283
- }
1284
- catch (error) {
1285
- this.throwIfBondingStopped(signal);
1286
- throw error;
1287
- }
1288
- this.throwIfBondingStopped(signal);
1289
- if (bondState.bonding) {
1290
- yield onDeviceBondState(uuid, signal, {
1291
- systemInitiated: bondState.initiated === false,
1292
- });
1293
- this.throwIfBondingStopped(signal);
1294
- this.knownBondedDevices.add(key);
1295
- return;
1296
- }
1297
- if (bondState.bonded) {
1298
- this.knownBondedDevices.add(key);
1299
- return;
1300
- }
1301
- if (attempt + 1 < ANDROID_BOND_ATTEMPTS) {
1302
- yield this.delayUnlessBondingStopped(ANDROID_BOND_RETRY_DELAY_MS, signal);
1303
- }
1304
- }
1305
- this.throwIfBondingStopped(signal);
1306
- if (this.knownBondedDevices.has(key)) {
1307
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceBondError, 'Bluetooth pairing could not be restarted for a previously paired device', { phase: 'bond', reason: 'peer_removed_pairing', attempts: ANDROID_BOND_ATTEMPTS });
1308
- }
1309
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
1310
- }
1311
- finally {
1312
- if (localController) {
1313
- this.releaseBondAbortController(uuid, localController);
1314
- }
1315
- }
1316
- });
1317
- }
1318
1160
  acquireUnlocked(input) {
1319
1161
  var _a;
1320
1162
  return __awaiter(this, void 0, void 0, function* () {
1321
- this.throwIfBondingStopped();
1163
+ if (this.stopped)
1164
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1322
1165
  const { uuid, forceCleanRunPromise, expectedProtocol, skipProtocolProbe } = input;
1323
- const bondController = this.createBondAbortController(uuid);
1324
- const bondSignal = bondController.signal;
1325
- try {
1326
- const cachedTransport = transportCache[uuid];
1327
- if (skipProtocolProbe && !cachedTransport && this.blePlxManager) {
1328
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh uncached BLE connection for firmware install:', uuid);
1166
+ const cachedTransport = transportCache[uuid];
1167
+ if (skipProtocolProbe && !cachedTransport && this.blePlxManager) {
1168
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh uncached BLE connection for firmware install:', uuid);
1169
+ const manager = this.blePlxManager;
1170
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
1171
+ yield this.runBestEffortNativeOperation('firmware install reconnect: cancel uncached device connection', () => manager.cancelDeviceConnection(uuid));
1172
+ }));
1173
+ }
1174
+ if (cachedTransport) {
1175
+ if (skipProtocolProbe) {
1176
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh cached BLE connection for firmware install:', uuid);
1329
1177
  const manager = this.blePlxManager;
1178
+ yield this.releaseUnlocked(uuid, true);
1330
1179
  yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
1331
- yield this.runBestEffortNativeOperation('firmware install reconnect: cancel uncached device connection', () => manager.cancelDeviceConnection(uuid));
1180
+ const operations = [];
1181
+ if (manager) {
1182
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: cancel device connection', () => manager.cancelDeviceConnection(uuid)));
1183
+ }
1184
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: device cancel connection', () => cachedTransport.device.cancelConnection()));
1185
+ yield Promise.all(operations);
1332
1186
  }));
1333
1187
  }
1334
- if (cachedTransport) {
1335
- if (skipProtocolProbe) {
1336
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh cached BLE connection for firmware install:', uuid);
1337
- const manager = this.blePlxManager;
1338
- yield this.releaseUnlocked(uuid, true);
1339
- yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
1340
- const operations = [];
1341
- if (manager) {
1342
- operations.push(this.runBestEffortNativeOperation('firmware install reconnect: cancel device connection', () => manager.cancelDeviceConnection(uuid)));
1343
- }
1344
- operations.push(this.runBestEffortNativeOperation('firmware install reconnect: device cancel connection', () => cachedTransport.device.cancelConnection()));
1345
- yield Promise.all(operations);
1346
- }));
1347
- }
1348
- else {
1349
- const cachedProtocol = this.deviceProtocol.get(uuid);
1350
- const isCachedDeviceConnected = yield cachedTransport.device
1351
- .isConnected()
1352
- .catch(() => false);
1353
- const isCachedAndroidLinkUsable = reactNative.Platform.OS !== 'android' || !this.androidGattCacheRefreshes.has(uuid);
1354
- if (isCachedDeviceConnected &&
1355
- isCachedAndroidLinkUsable &&
1356
- cachedProtocol &&
1357
- (!expectedProtocol || cachedProtocol === expectedProtocol)) {
1358
- this.throwIfBondingStopped(bondSignal);
1359
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
1360
- return { uuid, protocolType: cachedProtocol };
1361
- }
1362
- Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
1363
- yield this.releaseUnlocked(uuid, true);
1188
+ else {
1189
+ const cachedProtocol = this.deviceProtocol.get(uuid);
1190
+ const isCachedDeviceConnected = yield cachedTransport.device
1191
+ .isConnected()
1192
+ .catch(() => false);
1193
+ const isCachedAndroidLinkUsable = reactNative.Platform.OS !== 'android' || !this.androidGattCacheRefreshes.has(uuid);
1194
+ if (isCachedDeviceConnected &&
1195
+ isCachedAndroidLinkUsable &&
1196
+ cachedProtocol &&
1197
+ (!expectedProtocol || cachedProtocol === expectedProtocol)) {
1198
+ if (this.stopped)
1199
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1200
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
1201
+ return { uuid, protocolType: cachedProtocol };
1364
1202
  }
1203
+ Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
1204
+ yield this.releaseUnlocked(uuid, true);
1365
1205
  }
1366
- let device = null;
1367
- const isAndroid = reactNative.Platform.OS === 'android';
1368
- const refreshAndroidGattCache = isAndroid && (!!skipProtocolProbe || this.androidGattCacheRefreshes.has(uuid));
1369
- let nativeConnectOptions = connectOptions;
1370
- let bareConnectOptions = fallbackConnectOptions;
1371
- let connectBackstopMs = BLE_CONNECT_TIMEOUT_MS;
1372
- if (isAndroid) {
1373
- nativeConnectOptions = refreshAndroidGattCache
1374
- ? androidRefreshGattConnectOptions
1375
- : fallbackConnectOptions;
1376
- }
1377
- else if (this.takeIosPresentDeviceSighting(uuid, skipProtocolProbe)) {
1378
- const timeout = IOS_PRESENT_DEVICE_CONNECT_TIMEOUT_MS;
1379
- nativeConnectOptions = Object.assign(Object.assign({}, connectOptions), { timeout });
1380
- bareConnectOptions = Object.assign(Object.assign({}, fallbackConnectOptions), { timeout });
1381
- connectBackstopMs = IOS_PRESENT_DEVICE_CONNECT_BACKSTOP_MS;
1382
- }
1383
- let androidRefreshConnectRan = false;
1384
- if (forceCleanRunPromise && this.runPromise) {
1385
- const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
1386
- this.runPromise.reject(error);
1387
- this.runPromise = null;
1388
- this.runPromiseDeviceId = null;
1389
- Log === null || Log === void 0 ? void 0 : Log.debug('Force clean Bluetooth run promise, forceCleanRunPromise: ', forceCleanRunPromise);
1390
- }
1391
- const blePlxManager = yield this.getPlxManager();
1392
- let skipPostConnectMtu = false;
1206
+ }
1207
+ let device = null;
1208
+ const isAndroid = reactNative.Platform.OS === 'android';
1209
+ const refreshAndroidGattCache = isAndroid && (!!skipProtocolProbe || this.androidGattCacheRefreshes.has(uuid));
1210
+ let nativeConnectOptions = connectOptions;
1211
+ if (isAndroid) {
1212
+ nativeConnectOptions = refreshAndroidGattCache
1213
+ ? androidRefreshGattConnectOptions
1214
+ : fallbackConnectOptions;
1215
+ }
1216
+ let androidRefreshConnectRan = false;
1217
+ if (forceCleanRunPromise && this.runPromise) {
1218
+ const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
1219
+ this.runPromise.reject(error);
1220
+ this.runPromise = null;
1221
+ this.runPromiseDeviceId = null;
1222
+ Log === null || Log === void 0 ? void 0 : Log.debug('Force clean Bluetooth run promise, forceCleanRunPromise: ', forceCleanRunPromise);
1223
+ }
1224
+ const blePlxManager = yield this.getPlxManager();
1225
+ let skipPostConnectMtu = false;
1226
+ try {
1227
+ yield subscribeBleOn(blePlxManager);
1228
+ }
1229
+ catch (error) {
1230
+ Log === null || Log === void 0 ? void 0 : Log.debug('subscribeBleOn error: ', error);
1231
+ throw error;
1232
+ }
1233
+ if (this.stopped)
1234
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1235
+ if (reactNative.Platform.OS === 'android') {
1393
1236
  try {
1394
- yield subscribeBleOn(blePlxManager);
1237
+ const bondState = yield pairDevice(uuid);
1238
+ if (bondState.bonding) {
1239
+ yield onDeviceBondState(uuid, this.bondAbortController.signal, {
1240
+ systemInitiated: bondState.initiated === false,
1241
+ });
1242
+ }
1243
+ else if (!bondState.bonded) {
1244
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
1245
+ }
1395
1246
  }
1396
1247
  catch (error) {
1397
- Log === null || Log === void 0 ? void 0 : Log.debug('subscribeBleOn error: ', error);
1248
+ yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
1249
+ yield this.runBestEffortNativeOperation('bond failure: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid));
1250
+ }));
1398
1251
  throw error;
1399
1252
  }
1400
- this.throwIfBondingStopped(bondSignal);
1401
- if (reactNative.Platform.OS === 'android') {
1402
- try {
1403
- yield this.ensureAndroidBond(uuid, bondSignal);
1253
+ }
1254
+ if (this.stopped)
1255
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1256
+ if (!device) {
1257
+ const devices = yield blePlxManager.devices([uuid]);
1258
+ [device] = devices;
1259
+ }
1260
+ if (!device) {
1261
+ const connectedDevice = yield blePlxManager.connectedDevices(getBluetoothServiceUuids());
1262
+ const deviceFilter = connectedDevice.filter(device => device.id === uuid);
1263
+ Log === null || Log === void 0 ? void 0 : Log.debug(`found connected device count: ${deviceFilter.length}`);
1264
+ [device] = deviceFilter;
1265
+ }
1266
+ if (!device) {
1267
+ Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device: ', uuid);
1268
+ try {
1269
+ device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, nativeConnectOptions));
1270
+ androidRefreshConnectRan = refreshAndroidGattCache;
1271
+ }
1272
+ catch (e) {
1273
+ Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device has error: ', e);
1274
+ if (shouldRethrowBleSetupError(e)) {
1275
+ throw e;
1404
1276
  }
1405
- catch (error) {
1406
- yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
1407
- yield this.runBestEffortNativeOperation('bond failure: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid));
1408
- }));
1409
- throw error;
1277
+ if (isMtuOrCancelledConnectError(e)) {
1278
+ skipPostConnectMtu = true;
1279
+ Log === null || Log === void 0 ? void 0 : Log.debug('first try to reconnect without params');
1280
+ device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, fallbackConnectOptions));
1410
1281
  }
1411
- }
1412
- this.throwIfBondingStopped(bondSignal);
1413
- if (!device) {
1414
- const devices = yield blePlxManager.devices([uuid]);
1415
- [device] = devices;
1416
- }
1417
- if (!device) {
1418
- const connectedDevice = yield blePlxManager.connectedDevices(getBluetoothServiceUuids());
1419
- const deviceFilter = connectedDevice.filter(device => device.id === uuid);
1420
- Log === null || Log === void 0 ? void 0 : Log.debug(`found connected device count: ${deviceFilter.length}`);
1421
- [device] = deviceFilter;
1422
- }
1423
- if (!device) {
1424
- Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device: ', uuid);
1425
- try {
1426
- device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, nativeConnectOptions), connectBackstopMs);
1427
- androidRefreshConnectRan = refreshAndroidGattCache;
1282
+ else if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
1283
+ Log === null || Log === void 0 ? void 0 : Log.debug('device already connected');
1284
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleAlreadyConnected);
1428
1285
  }
1429
- catch (e) {
1430
- Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device has error: ', e);
1431
- if (shouldRethrowBleSetupError(e)) {
1432
- throw e;
1433
- }
1434
- if (isMtuOrCancelledConnectError(e)) {
1435
- skipPostConnectMtu = true;
1436
- Log === null || Log === void 0 ? void 0 : Log.debug('first try to reconnect without params');
1437
- device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, bareConnectOptions), connectBackstopMs);
1438
- }
1439
- else if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
1440
- Log === null || Log === void 0 ? void 0 : Log.debug('device already connected');
1441
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleAlreadyConnected);
1442
- }
1443
- else {
1444
- remapError(e);
1445
- }
1286
+ else {
1287
+ remapError(e);
1446
1288
  }
1447
1289
  }
1448
- if (!device) {
1449
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'unable to connect to device');
1450
- }
1451
- if (refreshAndroidGattCache &&
1452
- !androidRefreshConnectRan &&
1453
- (yield device.isConnected().catch(() => false))) {
1454
- yield this.dropAndroidLink(uuid, blePlxManager, device, 'gatt cache refresh');
1455
- this.throwIfBondingStopped(bondSignal);
1290
+ }
1291
+ if (!device) {
1292
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'unable to connect to device');
1293
+ }
1294
+ if (refreshAndroidGattCache &&
1295
+ !androidRefreshConnectRan &&
1296
+ (yield device.isConnected().catch(() => false))) {
1297
+ yield this.dropAndroidLink(uuid, blePlxManager, device, 'gatt cache refresh');
1298
+ if (this.stopped)
1299
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1300
+ }
1301
+ if (!(yield device.isConnected())) {
1302
+ Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device: ', uuid);
1303
+ const disconnectedDevice = device;
1304
+ try {
1305
+ device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(nativeConnectOptions));
1306
+ androidRefreshConnectRan = refreshAndroidGattCache;
1456
1307
  }
1457
- if (!(yield device.isConnected())) {
1458
- Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device: ', uuid);
1459
- const disconnectedDevice = device;
1460
- try {
1461
- device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(nativeConnectOptions), connectBackstopMs);
1462
- androidRefreshConnectRan = refreshAndroidGattCache;
1308
+ catch (e) {
1309
+ Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device has error: ', e);
1310
+ if (shouldRethrowBleSetupError(e)) {
1311
+ throw e;
1463
1312
  }
1464
- catch (e) {
1465
- Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device has error: ', e);
1466
- if (shouldRethrowBleSetupError(e)) {
1467
- throw e;
1313
+ if (isMtuOrCancelledConnectError(e)) {
1314
+ skipPostConnectMtu = true;
1315
+ Log === null || Log === void 0 ? void 0 : Log.debug('second try to reconnect without params');
1316
+ try {
1317
+ device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
1468
1318
  }
1469
- if (isMtuOrCancelledConnectError(e)) {
1470
- skipPostConnectMtu = true;
1471
- Log === null || Log === void 0 ? void 0 : Log.debug('second try to reconnect without params');
1472
- try {
1473
- device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(bareConnectOptions), connectBackstopMs);
1319
+ catch (fallbackError) {
1320
+ Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect error: ', fallbackError);
1321
+ if (fallbackError.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
1322
+ Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect');
1323
+ yield disconnectedDevice.cancelConnection();
1324
+ device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
1474
1325
  }
1475
- catch (fallbackError) {
1476
- Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect error: ', fallbackError);
1477
- if (fallbackError.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
1478
- Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect');
1479
- yield disconnectedDevice.cancelConnection();
1480
- device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(bareConnectOptions), connectBackstopMs);
1481
- }
1482
- else {
1483
- remapError(fallbackError);
1484
- }
1326
+ else {
1327
+ remapError(fallbackError);
1485
1328
  }
1486
1329
  }
1487
- else {
1488
- remapError(e);
1489
- }
1330
+ }
1331
+ else {
1332
+ remapError(e);
1490
1333
  }
1491
1334
  }
1492
- if (this.stopped || bondSignal.aborted) {
1493
- yield this.disconnectUnlocked(uuid);
1494
- this.throwIfBondingStopped(bondSignal);
1495
- }
1496
- if (reactNative.Platform.OS === 'android' && !(yield device.isConnected().catch(() => false))) {
1497
- const disconnectedDevice = device;
1335
+ }
1336
+ if (this.stopped)
1337
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1338
+ if (reactNative.Platform.OS === 'android' && !(yield device.isConnected().catch(() => false))) {
1339
+ const disconnectedDevice = device;
1340
+ yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
1341
+ yield Promise.all([
1342
+ this.runBestEffortNativeOperation('connect failure: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid)),
1343
+ this.runBestEffortNativeOperation('connect failure: cancel device connection', () => disconnectedDevice.cancelConnection()),
1344
+ ]);
1345
+ }));
1346
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'device is not connected');
1347
+ }
1348
+ if (this.stopped)
1349
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1350
+ let characteristics;
1351
+ if (isAndroid) {
1352
+ if (refreshAndroidGattCache) {
1353
+ characteristics = yield this.resolveCharacteristicsWithTimeout(uuid, device);
1354
+ if (androidRefreshConnectRan)
1355
+ this.androidGattCacheRefreshes.delete(uuid);
1356
+ if (this.stopped)
1357
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1358
+ }
1359
+ device = yield this.negotiateAndroidMtu(uuid, blePlxManager, device);
1360
+ }
1361
+ else if (!skipPostConnectMtu) {
1362
+ const mtuResult = yield resolveNegotiatedMtu(device, transactionId => blePlxManager.cancelTransaction(transactionId));
1363
+ device = mtuResult.device;
1364
+ if (mtuResult.timedOut) {
1365
+ if (this.stopped)
1366
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1367
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] post-connect MTU timed out, reconnecting without requesting MTU');
1368
+ const timedOutDevice = device;
1369
+ let mtuTeardownSettled = false;
1498
1370
  yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
1499
- yield Promise.all([
1500
- this.runBestEffortNativeOperation('connect failure: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid)),
1501
- this.runBestEffortNativeOperation('connect failure: cancel device connection', () => disconnectedDevice.cancelConnection()),
1502
- ]);
1371
+ yield this.runBestEffortNativeOperation('mtu timeout: cancel device connection', () => timedOutDevice.cancelConnection());
1372
+ mtuTeardownSettled = true;
1503
1373
  }));
1504
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'device is not connected');
1505
- }
1506
- this.throwIfBondingStopped(bondSignal);
1507
- let characteristics;
1508
- if (isAndroid) {
1509
- if (refreshAndroidGattCache) {
1510
- characteristics = yield this.resolveCharacteristicsWithTimeout(uuid, device);
1511
- if (androidRefreshConnectRan)
1512
- this.androidGattCacheRefreshes.delete(uuid);
1513
- this.throwIfBondingStopped(bondSignal);
1374
+ if (this.stopped)
1375
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1376
+ if (!mtuTeardownSettled || this.blePlxManager !== blePlxManager) {
1377
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'BLE MTU cleanup timed out');
1514
1378
  }
1515
- device = yield this.negotiateAndroidMtu(uuid, blePlxManager, device);
1516
- }
1517
- else if (!skipPostConnectMtu) {
1518
- const mtuResult = yield resolveNegotiatedMtu(device, transactionId => blePlxManager.cancelTransaction(transactionId));
1519
- device = mtuResult.device;
1520
- if (mtuResult.timedOut) {
1521
- this.throwIfBondingStopped(bondSignal);
1522
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] post-connect MTU timed out, reconnecting without requesting MTU');
1523
- const timedOutDevice = device;
1524
- let mtuTeardownSettled = false;
1525
- yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
1526
- yield this.runBestEffortNativeOperation('mtu timeout: cancel device connection', () => timedOutDevice.cancelConnection());
1527
- mtuTeardownSettled = true;
1528
- }));
1529
- this.throwIfBondingStopped(bondSignal);
1530
- if (!mtuTeardownSettled || this.blePlxManager !== blePlxManager) {
1531
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'BLE MTU cleanup timed out');
1532
- }
1533
- try {
1534
- device = yield this.connectWithTimeout(uuid, () => timedOutDevice.connect(bareConnectOptions), connectBackstopMs);
1379
+ try {
1380
+ device = yield this.connectWithTimeout(uuid, () => timedOutDevice.connect(fallbackConnectOptions));
1381
+ }
1382
+ catch (error) {
1383
+ if (shouldRethrowBleSetupError(error))
1384
+ throw error;
1385
+ if ((error === null || error === void 0 ? void 0 : error.errorCode) === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
1386
+ device = timedOutDevice;
1535
1387
  }
1536
- catch (error) {
1537
- if (shouldRethrowBleSetupError(error))
1538
- throw error;
1539
- if ((error === null || error === void 0 ? void 0 : error.errorCode) === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
1540
- device = timedOutDevice;
1541
- }
1542
- else {
1543
- remapError(error);
1544
- }
1388
+ else {
1389
+ remapError(error);
1545
1390
  }
1546
1391
  }
1547
1392
  }
1548
- this.throwIfBondingStopped(bondSignal);
1549
- const acquiredDevice = device;
1550
- const { writeCharacteristic, notifyCharacteristic } = characteristics !== null && characteristics !== void 0 ? characteristics : (yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice));
1551
- this.throwIfBondingStopped(bondSignal);
1552
- const protocolHint = expectedProtocol
1553
- ? undefined
1554
- : (_a = input.protocolHint) !== null && _a !== void 0 ? _a : this.deviceProtocolHints.get(uuid);
1555
- yield this.releaseUnlocked(uuid, true);
1556
- if (protocolHint) {
1557
- this.deviceProtocolHints.set(uuid, protocolHint);
1558
- }
1559
- try {
1560
- yield this.installTransportForAcquire(uuid, acquiredDevice, {
1561
- writeCharacteristic,
1562
- notifyCharacteristic,
1563
- });
1564
- if (skipProtocolProbe) {
1565
- if (!expectedProtocol) {
1566
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires an expected BLE protocol');
1567
- }
1568
- const hasConfirmedProtocol = this.sessionProtocols.get(uuid) === expectedProtocol ||
1569
- (expectedProtocol === 'V2' && this.confirmedProtocolV2.has(uuid));
1570
- if (!hasConfirmedProtocol) {
1571
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires a previously confirmed protocol for this BLE endpoint');
1572
- }
1573
- this.deviceProtocol.set(uuid, expectedProtocol);
1574
- this.sessionProtocols.set(uuid, expectedProtocol);
1575
- this.protocolReprobeFailures.delete(uuid);
1576
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected without probe', {
1577
- deviceId: uuid,
1578
- protocol: expectedProtocol,
1579
- source: 'firmware-install-reconnect',
1580
- });
1581
- const currentTransport = transportCache[uuid];
1582
- if (!currentTransport) {
1583
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
1584
- }
1585
- this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
1586
- return { uuid, protocolType: expectedProtocol };
1393
+ }
1394
+ if (this.stopped)
1395
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1396
+ const acquiredDevice = device;
1397
+ const { writeCharacteristic, notifyCharacteristic } = characteristics !== null && characteristics !== void 0 ? characteristics : (yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice));
1398
+ if (this.stopped)
1399
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1400
+ const protocolHint = expectedProtocol
1401
+ ? undefined
1402
+ : (_a = input.protocolHint) !== null && _a !== void 0 ? _a : this.deviceProtocolHints.get(uuid);
1403
+ yield this.releaseUnlocked(uuid, true);
1404
+ if (protocolHint) {
1405
+ this.deviceProtocolHints.set(uuid, protocolHint);
1406
+ }
1407
+ try {
1408
+ yield this.installTransportForAcquire(uuid, acquiredDevice, {
1409
+ writeCharacteristic,
1410
+ notifyCharacteristic,
1411
+ });
1412
+ if (skipProtocolProbe) {
1413
+ if (!expectedProtocol) {
1414
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires an expected BLE protocol');
1587
1415
  }
1588
- const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint, () => __awaiter(this, void 0, void 0, function* () {
1589
- yield this.installTransportForAcquire(uuid, acquiredDevice);
1590
- }));
1591
- this.throwIfBondingStopped(bondSignal);
1416
+ const hasConfirmedProtocol = this.sessionProtocols.get(uuid) === expectedProtocol ||
1417
+ (expectedProtocol === 'V2' && this.confirmedProtocolV2.has(uuid));
1418
+ if (!hasConfirmedProtocol) {
1419
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires a previously confirmed protocol for this BLE endpoint');
1420
+ }
1421
+ this.deviceProtocol.set(uuid, expectedProtocol);
1422
+ this.sessionProtocols.set(uuid, expectedProtocol);
1423
+ this.protocolReprobeFailures.delete(uuid);
1424
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected without probe', {
1425
+ deviceId: uuid,
1426
+ protocol: expectedProtocol,
1427
+ source: 'firmware-install-reconnect',
1428
+ });
1592
1429
  const currentTransport = transportCache[uuid];
1593
1430
  if (!currentTransport) {
1594
1431
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
1595
1432
  }
1596
1433
  this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
1597
- return { uuid, protocolType };
1434
+ return { uuid, protocolType: expectedProtocol };
1598
1435
  }
1599
- catch (error) {
1600
- yield this.disconnectUnlocked(uuid);
1601
- throw error;
1436
+ const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint, () => __awaiter(this, void 0, void 0, function* () {
1437
+ yield this.installTransportForAcquire(uuid, acquiredDevice);
1438
+ }));
1439
+ if (this.stopped)
1440
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1441
+ const currentTransport = transportCache[uuid];
1442
+ if (!currentTransport) {
1443
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
1602
1444
  }
1445
+ this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
1446
+ return { uuid, protocolType };
1603
1447
  }
1604
- finally {
1605
- this.releaseBondAbortController(uuid, bondController);
1448
+ catch (error) {
1449
+ yield this.disconnectUnlocked(uuid);
1450
+ throw error;
1606
1451
  }
1607
1452
  });
1608
1453
  }
@@ -1622,17 +1467,6 @@ class ReactNativeBleTransport {
1622
1467
  Log === null || Log === void 0 ? void 0 : Log.debug('monitor error ignored for stale transport: ', uuid, notifyTransactionId);
1623
1468
  return;
1624
1469
  }
1625
- if (reactNative.Platform.OS === 'ios' && isIosPeerRemovedPairingInformation(error)) {
1626
- const staleBondError = toIosStaleBondError(error);
1627
- if (this.getActiveProtocol(uuid) === 'V2') {
1628
- this.rejectProtocolV2Frames(uuid, staleBondError);
1629
- return;
1630
- }
1631
- if (this.runPromise && this.runPromiseDeviceId === uuid) {
1632
- this.runPromise.reject(staleBondError);
1633
- }
1634
- return;
1635
- }
1636
1470
  if (reactNative.Platform.OS === 'android' && isStaleGattTableNotifyReason(error.reason)) {
1637
1471
  this.androidGattCacheRefreshes.add(uuid);
1638
1472
  }
@@ -2024,7 +1858,7 @@ class ReactNativeBleTransport {
2024
1858
  if (this.stopPromise)
2025
1859
  return this.stopPromise;
2026
1860
  this.stopped = true;
2027
- this.abortActiveBonding();
1861
+ this.bondAbortController.abort();
2028
1862
  const deviceIds = new Set([
2029
1863
  ...this.monitorTokens.keys(),
2030
1864
  ...this.sessionProtocols.keys(),
@@ -2035,7 +1869,6 @@ class ReactNativeBleTransport {
2035
1869
  this.androidPriorityResetTimers.forEach(timeout => clearTimeout(timeout));
2036
1870
  this.androidPriorityResetTimers.clear();
2037
1871
  this.androidHighPriorityDevices.clear();
2038
- this.iosLastAdvertisedAt.clear();
2039
1872
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
2040
1873
  (_a = this.runPromise) === null || _a === void 0 ? void 0 : _a.reject(error);
2041
1874
  this.runPromise = null;
@@ -2061,7 +1894,6 @@ class ReactNativeBleTransport {
2061
1894
  }
2062
1895
  disconnect(session) {
2063
1896
  return __awaiter(this, void 0, void 0, function* () {
2064
- this.abortActiveBonding(session);
2065
1897
  return this.runLifecycleOperation(session, () => this.disconnectUnlocked(session));
2066
1898
  });
2067
1899
  }
@@ -2190,13 +2022,12 @@ class ReactNativeBleTransport {
2190
2022
  }
2191
2023
  });
2192
2024
  }
2193
- cancel(uuid) {
2025
+ cancel() {
2194
2026
  return __awaiter(this, void 0, void 0, function* () {
2195
- Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native transport cancel', uuid);
2196
- this.abortActiveBonding(uuid);
2027
+ Log === null || Log === void 0 ? void 0 : Log.debug('transport-react-native transport cancel');
2197
2028
  const pending = this.runPromise;
2198
2029
  const deviceId = this.runPromiseDeviceId;
2199
- if (pending && (uuid === undefined || deviceId === uuid)) {
2030
+ if (pending) {
2200
2031
  pending.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled));
2201
2032
  if (this.runPromise === pending) {
2202
2033
  this.runPromise = null;
@@ -2273,16 +2104,7 @@ class ReactNativeBleTransport {
2273
2104
  });
2274
2105
  });
2275
2106
  }
2276
- takeIosPresentDeviceSighting(uuid, skipProtocolProbe) {
2277
- if (reactNative.Platform.OS !== 'ios')
2278
- return false;
2279
- const seenAt = this.iosLastAdvertisedAt.get(uuid);
2280
- this.iosLastAdvertisedAt.delete(uuid);
2281
- if (skipProtocolProbe || seenAt === undefined)
2282
- return false;
2283
- return Date.now() - seenAt <= IOS_PRESENT_DEVICE_WINDOW_MS;
2284
- }
2285
- connectWithTimeout(uuid, connect, backstopMs = BLE_CONNECT_TIMEOUT_MS) {
2107
+ connectWithTimeout(uuid, connect) {
2286
2108
  return __awaiter(this, void 0, void 0, function* () {
2287
2109
  if (this.stopped)
2288
2110
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
@@ -2298,8 +2120,8 @@ class ReactNativeBleTransport {
2298
2120
  new Promise((_, reject) => {
2299
2121
  timer = setTimeout(() => {
2300
2122
  timedOut = true;
2301
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, `BLE connect timeout after ${backstopMs}ms for ${uuid}`));
2302
- }, backstopMs);
2123
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, `BLE connect timeout after ${BLE_CONNECT_TIMEOUT_MS}ms for ${uuid}`));
2124
+ }, BLE_CONNECT_TIMEOUT_MS);
2303
2125
  }),
2304
2126
  ]);
2305
2127
  succeeded = true;
@@ -2322,7 +2144,6 @@ class ReactNativeBleTransport {
2322
2144
  elapsedMs: Date.now() - startedAt,
2323
2145
  succeeded,
2324
2146
  backstopExpired: timedOut,
2325
- backstopMs,
2326
2147
  });
2327
2148
  }
2328
2149
  });
@@ -2356,9 +2177,6 @@ class ReactNativeBleTransport {
2356
2177
  throw this.createWedgedBleSetupError();
2357
2178
  }
2358
2179
  }
2359
- if (reactNative.Platform.OS === 'ios' && isIosPeerRemovedPairingInformation(error)) {
2360
- throw toIosStaleBondError(error);
2361
- }
2362
2180
  if (isNativeBleDisconnectError(error)) {
2363
2181
  throw toBleDisconnectHardwareError(error);
2364
2182
  }
@@ -2476,7 +2294,6 @@ class ReactNativeBleTransport {
2476
2294
  resetPlxManager() {
2477
2295
  if (bleManagerResetPromise)
2478
2296
  return;
2479
- this.iosLastAdvertisedAt.clear();
2480
2297
  const manager = this.blePlxManager;
2481
2298
  this.blePlxManager = undefined;
2482
2299
  const reason = 'React Native BLE manager reset';
@@ -2723,31 +2540,25 @@ class ReactNativeBleTransport {
2723
2540
  }
2724
2541
  this.probingProtocols.set(uuid, 'V2');
2725
2542
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
2726
- try {
2727
- const detected = yield transportModule.probeProtocolV2({
2728
- call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
2729
- timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
2730
- logger: Log,
2731
- logPrefix: 'ProtocolV2 RN-BLE',
2732
- onProbeFailed: () => {
2733
- var _a;
2734
- (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
2735
- this.resetProtocolV2Frames(uuid);
2736
- },
2737
- shouldRethrow: shouldRethrowProtocolProbeError,
2738
- });
2739
- if (!detected) {
2740
- this.clearProbeProtocol(uuid, 'V2');
2741
- }
2742
- else {
2743
- this.probingProtocols.delete(uuid);
2744
- }
2745
- return detected;
2746
- }
2747
- catch (error) {
2543
+ const detected = yield transportModule.probeProtocolV2({
2544
+ call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
2545
+ timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
2546
+ logger: Log,
2547
+ logPrefix: 'ProtocolV2 RN-BLE',
2548
+ onProbeFailed: () => {
2549
+ var _a;
2550
+ (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
2551
+ this.resetProtocolV2Frames(uuid);
2552
+ },
2553
+ shouldRethrow: shouldRethrowProtocolProbeError,
2554
+ });
2555
+ if (!detected) {
2748
2556
  this.clearProbeProtocol(uuid, 'V2');
2749
- throw error;
2750
2557
  }
2558
+ else {
2559
+ this.probingProtocols.delete(uuid);
2560
+ }
2561
+ return detected;
2751
2562
  });
2752
2563
  }
2753
2564
  handleProtocolV2Notification(uuid, monitorToken, data) {
@@ -3262,9 +3073,6 @@ exports.BLE_NATIVE_TEARDOWN_TIMEOUT_MS = BLE_NATIVE_TEARDOWN_TIMEOUT_MS;
3262
3073
  exports.BLE_SETUP_WEDGED_MESSAGE = BLE_SETUP_WEDGED_MESSAGE;
3263
3074
  exports.BLE_WRITE_PACKET_TIMEOUT_MS = BLE_WRITE_PACKET_TIMEOUT_MS;
3264
3075
  exports.BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD;
3265
- exports.IOS_PRESENT_DEVICE_CONNECT_BACKSTOP_MS = IOS_PRESENT_DEVICE_CONNECT_BACKSTOP_MS;
3266
- exports.IOS_PRESENT_DEVICE_CONNECT_TIMEOUT_MS = IOS_PRESENT_DEVICE_CONNECT_TIMEOUT_MS;
3267
- exports.IOS_PRESENT_DEVICE_WINDOW_MS = IOS_PRESENT_DEVICE_WINDOW_MS;
3268
3076
  exports.PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = PROTOCOL_REPROBE_FALLBACK_ATTEMPTS;
3269
3077
  exports.configureProtocolV2BleTuning = configureProtocolV2BleTuning;
3270
3078
  exports["default"] = ReactNativeBleTransport;