@onekeyfe/hd-transport-react-native 1.2.0-alpha.145 → 1.2.0-alpha.147

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 CHANGED
@@ -121,10 +121,6 @@ declare class ReactNativeBleTransport {
121
121
  private deviceProtocolHints;
122
122
  /** Protocol this device actually answered on, kept across reconnects of one session. */
123
123
  private sessionProtocols;
124
- /** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
125
- private confirmedProtocolV2;
126
- /** First expected-V2 miss for an unconfirmed endpoint; the next miss is a stale bond. */
127
- private retryableV2Mismatch;
128
124
  /** Consecutive detections that failed while trusting sessionProtocols. */
129
125
  private protocolReprobeFailures;
130
126
  private protocolV2Assemblers;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA0BhC,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;AAgBjE,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;IAChC,mBAAmB,EAAE,cAAc,CAAC;IACpC,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC;AAkCF,eAAO,MAAM,+BAA+B,UACnC,OAAO,KACb,4BAA4B,G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B,iCAAiC;IAwC/C,OAAO,CAAC,wBAAwB;IAgChC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA6B1B,OAAO,CAAC,eAAe;IAkDvB,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YAsGd,iCAAiC;YAoDjC,eAAe;YAwBf,eAAe;IA0B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;YAiBnB,qBAAqB;YA2DrB,oBAAoB;YAgCpB,cAAc;YAqEd,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
@@ -311,6 +311,9 @@ function resetProtocolV2BleTuning() {
311
311
  function getProtocolV2BleTuning() {
312
312
  return Object.assign({}, protocolV2BleTuning);
313
313
  }
314
+ function inferProtocolHintFromDeviceName(name) {
315
+ return /\bpro\s*2\b/i.test(name !== null && name !== void 0 ? name : '') ? 'V2' : undefined;
316
+ }
314
317
  function getDeviceDisplayName(device) {
315
318
  return (device === null || device === void 0 ? void 0 : device.name) || (device === null || device === void 0 ? void 0 : device.localName) || null;
316
319
  }
@@ -401,8 +404,6 @@ class ReactNativeBleTransport {
401
404
  this.connectionSetupTimeoutCounts = new Map();
402
405
  this.deviceProtocolHints = new Map();
403
406
  this.sessionProtocols = new Map();
404
- this.confirmedProtocolV2 = new Set();
405
- this.retryableV2Mismatch = new Set();
406
407
  this.protocolReprobeFailures = new Map();
407
408
  this.protocolV2Assemblers = new Map();
408
409
  this.protocolV2FrameQueues = new Map();
@@ -720,11 +721,16 @@ class ReactNativeBleTransport {
720
721
  var _a;
721
722
  if (deviceList.every(d => d.id !== device.id)) {
722
723
  const displayName = (_a = getDeviceDisplayName(device)) !== null && _a !== void 0 ? _a : 'Unknown BLE Device';
724
+ const protocolHint = inferProtocolHintFromDeviceName(displayName);
725
+ if (protocolHint) {
726
+ this.deviceProtocolHints.set(device.id, protocolHint);
727
+ }
723
728
  deviceList.push(Object.assign(Object.assign({}, device), { name: displayName, commType: 'ble' }));
724
729
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] OneKey BLE device discovered', {
725
730
  deviceId: device.id,
726
731
  name: displayName,
727
732
  serviceUUIDs: device.serviceUUIDs,
733
+ protocolHint,
728
734
  });
729
735
  }
730
736
  };
@@ -796,7 +802,7 @@ class ReactNativeBleTransport {
796
802
  });
797
803
  }
