@onekeyfe/hd-transport-react-native 1.2.0-alpha.146 → 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 +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -19
- package/package.json +5 -5
- package/src/__tests__/protocolV2Link.test.ts +3 -56
- package/src/index.ts +18 -23
package/dist/index.d.ts
CHANGED
|
@@ -121,8 +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
124
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
127
125
|
private protocolReprobeFailures;
|
|
128
126
|
private protocolV2Assemblers;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAIL,UAAU,IAAI,aAAa,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,CA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|
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,7 +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
407
|
this.protocolReprobeFailures = new Map();
|
|
406
408
|
this.protocolV2Assemblers = new Map();
|
|
407
409
|
this.protocolV2FrameQueues = new Map();
|
|
@@ -719,11 +721,16 @@ class ReactNativeBleTransport {
|
|
|
719
721
|
var _a;
|
|
720
722
|
if (deviceList.every(d => d.id !== device.id)) {
|
|
721
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
|
+
}
|
|
722
728
|
deviceList.push(Object.assign(Object.assign({}, device), { name: displayName, commType: 'ble' }));
|
|
723
729
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] OneKey BLE device discovered', {
|
|
724
730
|
deviceId: device.id,
|
|
725
731
|
name: displayName,
|
|
726
732
|
serviceUUIDs: device.serviceUUIDs,
|
|
733
|
+
protocolHint,
|
|
727
734
|
});
|
|
728
735
|
}
|
|
729
736
|
};
|
|
@@ -795,7 +802,7 @@ class ReactNativeBleTransport {
|
|
|
795
802
|
});
|
|
796
803
|
}
|
|
797
804
|
acquireUnlocked(input) {
|
|
798
|
-
var _a;
|
|
805
|
+
var _a, _b;
|
|
799
806
|
return __awaiter(this, void 0, void 0, function* () {
|
|
800
807
|
const { uuid, forceCleanRunPromise, expectedProtocol } = input;
|
|
801
808
|
const cachedTransport = transportCache[uuid];
|
|
@@ -909,7 +916,7 @@ class ReactNativeBleTransport {
|
|
|
909
916
|
const { writeCharacteristic, notifyCharacteristic } = yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice);
|
|
910
917
|
const protocolHint = expectedProtocol
|
|
911
918
|
? undefined
|
|
912
|
-
: (_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));
|
|
913
920
|
yield this.releaseUnlocked(uuid, true);
|
|
914
921
|
if (protocolHint) {
|
|
915
922
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
@@ -930,12 +937,7 @@ class ReactNativeBleTransport {
|
|
|
930
937
|
return { uuid, protocolType };
|
|
931
938
|
}
|
|
932
939
|
catch (error) {
|
|
933
|
-
|
|
934
|
-
yield this.disconnectUnlocked(uuid);
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
yield this.releaseUnlocked(uuid, true);
|
|
938
|
-
}
|
|
940
|
+
yield this.releaseUnlocked(uuid, true);
|
|
939
941
|
throw error;
|
|
940
942
|
}
|
|
941
943
|
});
|
|
@@ -1657,7 +1659,6 @@ class ReactNativeBleTransport {
|
|
|
1657
1659
|
this.deviceProtocol.clear();
|
|
1658
1660
|
this.probingProtocols.clear();
|
|
1659
1661
|
this.sessionProtocols.clear();
|
|
1660
|
-
this.confirmedProtocolV2.clear();
|
|
1661
1662
|
this.protocolReprobeFailures.clear();
|
|
1662
1663
|
this.writeTimeoutCounts.clear();
|
|
1663
1664
|
this.connectionSetupTimeoutCounts.clear();
|
|
@@ -1670,9 +1671,8 @@ class ReactNativeBleTransport {
|
|
|
1670
1671
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE manager destroy failed (ignored):', error);
|
|
1671
1672
|
}
|
|
1672
1673
|
}
|
|
1673
|
-
createProtocolMismatchError(expected
|
|
1674
|
-
|
|
1675
|
-
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`);
|
|
1676
1676
|
}
|
|
1677
1677
|
createProtocolDetectionError() {
|
|
1678
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');
|
|
@@ -1712,13 +1712,12 @@ class ReactNativeBleTransport {
|
|
|
1712
1712
|
});
|
|
1713
1713
|
return 'V1';
|
|
1714
1714
|
}
|
|
1715
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
1715
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1716
1716
|
}
|
|
1717
1717
|
if (expectedProtocol === 'V2') {
|
|
1718
1718
|
if (yield this.probeProtocolV2(uuid)) {
|
|
1719
1719
|
this.deviceProtocol.set(uuid, 'V2');
|
|
1720
1720
|
this.sessionProtocols.set(uuid, 'V2');
|
|
1721
|
-
this.confirmedProtocolV2.add(uuid);
|
|
1722
1721
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1723
1722
|
deviceId: uuid,
|
|
1724
1723
|
protocol: 'V2',
|
|
@@ -1726,7 +1725,7 @@ class ReactNativeBleTransport {
|
|
|
1726
1725
|
});
|
|
1727
1726
|
return 'V2';
|
|
1728
1727
|
}
|
|
1729
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
1728
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1730
1729
|
}
|
|
1731
1730
|
const sessionProtocol = this.sessionProtocols.get(uuid);
|
|
1732
1731
|
const reprobeFailures = (_a = this.protocolReprobeFailures.get(uuid)) !== null && _a !== void 0 ? _a : 0;
|
|
@@ -1750,9 +1749,6 @@ class ReactNativeBleTransport {
|
|
|
1750
1749
|
if (detected) {
|
|
1751
1750
|
this.deviceProtocol.set(uuid, protocol);
|
|
1752
1751
|
this.sessionProtocols.set(uuid, protocol);
|
|
1753
|
-
if (protocol === 'V2') {
|
|
1754
|
-
this.confirmedProtocolV2.add(uuid);
|
|
1755
|
-
}
|
|
1756
1752
|
this.protocolReprobeFailures.delete(uuid);
|
|
1757
1753
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1758
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.
|
|
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.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
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": "
|
|
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('
|
|
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
|
|
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
|
|
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
|
-
'keeps a second expected Protocol V2 probe miss retryable on %s',
|
|
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.RuntimeError,
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
expect(device.cancelConnection).not.toHaveBeenCalled();
|
|
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,9 +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
384
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
384
385
|
private protocolReprobeFailures: Map<string, number> = new Map();
|
|
385
386
|
|
|
@@ -764,7 +765,10 @@ export default class ReactNativeBleTransport {
|
|
|
764
765
|
const addDevice = (device: Device) => {
|
|
765
766
|
if (deviceList.every(d => d.id !== device.id)) {
|
|
766
767
|
const displayName = getDeviceDisplayName(device) ?? 'Unknown BLE Device';
|
|
767
|
-
|
|
768
|
+
const protocolHint = inferProtocolHintFromDeviceName(displayName);
|
|
769
|
+
if (protocolHint) {
|
|
770
|
+
this.deviceProtocolHints.set(device.id, protocolHint);
|
|
771
|
+
}
|
|
768
772
|
deviceList.push({
|
|
769
773
|
...device,
|
|
770
774
|
name: displayName,
|
|
@@ -774,6 +778,7 @@ export default class ReactNativeBleTransport {
|
|
|
774
778
|
deviceId: device.id,
|
|
775
779
|
name: displayName,
|
|
776
780
|
serviceUUIDs: device.serviceUUIDs,
|
|
781
|
+
protocolHint,
|
|
777
782
|
});
|
|
778
783
|
}
|
|
779
784
|
};
|
|
@@ -1010,7 +1015,9 @@ export default class ReactNativeBleTransport {
|
|
|
1010
1015
|
|
|
1011
1016
|
const protocolHint = expectedProtocol
|
|
1012
1017
|
? undefined
|
|
1013
|
-
: input.protocolHint ??
|
|
1018
|
+
: input.protocolHint ??
|
|
1019
|
+
this.deviceProtocolHints.get(uuid) ??
|
|
1020
|
+
inferProtocolHintFromDeviceName(getDeviceDisplayName(acquiredDevice));
|
|
1014
1021
|
|
|
1015
1022
|
// release transport before new transport instance
|
|
1016
1023
|
await this.releaseUnlocked(uuid, true);
|
|
@@ -1039,11 +1046,7 @@ export default class ReactNativeBleTransport {
|
|
|
1039
1046
|
this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
|
|
1040
1047
|
return { uuid, protocolType };
|
|
1041
1048
|
} catch (error) {
|
|
1042
|
-
|
|
1043
|
-
await this.disconnectUnlocked(uuid);
|
|
1044
|
-
} else {
|
|
1045
|
-
await this.releaseUnlocked(uuid, true);
|
|
1046
|
-
}
|
|
1049
|
+
await this.releaseUnlocked(uuid, true);
|
|
1047
1050
|
throw error;
|
|
1048
1051
|
}
|
|
1049
1052
|
}
|
|
@@ -1241,7 +1244,7 @@ export default class ReactNativeBleTransport {
|
|
|
1241
1244
|
|
|
1242
1245
|
this.deviceProtocol.delete(uuid);
|
|
1243
1246
|
this.probingProtocols.delete(uuid);
|
|
1244
|
-
//
|
|
1247
|
+
// Preserve a name-derived hint across disconnects so reconnect can probe V2 first.
|
|
1245
1248
|
this.protocolV2Assemblers.get(uuid)?.reset();
|
|
1246
1249
|
this.protocolV2Assemblers.delete(uuid);
|
|
1247
1250
|
this.resetProtocolV2Frames(uuid);
|
|
@@ -1962,7 +1965,6 @@ export default class ReactNativeBleTransport {
|
|
|
1962
1965
|
this.deviceProtocol.clear();
|
|
1963
1966
|
this.probingProtocols.clear();
|
|
1964
1967
|
this.sessionProtocols.clear();
|
|
1965
|
-
this.confirmedProtocolV2.clear();
|
|
1966
1968
|
this.protocolReprobeFailures.clear();
|
|
1967
1969
|
this.writeTimeoutCounts.clear();
|
|
1968
1970
|
this.connectionSetupTimeoutCounts.clear();
|
|
@@ -1975,12 +1977,9 @@ export default class ReactNativeBleTransport {
|
|
|
1975
1977
|
}
|
|
1976
1978
|
}
|
|
1977
1979
|
|
|
1978
|
-
private createProtocolMismatchError(expected: ProtocolType
|
|
1979
|
-
// A generic Ping miss is not a bond failure. Only a later miss after this
|
|
1980
|
-
// endpoint already answered V2, or a native encryption/pairing error, is.
|
|
1981
|
-
const isStaleV2Bond = expected === 'V2' && this.confirmedProtocolV2.has(uuid);
|
|
1980
|
+
private createProtocolMismatchError(expected: ProtocolType) {
|
|
1982
1981
|
return ERRORS.TypedError(
|
|
1983
|
-
|
|
1982
|
+
HardwareErrorCode.RuntimeError,
|
|
1984
1983
|
`Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`
|
|
1985
1984
|
);
|
|
1986
1985
|
}
|
|
@@ -2036,14 +2035,13 @@ export default class ReactNativeBleTransport {
|
|
|
2036
2035
|
});
|
|
2037
2036
|
return 'V1';
|
|
2038
2037
|
}
|
|
2039
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
2038
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
2040
2039
|
}
|
|
2041
2040
|
|
|
2042
2041
|
if (expectedProtocol === 'V2') {
|
|
2043
2042
|
if (await this.probeProtocolV2(uuid)) {
|
|
2044
2043
|
this.deviceProtocol.set(uuid, 'V2');
|
|
2045
2044
|
this.sessionProtocols.set(uuid, 'V2');
|
|
2046
|
-
this.confirmedProtocolV2.add(uuid);
|
|
2047
2045
|
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
2048
2046
|
deviceId: uuid,
|
|
2049
2047
|
protocol: 'V2',
|
|
@@ -2051,7 +2049,7 @@ export default class ReactNativeBleTransport {
|
|
|
2051
2049
|
});
|
|
2052
2050
|
return 'V2';
|
|
2053
2051
|
}
|
|
2054
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
2052
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
2055
2053
|
}
|
|
2056
2054
|
|
|
2057
2055
|
// Protocol must be actively probed after connection. Name, PID, and descriptors only
|
|
@@ -2086,9 +2084,6 @@ export default class ReactNativeBleTransport {
|
|
|
2086
2084
|
if (detected) {
|
|
2087
2085
|
this.deviceProtocol.set(uuid, protocol);
|
|
2088
2086
|
this.sessionProtocols.set(uuid, protocol);
|
|
2089
|
-
if (protocol === 'V2') {
|
|
2090
|
-
this.confirmedProtocolV2.add(uuid);
|
|
2091
|
-
}
|
|
2092
2087
|
this.protocolReprobeFailures.delete(uuid);
|
|
2093
2088
|
Log?.debug('[ReactNativeBleTransport] protocol detected', {
|
|
2094
2089
|
deviceId: uuid,
|