@onekeyfe/hd-transport-react-native 1.2.8-alpha.127 → 1.2.8-alpha.129

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":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAsBnE,eAAO,MAAM,qBAAqB,iBAAkB,MAAM,EAAE,0BACZ,CAAC;AAEjD,eAAO,MAAM,gBAAgB,6BAAwC,CAAC;AAEtE,eAAO,MAAM,UAAU,eAAgB,MAAM,yEAAoC,CAAC;AAoClF,eAAO,MAAM,iBAAiB,kBACb,MAAM,WACZ,WAAW,YACV;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,KACtC,QAAQ,UAAU,GAAG,SAAS,CA6D7B,CAAC"}
1
+ {"version":3,"file":"BleManager.d.ts","sourceRoot":"","sources":["../src/BleManager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAyBnE,eAAO,MAAM,qBAAqB,iBAAkB,MAAM,EAAE,0BACZ,CAAC;AAEjD,eAAO,MAAM,gBAAgB,6BAAwC,CAAC;AAEtE,eAAO,MAAM,UAAU,eAAgB,MAAM,yEAAoC,CAAC;AAoClF,eAAO,MAAM,iBAAiB,kBACb,MAAM,WACZ,WAAW,YACV;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,KACtC,QAAQ,UAAU,GAAG,SAAS,CA6D7B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import * as transport from '@onekeyfe/hd-transport';
2
- import transport__default, { ProtocolType, OneKeyDeviceInfoBase, OneKeyMobileDeviceInfo, TransportCallOptions } from '@onekeyfe/hd-transport';
1
+ import * as transportModule from '@onekeyfe/hd-transport';
2
+ import transportModule__default, { ProtocolType, OneKeyDeviceInfoBase, OneKeyMobileDeviceInfo, TransportCallOptions } from '@onekeyfe/hd-transport';
3
3
  import { Device, Characteristic, Subscription, BleManager } from 'react-native-ble-plx';
4
4
  import { Deferred } from '@onekeyfe/hd-shared';
5
5
  import EventEmitter from 'events';
@@ -46,6 +46,7 @@ type FirmwareInstallBleAcquireInput = BleAcquireInput & {
46
46
  */
47
47
  skipProtocolProbe?: boolean;
48
48
  };
49
+ declare const transport: typeof transportModule__default;
49
50
  type FirmwareUploadWriteRetryType = 'congested';
50
51
  type ResolvedBleCharacteristics = {
51
52
  writeCharacteristic: Characteristic;
@@ -125,8 +126,8 @@ declare const BLE_SETUP_WEDGED_MESSAGE = "BLE setup wedged repeatedly";
125
126
  type IOneKeyDevice = OneKeyDeviceInfoBase & Device & Pick<OneKeyMobileDeviceInfo, 'bleColorCode'>;
126
127
  declare class ReactNativeBleTransport {
127
128
  blePlxManager: BleManager | undefined;
128
- _messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
129
- _messagesV2: ReturnType<typeof transport__default.parseConfigure> | undefined;
129
+ _messages: ReturnType<typeof transport.parseConfigure> | undefined;
130
+ _messagesV2: ReturnType<typeof transport.parseConfigure> | undefined;
130
131
  private protocolV2SchemaConfiguration;
131
132
  name: string;
132
133
  configured: boolean;
@@ -203,11 +204,11 @@ declare class ReactNativeBleTransport {
203
204
  }>;
204
205
  private acquireUnlocked;
205
206
  _monitorCharacteristic(characteristic: Characteristic, uuid: string, monitorToken: number, notifyTransactionId: string): Subscription;
206
- release(uuid: string, onclose?: boolean): Promise<boolean>;
207
+ release(uuid: string, onclose?: boolean, keepSession?: boolean): Promise<boolean>;
207
208
  private releaseUnlocked;
208
209
  private releaseNative;
209
210
  post(session: string, name: string, data: Record<string, unknown>): Promise<void>;
210
- call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<transport.MessageFromOneKey>;
211
+ call(uuid: string, name: string, data: Record<string, unknown>, options?: TransportCallOptions): Promise<transportModule.MessageFromOneKey>;
211
212
  private callProtocolV1;
212
213
  stop(): Promise<void>;
213
214
  disconnect(session: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAI3B,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA4BhC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE,KAAK,8BAA8B,GAAG,eAAe,GAAG;IAMtD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAkBF,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;IAChC,mBAAmB,EAAE,cAAc,CAAC;IACpC,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC;AAkCF,eAAO,MAAM,+BAA+B,UACnC,OAAO,KACb,4BAA4B,GAAG,IAsBjC,CAAC;AAcF,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAClD,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AA4BpD,eAAO,MAAM,yCAAyC,IAAI,CAAC;AAI3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAK7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAK3B,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,qBAAqB;IAoB7B,MAAM;YAoBE,mBAAmB;YA4DnB,eAAe;YA6Bf,kBAAkB;YAkDlB,iCAAiC;IA8D/C,OAAO,CAAC,wBAAwB;IAwChC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IAyC5B,OAAO,CAAC,kBAAkB;IA8B1B,OAAO,CAAC,eAAe;IAkEvB,OAAO,CAAC,2BAA2B;IAQnC,OAAO,CAAC,4BAA4B;IAIpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YA+Gd,0BAA0B;YAsB1B,iCAAiC;YAoDjC,eAAe;YAsBf,eAAe;IA2B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;YAiBnB,qBAAqB;YA8DrB,oBAAoB;IA2DlC,OAAO,CAAC,kCAAkC;YA2B5B,0BAA0B;IA+FxC,OAAO,CAAC,0BAA0B;IAMlC,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,0BAA0B;IAOlC,OAAO,CAAC,0BAA0B;YAQpB,cAAc;YAmHd,iCAAiC;IAsB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IA+BjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAwD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.js CHANGED
@@ -6,15 +6,15 @@ var reactNative = require('react-native');
6
6
  var buffer = require('buffer');
7
7
  var reactNativeBlePlx = require('react-native-ble-plx');
8
8
  var ByteBuffer = require('bytebuffer');
9
- var transport = require('@onekeyfe/hd-transport');
9
+ var transportModule = require('@onekeyfe/hd-transport');
10
10
  var hdShared = require('@onekeyfe/hd-shared');
11
- var BleUtils = require('@onekeyfe/react-native-ble-utils');
11
+ var BleUtilsModule = require('@onekeyfe/react-native-ble-utils');
12
12
 
13
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
14
 
15
15
  var ByteBuffer__default = /*#__PURE__*/_interopDefaultLegacy(ByteBuffer);
16
- var transport__default = /*#__PURE__*/_interopDefaultLegacy(transport);
17
- var BleUtils__default = /*#__PURE__*/_interopDefaultLegacy(BleUtils);
16
+ var transportModule__default = /*#__PURE__*/_interopDefaultLegacy(transportModule);
17
+ var BleUtilsModule__default = /*#__PURE__*/_interopDefaultLegacy(BleUtilsModule);
18
18
 
19
19
  /******************************************************************************
20
20
  Copyright (c) Microsoft Corporation.
@@ -56,7 +56,9 @@ const bleLogger = {
56
56
  warn: (...args) => { var _a; return (_a = activeLogger === null || activeLogger === void 0 ? void 0 : activeLogger.warn) === null || _a === void 0 ? void 0 : _a.call(activeLogger, ...args); },
57
57
  };
58
58
 
59
+ var _a$1;
59
60
  const Logger = bleLogger;
61
+ const BleUtils = (_a$1 = BleUtilsModule__default["default"].default) !== null && _a$1 !== void 0 ? _a$1 : BleUtilsModule__default["default"];
60
62
  const bondFailureReasons = {
61
63
  1: 'authentication_failed',
62
64
  2: 'rejected',
@@ -68,8 +70,8 @@ const bondFailureReasons = {
68
70
  8: 'remote_canceled',
69
71
  9: 'removed',
70
72
  };
71
- const getConnectedDeviceIds = (serviceUuids) => BleUtils__default["default"].getConnectedPeripherals(serviceUuids);
72
- const pairDevice = (macAddress) => BleUtils__default["default"].pairDevice(macAddress);
73
+ const getConnectedDeviceIds = (serviceUuids) => BleUtils.getConnectedPeripherals(serviceUuids);
74
+ const pairDevice = (macAddress) => BleUtils.pairDevice(macAddress);
73
75
  const SYSTEM_BONDING_RESTART_WINDOW_MS = 1500;
74
76
  const createBondFailureError = (bondState) => {
75
77
  var _a;
@@ -112,7 +114,7 @@ const onDeviceBondState = (bleMacAddress, signal, options) => new Promise((resol
112
114
  reason: 'timeout',
113
115
  }));
114
116
  }, 60 * 1000);
115
- const cleanupListener = BleUtils__default["default"].onDeviceBondState(peripheral => {
117
+ const cleanupListener = BleUtils.onDeviceBondState(peripheral => {
116
118
  var _a;
117
119
  if (((_a = peripheral.id) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== bleMacAddress.toLowerCase()) {
118
120
  return;
@@ -298,9 +300,9 @@ const isHeaderChunk = (chunk) => {
298
300
  if (chunk.length < 9)
299
301
  return false;
300
302
  const [MagicQuestionMark, sharp1, sharp2] = chunk;
301
- if (String.fromCharCode(MagicQuestionMark) === String.fromCharCode(transport.PROTOCOL_V1_REPORT_ID) &&
302
- String.fromCharCode(sharp1) === String.fromCharCode(transport.PROTOCOL_V1_HEADER_BYTE) &&
303
- String.fromCharCode(sharp2) === String.fromCharCode(transport.PROTOCOL_V1_HEADER_BYTE)) {
303
+ if (String.fromCharCode(MagicQuestionMark) === String.fromCharCode(transportModule.PROTOCOL_V1_REPORT_ID) &&
304
+ String.fromCharCode(sharp1) === String.fromCharCode(transportModule.PROTOCOL_V1_HEADER_BYTE) &&
305
+ String.fromCharCode(sharp2) === String.fromCharCode(transportModule.PROTOCOL_V1_HEADER_BYTE)) {
304
306
  return true;
305
307
  }
306
308
  return false;
@@ -321,7 +323,9 @@ class BleTransport {
321
323
  }
322
324
  }
323
325
 
324
- const { check, ProtocolV1, parseConfigure } = transport__default["default"];
326
+ var _a;
327
+ const transport = (_a = transportModule__default["default"].default) !== null && _a !== void 0 ? _a : transportModule__default["default"];
328
+ const { check, ProtocolV1, parseConfigure } = transport;
325
329
  const Log = bleLogger;
326
330
  const transportCache = {};
327
331
  let bleManagerResetPromise;
@@ -711,7 +715,7 @@ class ReactNativeBleTransport {
711
715
  this.protocolV2Assemblers = new Map();
712
716
  this.protocolV2FrameQueues = new Map();
713
717
  this.protocolV2FramePromises = new Map();
714
- this.protocolV2Links = new transport.ProtocolV2LinkManager({
718
+ this.protocolV2Links = new transportModule.ProtocolV2LinkManager({
715
719
  getSchemas: () => {
716
720
  if (!this._messages || !this._messagesV2) {
717
721
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
@@ -925,7 +929,7 @@ class ReactNativeBleTransport {
925
929
  return;
926
930
  }
927
931
  this.disconnectEventTokens.set(uuid, token);
928
- (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.emit(transport.TRANSPORT_EVENT.DEVICE_DISCONNECT, {
932
+ (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.emit(transportModule.TRANSPORT_EVENT.DEVICE_DISCONNECT, {
929
933
  name,
930
934
  id: uuid,
931
935
  connectId: uuid,
@@ -1113,18 +1117,18 @@ class ReactNativeBleTransport {
1113
1117
  const { writeCharacteristic, notifyCharacteristic } = characteristics !== null && characteristics !== void 0 ? characteristics : (yield this.resolveCharacteristicsWithTimeout(uuid, device));
1114
1118
  if (this.stopped)
1115
1119
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1116
- const transport$1 = new BleTransport(device, writeCharacteristic, notifyCharacteristic);
1117
- transport$1.mtuSize = typeof device.mtu === 'number' ? device.mtu : undefined;
1120
+ const transport = new BleTransport(device, writeCharacteristic, notifyCharacteristic);
1121
+ transport.mtuSize = typeof device.mtu === 'number' ? device.mtu : undefined;
1118
1122
  const monitorToken = this.nextMonitorToken;
1119
1123
  this.nextMonitorToken += 1;
1120
1124
  const notifyTransactionId = `${uuid}:notify:${monitorToken}`;
1121
- transport$1.monitorToken = monitorToken;
1122
- transport$1.notifyTransactionId = notifyTransactionId;
1125
+ transport.monitorToken = monitorToken;
1126
+ transport.notifyTransactionId = notifyTransactionId;
1123
1127
  this.monitorTokens.set(uuid, monitorToken);
1124
- transport$1.notifySubscription = this._monitorCharacteristic(transport$1.notifyCharacteristic, uuid, monitorToken, notifyTransactionId);
1125
- transportCache[uuid] = transport$1;
1128
+ transport.notifySubscription = this._monitorCharacteristic(transport.notifyCharacteristic, uuid, monitorToken, notifyTransactionId);
1129
+ transportCache[uuid] = transport;
1126
1130
  this.protocolV2HighVolumeLogSignatures.set(uuid, new Set());
1127
- this.protocolV2Assemblers.set(uuid, new transport.ProtocolV2FrameAssembler(transport.PROTOCOL_V2_BLE_FRAME_MAX_BYTES));
1131
+ this.protocolV2Assemblers.set(uuid, new transportModule.ProtocolV2FrameAssembler(transportModule.PROTOCOL_V2_BLE_FRAME_MAX_BYTES));
1128
1132
  if (reactNative.Platform.OS === 'ios') {
1129
1133
  yield new Promise(resolve => {
1130
1134
  setTimeout(resolve, IOS_NOTIFY_READY_DELAY_MS);
@@ -1139,9 +1143,9 @@ class ReactNativeBleTransport {
1139
1143
  connectionId: monitorToken,
1140
1144
  platform: reactNative.Platform.OS,
1141
1145
  requested: getRequestedBleMtu(),
1142
- actual: transport$1.mtuSize,
1146
+ actual: transport.mtuSize,
1143
1147
  });
1144
- return transport$1;
1148
+ return transport;
1145
1149
  });
1146
1150
  }
1147
1151
  acquire(input) {
@@ -1521,7 +1525,7 @@ class ReactNativeBleTransport {
1521
1525
  else {
1522
1526
  buffer$1 = buffer$1.concat([...data]);
1523
1527
  }
1524
- if (buffer$1.length - transport.PROTOCOL_V1_MESSAGE_HEADER_SIZE >= bufferLength) {
1528
+ if (buffer$1.length - transportModule.PROTOCOL_V1_MESSAGE_HEADER_SIZE >= bufferLength) {
1525
1529
  const value = buffer.Buffer.from(buffer$1);
1526
1530
  bufferLength = 0;
1527
1531
  buffer$1 = [];
@@ -1543,13 +1547,23 @@ class ReactNativeBleTransport {
1543
1547
  }, notifyTransactionId);
1544
1548
  return subscription;
1545
1549
  }
1546
- release(uuid, onclose = false) {
1550
+ release(uuid, onclose = false, keepSession = false) {
1547
1551
  return __awaiter(this, void 0, void 0, function* () {
1548
- return this.runLifecycleOperation(uuid, () => this.releaseUnlocked(uuid, onclose));
1552
+ return this.runLifecycleOperation(uuid, () => this.releaseUnlocked(uuid, onclose, keepSession));
1549
1553
  });
1550
1554
  }
1551
- releaseUnlocked(uuid, onclose = false) {
1555
+ releaseUnlocked(uuid, onclose = false, keepSession = false) {
1552
1556
  return __awaiter(this, void 0, void 0, function* () {
1557
+ const transport = transportCache[uuid];
1558
+ if (keepSession &&
1559
+ !onclose &&
1560
+ transport &&
1561
+ this.deviceProtocol.get(uuid) === 'V2' &&
1562
+ !this.protocolV2FrameWrites.has(uuid) &&
1563
+ !this.protocolV2FramePromises.has(uuid)) {
1564
+ yield this.runNativeTeardown(uuid, this.blePlxManager, () => this.restoreAndroidConnectionPriority(uuid, transport));
1565
+ return true;
1566
+ }
1553
1567
  const reason = 'React Native BLE transport released';
1554
1568
  this.cancelProtocolV2FrameWrite(uuid, new Error(reason));
1555
1569
  yield this.protocolV2Links.invalidateLink(uuid, reason);
@@ -2526,7 +2540,7 @@ class ReactNativeBleTransport {
2526
2540
  }
2527
2541
  this.probingProtocols.set(uuid, 'V2');
2528
2542
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
2529
- const detected = yield transport.probeProtocolV2({
2543
+ const detected = yield transportModule.probeProtocolV2({
2530
2544
  call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
2531
2545
  timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
2532
2546
  logger: Log,
@@ -2664,26 +2678,26 @@ class ReactNativeBleTransport {
2664
2678
  }
2665
2679
  });
2666
2680
  }
2667
- writeProtocolV2Frame(uuid, transport$1, frame, context, assertCurrentGeneration) {
2681
+ writeProtocolV2Frame(uuid, transport, frame, context, assertCurrentGeneration) {
2668
2682
  return __awaiter(this, void 0, void 0, function* () {
2669
2683
  const tuning = getProtocolV2BleTuning();
2670
2684
  const packetCapacity = resolveProtocolV2PacketCapacity({
2671
2685
  platform: reactNative.Platform.OS,
2672
2686
  iosPacketLength: tuning.iosPacketLength,
2673
2687
  androidPacketLength: tuning.androidPacketLength,
2674
- mtu: transport$1.mtuSize,
2688
+ mtu: transport.mtuSize,
2675
2689
  });
2676
2690
  const perf = this.getProtocolV2FileWritePerf(uuid, context);
2677
2691
  const startedAt = perf ? nowMs() : 0;
2678
2692
  const nativeFrameWriter = frame.length > packetCapacity
2679
- ? this.resolveProtocolV2NativeFrameWriter(transport$1, context, tuning.nativeFrameWrite)
2693
+ ? this.resolveProtocolV2NativeFrameWriter(transport, context, tuning.nativeFrameWrite)
2680
2694
  : undefined;
2681
2695
  perf === null || perf === void 0 ? void 0 : perf.startFrame(nativeFrameWriter ? 'native-frame' : 'per-packet');
2682
2696
  if (nativeFrameWriter) {
2683
- yield this.writeProtocolV2NativeFrame(uuid, transport$1, nativeFrameWriter, frame, packetCapacity, context, assertCurrentGeneration);
2697
+ yield this.writeProtocolV2NativeFrame(uuid, transport, nativeFrameWriter, frame, packetCapacity, context, assertCurrentGeneration);
2684
2698
  }
2685
2699
  else {
2686
- yield transport.writeProtocolV2BleFrame({
2700
+ yield transportModule.writeProtocolV2BleFrame({
2687
2701
  frame,
2688
2702
  packetCapacity,
2689
2703
  assertActive: assertCurrentGeneration,
@@ -2692,7 +2706,7 @@ class ReactNativeBleTransport {
2692
2706
  wait: delay,
2693
2707
  writePacket: (packet) => __awaiter(this, void 0, void 0, function* () {
2694
2708
  const packetStartedAt = perf ? nowMs() : 0;
2695
- yield this.writeProtocolV2Packet(uuid, transport$1, buffer.Buffer.from(packet).toString('base64'), context, assertCurrentGeneration);
2709
+ yield this.writeProtocolV2Packet(uuid, transport, buffer.Buffer.from(packet).toString('base64'), context, assertCurrentGeneration);
2696
2710
  perf === null || perf === void 0 ? void 0 : perf.recordPacket(nowMs() - packetStartedAt);
2697
2711
  }),
2698
2712
  });
@@ -2835,7 +2849,7 @@ class ReactNativeBleTransport {
2835
2849
  }
2836
2850
  const isProtocolProbe = this.probingProtocols.get(uuid) === 'V2';
2837
2851
  const callOptions = options;
2838
- const highThroughputWrite = transport.isProtocolV2HighThroughputCall(name);
2852
+ const highThroughputWrite = transportModule.isProtocolV2HighThroughputCall(name);
2839
2853
  if (highThroughputWrite) {
2840
2854
  yield this.ensureProtocolV2HighThroughputMtu(uuid);
2841
2855
  const tuning = getProtocolV2BleTuning();
@@ -3007,8 +3021,8 @@ class ReactNativeBleTransport {
3007
3021
  }
3008
3022
  };
3009
3023
  return {
3010
- router: transport.PROTOCOL_V2_CHANNEL_BLE_UART,
3011
- maxFrameBytes: transport.PROTOCOL_V2_BLE_FRAME_MAX_BYTES,
3024
+ router: transportModule.PROTOCOL_V2_CHANNEL_BLE_UART,
3025
+ maxFrameBytes: transportModule.PROTOCOL_V2_BLE_FRAME_MAX_BYTES,
3012
3026
  generation,
3013
3027
  prepareCall: () => {
3014
3028
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.8-alpha.127",
3
+ "version": "1.2.8-alpha.129",
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.8-alpha.127",
24
- "@onekeyfe/hd-shared": "1.2.8-alpha.127",
25
- "@onekeyfe/hd-transport": "1.2.8-alpha.127",
23
+ "@onekeyfe/hd-core": "1.2.8-alpha.129",
24
+ "@onekeyfe/hd-shared": "1.2.8-alpha.129",
25
+ "@onekeyfe/hd-transport": "1.2.8-alpha.129",
26
26
  "@onekeyfe/react-native-ble-utils": "0.1.9",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "1fdcafbc25357d5f4372dc8f89f8c97e561fd153"
29
+ "gitHead": "e340d9447b375a9d79afd737bec50ff8c5a46aba"
30
30
  }
package/src/BleManager.ts CHANGED
@@ -1,4 +1,4 @@
1
- import BleUtils from '@onekeyfe/react-native-ble-utils';
1
+ import BleUtilsModule from '@onekeyfe/react-native-ble-utils';
2
2
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
3
 
4
4
  import { bleLogger } from './logger';
@@ -6,6 +6,9 @@ import { bleLogger } from './logger';
6
6
  import type { Peripheral } from '@onekeyfe/react-native-ble-utils';
7
7
 
8
8
  const Logger = bleLogger;
9
+ const BleUtils =
10
+ (BleUtilsModule as typeof BleUtilsModule & { default?: typeof BleUtilsModule }).default ??
11
+ BleUtilsModule;
9
12
 
10
13
  // Android BluetoothDevice.EXTRA_UNBOND_REASON values.
11
14
  const bondFailureReasons: Record<number, string> = {
@@ -0,0 +1,48 @@
1
+ import { getConnectedDeviceIds } from '../BleManager';
2
+ import ReactNativeBleTransport from '../index';
3
+
4
+ jest.mock('react-native', () => ({ PermissionsAndroid: {}, Platform: { OS: 'android' } }), {
5
+ virtual: true,
6
+ });
7
+
8
+ jest.mock('react-native-ble-plx', () => ({
9
+ BleError: class BleError extends Error {},
10
+ BleErrorCode: {},
11
+ BleManager: jest.fn(),
12
+ ConnectionPriority: { Balanced: 0, High: 1, LowPower: 2 },
13
+ ScanMode: { LowLatency: 2 },
14
+ }));
15
+
16
+ jest.mock('../subscribeBleOn', () => ({
17
+ subscribeBleOn: jest.fn(),
18
+ }));
19
+
20
+ jest.mock('@onekeyfe/react-native-ble-utils', () => ({
21
+ default: { getConnectedPeripherals: jest.fn(() => Promise.resolve([])) },
22
+ }));
23
+
24
+ jest.mock('@onekeyfe/hd-transport', () => {
25
+ const actual = jest.requireActual('@onekeyfe/hd-transport');
26
+ return { ...actual, __esModule: true, default: actual };
27
+ });
28
+
29
+ describe('CommonJS external module interop', () => {
30
+ test('reads the BLE utilities singleton from its default export', async () => {
31
+ await expect(getConnectedDeviceIds([])).resolves.toEqual([]);
32
+ });
33
+
34
+ test('configures both protocol schemas through the transport default export', () => {
35
+ const transport = new ReactNativeBleTransport({ scanTimeout: 1 });
36
+ const schema = {
37
+ nested: {
38
+ Ping: { fields: {} },
39
+ MessageType: { values: { MessageType_Ping: 60206 } },
40
+ },
41
+ };
42
+
43
+ expect(() => transport.configure(schema)).not.toThrow();
44
+ expect(() => transport.configureProtocolV2(schema)).not.toThrow();
45
+ expect(transport.configured).toBe(true);
46
+ expect(transport._messagesV2).toBeDefined();
47
+ });
48
+ });
@@ -207,6 +207,7 @@ const createHarness = ({
207
207
  bleManager,
208
208
  sentSeqs,
209
209
  writeCharacteristic,
210
+ notifyCharacteristic,
210
211
  setShouldRespond(value: boolean) {
211
212
  shouldRespond = value;
212
213
  },
@@ -1886,6 +1887,80 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
1886
1887
  await transport.release(uuid, true);
1887
1888
  });
1888
1889
 
1890
+ test.each(['ios', 'android'] as const)(
1891
+ 'reuses the connection, monitor and V2 sequence after a kept-alive release on %s',
1892
+ async platform => {
1893
+ setPlatformOS(platform);
1894
+ const { transport, uuid, device, bleManager, notifyCharacteristic, sentSeqs } =
1895
+ createHarness();
1896
+ await transport.acquire({ uuid, expectedProtocol: 'V2' });
1897
+ await transport.call(uuid, 'Ping', { message: 'before-release' });
1898
+ const connectCount = device.connect.mock.calls.length;
1899
+ const cancelTransactionCount = bleManager.cancelTransaction.mock.calls.length;
1900
+ const subscription = notifyCharacteristic.monitor.mock.results[0].value;
1901
+ const invalidateLink = jest.spyOn((transport as any).protocolV2Links, 'invalidateLink');
1902
+
1903
+ try {
1904
+ await transport.release(uuid, false, true);
1905
+ expect(transport.getProtocolType(uuid)).toBe('V2');
1906
+ expect(subscription.remove).not.toHaveBeenCalled();
1907
+ expect(invalidateLink).not.toHaveBeenCalled();
1908
+ expect(bleManager.cancelTransaction).toHaveBeenCalledTimes(cancelTransactionCount);
1909
+ expect(bleManager.cancelDeviceConnection).not.toHaveBeenCalled();
1910
+
1911
+ await transport.acquire({ uuid, expectedProtocol: 'V2' });
1912
+ await expect(
1913
+ transport.call(uuid, 'Ping', { message: 'after-release' })
1914
+ ).resolves.toMatchObject({
1915
+ type: 'Success',
1916
+ });
1917
+ expect(device.connect).toHaveBeenCalledTimes(connectCount);
1918
+ expect(notifyCharacteristic.monitor).toHaveBeenCalledTimes(1);
1919
+ expect(device.onDisconnected).toHaveBeenCalledTimes(1);
1920
+ expect(sentSeqs).toEqual([1, 2, 3]);
1921
+ } finally {
1922
+ await transport.disconnect(uuid);
1923
+ }
1924
+ }
1925
+ );
1926
+
1927
+ test.each(['ios', 'android'] as const)(
1928
+ 'keeps the legacy release path without retention and for V1 on %s',
1929
+ async platform => {
1930
+ setPlatformOS(platform);
1931
+ for (const protocol of ['V1', 'V2'] as const) {
1932
+ const { transport, uuid } = protocol === 'V1' ? createV1Harness() : createHarness();
1933
+ await transport.acquire({ uuid, expectedProtocol: protocol });
1934
+ const releaseNative = jest.spyOn(transport as any, 'releaseNative');
1935
+ await transport.release(uuid, false, protocol === 'V1');
1936
+ expect(releaseNative).toHaveBeenCalledWith(uuid, false);
1937
+ await transport.release(uuid, true);
1938
+ }
1939
+ }
1940
+ );
1941
+
1942
+ test.each([
1943
+ ['ios', 'disconnect'],
1944
+ ['android', 'disconnect'],
1945
+ ['ios', 'stop'],
1946
+ ['android', 'stop'],
1947
+ ['ios', 'onclose'],
1948
+ ['android', 'onclose'],
1949
+ ] as const)('cleans up a retained link on %s / %s', async (platform, action) => {
1950
+ setPlatformOS(platform);
1951
+ const { transport, uuid, notifyCharacteristic } = createHarness();
1952
+ await transport.acquire({ uuid, expectedProtocol: 'V2' });
1953
+ await transport.release(uuid, false, true);
1954
+ const subscription = notifyCharacteristic.monitor.mock.results[0].value;
1955
+
1956
+ if (action === 'onclose') await transport.release(uuid, true, true);
1957
+ else if (action === 'stop') await transport.stop();
1958
+ else await transport.disconnect(uuid);
1959
+
1960
+ expect(subscription.remove).toHaveBeenCalledTimes(1);
1961
+ expect(transport.getProtocolType(uuid)).toBeUndefined();
1962
+ });
1963
+
1889
1964
  test('rejects the active Protocol V2 reader when the current monitor errors', async () => {
1890
1965
  const harness = createHarness();
1891
1966
  const { transport, uuid, sentSeqs } = harness;
@@ -1929,6 +2004,8 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
1929
2004
  return Promise.resolve();
1930
2005
  });
1931
2006
 
2007
+ await transport.acquire({ uuid, expectedProtocol: 'V2' });
2008
+ await transport.release(uuid, false, true);
1932
2009
  await transport.acquire({ uuid, expectedProtocol: 'V2' });
1933
2010
  harness.setShouldRespond(false);
1934
2011
  await expect(transport.call(uuid, 'Ping', {}, { timeoutMs: 10 })).rejects.toMatchObject({
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  ScanMode,
9
9
  } from 'react-native-ble-plx';
10
10
  import ByteBuffer from 'bytebuffer';
11
- import transport, {
11
+ import transportModule, {
12
12
  type OneKeyDeviceInfoBase,
13
13
  type OneKeyMobileDeviceInfo,
14
14
  PROTOCOL_V1_MESSAGE_HEADER_SIZE,
@@ -69,6 +69,9 @@ type FirmwareInstallBleAcquireInput = BleAcquireInput & {
69
69
  skipProtocolProbe?: boolean;
70
70
  };
71
71
 
72
+ const transport: typeof transportModule =
73
+ (transportModule as typeof transportModule & { default?: typeof transportModule }).default ??
74
+ transportModule;
72
75
  const { check, ProtocolV1, parseConfigure } = transport;
73
76
 
74
77
  const Log = bleLogger;
@@ -1747,11 +1750,26 @@ export default class ReactNativeBleTransport {
1747
1750
  return subscription;
1748
1751
  }
1749
1752
 
1750
- async release(uuid: string, onclose = false) {
1751
- return this.runLifecycleOperation(uuid, () => this.releaseUnlocked(uuid, onclose));
1753
+ async release(uuid: string, onclose = false, keepSession = false) {
1754
+ return this.runLifecycleOperation(uuid, () => this.releaseUnlocked(uuid, onclose, keepSession));
1752
1755
  }
1753
1756
 
1754
- private async releaseUnlocked(uuid: string, onclose = false) {
1757
+ private async releaseUnlocked(uuid: string, onclose = false, keepSession = false) {
1758
+ const transport = transportCache[uuid];
1759
+ if (
1760
+ keepSession &&
1761
+ !onclose &&
1762
+ transport &&
1763
+ this.deviceProtocol.get(uuid) === 'V2' &&
1764
+ !this.protocolV2FrameWrites.has(uuid) &&
1765
+ !this.protocolV2FramePromises.has(uuid)
1766
+ ) {
1767
+ // Keep the monitor generation and V2 session together when reusing the link.
1768
+ await this.runNativeTeardown(uuid, this.blePlxManager, () =>
1769
+ this.restoreAndroidConnectionPriority(uuid, transport)
1770
+ );
1771
+ return true;
1772
+ }
1755
1773
  const reason = 'React Native BLE transport released';
1756
1774
  this.cancelProtocolV2FrameWrite(uuid, new Error(reason));
1757
1775
  await this.protocolV2Links.invalidateLink(uuid, reason);