@mebius-io/web 0.5.2 → 0.5.4
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 +28 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +28 -11
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +28 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -471,7 +471,7 @@ var LIVE_FLV_CONFIG = {
|
|
|
471
471
|
var MAX_DRIFT_S = 2;
|
|
472
472
|
var EDGE_MARGIN_S = 0.4;
|
|
473
473
|
var AUDIO_RETRY_MS = 2500;
|
|
474
|
-
var
|
|
474
|
+
var UPSTREAM_LATENCY_MS = 800;
|
|
475
475
|
function stalledWithData(video, ms) {
|
|
476
476
|
if (video.currentTime > 0) return Promise.resolve(false);
|
|
477
477
|
return new Promise((resolve) => {
|
|
@@ -601,13 +601,24 @@ var FlvViewTransport = class {
|
|
|
601
601
|
return { bitrateKbps, framesPerSecond, latencyMs: void 0 };
|
|
602
602
|
}
|
|
603
603
|
/**
|
|
604
|
-
* Estimate
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
604
|
+
* Estimate — FLV carries no wall clock, so this is measured where possible
|
|
605
|
+
* and assumed where not (see {@link UPSTREAM_LATENCY_MS}).
|
|
606
|
+
*
|
|
607
|
+
* The measurable half is the decoded media queued ahead of the playhead:
|
|
608
|
+
* whatever is buffered but not yet shown is, by definition, how far behind
|
|
609
|
+
* the newest received frame this viewer is watching. A flat guess for the
|
|
610
|
+
* whole delay was previously used, and being too generous costs real time —
|
|
611
|
+
* every millisecond of over-estimate is a caption withheld for no reason,
|
|
612
|
+
* on top of the STT latency the viewer already pays.
|
|
608
613
|
*/
|
|
609
614
|
playheadEpochMs() {
|
|
610
|
-
|
|
615
|
+
let bufferedAheadMs = 0;
|
|
616
|
+
const ranges = this.video?.buffered;
|
|
617
|
+
if (ranges && ranges.length > 0 && this.video) {
|
|
618
|
+
const ahead = ranges.end(ranges.length - 1) - this.video.currentTime;
|
|
619
|
+
if (Number.isFinite(ahead) && ahead > 0) bufferedAheadMs = ahead * 1e3;
|
|
620
|
+
}
|
|
621
|
+
return Date.now() - UPSTREAM_LATENCY_MS - bufferedAheadMs;
|
|
611
622
|
}
|
|
612
623
|
};
|
|
613
624
|
|
|
@@ -840,6 +851,7 @@ function normalize(c, fallback) {
|
|
|
840
851
|
// src/captions.ts
|
|
841
852
|
var TICK_MS = 100;
|
|
842
853
|
var STALE_MS = 5e3;
|
|
854
|
+
var MAX_QUEUE_MS = 1500;
|
|
843
855
|
var MebiusCaptions = class extends TypedEmitter {
|
|
844
856
|
/** @internal */
|
|
845
857
|
constructor(signaling, player, opts) {
|
|
@@ -881,22 +893,27 @@ var MebiusCaptions = class extends TypedEmitter {
|
|
|
881
893
|
if (frame.type !== "caption" || !frame.segmentId) return;
|
|
882
894
|
const prev = this.pending.get(frame.segmentId);
|
|
883
895
|
if (prev && (frame.rev ?? 0) < (prev.rev ?? 0)) return;
|
|
896
|
+
frame.receivedAtMs = Date.now();
|
|
884
897
|
this.pending.set(frame.segmentId, frame);
|
|
885
898
|
}
|
|
886
899
|
tick() {
|
|
887
900
|
const now = this.player.currentEpochMs();
|
|
888
|
-
if (now == null) return;
|
|
889
901
|
for (const [id, frame] of this.pending) {
|
|
890
902
|
const due = frame.epochMs ?? 0;
|
|
891
|
-
|
|
892
|
-
|
|
903
|
+
const waitedMs = Date.now() - (frame.receivedAtMs ?? 0);
|
|
904
|
+
const dueNow = now == null ? true : due <= now;
|
|
905
|
+
if (!dueNow) {
|
|
906
|
+
if (waitedMs < MAX_QUEUE_MS) continue;
|
|
907
|
+
}
|
|
908
|
+
if (waitedMs > STALE_MS && this.shown.has(id)) {
|
|
893
909
|
this.pending.delete(id);
|
|
894
|
-
|
|
910
|
+
this.shown.delete(id);
|
|
911
|
+
this.emit("cleared", { segmentId: id });
|
|
895
912
|
continue;
|
|
896
913
|
}
|
|
914
|
+
if (this.shown.has(id) && frame.state === "final") continue;
|
|
897
915
|
this.shown.add(id);
|
|
898
916
|
this.emit("segment", toSegment(id, frame, this.opts.lang));
|
|
899
|
-
if (frame.state === "final") this.pending.delete(id);
|
|
900
917
|
}
|
|
901
918
|
}
|
|
902
919
|
};
|