798
804
  acquireUnlocked(input) {
799
- var _a;
805
+ var _a, _b;
800
806
  return __awaiter(this, void 0, void 0, function* () {
801
807
  const { uuid, forceCleanRunPromise, expectedProtocol } = input;
802
808
  const cachedTransport = transportCache[uuid];
@@ -910,7 +916,7 @@ class ReactNativeBleTransport {
910
916
  const { writeCharacteristic, notifyCharacteristic } = yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice);
911
917
  const protocolHint = expectedProtocol
912
918
  ? undefined
913
- : (_a = input.protocolHint) !== null && _a !== void 0 ? _a : this.deviceProtocolHints.get(uuid);
919
+ : (_b = (_a = input.protocolHint) !== null && _a !== void 0 ? _a : this.deviceProtocolHints.get(uuid)) !== null && _b !== void 0 ? _b : inferProtocolHintFromDeviceName(getDeviceDisplayName(acquiredDevice));
914
920
  yield this.releaseUnlocked(uuid, true);
915
921
  if (protocolHint) {
916
922
  this.deviceProtocolHints.set(uuid, protocolHint);
@@ -931,12 +937,7 @@ class ReactNativeBleTransport {
931
937
  return { uuid, protocolType };
932
938
  }
933
939
  catch (error) {
934
- if ((error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.BleDeviceBondError) {
935
- yield this.disconnectUnlocked(uuid);
936
- }
937
- else {
938
- yield this.releaseUnlocked(uuid, true);
939
- }
940
+ yield this.releaseUnlocked(uuid, true);
940
941
  throw error;
941
942
  }
942
943
  });
@@ -1658,8 +1659,6 @@ class ReactNativeBleTransport {
1658
1659
  this.deviceProtocol.clear();
1659
1660
  this.probingProtocols.clear();
1660
1661
  this.sessionProtocols.clear();
1661
- this.confirmedProtocolV2.clear();
1662
- this.retryableV2Mismatch.clear();
1663
1662
  this.protocolReprobeFailures.clear();
1664
1663
  this.writeTimeoutCounts.clear();
1665
1664
  this.connectionSetupTimeoutCounts.clear();
@@ -1672,16 +1671,8 @@ class ReactNativeBleTransport {
1672
1671
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE manager destroy failed (ignored):', error);
1673
1672
  }
1674
1673
  }
1675
- createProtocolMismatchError(expected, uuid) {
1676
- const isStaleV2Bond = expected === 'V2' &&
1677
- (this.confirmedProtocolV2.has(uuid) || this.retryableV2Mismatch.has(uuid));
1678
- if (expected === 'V2' && !isStaleV2Bond) {
1679
- this.retryableV2Mismatch.add(uuid);
1680
- }
1681
- else if (isStaleV2Bond) {
1682
- this.retryableV2Mismatch.delete(uuid);
1683
- }
1684
- return hdShared.ERRORS.TypedError(isStaleV2Bond ? hdShared.HardwareErrorCode.BleDeviceBondError : hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
1674
+ createProtocolMismatchError(expected) {
1675
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
1685
1676
  }
1686
1677
  createProtocolDetectionError() {
1687
1678
  return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
@@ -1721,14 +1712,12 @@ class ReactNativeBleTransport {
1721
1712
  });
1722
1713
  return 'V1';
1723
1714
  }
1724
- throw this.createProtocolMismatchError(expectedProtocol, uuid);
1715
+ throw this.createProtocolMismatchError(expectedProtocol);
1725
1716
  }
1726
1717
  if (expectedProtocol === 'V2') {
1727
1718
  if (yield this.probeProtocolV2(uuid)) {
1728
1719
  this.deviceProtocol.set(uuid, 'V2');
1729
1720
  this.sessionProtocols.set(uuid, 'V2');
1730
- this.confirmedProtocolV2.add(uuid);
1731
- this.retryableV2Mismatch.delete(uuid);
1732
1721
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
1733
1722
  deviceId: uuid,
1734
1723
  protocol: 'V2',
@@ -1736,7 +1725,7 @@ class ReactNativeBleTransport {
1736
1725
  });
1737
1726
  return 'V2';
1738
1727
  }
1739
- throw this.createProtocolMismatchError(expectedProtocol, uuid);
1728
+ throw this.createProtocolMismatchError(expectedProtocol);
1740
1729
  }
1741
1730
  const sessionProtocol = this.sessionProtocols.get(uuid);
1742
1731
  const reprobeFailures = (_a = this.protocolReprobeFailures.get(uuid)) !== null && _a !== void 0 ? _a : 0;
@@ -1760,10 +1749,6 @@ class ReactNativeBleTransport {
1760
1749
  if (detected) {
1761
1750
  this.deviceProtocol.set(uuid, protocol);
1762
1751
  this.sessionProtocols.set(uuid, protocol);
1763
- if (protocol === 'V2') {
1764
- this.confirmedProtocolV2.add(uuid);
1765
- this.retryableV2Mismatch.delete(uuid);
1766
- }
1767
1752
  this.protocolReprobeFailures.delete(uuid);
1768
1753
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
1769
1754
  deviceId: uuid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.0-alpha.145",
3
+ "version": "1.2.0-alpha.147",
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.0-alpha.145",
24
- "@onekeyfe/hd-shared": "1.2.0-alpha.145",
25
- "@onekeyfe/hd-transport": "1.2.0-alpha.145",
23
+ "@onekeyfe/hd-core": "1.2.0-alpha.147",
24
+ "@onekeyfe/hd-shared": "1.2.0-alpha.147",
25
+ "@onekeyfe/hd-transport": "1.2.0-alpha.147",
26
26
  "@onekeyfe/react-native-ble-utils": "^0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "9a136f881865c15e603ef271ae820c2b5a991dcc"
29
+ "gitHead": "a34e98865e6be227cf3e00d486146e6592761db0"
30
30
  }
@@ -405,7 +405,7 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
405
405
  await transport.release(uuid, true);
406
406
  });
407
407
 
408
- test('detects Protocol V2 on iOS without using the BLE name as a protocol hint', async () => {
408
+ test('actively probes Protocol V2 on iOS when only a name-derived hint is available', async () => {
409
409
  const { transport, uuid, device, sentSeqs, writeCharacteristic } = createHarness({
410
410
  deviceName: 'Pro2 6E9E',
411
411
  });
@@ -415,68 +415,15 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
415
415
  protocolType: 'V2',
416
416
  });
417
417
  expect(device.requestMTU).toHaveBeenCalledWith(247);
418
- expect(writeCharacteristic.writeWithResponse.mock.calls.length).toBeGreaterThan(1);
418
+ expect(writeCharacteristic.writeWithResponse).toHaveBeenCalledTimes(1);
419
419
 
420
420
  await expect(
421
421
  transport.call(uuid, 'Ping', { message: 'first-core-command' })
422
422
  ).resolves.toBeDefined();
423
- expect(sentSeqs.filter(seq => seq > 0)).toEqual([1, 2]);
423
+ expect(sentSeqs).toEqual([1, 2]);
424
424
  await transport.release(uuid, true);
425
425
  });
426
426
 
427
- test.each(['ios', 'android'] as const)(
428
- 'keeps a first expected Protocol V2 probe miss retryable on %s',
429
- async platform => {
430
- setPlatformOS(platform);
431
- const { transport, uuid, device } = createHarness();
432
- jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
433
-
434
- await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
435
- errorCode: HardwareErrorCode.RuntimeError,
436
- });
437
-
438
- expect(device.cancelConnection).not.toHaveBeenCalled();
439
- expect(transport.getProtocolType(uuid)).toBeUndefined();
440
- }
441
- );
442
-
443
- test.each(['ios', 'android'] as const)(
444
- 'reports a stale bond on %s after a second expected Protocol V2 probe miss',
445
- async platform => {
446
- setPlatformOS(platform);
447
- const { transport, uuid, device } = createHarness();
448
- jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
449
-
450
- await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
451
- errorCode: HardwareErrorCode.RuntimeError,
452
- });
453
- await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
454
- errorCode: HardwareErrorCode.BleDeviceBondError,
455
- });
456
-
457
- expect(device.cancelConnection).toHaveBeenCalledTimes(1);
458
- expect(transport.getProtocolType(uuid)).toBeUndefined();
459
- }
460
- );
461
-
462
- test.each(['ios', 'android'] as const)(
463
- 'reports a stale bond on %s when a previously confirmed Protocol V2 device stops responding',
464
- async platform => {
465
- setPlatformOS(platform);
466
- const { transport, uuid, device } = createHarness();
467
- await transport.acquire({ uuid, expectedProtocol: 'V2' });
468
- await transport.release(uuid, true);
469
- jest.spyOn(transport as any, 'probeProtocolV2').mockResolvedValue(false);
470
-
471
- await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
472
- errorCode: HardwareErrorCode.BleDeviceBondError,
473
- });
474
-
475
- expect(device.cancelConnection).toHaveBeenCalled();
476
- expect(transport.getProtocolType(uuid)).toBeUndefined();
477
- }
478
- );
479
-
480
427
  test('waits for an in-flight release before reacquiring the same device', async () => {
481
428
  const { transport, uuid } = createHarness();
482
429
  await transport.acquire({ uuid, expectedProtocol: 'V2' });
package/src/index.ts CHANGED
@@ -203,6 +203,10 @@ export function getProtocolV2BleTuning() {
203
203
  return { ...protocolV2BleTuning };
204
204
  }
205
205
 
206
+ function inferProtocolHintFromDeviceName(name?: string | null): ProtocolType | undefined {
207
+ return /\bpro\s*2\b/i.test(name ?? '') ? 'V2' : undefined;
208
+ }
209
+
206
210
  function getDeviceDisplayName(device?: Device | null) {
207
211
  return device?.name || device?.localName || null;
208
212
  }
@@ -377,12 +381,6 @@ export default class ReactNativeBleTransport {
377
381
  /** Protocol this device actually answered on, kept across reconnects of one session. */
378
382
  private sessionProtocols: Map<string, ProtocolType> = new Map();
379
383
 
380
- /** Endpoints that answered a V2 probe in this transport lifetime. Survives disconnect. */
381
- private confirmedProtocolV2 = new Set<string>();
382
-
383
- /** First expected-V2 miss for an unconfirmed endpoint; the next miss is a stale bond. */
384
- private retryableV2Mismatch = new Set<string>();
385
-
386
384
  /** Consecutive detections that failed while trusting sessionProtocols. */
387
385
  private protocolReprobeFailures: Map<string, number> = new Map();
388
386
 
@@ -767,7 +765,10 @@ export default class ReactNativeBleTransport {
767
765
  const addDevice = (device: Device) => {
768
766
  if (deviceList.every(d => d.id !== device.id)) {
769
767
  const displayName = getDeviceDisplayName(device) ?? 'Unknown BLE Device';
770
-
768
+ const protocolHint = inferProtocolHintFromDeviceName(displayName);
769
+ if (protocolHint) {
770
+ this.deviceProtocolHints.set(device.id, protocolHint);
771
+ }
771
772
  deviceList.push({
772
773
  ...device,
773
774
  name: displayName,
@@ -777,6 +778,7 @@ export default class ReactNativeBleTransport {
777
778
  deviceId: device.id,
778
779
  name: displayName,
779
780
  serviceUUIDs: device.serviceUUIDs,
781
+ protocolHint,
780
782
  });
781
783
  }
782
784
  };
@@ -1013,7 +1015,9 @@ export default class ReactNativeBleTransport {
1013
1015
 
1014
1016
  const protocolHint = expectedProtocol
1015
1017
  ? undefined
1016
- : input.protocolHint ?? this.deviceProtocolHints.get(uuid);
1018
+ : input.protocolHint ??
1019
+ this.deviceProtocolHints.get(uuid) ??
1020
+ inferProtocolHintFromDeviceName(getDeviceDisplayName(acquiredDevice));
1017
1021
 
1018
1022
  // release transport before new transport instance
1019
1023
  await this.releaseUnlocked(uuid, true);
@@ -1042,11 +1046,7 @@ export default class ReactNativeBleTransport {
1042
1046
  this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
1043
1047
  return { uuid, protocolType };
1044
1048
  } catch (error) {
1045
- if ((error as { errorCode?: unknown })?.errorCode === HardwareErrorCode.BleDeviceBondError) {
1046
- await this.disconnectUnlocked(uuid);
1047
- } else {
1048
- await this.releaseUnlocked(uuid, true);
1049
- }
1049
+ await this.releaseUnlocked(uuid, true);
1050
1050
  throw error;
1051
1051
  }
1052
1052
  }
@@ -1244,7 +1244,7 @@ export default class ReactNativeBleTransport {
1244
1244
 
1245
1245
  this.deviceProtocol.delete(uuid);
1246
1246
  this.probingProtocols.delete(uuid);
1247
- // Confirmed protocol and caller hints stay in deviceProtocol / protocolHint.
1247
+ // Preserve a name-derived hint across disconnects so reconnect can probe V2 first.
1248
1248
  this.protocolV2Assemblers.get(uuid)?.reset();
1249
1249
  this.protocolV2Assemblers.delete(uuid);
1250
1250
  this.resetProtocolV2Frames(uuid);
@@ -1965,8 +1965,6 @@ export default class ReactNativeBleTransport {
1965
1965
  this.deviceProtocol.clear();
1966
1966
  this.probingProtocols.clear();
1967
1967
  this.sessionProtocols.clear();
1968
- this.confirmedProtocolV2.clear();
1969
- this.retryableV2Mismatch.clear();
1970
1968
  this.protocolReprobeFailures.clear();
1971
1969
  this.writeTimeoutCounts.clear();
1972
1970
  this.connectionSetupTimeoutCounts.clear();
@@ -1979,20 +1977,9 @@ export default class ReactNativeBleTransport {
1979
1977
  }
1980
1978
  }
1981
1979
 
1982
- private createProtocolMismatchError(expected: ProtocolType, uuid: string) {
1983
- // Caller `expectedProtocol: 'V2'` is not proof this endpoint already answered.
1984
- // A first-connect or flaky Ping must stay retryable. A later miss after a
1985
- // confirmed V2 answer, or a second miss on the same uuid, is a stale bond.
1986
- const isStaleV2Bond =
1987
- expected === 'V2' &&
1988
- (this.confirmedProtocolV2.has(uuid) || this.retryableV2Mismatch.has(uuid));
1989
- if (expected === 'V2' && !isStaleV2Bond) {
1990
- this.retryableV2Mismatch.add(uuid);
1991
- } else if (isStaleV2Bond) {
1992
- this.retryableV2Mismatch.delete(uuid);
1993
- }
1980
+ private createProtocolMismatchError(expected: ProtocolType) {
1994
1981
  return ERRORS.TypedError(
1995
- isStaleV2Bond ? HardwareErrorCode.BleDeviceBondError : HardwareErrorCode.RuntimeError,
1982
+ HardwareErrorCode.RuntimeError,
1996
1983
  `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`
1997
1984
  );
1998
1985
  }
@@ -2048,15 +2035,13 @@ export default class ReactNativeBleTransport {
2048
2035
  });
2049
2036
  return 'V1';
2050
2037
  }
2051
- throw this.createProtocolMismatchError(expectedProtocol, uuid);
2038
+ throw this.createProtocolMismatchError(expectedProtocol);
2052
2039
  }
2053
2040
 
2054
2041
  if (expectedProtocol === 'V2') {
2055
2042
  if (await this.probeProtocolV2(uuid)) {
2056
2043
  this.deviceProtocol.set(uuid, 'V2');
2057
2044
  this.sessionProtocols.set(uuid, 'V2');
2058
- this.confirmedProtocolV2.add(uuid);
2059
- this.retryableV2Mismatch.delete(uuid);
2060
2045
  Log?.debug('[ReactNativeBleTransport] protocol detected', {
2061
2046
  deviceId: uuid,
2062
2047
  protocol: 'V2',
@@ -2064,7 +2049,7 @@ export default class ReactNativeBleTransport {
2064
2049
  });
2065
2050
  return 'V2';
2066
2051
  }
2067
- throw this.createProtocolMismatchError(expectedProtocol, uuid);
2052
+ throw this.createProtocolMismatchError(expectedProtocol);
2068
2053
  }
2069
2054
 
2070
2055
  // Protocol must be actively probed after connection. Name, PID, and descriptors only
@@ -2099,10 +2084,6 @@ export default class ReactNativeBleTransport {
2099
2084
  if (detected) {
2100
2085
  this.deviceProtocol.set(uuid, protocol);
2101
2086
  this.sessionProtocols.set(uuid, protocol);
2102
- if (protocol === 'V2') {
2103
- this.confirmedProtocolV2.add(uuid);
2104
- this.retryableV2Mismatch.delete(uuid);
2105
- }
2106
2087
  this.protocolReprobeFailures.delete(uuid);
2107
2088
  Log?.debug('[ReactNativeBleTransport] protocol detected', {
2108
2089
  deviceId: uuid,