@mebius-io/web 0.5.2 → 0.5.3

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
@@ -798,6 +798,7 @@ function normalize(c, fallback) {
798
798
  // src/captions.ts
799
799
  var TICK_MS = 100;
800
800
  var STALE_MS = 5e3;
801
+ var MAX_QUEUE_MS = 4e3;
801
802
  var MebiusCaptions = class extends TypedEmitter {
802
803
  /** @internal */
803
804
  constructor(signaling, player, opts) {
@@ -839,22 +840,27 @@ var MebiusCaptions = class extends TypedEmitter {
839
840
  if (frame.type !== "caption" || !frame.segmentId) return;
840
841
  const prev = this.pending.get(frame.segmentId);
841
842
  if (prev && (frame.rev ?? 0) < (prev.rev ?? 0)) return;
843
+ frame.receivedAtMs = Date.now();
842
844
  this.pending.set(frame.segmentId, frame);
843
845
  }
844
846
  tick() {
845
847
  const now = this.player.currentEpochMs();
846
- if (now == null) return;
847
848
  for (const [id, frame] of this.pending) {
848
849
  const due = frame.epochMs ?? 0;
849
- if (due > now) continue;
850
- if (due < now - STALE_MS) {
850
+ const waitedMs = Date.now() - (frame.receivedAtMs ?? 0);
851
+ const dueNow = now == null ? true : due <= now;
852
+ if (!dueNow) {
853
+ if (waitedMs < MAX_QUEUE_MS) continue;
854
+ }
855
+ if (waitedMs > STALE_MS && this.shown.has(id)) {
851
856
  this.pending.delete(id);
852
- if (this.shown.delete(id)) this.emit("cleared", { segmentId: id });
857
+ this.shown.delete(id);
858
+ this.emit("cleared", { segmentId: id });
853
859
  continue;
854
860
  }
861
+ if (this.shown.has(id) && frame.state === "final") continue;
855
862
  this.shown.add(id);
856
863
  this.emit("segment", toSegment(id, frame, this.opts.lang));
857
- if (frame.state === "final") this.pending.delete(id);
858
864
  }
859
865
  }
860
866
  };