@onekeyfe/hd-transport-react-native 1.2.8-alpha.115 → 1.2.8-alpha.116

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
@@ -67,12 +67,18 @@ declare const BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
67
67
  type ProtocolV2BleTuning = {
68
68
  iosPacketLength?: number;
69
69
  androidPacketLength?: number;
70
+ /**
71
+ * Write each multi-packet high-throughput frame with one native call when the native
72
+ * BLE module supports it. Defaults to true; false keeps the per-packet JS write loop.
73
+ */
74
+ nativeFrameWrite?: boolean;
70
75
  };
71
76
  declare function configureProtocolV2BleTuning(tuning?: ProtocolV2BleTuning): void;
72
77
  declare function resetProtocolV2BleTuning(): void;
73
78
  declare function getProtocolV2BleTuning(): {
74
79
  iosPacketLength: number;
75
80
  androidPacketLength: number;
81
+ nativeFrameWrite: boolean;
76
82
  };
77
83
  /**
78
84
  * With no cached GATT table the stack runs its own discovery (up to ~8s) before the MTU
@@ -158,6 +164,10 @@ declare class ReactNativeBleTransport {
158
164
  private protocolV2HighVolumeLogSignatures;
159
165
  private androidHighPriorityDevices;
160
166
  private androidPriorityResetTimers;
167
+ /** In-flight native frame write per device; Protocol V2 writes are serialized per device. */
168
+ private protocolV2FrameWrites;
169
+ private protocolV2FrameWriteCounter;
170
+ private protocolV2FileWritePerfs;
161
171
  private nextMonitorToken;
162
172
  /** Serializes transport lifecycle changes for the same physical device. */
163
173
  private lifecycleOperations;
