@qq1948037137/adminsmart-ui 0.1.23 → 0.1.24

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.js CHANGED
@@ -535,6 +535,38 @@ function replayRange(totalTime, startOffsetMs = 0, endOffsetMs) {
535
535
  // 内部转可见。
536
536
  };
537
537
  }
538
+ function replayPlaybackWindow(events, startOffsetMs = 0, endOffsetMs) {
539
+ const firstTimestamp = finiteReplayNumber(events[0]?.timestamp);
540
+ const originalTotal = Math.max(0, finiteReplayNumber(events.at(-1)?.timestamp) - firstTimestamp);
541
+ const range = replayRange(originalTotal, startOffsetMs, endOffsetMs);
542
+ if (endOffsetMs === void 0) return { events: structuredClone(events), range };
543
+ const endTimestamp = firstTimestamp + range.end;
544
+ const withinEnd = events.filter((event) => event.timestamp <= endTimestamp);
545
+ if (!withinEnd.some((event) => event.type === 2))
546
+ throw new Error("\u5F53\u524D\u56DE\u653E\u7A97\u53E3\u65E9\u4E8E\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762");
547
+ const completeEvents = withinEnd.filter((event, index) => {
548
+ if (event.type !== 4) return true;
549
+ for (let next = index + 1; next < withinEnd.length; next += 1) {
550
+ if (withinEnd[next].type === 2) return true;
551
+ if (withinEnd[next].type === 4) break;
552
+ }
553
+ return false;
554
+ });
555
+ const copied = structuredClone(completeEvents);
556
+ copied.push({
557
+ type: 5,
558
+ // 官方Custom事件只提供时间调度,不改变页面DOM。
559
+ timestamp: endTimestamp,
560
+ // 请求终点成为官方metadata真实终点,尾部观察时间不缩短。
561
+ data: {
562
+ tag: "adminsmart-replay-boundary",
563
+ // 内部固定标记,不承载业务信息或外部回调。
564
+ payload: null
565
+ // 空载荷不包含用户数据。
566
+ }
567
+ });
568
+ return { events: copied, range };
569
+ }
538
570
  function inclusivePauseOffset(events, target) {
539
571
  const logicalTarget = Math.max(0, finiteReplayNumber(target));
540
572
  const baseline = finiteReplayNumber(events[0]?.timestamp) + logicalTarget;
@@ -627,11 +659,13 @@ function useSessionReplay(options) {
627
659
  publish(initialState("empty"));
628
660
  return;
629
661
  }
662
+ let playback;
630
663
  let prepared;
631
664
  try {
632
- prepared = prepareReplayEvents(events);
665
+ playback = replayPlaybackWindow(prepareReplayEvents(events), startOffsetMs, endOffsetMs);
666
+ prepared = playback.events;
633
667
  } catch (reason) {
634
- const knownMessages = ["\u5F53\u524D\u56DE\u653E\u6CA1\u6709\u8DB3\u591F\u7684\u9875\u9762\u4E8B\u4EF6", "\u5F53\u524D\u56DE\u653E\u4E8B\u4EF6\u65F6\u95F4\u65E0\u6548\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762", "\u5F53\u524D\u56DE\u653E\u7F3A\u5C11\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762"];
668
+ const knownMessages = ["\u5F53\u524D\u56DE\u653E\u6CA1\u6709\u8DB3\u591F\u7684\u9875\u9762\u4E8B\u4EF6", "\u5F53\u524D\u56DE\u653E\u4E8B\u4EF6\u65F6\u95F4\u65E0\u6548\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762", "\u5F53\u524D\u56DE\u653E\u7F3A\u5C11\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762", "\u5F53\u524D\u56DE\u653E\u7A97\u53E3\u65E9\u4E8E\u5B8C\u6574\u9875\u9762\u5FEB\u7167\uFF0C\u65E0\u6CD5\u8FD8\u539F\u9875\u9762"];
635
669
  const problem = { code: "invalid-events", message: reason instanceof Error && knownMessages.includes(reason.message) ? reason.message : "\u5F53\u524D\u56DE\u653E\u6570\u636E\u65E0\u6CD5\u8FD8\u539F\u9875\u9762" };
636
670
  publish(initialState("error"));
637
671
  callbackRef.current.onError?.(problem);
@@ -737,7 +771,7 @@ function useSessionReplay(options) {
737
771
  // 官方日志不会带事件进入控制台。
738
772
  });
739
773
  engineRef.current = player;
740
- rangeRef.current = replayRange(player.getMetaData().totalTime, startOffsetMs, endOffsetMs);
774
+ rangeRef.current = playback.range;
741
775
  const listen = (eventName, handler) => {
742
776
  listeners.push([eventName, handler]);
743
777
  player.on(eventName, handler);