@onekeyfe/hd-transport-react-native 1.2.0-alpha.175 → 1.2.0-alpha.176

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.
@@ -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;AAEjE,KAAK,8BAA8B,GAAG,eAAe,GAAG;IAMtD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAgBF,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,IAsBjC,CAAC;AAcF,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAClD,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AAOpD,eAAO,MAAM,yCAAyC,IAAI,CAAC;AAI3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC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,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA6B1B,OAAO,CAAC,eAAe;IAmDvB,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YA0Gd,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
@@ -804,17 +804,41 @@ class ReactNativeBleTransport {
804
804
  return __awaiter(this, void 0, void 0, function* () {
805
805
  const { uuid, forceCleanRunPromise, expectedProtocol, skipProtocolProbe } = input;
806
806
  const cachedTransport = transportCache[uuid];
807
+ if (skipProtocolProbe && !cachedTransport && this.blePlxManager) {
808
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh uncached BLE connection for firmware install:', uuid);
809
+ const manager = this.blePlxManager;
810
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
811
+ yield this.runBestEffortNativeOperation('firmware install reconnect: cancel uncached device connection', () => manager.cancelDeviceConnection(uuid));
812
+ }));
813
+ }
807
814
  if (cachedTransport) {
808
- const cachedProtocol = this.deviceProtocol.get(uuid);
809
- const isCachedDeviceConnected = yield cachedTransport.device.isConnected().catch(() => false);
810
- if (isCachedDeviceConnected &&
811
- cachedProtocol &&
812
- (!expectedProtocol || cachedProtocol === expectedProtocol)) {
813
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
814
- return { uuid, protocolType: cachedProtocol };
815
+ if (skipProtocolProbe) {
816
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh cached BLE connection for firmware install:', uuid);
817
+ const manager = this.blePlxManager;
818
+ yield this.releaseUnlocked(uuid, true);
819
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
820
+ const operations = [];
821
+ if (manager) {
822
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: cancel device connection', () => manager.cancelDeviceConnection(uuid)));
823
+ }
824
+ operations.push(this.runBestEffortNativeOperation('firmware install reconnect: device cancel connection', () => cachedTransport.device.cancelConnection()));
825
+ yield Promise.all(operations);
826
+ }));
827
+ }
828
+ else {
829
+ const cachedProtocol = this.deviceProtocol.get(uuid);
830
+ const isCachedDeviceConnected = yield cachedTransport.device
831
+ .isConnected()
832
+ .catch(() => false);
833
+ if (isCachedDeviceConnected &&
834
+ cachedProtocol &&
835
+ (!expectedProtocol || cachedProtocol === expectedProtocol)) {
836
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
837
+ return { uuid, protocolType: cachedProtocol };
838
+ }
839
+ Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
840
+ yield this.releaseUnlocked(uuid, true);
815
841
  }
816
- Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
817
- yield this.releaseUnlocked(uuid, true);
818
842
  }
819
843
  let device = null;