@@ -259,6 +269,21 @@ declare class ReactNativeBleTransport {
259
269
  private readProtocolV2Frame;
260
270
  private writeProtocolV2Packet;
261
271
  private writeProtocolV2Frame;
272
+ /**
273
+ * The native frame write only replaces the per-packet loop where its JS<->native round trips
274
+ * dominate: multi-packet (checked by the caller) high-throughput frames written without response.
275
+ */
276
+ private resolveProtocolV2NativeFrameWriter;
277
+ /**
278
+ * Writes one frame with a single native call that sends its packets in order without response.
279
+ * Nothing here retries it: a resend could duplicate bytes the device already received. The
280
+ * native transaction is cancelled on abort, watchdog expiry, generation change and link
281
+ * teardown so the native side stops writing a frame nobody waits for any more.
282
+ */
283
+ private writeProtocolV2NativeFrame;
284
+ /** Stops the native frame write in flight on `uuid`, optionally only one of `generation`. */
285
+ private cancelProtocolV2FrameWrite;
286
+ private cancelNativeTransaction;
262
287
  private callProtocolV2;
263
288
  private ensureProtocolV2HighThroughputMtu;
264
289
  private clearAndroidPriorityResetTimer;
@@ -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,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA2BhC,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,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BAA0B;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;IA8DlC,OAAO,CAAC,kCAAkC;YA0B5B,0BAA0B;IAgHxC,OAAO,CAAC,0BAA0B;IAMlC,OAAO,CAAC,uBAAuB;YAYjB,cAAc;YA0Hd,iCAAiC;IAsB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IAsBjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IA2D/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.js CHANGED
@@ -400,6 +400,7 @@ const ANDROID_NOTIFY_READY_DELAY_MS = 300;
400
400
  const DEFAULT_PROTOCOL_V2_BLE_TUNING = {
401
401
  iosPacketLength: IOS_PROTOCOL_V2_PACKET_LENGTH,
402
402
  androidPacketLength: ANDROID_PROTOCOL_V2_PACKET_LENGTH,
403
+ nativeFrameWrite: true,
403
404
  };
404
405
  let protocolV2BleTuning = Object.assign({}, DEFAULT_PROTOCOL_V2_BLE_TUNING);
405
406
  const normalizePositiveInteger = (value, fallback) => {
@@ -412,6 +413,9 @@ function configureProtocolV2BleTuning(tuning = {}) {
412
413
  protocolV2BleTuning = {
413
414
  iosPacketLength: normalizePositiveInteger(tuning.iosPacketLength, protocolV2BleTuning.iosPacketLength),
414
415
  androidPacketLength: normalizePositiveInteger(tuning.androidPacketLength, protocolV2BleTuning.androidPacketLength),
416
+ nativeFrameWrite: typeof tuning.nativeFrameWrite === 'boolean'
417
+ ? tuning.nativeFrameWrite
418
+ : protocolV2BleTuning.nativeFrameWrite,
415
419
  };
416
420
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
417
421
  }
@@ -422,6 +426,91 @@ function resetProtocolV2BleTuning() {
422
426
  function getProtocolV2BleTuning() {
423
427
  return Object.assign({}, protocolV2BleTuning);
424
428
  }
429
+ const getProtocolV2NativeFrameWriter = (manager) => {
430
+ var _a;
431
+ const candidate = manager;
432
+ if (!candidate || typeof candidate.writeCharacteristicWithoutResponseFrame !== 'function') {
433
+ return undefined;
434
+ }
435
+ try {
436
+ return ((_a = candidate.isWriteCharacteristicWithoutResponseFrameSupported) === null || _a === void 0 ? void 0 : _a.call(candidate)) === true
437
+ ? candidate
438
+ : undefined;
439
+ }
440
+ catch (_b) {
441
+ return undefined;
442
+ }
443
+ };
444
+ const getNativeBleErrorReason = (error) => {
445
+ const { reason, message } = (error !== null && error !== void 0 ? error : {});
446
+ if (typeof reason === 'string' && reason)
447
+ return reason;
448
+ return typeof message === 'string' && message ? message : undefined;
449
+ };
450
+ const nowMs = () => typeof performance !== 'undefined' && typeof performance.now === 'function'
451
+ ? performance.now()
452
+ : Date.now();
453
+ const roundMs = (ms) => Math.round(ms * 10) / 10;
454
+ const FILE_WRITE_PACKET_HISTOGRAM_BOUNDS_MS = [1, 2, 3, 5, 8];
455
+ const createDurationStats = () => {
456
+ let total = 0;
457
+ let count = 0;
458
+ let max = 0;
459
+ return {
460
+ add(ms) {
461
+ total += ms;
462
+ count += 1;
463
+ max = Math.max(max, ms);
464
+ },
465
+ summarize: () => ({
466
+ total: roundMs(total),
467
+ avg: count ? roundMs(total / count) : 0,
468
+ max: roundMs(max),
469
+ }),
470
+ };
471
+ };
472
+ const createProtocolV2FileWritePerf = () => {
473
+ const startedAt = nowMs();
474
+ let nativeFrames = 0;
475
+ let frames = 0;
476
+ let packets = 0;
477
+ let frameBytes = 0;
478
+ const write = createDurationStats();
479
+ const readWait = createDurationStats();
480
+ const packet = createDurationStats();
481
+ const packetHistogram = FILE_WRITE_PACKET_HISTOGRAM_BOUNDS_MS.map(() => 0).concat(0);
482
+ return {
483
+ startFrame(mode) {
484
+ if (mode === 'native-frame')
485
+ nativeFrames += 1;
486
+ },
487
+ recordFrame(bytes, framePackets, elapsedMs) {
488
+ frames += 1;
489
+ packets += framePackets;
490
+ frameBytes += bytes;
491
+ write.add(elapsedMs);
492
+ },
493
+ recordPacket(elapsedMs) {
494
+ packet.add(elapsedMs);
495
+ const bucket = FILE_WRITE_PACKET_HISTOGRAM_BOUNDS_MS.findIndex(bound => elapsedMs < bound);
496
+ packetHistogram[bucket < 0 ? FILE_WRITE_PACKET_HISTOGRAM_BOUNDS_MS.length : bucket] += 1;
497
+ },
498
+ recordReadWait(elapsedMs) {
499
+ readWait.add(elapsedMs);
500
+ },
501
+ summarize(ok) {
502
+ const mode = nativeFrames > 0 ? 'native-frame' : 'per-packet';
503
+ const packetStats = packet.summarize();
504
+ return Object.assign({ platform: reactNative.Platform.OS, mode,
505
+ ok,
506
+ frames,
507
+ packets,
508
+ frameBytes, elapsedMs: roundMs(nowMs() - startedAt), writeMs: write.summarize(), readWaitMs: readWait.summarize() }, (mode === 'per-packet'
509
+ ? { packetMs: { avg: packetStats.avg, max: packetStats.max, hist: [...packetHistogram] } }
510
+ : {}));
511
+ },
512
+ };
513
+ };
425
514
  function getDeviceDisplayName(device) {
426
515
  return (device === null || device === void 0 ? void 0 : device.name) || (device === null || device === void 0 ? void 0 : device.localName) || null;
427
516
  }
@@ -620,6 +709,9 @@ class ReactNativeBleTransport {
620
709
  this.protocolV2HighVolumeLogSignatures = new Map();
621
710
  this.androidHighPriorityDevices = new Set();
622
711
  this.androidPriorityResetTimers = new Map();
712
+ this.protocolV2FrameWrites = new Map();
713
+ this.protocolV2FrameWriteCounter = 0;
714
+ this.protocolV2FileWritePerfs = new Map();
623
715
  this.nextMonitorToken = 1;
624
716
  this.lifecycleOperations = new Map();
625
717
  this.scanCleanups = new Set();
@@ -1418,6 +1510,7 @@ class ReactNativeBleTransport {
1418
1510
  }
1419
1511
  releaseUnlocked(uuid, onclose = false) {
1420
1512
  return __awaiter(this, void 0, void 0, function* () {
1513
+ this.cancelProtocolV2FrameWrite(uuid, new Error('React Native BLE transport released'));
1421
1514
  yield this.protocolV2Links.invalidateLink(uuid, 'React Native BLE transport released');
1422
1515
  return this.releaseNative(uuid, onclose);
1423
1516
  });
@@ -1425,6 +1518,7 @@ class ReactNativeBleTransport {
1425
1518
  releaseNative(uuid, onclose = false) {
1426
1519
  var _a, _b, _c, _d, _e;
1427
1520
  return __awaiter(this, void 0, void 0, function* () {
1521
+ this.cancelProtocolV2FrameWrite(uuid, new Error('React Native BLE transport released'));
1428
1522
  const transport = transportCache[uuid];
1429
1523
  const manager = this.blePlxManager;
1430
1524
  if (this.runPromise && this.runPromiseDeviceId === uuid) {
@@ -1751,6 +1845,7 @@ class ReactNativeBleTransport {
1751
1845
  disconnectUnlocked(session) {
1752
1846
  var _a, _b, _c;
1753
1847
  return __awaiter(this, void 0, void 0, function* () {
1848
+ this.cancelProtocolV2FrameWrite(session, new Error('React Native BLE transport disconnected'));
1754
1849
  yield this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
1755
1850
  const transport = transportCache[session];
1756
1851
  const manager = this.blePlxManager;
@@ -2120,6 +2215,7 @@ class ReactNativeBleTransport {
2120
2215
  Log === null || Log === void 0 ? void 0 : Log.error('[ReactNativeBleTransport] BLE write timed out, tearing down link:', uuid, {
2121
2216
  consecutiveWriteTimeouts: timeouts,
2122
2217
  });
2218
+ this.cancelProtocolV2FrameWrite(uuid, hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, `BLE write timeout after ${BLE_WRITE_PACKET_TIMEOUT_MS}ms`));
2123
2219
  const wedged = transportCache[uuid];
2124
2220
  this.disconnect(uuid).catch(error => {
2125
2221
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] wedged link teardown failed (ignored):', error);
@@ -2143,6 +2239,7 @@ class ReactNativeBleTransport {
2143
2239
  const manager = this.blePlxManager;
2144
2240
  this.blePlxManager = undefined;
2145
2241
  const reason = 'React Native BLE manager reset';
2242
+ Array.from(this.protocolV2FrameWrites.keys()).forEach(uuid => this.cancelProtocolV2FrameWrite(uuid, new Error(reason)));
2146
2243
  Object.entries(transportCache).forEach(([uuid, cachedTransport]) => {
2147
2244
  var _a, _b, _c, _d;
2148
2245
  try {
@@ -2532,16 +2629,162 @@ class ReactNativeBleTransport {
2532
2629
  androidPacketLength: tuning.androidPacketLength,
2533
2630
  mtu: transport$1.mtuSize,
2534
2631
  });
2535
- yield transport.writeProtocolV2BleFrame({
2536
- frame,
2537
- packetCapacity,
2538
- assertActive: assertCurrentGeneration,
2539
- signal: context.signal,
2540
- abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
2541
- wait: delay,
2542
- writePacket: packet => this.writeProtocolV2Packet(uuid, transport$1, buffer.Buffer.from(packet).toString('base64'), context, assertCurrentGeneration),
2632
+ const perf = context.messageName === 'FilesystemFileWrite'
2633
+ ? this.protocolV2FileWritePerfs.get(uuid)
2634
+ : undefined;
2635
+ const startedAt = perf ? nowMs() : 0;
2636
+ const nativeFrameWriter = frame.length > packetCapacity
2637
+ ? this.resolveProtocolV2NativeFrameWriter(transport$1, context, tuning.nativeFrameWrite)
2638
+ : undefined;
2639
+ perf === null || perf === void 0 ? void 0 : perf.startFrame(nativeFrameWriter ? 'native-frame' : 'per-packet');
2640
+ if (nativeFrameWriter) {
2641
+ yield this.writeProtocolV2NativeFrame(uuid, transport$1, nativeFrameWriter, frame, packetCapacity, context, assertCurrentGeneration);
2642
+ }
2643
+ else {
2644
+ yield transport.writeProtocolV2BleFrame({
2645
+ frame,
2646
+ packetCapacity,
2647
+ assertActive: assertCurrentGeneration,
2648
+ signal: context.signal,
2649
+ abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
2650
+ wait: delay,
2651
+ writePacket: (packet) => __awaiter(this, void 0, void 0, function* () {
2652
+ const packetStartedAt = perf ? nowMs() : 0;
2653
+ yield this.writeProtocolV2Packet(uuid, transport$1, buffer.Buffer.from(packet).toString('base64'), context, assertCurrentGeneration);
2654
+ perf === null || perf === void 0 ? void 0 : perf.recordPacket(nowMs() - packetStartedAt);
2655
+ }),
2656
+ });
2657
+ }
2658
+ perf === null || perf === void 0 ? void 0 : perf.recordFrame(frame.length, Math.ceil(frame.length / packetCapacity), nowMs() - startedAt);
2659
+ });
2660
+ }
2661
+ resolveProtocolV2NativeFrameWriter(transport, context, nativeFrameWrite) {
2662
+ if (!context.highThroughput || nativeFrameWrite === false)
2663
+ return undefined;
2664
+ if (shouldWriteProtocolV2WithResponse({
2665
+ platform: reactNative.Platform.OS,
2666
+ highThroughput: context.highThroughput,
2667
+ requestedWithResponse: context.writeWithResponse,
2668
+ characteristic: transport.writeCharacteristic,
2669
+ })) {
2670
+ return undefined;
2671
+ }
2672
+ if (typeof transport.writeCharacteristic.id !== 'number')
2673
+ return undefined;
2674
+ return getProtocolV2NativeFrameWriter(this.blePlxManager);
2675
+ }
2676
+ writeProtocolV2NativeFrame(uuid, transport, manager, frame, packetCapacity, context, assertCurrentGeneration) {
2677
+ return __awaiter(this, void 0, void 0, function* () {
2678
+ const abortMessage = `Protocol V2 BLE write aborted for ${context.messageName}`;
2679
+ assertCurrentGeneration();
2680
+ if (context.signal.aborted) {
2681
+ throw new Error(abortMessage);
2682
+ }
2683
+ this.protocolV2FrameWriteCounter += 1;
2684
+ const transactionId = `${uuid}:v2frame:${context.generation}:${this.protocolV2FrameWriteCounter}`;
2685
+ let cancelError;
2686
+ let rejectCancelled = () => undefined;
2687
+ const cancelled = new Promise((_, reject) => {
2688
+ rejectCancelled = reject;
2543
2689
  });
2690
+ const active = {
2691
+ transactionId,
2692
+ generation: context.generation,
2693
+ cancel: error => {
2694
+ if (cancelError)
2695
+ return;
2696
+ cancelError = error;
2697
+ if (this.protocolV2FrameWrites.get(uuid) === active) {
2698
+ this.protocolV2FrameWrites.delete(uuid);
2699
+ }
2700
+ rejectCancelled(error);
2701
+ this.cancelNativeTransaction(manager, transactionId);
2702
+ },
2703
+ };
2704
+ const isCurrentOwner = () => {
2705
+ try {
2706
+ assertCurrentGeneration();
2707
+ return !context.signal.aborted;
2708
+ }
2709
+ catch (_a) {
2710
+ return false;
2711
+ }
2712
+ };
2713
+ const onAbort = () => active.cancel(new Error(abortMessage));
2714
+ let timer;
2715
+ let completed = false;
2716
+ let nativeError;
2717
+ try {
2718
+ const nativeWrite = Promise.resolve(manager.writeCharacteristicWithoutResponseFrame(transport.writeCharacteristic.id, buffer.Buffer.from(frame).toString('base64'), packetCapacity, transactionId));
2719
+ nativeWrite.catch(() => undefined);
2720
+ this.protocolV2FrameWrites.set(uuid, active);
2721
+ context.signal.addEventListener('abort', onAbort);
2722
+ yield Promise.race([
2723
+ nativeWrite,
2724
+ cancelled,
2725
+ new Promise((_, reject) => {
2726
+ timer = setTimeout(() => {
2727
+ const owner = isCurrentOwner();
2728
+ const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, `BLE write timeout after ${BLE_WRITE_PACKET_TIMEOUT_MS}ms`);
2729
+ active.cancel(error);
2730
+ reject(error);
2731
+ if (owner) {
2732
+ this.tearDownWedgedLink(uuid);
2733
+ }
2734
+ else {
2735
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] stale BLE frame write timed out, link kept');
2736
+ }
2737
+ }, BLE_WRITE_PACKET_TIMEOUT_MS);
2738
+ }),
2739
+ ]);
2740
+ completed = true;
2741
+ }
2742
+ catch (error) {
2743
+ nativeError = error;
2744
+ }
2745
+ finally {
2746
+ if (timer)
2747
+ clearTimeout(timer);
2748
+ context.signal.removeEventListener('abort', onAbort);
2749
+ }
2750
+ if (completed) {
2751
+ this.writeTimeoutCounts.delete(uuid);
2752
+ try {
2753
+ assertCurrentGeneration();
2754
+ }
2755
+ catch (error) {
2756
+ active.cancel(error instanceof Error ? error : new Error(String(error)));
2757
+ }
2758
+ }
2759
+ if (this.protocolV2FrameWrites.get(uuid) === active) {
2760
+ this.protocolV2FrameWrites.delete(uuid);
2761
+ }
2762
+ if (cancelError)
2763
+ throw cancelError;
2764
+ if (completed)
2765
+ return;
2766
+ if (isNativeBleDisconnectError(nativeError)) {
2767
+ throw toBleDisconnectHardwareError(nativeError);
2768
+ }
2769
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, getNativeBleErrorReason(nativeError));
2770
+ });
2771
+ }
2772
+ cancelProtocolV2FrameWrite(uuid, error, generation) {
2773
+ const active = this.protocolV2FrameWrites.get(uuid);
2774
+ if (!active || (generation !== undefined && active.generation !== generation))
2775
+ return;
2776
+ active.cancel(error);
2777
+ }
2778
+ cancelNativeTransaction(manager, transactionId) {
2779
+ const logFailure = (error) => Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 frame write cancellation failed', {
2780
+ error: error instanceof Error ? error.message : String(error),
2544
2781
  });
2782
+ try {
2783
+ Promise.resolve(manager.cancelTransaction(transactionId)).catch(logFailure);
2784
+ }
2785
+ catch (error) {
2786
+ logFailure(error);
2787
+ }
2545
2788
  }
2546
2789
  callProtocolV2(uuid, name, data, options) {
2547
2790
  var _a;
@@ -2581,12 +2824,36 @@ class ReactNativeBleTransport {
2581
2824
  packetCapacity,
2582
2825
  });
2583
2826
  }
2827
+ const frameWriteMode = this.resolveProtocolV2NativeFrameWriter(currentTransport, { highThroughput: true, writeWithResponse: options === null || options === void 0 ? void 0 : options.writeWithResponse }, tuning.nativeFrameWrite)
2828
+ ? 'native-frame'
2829
+ : 'per-packet';
2830
+ const frameWriteModeSignature = `frameWriteMode:${frameWriteMode}`;
2831
+ if (!loggedSignatures.has(frameWriteModeSignature)) {
2832
+ loggedSignatures.add(frameWriteModeSignature);
2833
+ this.protocolV2HighVolumeLogSignatures.set(uuid, loggedSignatures);
2834
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 frame write mode', {
2835
+ platform: reactNative.Platform.OS,
2836
+ mode: frameWriteMode,
2837
+ nativeFrameWrite: tuning.nativeFrameWrite,
2838
+ nativeFrameWriteSupported: !!getProtocolV2NativeFrameWriter(this.blePlxManager),
2839
+ packetCapacity,
2840
+ });
2841
+ }
2584
2842
  }
2585
2843
  if (highThroughputWrite) {
2586
2844
  yield this.enableAndroidHighConnectionPriority(uuid);
2587
2845
  }
2846
+ const fileWritePerf = name === 'FilesystemFileWrite' && (options === null || options === void 0 ? void 0 : options.fileWritePipeline)
2847
+ ? createProtocolV2FileWritePerf()
2848
+ : undefined;
2849
+ if (fileWritePerf) {
2850
+ this.protocolV2FileWritePerfs.set(uuid, fileWritePerf);
2851
+ }
2852
+ let fileWriteOk = false;
2588
2853
  try {
2589
- return yield this.protocolV2Links.call(uuid, () => this.createProtocolV2Adapter(uuid), name, data, callOptions);
2854
+ const response = yield this.protocolV2Links.call(uuid, () => this.createProtocolV2Adapter(uuid), name, data, callOptions);
2855
+ fileWriteOk = response.type !== 'Failure';
2856
+ return response;
2590
2857
  }
2591
2858
  catch (e) {
2592
2859
  Log === null || Log === void 0 ? void 0 : Log.error('[ReactNativeBleTransport] Protocol V2 call error:', e);
@@ -2604,6 +2871,12 @@ class ReactNativeBleTransport {
2604
2871
  if (highThroughputWrite) {
2605
2872
  this.scheduleAndroidBalancedConnectionPriority(uuid);
2606
2873
  }
2874
+ if (fileWritePerf) {
2875
+ if (this.protocolV2FileWritePerfs.get(uuid) === fileWritePerf) {
2876
+ this.protocolV2FileWritePerfs.delete(uuid);
2877
+ }
2878
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] FileWrite perf', fileWritePerf.summarize(fileWriteOk));
2879
+ }
2607
2880
  }
2608
2881
  });
2609
2882
  }
@@ -2704,9 +2977,14 @@ class ReactNativeBleTransport {
2704
2977
  const currentTransport = this.getCachedTransport(uuid);
2705
2978
  yield this.writeProtocolV2Frame(uuid, currentTransport, frame, context, assertCurrentGeneration);
2706
2979
  }),
2707
- readFrame: () => __awaiter(this, void 0, void 0, function* () {
2980
+ readFrame: (context) => __awaiter(this, void 0, void 0, function* () {
2708
2981
  assertCurrentGeneration();
2982
+ const perf = (context === null || context === void 0 ? void 0 : context.messageName) === 'FilesystemFileWrite'
2983
+ ? this.protocolV2FileWritePerfs.get(uuid)
2984
+ : undefined;
2985
+ const startedAt = perf ? nowMs() : 0;
2709
2986
  const rxFrame = yield this.readProtocolV2Frame(uuid);
2987
+ perf === null || perf === void 0 ? void 0 : perf.recordReadWait(nowMs() - startedAt);
2710
2988
  if (!(rxFrame instanceof Uint8Array)) {
2711
2989
  throw new Error('Protocol V2 response is not Uint8Array');
2712
2990
  }
@@ -2714,6 +2992,7 @@ class ReactNativeBleTransport {
2714
2992
  }),
2715
2993
  reset: (reason) => {
2716
2994
  var _a;
2995
+ this.cancelProtocolV2FrameWrite(uuid, new Error(reason), generation);
2717
2996
  if (this.monitorTokens.get(uuid) !== generation)
2718
2997
  return;
2719
2998
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.8-alpha.115",
3
+ "version": "1.2.8-alpha.116",
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.115",
24
- "@onekeyfe/hd-shared": "1.2.8-alpha.115",
25
- "@onekeyfe/hd-transport": "1.2.8-alpha.115",
23
+ "@onekeyfe/hd-core": "1.2.8-alpha.116",
24
+ "@onekeyfe/hd-shared": "1.2.8-alpha.116",
25
+ "@onekeyfe/hd-transport": "1.2.8-alpha.116",
26
26
  "@onekeyfe/react-native-ble-utils": "0.1.9",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "4f30138a51d564cd664fa9886f30229bebe469a5"
29
+ "gitHead": "3278c53853e85c2b3dff67caf65fcc59481f28eb"
30
30
  }