@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.cjs +11 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +11 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -840,6 +840,7 @@ function normalize(c, fallback) {
|
|
|
840
840
|
// src/captions.ts
|
|
841
841
|
var TICK_MS = 100;
|
|
842
842
|
var STALE_MS = 5e3;
|
|
843
|
+
var MAX_QUEUE_MS = 4e3;
|
|
843
844
|
var MebiusCaptions = class extends TypedEmitter {
|
|
844
845
|
/** @internal */
|
|
845
846
|
constructor(signaling, player, opts) {
|
|
@@ -881,22 +882,27 @@ var MebiusCaptions = class extends TypedEmitter {
|
|
|
881
882
|
if (frame.type !== "caption" || !frame.segmentId) return;
|
|
882
883
|
const prev = this.pending.get(frame.segmentId);
|
|
883
884
|
if (prev && (frame.rev ?? 0) < (prev.rev ?? 0)) return;
|
|
885
|
+
frame.receivedAtMs = Date.now();
|
|
884
886
|
this.pending.set(frame.segmentId, frame);
|
|
885
887
|
}
|
|
886
888
|
tick() {
|
|
887
889
|
const now = this.player.currentEpochMs();
|
|
888
|
-
if (now == null) return;
|
|
889
890
|
for (const [id, frame] of this.pending) {
|
|
890
891
|
const due = frame.epochMs ?? 0;
|
|
891
|
-
|
|
892
|
-
|
|
892
|
+
const waitedMs = Date.now() - (frame.receivedAtMs ?? 0);
|
|
893
|
+
const dueNow = now == null ? true : due <= now;
|
|
894
|
+
if (!dueNow) {
|
|
895
|
+
if (waitedMs < MAX_QUEUE_MS) continue;
|
|
896
|
+
}
|
|
897
|
+
if (waitedMs > STALE_MS && this.shown.has(id)) {
|
|
893
898
|
this.pending.delete(id);
|
|
894
|
-
|
|
899
|
+
this.shown.delete(id);
|
|
900
|
+
this.emit("cleared", { segmentId: id });
|
|
895
901
|
continue;
|
|
896
902
|
}
|
|
903
|
+
if (this.shown.has(id) && frame.state === "final") continue;
|
|
897
904
|
this.shown.add(id);
|
|
898
905
|
this.emit("segment", toSegment(id, frame, this.opts.lang));
|
|
899
|
-
if (frame.state === "final") this.pending.delete(id);
|
|
900
906
|
}
|
|
901
907
|
}
|
|
902
908
|
};
|