@livo-tv/blocks 1.12.1 → 1.14.0
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 +321 -186
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +255 -120
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -772,6 +772,8 @@ interface VideoPlayerLabels {
|
|
|
772
772
|
captionsEn?: string;
|
|
773
773
|
captionsEs?: string;
|
|
774
774
|
captionsPt?: string;
|
|
775
|
+
/** Jump the live teleprompter stack back to the newest cue. */
|
|
776
|
+
captionsLatest?: string;
|
|
775
777
|
}
|
|
776
778
|
interface VideoPlayerProps {
|
|
777
779
|
src: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -772,6 +772,8 @@ interface VideoPlayerLabels {
|
|
|
772
772
|
captionsEn?: string;
|
|
773
773
|
captionsEs?: string;
|
|
774
774
|
captionsPt?: string;
|
|
775
|
+
/** Jump the live teleprompter stack back to the newest cue. */
|
|
776
|
+
captionsLatest?: string;
|
|
775
777
|
}
|
|
776
778
|
interface VideoPlayerProps {
|
|
777
779
|
src: string;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import * as
|
|
2
|
+
import * as React9 from 'react';
|
|
3
3
|
import { createContext, useContext, useState, useRef, useId, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
4
4
|
import { Loader2, AlertTriangle, Inbox, Bell, Monitor, Sun, Moon, Languages, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, X, User, Pencil, Check, Play, AlertCircle, VolumeX, Pause, Volume1, Volume2, Captions, Settings, Cast, PictureInPicture2, Minimize, Maximize, XIcon } from 'lucide-react';
|
|
5
5
|
import { clsx } from 'clsx';
|
|
@@ -1310,7 +1310,7 @@ function Slider({
|
|
|
1310
1310
|
max = 100,
|
|
1311
1311
|
...props
|
|
1312
1312
|
}) {
|
|
1313
|
-
const _values =
|
|
1313
|
+
const _values = React9.useMemo(
|
|
1314
1314
|
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
1315
1315
|
[value, defaultValue, min, max]
|
|
1316
1316
|
);
|
|
@@ -2378,8 +2378,8 @@ function probeVideoAudio(el) {
|
|
|
2378
2378
|
return "unknown";
|
|
2379
2379
|
}
|
|
2380
2380
|
function usePrefersReducedMotion() {
|
|
2381
|
-
const [reduced, setReduced] =
|
|
2382
|
-
|
|
2381
|
+
const [reduced, setReduced] = React9.useState(false);
|
|
2382
|
+
React9.useEffect(() => {
|
|
2383
2383
|
const media = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
2384
2384
|
const sync = () => setReduced(media.matches);
|
|
2385
2385
|
sync();
|
|
@@ -2396,11 +2396,11 @@ function CurtainVideo({
|
|
|
2396
2396
|
allowSound,
|
|
2397
2397
|
labels
|
|
2398
2398
|
}) {
|
|
2399
|
-
const videoRef =
|
|
2400
|
-
const [playback, setPlayback] =
|
|
2401
|
-
const [muted, setMuted] =
|
|
2402
|
-
const [audio, setAudio] =
|
|
2403
|
-
|
|
2399
|
+
const videoRef = React9.useRef(null);
|
|
2400
|
+
const [playback, setPlayback] = React9.useState("pending");
|
|
2401
|
+
const [muted, setMuted] = React9.useState(true);
|
|
2402
|
+
const [audio, setAudio] = React9.useState("unknown");
|
|
2403
|
+
React9.useEffect(() => {
|
|
2404
2404
|
const el = videoRef.current;
|
|
2405
2405
|
if (!el) return;
|
|
2406
2406
|
el.setAttribute("webkit-playsinline", "");
|
|
@@ -2441,7 +2441,7 @@ function CurtainVideo({
|
|
|
2441
2441
|
el.removeEventListener("loadedmetadata", applyAudio);
|
|
2442
2442
|
};
|
|
2443
2443
|
}, [url, freeze]);
|
|
2444
|
-
const startPlayback =
|
|
2444
|
+
const startPlayback = React9.useCallback(() => {
|
|
2445
2445
|
const el = videoRef.current;
|
|
2446
2446
|
if (!el) return;
|
|
2447
2447
|
el.muted = true;
|
|
@@ -2457,7 +2457,7 @@ function CurtainVideo({
|
|
|
2457
2457
|
}
|
|
2458
2458
|
);
|
|
2459
2459
|
}, []);
|
|
2460
|
-
const setVideoMuted =
|
|
2460
|
+
const setVideoMuted = React9.useCallback((next) => {
|
|
2461
2461
|
const el = videoRef.current;
|
|
2462
2462
|
if (el) el.muted = next;
|
|
2463
2463
|
setMuted(next);
|
|
@@ -2564,9 +2564,9 @@ function isVideoKind(kind) {
|
|
|
2564
2564
|
return kind === "video";
|
|
2565
2565
|
}
|
|
2566
2566
|
function useElementInView(enabled) {
|
|
2567
|
-
const [node, setNode] =
|
|
2568
|
-
const [inView, setInView] =
|
|
2569
|
-
|
|
2567
|
+
const [node, setNode] = React9.useState(null);
|
|
2568
|
+
const [inView, setInView] = React9.useState(false);
|
|
2569
|
+
React9.useEffect(() => {
|
|
2570
2570
|
if (!enabled || !node || typeof IntersectionObserver === "undefined") {
|
|
2571
2571
|
setInView(false);
|
|
2572
2572
|
return;
|
|
@@ -2738,7 +2738,7 @@ function CurtainPicker({
|
|
|
2738
2738
|
actionsPending = false
|
|
2739
2739
|
}) {
|
|
2740
2740
|
const copy = { ...DEFAULT_CURTAIN_PICKER_LABELS, ...labels };
|
|
2741
|
-
const groupName =
|
|
2741
|
+
const groupName = React9.useId();
|
|
2742
2742
|
const selectable = typeof onChange === "function";
|
|
2743
2743
|
const compact = variant === "compact";
|
|
2744
2744
|
const selectedId = value === "" ? null : value ?? null;
|
|
@@ -2754,7 +2754,7 @@ function CurtainPicker({
|
|
|
2754
2754
|
canMakeDefault,
|
|
2755
2755
|
canDelete
|
|
2756
2756
|
) : {};
|
|
2757
|
-
const grouped =
|
|
2757
|
+
const grouped = React9.useMemo(() => {
|
|
2758
2758
|
if (!groupByOwner) {
|
|
2759
2759
|
return [{ group: null, items: ready }];
|
|
2760
2760
|
}
|
|
@@ -3079,8 +3079,8 @@ function WaitingRoom({
|
|
|
3079
3079
|
labels,
|
|
3080
3080
|
className
|
|
3081
3081
|
}) {
|
|
3082
|
-
const [now, setNow] =
|
|
3083
|
-
|
|
3082
|
+
const [now, setNow] = React9.useState(nowMs ?? Date.now());
|
|
3083
|
+
React9.useEffect(() => {
|
|
3084
3084
|
if (nowMs != null) {
|
|
3085
3085
|
setNow(nowMs);
|
|
3086
3086
|
return;
|
|
@@ -3262,22 +3262,22 @@ function SeekBar({
|
|
|
3262
3262
|
onSeek,
|
|
3263
3263
|
formatTime: formatTime2
|
|
3264
3264
|
}) {
|
|
3265
|
-
const trackRef =
|
|
3266
|
-
const [hoverTime, setHoverTime] =
|
|
3267
|
-
const [cues, setCues] =
|
|
3268
|
-
const loadedSrc =
|
|
3269
|
-
|
|
3265
|
+
const trackRef = React9.useRef(null);
|
|
3266
|
+
const [hoverTime, setHoverTime] = React9.useState(null);
|
|
3267
|
+
const [cues, setCues] = React9.useState(null);
|
|
3268
|
+
const loadedSrc = React9.useRef(null);
|
|
3269
|
+
React9.useEffect(() => {
|
|
3270
3270
|
setCues(null);
|
|
3271
3271
|
loadedSrc.current = null;
|
|
3272
3272
|
}, [src]);
|
|
3273
|
-
const ensureCues =
|
|
3273
|
+
const ensureCues = React9.useCallback(() => {
|
|
3274
3274
|
if (loadedSrc.current === src) return;
|
|
3275
3275
|
loadedSrc.current = src;
|
|
3276
3276
|
void loadThumbnailsVtt(src).then((next) => {
|
|
3277
3277
|
setCues(next);
|
|
3278
3278
|
});
|
|
3279
3279
|
}, [src]);
|
|
3280
|
-
const updateHover =
|
|
3280
|
+
const updateHover = React9.useCallback(
|
|
3281
3281
|
(clientX) => {
|
|
3282
3282
|
const rect = trackRef.current?.getBoundingClientRect();
|
|
3283
3283
|
if (!rect) return;
|
|
@@ -3534,27 +3534,27 @@ function useHlsPlayback({
|
|
|
3534
3534
|
onError,
|
|
3535
3535
|
onPlayingChange
|
|
3536
3536
|
}) {
|
|
3537
|
-
const videoRef =
|
|
3538
|
-
const hlsRef =
|
|
3539
|
-
const [state, setState] =
|
|
3540
|
-
const [qualities, setQualities] =
|
|
3541
|
-
const [activeLevel, setActiveLevel] =
|
|
3542
|
-
const [autoplayState, setAutoplayState] =
|
|
3543
|
-
const [error, setError] =
|
|
3544
|
-
const [reloadKey, setReloadKey] =
|
|
3545
|
-
const onErrorRef =
|
|
3546
|
-
const onPlayingChangeRef =
|
|
3547
|
-
|
|
3537
|
+
const videoRef = React9.useRef(null);
|
|
3538
|
+
const hlsRef = React9.useRef(null);
|
|
3539
|
+
const [state, setState] = React9.useState("idle");
|
|
3540
|
+
const [qualities, setQualities] = React9.useState([]);
|
|
3541
|
+
const [activeLevel, setActiveLevel] = React9.useState(-1);
|
|
3542
|
+
const [autoplayState, setAutoplayState] = React9.useState("none");
|
|
3543
|
+
const [error, setError] = React9.useState(null);
|
|
3544
|
+
const [reloadKey, setReloadKey] = React9.useState(0);
|
|
3545
|
+
const onErrorRef = React9.useRef(onError);
|
|
3546
|
+
const onPlayingChangeRef = React9.useRef(onPlayingChange);
|
|
3547
|
+
React9.useEffect(() => {
|
|
3548
3548
|
onErrorRef.current = onError;
|
|
3549
3549
|
onPlayingChangeRef.current = onPlayingChange;
|
|
3550
3550
|
}, [onError, onPlayingChange]);
|
|
3551
|
-
const retry =
|
|
3551
|
+
const retry = React9.useCallback(() => {
|
|
3552
3552
|
setError(null);
|
|
3553
3553
|
setState("loading");
|
|
3554
3554
|
setAutoplayState("none");
|
|
3555
3555
|
setReloadKey((k) => k + 1);
|
|
3556
3556
|
}, []);
|
|
3557
|
-
|
|
3557
|
+
React9.useEffect(() => {
|
|
3558
3558
|
const media = videoRef.current;
|
|
3559
3559
|
if (!media || !src || !active) {
|
|
3560
3560
|
setState("idle");
|
|
@@ -3840,7 +3840,7 @@ function useHlsPlayback({
|
|
|
3840
3840
|
destroyHls();
|
|
3841
3841
|
};
|
|
3842
3842
|
}, [src, mode, active, autoPlay, muted, reloadKey]);
|
|
3843
|
-
const setLevel =
|
|
3843
|
+
const setLevel = React9.useCallback((index) => {
|
|
3844
3844
|
const hls = hlsRef.current;
|
|
3845
3845
|
if (!hls) return;
|
|
3846
3846
|
hls.nextLevel = index;
|
|
@@ -3860,7 +3860,8 @@ function useHlsPlayback({
|
|
|
3860
3860
|
|
|
3861
3861
|
// src/components/video/captions.ts
|
|
3862
3862
|
var CAPTION_LOCALES = ["en", "es", "pt"];
|
|
3863
|
-
var
|
|
3863
|
+
var LIVE_CUE_EXTRA_LAG_MS = 2e3;
|
|
3864
|
+
var LIVE_STACK_MAX_CUES = 150;
|
|
3864
3865
|
var LIVE_LAG_SPIKE_MS = 2500;
|
|
3865
3866
|
function stabilizeLiveLagMs(previous, next) {
|
|
3866
3867
|
if (previous == null || !Number.isFinite(previous)) return next;
|
|
@@ -3871,6 +3872,22 @@ function stabilizeLiveLagMs(previous, next) {
|
|
|
3871
3872
|
function isCaptionLocale(value) {
|
|
3872
3873
|
return CAPTION_LOCALES.includes(value);
|
|
3873
3874
|
}
|
|
3875
|
+
function isLivePlaylistSrc(src) {
|
|
3876
|
+
return /\/live\//i.test(src);
|
|
3877
|
+
}
|
|
3878
|
+
function zeroAnchorCaptionCues(cues) {
|
|
3879
|
+
if (cues.length === 0) return cues;
|
|
3880
|
+
let origin = Number.POSITIVE_INFINITY;
|
|
3881
|
+
for (const cue of cues) {
|
|
3882
|
+
if (Number.isFinite(cue.start) && cue.start < origin) origin = cue.start;
|
|
3883
|
+
}
|
|
3884
|
+
if (!Number.isFinite(origin) || origin <= 0) return cues;
|
|
3885
|
+
return cues.map((cue) => ({
|
|
3886
|
+
...cue,
|
|
3887
|
+
start: Math.max(0, cue.start - origin),
|
|
3888
|
+
end: Math.max(0, cue.end - origin)
|
|
3889
|
+
}));
|
|
3890
|
+
}
|
|
3874
3891
|
function captionsVttUrlFromPlayback(src, locale) {
|
|
3875
3892
|
const trimmed = src.trim();
|
|
3876
3893
|
if (!trimmed) return null;
|
|
@@ -3911,26 +3928,49 @@ function captionAtTime(cues, time, options) {
|
|
|
3911
3928
|
if (matched) return matched;
|
|
3912
3929
|
return null;
|
|
3913
3930
|
}
|
|
3914
|
-
function
|
|
3915
|
-
|
|
3931
|
+
function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
3932
|
+
if (lagMs == null || !Number.isFinite(lagMs) || lagMs < 0) return [];
|
|
3933
|
+
const threshold = lagMs + extraLagMs;
|
|
3934
|
+
return cues.filter(
|
|
3935
|
+
(cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
|
|
3936
|
+
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
3937
|
+
}
|
|
3938
|
+
function normalizeLiveCaptionText(text) {
|
|
3939
|
+
return text.trim().replace(/\s+/g, " ").toLowerCase();
|
|
3940
|
+
}
|
|
3941
|
+
function coalesceLiveCaptionCues(cues) {
|
|
3942
|
+
const out = [];
|
|
3916
3943
|
for (const cue of cues) {
|
|
3917
|
-
|
|
3918
|
-
if (
|
|
3919
|
-
|
|
3944
|
+
const text = cue.text.trim();
|
|
3945
|
+
if (!text) continue;
|
|
3946
|
+
const last = out[out.length - 1];
|
|
3947
|
+
if (!last) {
|
|
3948
|
+
out.push({ text, receivedAt: cue.receivedAt });
|
|
3949
|
+
continue;
|
|
3950
|
+
}
|
|
3951
|
+
const lastNorm = normalizeLiveCaptionText(last.text);
|
|
3952
|
+
const nextNorm = normalizeLiveCaptionText(text);
|
|
3953
|
+
if (lastNorm === nextNorm) continue;
|
|
3954
|
+
if (nextNorm.startsWith(lastNorm) || lastNorm.startsWith(nextNorm)) {
|
|
3955
|
+
out[out.length - 1] = {
|
|
3956
|
+
text: nextNorm.length >= lastNorm.length ? text : last.text,
|
|
3957
|
+
receivedAt: cue.receivedAt
|
|
3958
|
+
};
|
|
3959
|
+
continue;
|
|
3960
|
+
}
|
|
3961
|
+
out.push({ text, receivedAt: cue.receivedAt });
|
|
3920
3962
|
}
|
|
3921
|
-
return
|
|
3922
|
-
}
|
|
3923
|
-
function
|
|
3924
|
-
|
|
3925
|
-
const
|
|
3926
|
-
|
|
3927
|
-
if (dueInHold && (!previous || dueInHold.receivedAt > previous.cue.receivedAt)) {
|
|
3928
|
-
return { cue: dueInHold, shownAt: now, lagMs };
|
|
3963
|
+
return out;
|
|
3964
|
+
}
|
|
3965
|
+
function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
|
|
3966
|
+
const map = /* @__PURE__ */ new Map();
|
|
3967
|
+
for (const cue of existing) {
|
|
3968
|
+
if (Number.isFinite(cue.receivedAt)) map.set(cue.receivedAt, cue);
|
|
3929
3969
|
}
|
|
3930
|
-
|
|
3931
|
-
|
|
3970
|
+
for (const cue of incoming) {
|
|
3971
|
+
if (Number.isFinite(cue.receivedAt)) map.set(cue.receivedAt, cue);
|
|
3932
3972
|
}
|
|
3933
|
-
return
|
|
3973
|
+
return [...map.values()].sort((left, right) => left.receivedAt - right.receivedAt).slice(-Math.max(1, cap));
|
|
3934
3974
|
}
|
|
3935
3975
|
async function loadCaptionVtt(url) {
|
|
3936
3976
|
try {
|
|
@@ -3969,6 +4009,107 @@ async function loadLiveCaptions(url) {
|
|
|
3969
4009
|
return { ok: false, cues: [] };
|
|
3970
4010
|
}
|
|
3971
4011
|
}
|
|
4012
|
+
var NEAR_BOTTOM_PX = 24;
|
|
4013
|
+
function LiveCaptionStack({ cues, latestLabel }) {
|
|
4014
|
+
const scrollerRef = React9.useRef(null);
|
|
4015
|
+
const followRef = React9.useRef(true);
|
|
4016
|
+
const ignoreScrollRef = React9.useRef(false);
|
|
4017
|
+
const [following, setFollowing] = React9.useState(true);
|
|
4018
|
+
const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
|
|
4019
|
+
const lastReceivedAt = cues[cues.length - 1]?.receivedAt;
|
|
4020
|
+
const scrollToLatest = React9.useCallback(() => {
|
|
4021
|
+
const scroller = scrollerRef.current;
|
|
4022
|
+
if (!scroller) return;
|
|
4023
|
+
ignoreScrollRef.current = true;
|
|
4024
|
+
scroller.scrollTo({
|
|
4025
|
+
top: scroller.scrollHeight,
|
|
4026
|
+
behavior: prefersReduced ? "auto" : "smooth"
|
|
4027
|
+
});
|
|
4028
|
+
followRef.current = true;
|
|
4029
|
+
setFollowing(true);
|
|
4030
|
+
window.requestAnimationFrame(() => {
|
|
4031
|
+
window.requestAnimationFrame(() => {
|
|
4032
|
+
ignoreScrollRef.current = false;
|
|
4033
|
+
});
|
|
4034
|
+
});
|
|
4035
|
+
}, [prefersReduced]);
|
|
4036
|
+
React9.useLayoutEffect(() => {
|
|
4037
|
+
if (!followRef.current) return;
|
|
4038
|
+
const scroller = scrollerRef.current;
|
|
4039
|
+
if (!scroller) return;
|
|
4040
|
+
ignoreScrollRef.current = true;
|
|
4041
|
+
scroller.scrollTo({
|
|
4042
|
+
top: scroller.scrollHeight,
|
|
4043
|
+
behavior: prefersReduced ? "auto" : "smooth"
|
|
4044
|
+
});
|
|
4045
|
+
window.requestAnimationFrame(() => {
|
|
4046
|
+
window.requestAnimationFrame(() => {
|
|
4047
|
+
ignoreScrollRef.current = false;
|
|
4048
|
+
});
|
|
4049
|
+
});
|
|
4050
|
+
}, [lastReceivedAt, prefersReduced, cues.length]);
|
|
4051
|
+
if (cues.length === 0) return null;
|
|
4052
|
+
return /* @__PURE__ */ jsx(
|
|
4053
|
+
"div",
|
|
4054
|
+
{
|
|
4055
|
+
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4056
|
+
"data-slot": "video-captions",
|
|
4057
|
+
children: /* @__PURE__ */ jsxs("div", { className: "relative w-full max-w-[90%]", children: [
|
|
4058
|
+
!following && /* @__PURE__ */ jsx(
|
|
4059
|
+
"button",
|
|
4060
|
+
{
|
|
4061
|
+
type: "button",
|
|
4062
|
+
className: "pointer-events-auto absolute -top-8 right-0 rounded-sm bg-black/70 px-2 py-0.5 text-xs font-medium text-white shadow-sm",
|
|
4063
|
+
onClick: scrollToLatest,
|
|
4064
|
+
children: latestLabel
|
|
4065
|
+
}
|
|
4066
|
+
),
|
|
4067
|
+
/* @__PURE__ */ jsx(
|
|
4068
|
+
"div",
|
|
4069
|
+
{
|
|
4070
|
+
ref: scrollerRef,
|
|
4071
|
+
role: "log",
|
|
4072
|
+
"aria-relevant": "additions",
|
|
4073
|
+
className: "pointer-events-auto max-h-[4.5rem] overflow-x-hidden overflow-y-auto rounded-sm bg-black/70 px-3 py-1.5 text-sm font-medium text-white shadow-sm",
|
|
4074
|
+
onScroll: (event) => {
|
|
4075
|
+
if (ignoreScrollRef.current) return;
|
|
4076
|
+
const scroller = event.currentTarget;
|
|
4077
|
+
const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
|
|
4078
|
+
followRef.current = nearBottom;
|
|
4079
|
+
setFollowing(nearBottom);
|
|
4080
|
+
},
|
|
4081
|
+
children: /* @__PURE__ */ jsx(
|
|
4082
|
+
"p",
|
|
4083
|
+
{
|
|
4084
|
+
className: cn(
|
|
4085
|
+
"text-justify [text-align-last:left] leading-5 break-words",
|
|
4086
|
+
!prefersReduced && "transition-opacity"
|
|
4087
|
+
),
|
|
4088
|
+
children: cues.map((cue, index) => {
|
|
4089
|
+
const fromEnd = cues.length - 1 - index;
|
|
4090
|
+
const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
|
|
4091
|
+
const newest = fromEnd === 0;
|
|
4092
|
+
return /* @__PURE__ */ jsxs(
|
|
4093
|
+
"span",
|
|
4094
|
+
{
|
|
4095
|
+
style: { opacity },
|
|
4096
|
+
"aria-live": newest ? "polite" : void 0,
|
|
4097
|
+
children: [
|
|
4098
|
+
index > 0 ? " " : "",
|
|
4099
|
+
cue.text
|
|
4100
|
+
]
|
|
4101
|
+
},
|
|
4102
|
+
cue.receivedAt
|
|
4103
|
+
);
|
|
4104
|
+
})
|
|
4105
|
+
}
|
|
4106
|
+
)
|
|
4107
|
+
}
|
|
4108
|
+
)
|
|
4109
|
+
] })
|
|
4110
|
+
}
|
|
4111
|
+
);
|
|
4112
|
+
}
|
|
3972
4113
|
var DEFAULT_LABELS3 = {
|
|
3973
4114
|
play: "Play",
|
|
3974
4115
|
pause: "Pause",
|
|
@@ -3997,7 +4138,8 @@ var DEFAULT_LABELS3 = {
|
|
|
3997
4138
|
captionsOff: "Off",
|
|
3998
4139
|
captionsEn: "English",
|
|
3999
4140
|
captionsEs: "Espa\xF1ol",
|
|
4000
|
-
captionsPt: "Portugu\xEAs"
|
|
4141
|
+
captionsPt: "Portugu\xEAs",
|
|
4142
|
+
captionsLatest: "Latest"
|
|
4001
4143
|
};
|
|
4002
4144
|
var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
4003
4145
|
var CONTROLS_HIDE_MS = 3e3;
|
|
@@ -4059,12 +4201,12 @@ function VideoPlayer({
|
|
|
4059
4201
|
liveCaptionsBaseUrl
|
|
4060
4202
|
}) {
|
|
4061
4203
|
const t = { ...DEFAULT_LABELS3, ...labels };
|
|
4062
|
-
const containerRef =
|
|
4063
|
-
const firstPlayFiredRef =
|
|
4064
|
-
const [userStarted, setUserStarted] =
|
|
4204
|
+
const containerRef = React9.useRef(null);
|
|
4205
|
+
const firstPlayFiredRef = React9.useRef(false);
|
|
4206
|
+
const [userStarted, setUserStarted] = React9.useState(false);
|
|
4065
4207
|
const active = autoPlay || !poster || userStarted;
|
|
4066
4208
|
const autoplayActive = autoPlay || userStarted;
|
|
4067
|
-
const handlePlayingChange =
|
|
4209
|
+
const handlePlayingChange = React9.useCallback(
|
|
4068
4210
|
(playing) => {
|
|
4069
4211
|
setIsPlaying(playing);
|
|
4070
4212
|
if (playing && !firstPlayFiredRef.current) {
|
|
@@ -4093,30 +4235,29 @@ function VideoPlayer({
|
|
|
4093
4235
|
onError,
|
|
4094
4236
|
onPlayingChange: handlePlayingChange
|
|
4095
4237
|
});
|
|
4096
|
-
const [isPlaying, setIsPlaying] =
|
|
4097
|
-
const [isMuted, setIsMuted] =
|
|
4098
|
-
const isMutedRef =
|
|
4238
|
+
const [isPlaying, setIsPlaying] = React9.useState(false);
|
|
4239
|
+
const [isMuted, setIsMuted] = React9.useState(muted);
|
|
4240
|
+
const isMutedRef = React9.useRef(isMuted);
|
|
4099
4241
|
isMutedRef.current = isMuted;
|
|
4100
|
-
const [volume, setVolume] =
|
|
4101
|
-
const [currentTime, setCurrentTime] =
|
|
4102
|
-
const [duration, setDuration] =
|
|
4103
|
-
const [buffered, setBuffered] =
|
|
4104
|
-
const [isFullscreen, setIsFullscreen] =
|
|
4105
|
-
const [pipActive, setPipActive] =
|
|
4106
|
-
const [controlsVisible, setControlsVisible] =
|
|
4107
|
-
const [playbackRate, setPlaybackRate] =
|
|
4108
|
-
const [openMenu, setOpenMenu] =
|
|
4109
|
-
const [captionLocale, setCaptionLocale] =
|
|
4110
|
-
const [captionCues, setCaptionCues] =
|
|
4111
|
-
const [liveCaptionCues, setLiveCaptionCues] =
|
|
4112
|
-
const [liveLagMs, setLiveLagMs] =
|
|
4113
|
-
const
|
|
4114
|
-
const [
|
|
4115
|
-
const
|
|
4116
|
-
const hideTimerRef = React8.useRef(null);
|
|
4242
|
+
const [volume, setVolume] = React9.useState(1);
|
|
4243
|
+
const [currentTime, setCurrentTime] = React9.useState(0);
|
|
4244
|
+
const [duration, setDuration] = React9.useState(0);
|
|
4245
|
+
const [buffered, setBuffered] = React9.useState(0);
|
|
4246
|
+
const [isFullscreen, setIsFullscreen] = React9.useState(false);
|
|
4247
|
+
const [pipActive, setPipActive] = React9.useState(false);
|
|
4248
|
+
const [controlsVisible, setControlsVisible] = React9.useState(true);
|
|
4249
|
+
const [playbackRate, setPlaybackRate] = React9.useState(1);
|
|
4250
|
+
const [openMenu, setOpenMenu] = React9.useState(null);
|
|
4251
|
+
const [captionLocale, setCaptionLocale] = React9.useState(defaultCaptionLocale ?? "off");
|
|
4252
|
+
const [captionCues, setCaptionCues] = React9.useState([]);
|
|
4253
|
+
const [liveCaptionCues, setLiveCaptionCues] = React9.useState([]);
|
|
4254
|
+
const [liveLagMs, setLiveLagMs] = React9.useState(null);
|
|
4255
|
+
const [behindLive, setBehindLive] = React9.useState(false);
|
|
4256
|
+
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9.useState(false);
|
|
4257
|
+
const hideTimerRef = React9.useRef(null);
|
|
4117
4258
|
const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
|
|
4118
4259
|
const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported;
|
|
4119
|
-
|
|
4260
|
+
React9.useEffect(() => {
|
|
4120
4261
|
const video = videoRef.current;
|
|
4121
4262
|
if (!video || !active) return;
|
|
4122
4263
|
const onTimeUpdate = () => {
|
|
@@ -4158,25 +4299,25 @@ function VideoPlayer({
|
|
|
4158
4299
|
video.removeEventListener("playing", onPlaying);
|
|
4159
4300
|
};
|
|
4160
4301
|
}, [videoRef, active, mode, liveCaptionsBaseUrl]);
|
|
4161
|
-
|
|
4302
|
+
React9.useLayoutEffect(() => {
|
|
4162
4303
|
const video = videoRef.current;
|
|
4163
4304
|
if (video) video.muted = isMuted;
|
|
4164
4305
|
}, [isMuted, active, videoRef]);
|
|
4165
|
-
|
|
4306
|
+
React9.useEffect(() => {
|
|
4166
4307
|
const video = videoRef.current;
|
|
4167
4308
|
if (!paused || !video || !isPlaying) return;
|
|
4168
4309
|
video.pause();
|
|
4169
4310
|
}, [paused, videoRef, isPlaying]);
|
|
4170
|
-
|
|
4311
|
+
React9.useEffect(() => {
|
|
4171
4312
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
4172
4313
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
4173
4314
|
}, [videoRef, active]);
|
|
4174
|
-
|
|
4315
|
+
React9.useEffect(() => {
|
|
4175
4316
|
const onFsChange = () => setIsFullscreen(document.fullscreenElement === containerRef.current);
|
|
4176
4317
|
document.addEventListener("fullscreenchange", onFsChange);
|
|
4177
4318
|
return () => document.removeEventListener("fullscreenchange", onFsChange);
|
|
4178
4319
|
}, []);
|
|
4179
|
-
|
|
4320
|
+
React9.useEffect(() => {
|
|
4180
4321
|
const video = asWebkitVideo(videoRef.current);
|
|
4181
4322
|
if (!video) return;
|
|
4182
4323
|
const onBegin = () => setIsFullscreen(true);
|
|
@@ -4188,7 +4329,7 @@ function VideoPlayer({
|
|
|
4188
4329
|
video.removeEventListener("webkitendfullscreen", onEnd);
|
|
4189
4330
|
};
|
|
4190
4331
|
}, [videoRef, active]);
|
|
4191
|
-
|
|
4332
|
+
React9.useEffect(() => {
|
|
4192
4333
|
const video = videoRef.current;
|
|
4193
4334
|
if (!video) return;
|
|
4194
4335
|
const onEnter = () => setPipActive(true);
|
|
@@ -4200,29 +4341,29 @@ function VideoPlayer({
|
|
|
4200
4341
|
video.removeEventListener("leavepictureinpicture", onLeave);
|
|
4201
4342
|
};
|
|
4202
4343
|
}, [videoRef]);
|
|
4203
|
-
const scheduleHide =
|
|
4344
|
+
const scheduleHide = React9.useCallback(() => {
|
|
4204
4345
|
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
4205
4346
|
hideTimerRef.current = setTimeout(() => {
|
|
4206
4347
|
setControlsVisible(false);
|
|
4207
4348
|
setOpenMenu(null);
|
|
4208
4349
|
}, CONTROLS_HIDE_MS);
|
|
4209
4350
|
}, []);
|
|
4210
|
-
const revealControls =
|
|
4351
|
+
const revealControls = React9.useCallback(() => {
|
|
4211
4352
|
setControlsVisible(true);
|
|
4212
4353
|
scheduleHide();
|
|
4213
4354
|
}, [scheduleHide]);
|
|
4214
|
-
|
|
4355
|
+
React9.useEffect(() => {
|
|
4215
4356
|
return () => {
|
|
4216
4357
|
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
4217
4358
|
};
|
|
4218
4359
|
}, []);
|
|
4219
|
-
|
|
4360
|
+
React9.useEffect(() => {
|
|
4220
4361
|
if (captionLocale === "off") {
|
|
4221
4362
|
setCaptionCues([]);
|
|
4222
4363
|
setLiveCaptionCues([]);
|
|
4223
|
-
liveCaptionLatchRef.current = null;
|
|
4224
4364
|
return;
|
|
4225
4365
|
}
|
|
4366
|
+
setLiveCaptionCues([]);
|
|
4226
4367
|
let cancelled = false;
|
|
4227
4368
|
const load = async () => {
|
|
4228
4369
|
const liveBase = liveCaptionsBaseUrl?.trim();
|
|
@@ -4230,7 +4371,9 @@ function VideoPlayer({
|
|
|
4230
4371
|
const loaded = await loadLiveCaptions(
|
|
4231
4372
|
liveCaptionsUrl(liveBase, captionLocale)
|
|
4232
4373
|
);
|
|
4233
|
-
if (!cancelled && loaded.ok)
|
|
4374
|
+
if (!cancelled && loaded.ok) {
|
|
4375
|
+
setLiveCaptionCues((prev) => mergeLiveCaptionCues(prev, loaded.cues));
|
|
4376
|
+
}
|
|
4234
4377
|
return;
|
|
4235
4378
|
}
|
|
4236
4379
|
const url = captionsVttUrlFromPlayback(src, captionLocale);
|
|
@@ -4239,7 +4382,8 @@ function VideoPlayer({
|
|
|
4239
4382
|
return;
|
|
4240
4383
|
}
|
|
4241
4384
|
const cues = await loadCaptionVtt(url);
|
|
4242
|
-
|
|
4385
|
+
const next = isLivePlaylistSrc(src) ? zeroAnchorCaptionCues(cues) : cues;
|
|
4386
|
+
if (!cancelled) setCaptionCues(next);
|
|
4243
4387
|
};
|
|
4244
4388
|
void load();
|
|
4245
4389
|
if (!liveCaptionsBaseUrl) return;
|
|
@@ -4249,20 +4393,10 @@ function VideoPlayer({
|
|
|
4249
4393
|
window.clearInterval(timer);
|
|
4250
4394
|
};
|
|
4251
4395
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4252
|
-
const
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
liveCaptionLatchRef.current = null;
|
|
4257
|
-
}
|
|
4258
|
-
const liveLatch = liveCaptionsBaseUrl ? captionAtLiveLag(
|
|
4259
|
-
liveCaptionCues,
|
|
4260
|
-
Date.now(),
|
|
4261
|
-
liveLagMs,
|
|
4262
|
-
liveCaptionLatchRef.current
|
|
4263
|
-
) : null;
|
|
4264
|
-
liveCaptionLatchRef.current = liveLatch;
|
|
4265
|
-
const activeCaption = liveCaptionsBaseUrl ? liveLatch?.cue ?? null : captionAtTime(captionCues, currentTime);
|
|
4396
|
+
const liveDueCues = liveCaptionsBaseUrl ? coalesceLiveCaptionCues(
|
|
4397
|
+
liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
|
|
4398
|
+
) : [];
|
|
4399
|
+
const activeCaption = liveCaptionsBaseUrl ? null : captionAtTime(captionCues, currentTime);
|
|
4266
4400
|
function togglePlay() {
|
|
4267
4401
|
const video = videoRef.current;
|
|
4268
4402
|
if (!video) return;
|
|
@@ -4492,7 +4626,8 @@ function VideoPlayer({
|
|
|
4492
4626
|
] }),
|
|
4493
4627
|
typeof stats?.viewers === "number" && /* @__PURE__ */ jsx("span", { className: "rounded bg-black/60 px-2 py-0.5 text-xs", children: t.formatViewers ? t.formatViewers(stats.viewers) : `\u{1F441} ${stats.viewers}` })
|
|
4494
4628
|
] }),
|
|
4495
|
-
|
|
4629
|
+
liveCaptionsBaseUrl && captionLocale !== "off" && /* @__PURE__ */ jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
|
|
4630
|
+
!liveCaptionsBaseUrl && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsx(
|
|
4496
4631
|
"div",
|
|
4497
4632
|
{
|
|
4498
4633
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
@@ -4785,16 +4920,16 @@ function videoInPictureInPicture(container) {
|
|
|
4785
4920
|
return container.contains(pip);
|
|
4786
4921
|
}
|
|
4787
4922
|
function useFeedExclusivePlayback(playbackId) {
|
|
4788
|
-
const containerRef =
|
|
4789
|
-
const [forcePaused, setForcePaused] =
|
|
4790
|
-
const requestPause =
|
|
4923
|
+
const containerRef = React9.useRef(null);
|
|
4924
|
+
const [forcePaused, setForcePaused] = React9.useState(false);
|
|
4925
|
+
const requestPause = React9.useCallback(() => {
|
|
4791
4926
|
if (videoInPictureInPicture(containerRef.current)) return;
|
|
4792
4927
|
setForcePaused(true);
|
|
4793
4928
|
}, []);
|
|
4794
|
-
|
|
4929
|
+
React9.useEffect(() => {
|
|
4795
4930
|
return registerFeedPlayer(playbackId, requestPause);
|
|
4796
4931
|
}, [playbackId, requestPause]);
|
|
4797
|
-
|
|
4932
|
+
React9.useEffect(() => {
|
|
4798
4933
|
const node = containerRef.current;
|
|
4799
4934
|
if (!node || typeof IntersectionObserver === "undefined") return;
|
|
4800
4935
|
const observer = new IntersectionObserver(
|
|
@@ -4810,14 +4945,14 @@ function useFeedExclusivePlayback(playbackId) {
|
|
|
4810
4945
|
observer.observe(node);
|
|
4811
4946
|
return () => observer.disconnect();
|
|
4812
4947
|
}, [requestPause]);
|
|
4813
|
-
|
|
4948
|
+
React9.useEffect(() => {
|
|
4814
4949
|
const onVisibility = () => {
|
|
4815
4950
|
if (document.hidden) requestPause();
|
|
4816
4951
|
};
|
|
4817
4952
|
document.addEventListener("visibilitychange", onVisibility);
|
|
4818
4953
|
return () => document.removeEventListener("visibilitychange", onVisibility);
|
|
4819
4954
|
}, [requestPause]);
|
|
4820
|
-
const onPlayingChange =
|
|
4955
|
+
const onPlayingChange = React9.useCallback(
|
|
4821
4956
|
(playing) => {
|
|
4822
4957
|
if (!playing) return;
|
|
4823
4958
|
setForcePaused(false);
|
|
@@ -4844,7 +4979,7 @@ function FeedVideoPlayer({
|
|
|
4844
4979
|
paused: exclusivePaused,
|
|
4845
4980
|
onPlayingChange: onExclusivePlayingChange
|
|
4846
4981
|
} = useFeedExclusivePlayback(playbackId);
|
|
4847
|
-
const handlePlayingChange =
|
|
4982
|
+
const handlePlayingChange = React9.useCallback(
|
|
4848
4983
|
(playing) => {
|
|
4849
4984
|
onExclusivePlayingChange(playing);
|
|
4850
4985
|
onPlayingChange?.(playing);
|
|
@@ -4871,8 +5006,8 @@ function FeedVideoPlayer({
|
|
|
4871
5006
|
);
|
|
4872
5007
|
}
|
|
4873
5008
|
function usePlaybackStats(statsUrl, { intervalMs = 15e3, enabled = true } = {}) {
|
|
4874
|
-
const [stats, setStats] =
|
|
4875
|
-
|
|
5009
|
+
const [stats, setStats] = React9.useState({});
|
|
5010
|
+
React9.useEffect(() => {
|
|
4876
5011
|
if (!statsUrl || !enabled) return;
|
|
4877
5012
|
let cancelled = false;
|
|
4878
5013
|
const controller = new AbortController();
|