820
844
  if (forceCleanRunPromise && this.runPromise) {
@@ -1730,15 +1754,27 @@ class ReactNativeBleTransport {
1730
1754
  detectProtocol(uuid, expectedProtocol, protocolHint, rebuildTransport) {
1731
1755
  var _a;
1732
1756
  return __awaiter(this, void 0, void 0, function* () {
1733
- if (expectedProtocol === 'V1') {
1734
- this.deviceProtocol.set(uuid, 'V1');
1735
- this.sessionProtocols.set(uuid, 'V1');
1757
+ if (reactNative.Platform.OS === 'ios' && expectedProtocol === 'V1') {
1758
+ this.deviceProtocol.set(uuid, expectedProtocol);
1736
1759
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected', {
1737
1760
  deviceId: uuid,
1738
- protocol: 'V1',
1761
+ protocol: expectedProtocol,
1739
1762
  source: 'expected',
1740
1763
  });
1741
- return 'V1';
1764
+ return expectedProtocol;
1765
+ }
1766
+ if (expectedProtocol === 'V1') {
1767
+ if (yield this.probeProtocolV1(uuid)) {
1768
+ this.deviceProtocol.set(uuid, 'V1');
1769
+ this.sessionProtocols.set(uuid, 'V1');
1770
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
1771
+ deviceId: uuid,
1772
+ protocol: 'V1',
1773
+ source: 'expected',
1774
+ });
1775
+ return 'V1';
1776
+ }
1777
+ throw this.createProtocolMismatchError(expectedProtocol, uuid);
1742
1778
  }
1743
1779
  if (expectedProtocol === 'V2') {
1744
1780
  if (yield this.probeProtocolV2(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.175",
3
+ "version": "1.2.0-alpha.176",
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.175",
24
- "@onekeyfe/hd-shared": "1.2.0-alpha.175",
25
- "@onekeyfe/hd-transport": "1.2.0-alpha.175",
23
+ "@onekeyfe/hd-core": "1.2.0-alpha.176",
24
+ "@onekeyfe/hd-shared": "1.2.0-alpha.176",
25
+ "@onekeyfe/hd-transport": "1.2.0-alpha.176",
26
26
  "@onekeyfe/react-native-ble-utils": "^0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "b2cb2451bd3a56b219d18e0078597b316dbc3ba7"
29
+ "gitHead": "a5152148317effe811cde8adecdfe75c28e82657"
30
30
  }
@@ -424,10 +424,12 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
424
424
  await transport.release(uuid, true);
425
425
  });
426
426
 
427
- test('reacquires a known Protocol V2 firmware install link without sending Ping', async () => {
428
- const { transport, uuid, writeCharacteristic } = createHarness();
427
+ test('physically refreshes an uncached Protocol V2 firmware install link without Ping', async () => {
428
+ const { transport, uuid, device, bleManager, writeCharacteristic } = createHarness();
429
429
  const probeProtocolV2 = jest.spyOn(transport as any, 'probeProtocolV2');
430
430
  (transport as any).sessionProtocols.set(uuid, 'V2');
431
+ device.connect = jest.fn().mockResolvedValue(device);
432
+ device.isConnected.mockResolvedValueOnce(false);
431
433
 
432
434
  await expect(
433
435
  transport.acquire({ uuid, expectedProtocol: 'V2', skipProtocolProbe: true })
@@ -436,6 +438,9 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
436
438
  protocolType: 'V2',
437
439
  });
438
440
 
441
+ expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(uuid);
442
+ expect(device.cancelConnection).not.toHaveBeenCalled();
443
+ expect(device.connect).toHaveBeenCalled();
439
444
  expect(probeProtocolV2).not.toHaveBeenCalled();
440
445
  expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
441
446
  expect(writeCharacteristic.writeWithoutResponse).not.toHaveBeenCalled();
@@ -443,6 +448,32 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
443
448
  await transport.release(uuid, true);
444
449
  });
445
450
 
451
+ test('refreshes a cached firmware install connection instead of trusting GATT state', async () => {
452
+ const { transport, uuid, device, bleManager, writeCharacteristic } = createHarness();
453
+ const probeProtocolV2 = jest.spyOn(transport as any, 'probeProtocolV2');
454
+
455
+ await transport.acquire({ uuid, expectedProtocol: 'V2' });
456
+ device.connect = jest.fn().mockResolvedValue(device);
457
+ device.isConnected.mockResolvedValueOnce(false);
458
+ writeCharacteristic.writeWithResponse.mockClear();
459
+ writeCharacteristic.writeWithoutResponse.mockClear();
460
+
461
+ await expect(
462
+ transport.acquire({ uuid, expectedProtocol: 'V2', skipProtocolProbe: true })
463
+ ).resolves.toEqual({
464
+ uuid,
465
+ protocolType: 'V2',
466
+ });
467
+
468
+ expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(uuid);
469
+ expect(device.cancelConnection).toHaveBeenCalled();
470
+ expect(device.connect).toHaveBeenCalled();
471
+ expect(probeProtocolV2).toHaveBeenCalledTimes(1);
472
+ expect(writeCharacteristic.writeWithResponse).not.toHaveBeenCalled();
473
+ expect(writeCharacteristic.writeWithoutResponse).not.toHaveBeenCalled();
474
+ await transport.release(uuid, true);
475
+ });
476
+
446
477
  test('rejects no-probe acquire before the BLE endpoint has confirmed a protocol', async () => {
447
478
  const { transport, uuid } = createHarness();
448
479
 
package/src/index.ts CHANGED
@@ -888,24 +888,66 @@ export default class ReactNativeBleTransport {
888
888
  const { uuid, forceCleanRunPromise, expectedProtocol, skipProtocolProbe } = input;
889
889
 
890
890
  const cachedTransport = transportCache[uuid];
891
+ if (skipProtocolProbe && !cachedTransport && this.blePlxManager) {
892
+ Log?.debug(
893
+ '[ReactNativeBleTransport] refresh uncached BLE connection for firmware install:',
894
+ uuid
895
+ );
896
+ const manager = this.blePlxManager;
897
+ await this.runNativeTeardown(uuid, manager, async () => {
898
+ await this.runBestEffortNativeOperation(
899
+ 'firmware install reconnect: cancel uncached device connection',
900
+ () => manager.cancelDeviceConnection(uuid)
901
+ );
902
+ });
903
+ }
891
904
  if (cachedTransport) {
892
- const cachedProtocol = this.deviceProtocol.get(uuid);
893
- const isCachedDeviceConnected = await cachedTransport.device.isConnected().catch(() => false);
894
- if (
895
- isCachedDeviceConnected &&
896
- cachedProtocol &&
897
- (!expectedProtocol || cachedProtocol === expectedProtocol)
898
- ) {
899
- Log?.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
900
- return { uuid, protocolType: cachedProtocol };
901
- }
905
+ if (skipProtocolProbe) {
906
+ Log?.debug(
907
+ '[ReactNativeBleTransport] refresh cached BLE connection for firmware install:',
908
+ uuid
909
+ );
910
+ const manager = this.blePlxManager;
911
+ await this.releaseUnlocked(uuid, true);
912
+ await this.runNativeTeardown(uuid, manager, async () => {
913
+ const operations: Promise<unknown>[] = [];
914
+ if (manager) {
915
+ operations.push(
916
+ this.runBestEffortNativeOperation(
917
+ 'firmware install reconnect: cancel device connection',
918
+ () => manager.cancelDeviceConnection(uuid)
919
+ )
920
+ );
921
+ }
922
+ operations.push(
923
+ this.runBestEffortNativeOperation(
924
+ 'firmware install reconnect: device cancel connection',
925
+ () => cachedTransport.device.cancelConnection()
926
+ )
927
+ );
928
+ await Promise.all(operations);
929
+ });
930
+ } else {
931
+ const cachedProtocol = this.deviceProtocol.get(uuid);
932
+ const isCachedDeviceConnected = await cachedTransport.device
933
+ .isConnected()
934
+ .catch(() => false);
935
+ if (
936
+ isCachedDeviceConnected &&
937
+ cachedProtocol &&
938
+ (!expectedProtocol || cachedProtocol === expectedProtocol)
939
+ ) {
940
+ Log?.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
941
+ return { uuid, protocolType: cachedProtocol };
942
+ }
902
943
 
903
- /**
904
- * If the transport is not reusable due to a protocol mismatch or stale
905
- * connection, clean it up before creating a new transport instance.
906
- */
907
- Log?.debug('transport not reusable, will release: ', uuid);
908
- await this.releaseUnlocked(uuid, true);
944
+ /**
945
+ * If the transport is not reusable due to a protocol mismatch or stale
946
+ * connection, clean it up before creating a new transport instance.
947
+ */
948
+ Log?.debug('transport not reusable, will release: ', uuid);
949
+ await this.releaseUnlocked(uuid, true);
950
+ }
909
951
  }
910
952
 
911
953
  let device: Device | null = null;
@@ -2078,23 +2120,31 @@ export default class ReactNativeBleTransport {
2078
2120
  protocolHint?: ProtocolType,
2079
2121
  rebuildTransport?: () => Promise<void>
2080
2122
  ): Promise<ProtocolType> {
2081
- // A declared V1 is taken at face value on every platform, as iOS has done
2082
- // since protocol probing arrived: the caller reads the protocol off its own
2083
- // device record, so the probe re-asks a question that is already answered
2084
- // and costs a round trip on every acquire. Expected V2 must still Ping so
2085
- // USB-priority `link disabled` surfaces here instead of as a later unmapped
2086
- // RuntimeError. sessionProtocols is stamped too — the iOS path skipped it,
2087
- // which left the firmware-install reconnect (skipProtocolProbe) without the
2088
- // confirmed protocol it requires.
2089
- if (expectedProtocol === 'V1') {
2090
- this.deviceProtocol.set(uuid, 'V1');
2091
- this.sessionProtocols.set(uuid, 'V1');
2123
+ // iOS still skips an extra V1 Initialize during acquire. Expected V2 must
2124
+ // Ping so USB-priority `link disabled` can surface instead of a later
2125
+ // unmapped RuntimeError.
2126
+ if (Platform.OS === 'ios' && expectedProtocol === 'V1') {
2127
+ this.deviceProtocol.set(uuid, expectedProtocol);
2092
2128
  Log?.debug('[ReactNativeBleTransport] protocol selected', {
2093
2129
  deviceId: uuid,
2094
- protocol: 'V1',
2130
+ protocol: expectedProtocol,
2095
2131
  source: 'expected',
2096
2132
  });
2097
- return 'V1';
2133
+ return expectedProtocol;
2134
+ }
2135
+
2136
+ if (expectedProtocol === 'V1') {
2137
+ if (await this.probeProtocolV1(uuid)) {
2138
+ this.deviceProtocol.set(uuid, 'V1');
2139
+ this.sessionProtocols.set(uuid, 'V1');
2140
+ Log?.debug('[ReactNativeBleTransport] protocol detected', {
2141
+ deviceId: uuid,
2142
+ protocol: 'V1',
2143
+ source: 'expected',
2144
+ });
2145
+ return 'V1';
2146
+ }
2147
+ throw this.createProtocolMismatchError(expectedProtocol, uuid);
2098
2148
  }
2099
2149
 
2100
2150
  if (expectedProtocol === 'V2') {