@livo-tv/blocks 1.12.0 → 1.13.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 +255 -188
- 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 +189 -122
- 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;
|
|
@@ -3911,26 +3912,22 @@ function captionAtTime(cues, time, options) {
|
|
|
3911
3912
|
if (matched) return matched;
|
|
3912
3913
|
return null;
|
|
3913
3914
|
}
|
|
3914
|
-
function
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3915
|
+
function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
3916
|
+
if (lagMs == null || !Number.isFinite(lagMs) || lagMs < 0) return [];
|
|
3917
|
+
const threshold = lagMs + extraLagMs;
|
|
3918
|
+
return cues.filter(
|
|
3919
|
+
(cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
|
|
3920
|
+
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
3921
|
+
}
|
|
3922
|
+
function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
|
|
3923
|
+
const map = /* @__PURE__ */ new Map();
|
|
3924
|
+
for (const cue of existing) {
|
|
3925
|
+
if (Number.isFinite(cue.receivedAt)) map.set(cue.receivedAt, cue);
|
|
3920
3926
|
}
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
function captionAtLiveLag(cues, now, lagMs, previous = null, holdMs = LIVE_CUE_HOLD_MS) {
|
|
3924
|
-
if (lagMs == null || !Number.isFinite(lagMs) || lagMs < 0) return null;
|
|
3925
|
-
const due = newestDueCue(cues, now, lagMs);
|
|
3926
|
-
const dueInHold = due && now < due.receivedAt + lagMs + holdMs ? due : null;
|
|
3927
|
-
if (dueInHold && (!previous || dueInHold.receivedAt > previous.cue.receivedAt)) {
|
|
3928
|
-
return { cue: dueInHold, shownAt: now, lagMs };
|
|
3927
|
+
for (const cue of incoming) {
|
|
3928
|
+
if (Number.isFinite(cue.receivedAt)) map.set(cue.receivedAt, cue);
|
|
3929
3929
|
}
|
|
3930
|
-
|
|
3931
|
-
return previous;
|
|
3932
|
-
}
|
|
3933
|
-
return null;
|
|
3930
|
+
return [...map.values()].sort((left, right) => left.receivedAt - right.receivedAt).slice(-Math.max(1, cap));
|
|
3934
3931
|
}
|
|
3935
3932
|
async function loadCaptionVtt(url) {
|
|
3936
3933
|
try {
|
|
@@ -3969,6 +3966,85 @@ async function loadLiveCaptions(url) {
|
|
|
3969
3966
|
return { ok: false, cues: [] };
|
|
3970
3967
|
}
|
|
3971
3968
|
}
|
|
3969
|
+
var NEAR_BOTTOM_PX = 24;
|
|
3970
|
+
function LiveCaptionStack({ cues, latestLabel }) {
|
|
3971
|
+
const scrollerRef = React9.useRef(null);
|
|
3972
|
+
const followRef = React9.useRef(true);
|
|
3973
|
+
const [following, setFollowing] = React9.useState(true);
|
|
3974
|
+
const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
|
|
3975
|
+
const lastReceivedAt = cues[cues.length - 1]?.receivedAt;
|
|
3976
|
+
const scrollToLatest = React9.useCallback(() => {
|
|
3977
|
+
const scroller = scrollerRef.current;
|
|
3978
|
+
if (!scroller) return;
|
|
3979
|
+
scroller.scrollTo({
|
|
3980
|
+
top: scroller.scrollHeight,
|
|
3981
|
+
behavior: prefersReduced ? "auto" : "smooth"
|
|
3982
|
+
});
|
|
3983
|
+
followRef.current = true;
|
|
3984
|
+
setFollowing(true);
|
|
3985
|
+
}, [prefersReduced]);
|
|
3986
|
+
React9.useLayoutEffect(() => {
|
|
3987
|
+
if (!followRef.current) return;
|
|
3988
|
+
const scroller = scrollerRef.current;
|
|
3989
|
+
if (!scroller) return;
|
|
3990
|
+
scroller.scrollTo({
|
|
3991
|
+
top: scroller.scrollHeight,
|
|
3992
|
+
behavior: prefersReduced ? "auto" : "smooth"
|
|
3993
|
+
});
|
|
3994
|
+
}, [lastReceivedAt, prefersReduced, cues.length]);
|
|
3995
|
+
if (cues.length === 0) return null;
|
|
3996
|
+
return /* @__PURE__ */ jsx(
|
|
3997
|
+
"div",
|
|
3998
|
+
{
|
|
3999
|
+
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4000
|
+
"data-slot": "video-captions",
|
|
4001
|
+
children: /* @__PURE__ */ jsxs("div", { className: "relative w-full max-w-[90%]", children: [
|
|
4002
|
+
!following && /* @__PURE__ */ jsx(
|
|
4003
|
+
"button",
|
|
4004
|
+
{
|
|
4005
|
+
type: "button",
|
|
4006
|
+
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",
|
|
4007
|
+
onClick: scrollToLatest,
|
|
4008
|
+
children: latestLabel
|
|
4009
|
+
}
|
|
4010
|
+
),
|
|
4011
|
+
/* @__PURE__ */ jsx(
|
|
4012
|
+
"div",
|
|
4013
|
+
{
|
|
4014
|
+
ref: scrollerRef,
|
|
4015
|
+
role: "log",
|
|
4016
|
+
"aria-relevant": "additions",
|
|
4017
|
+
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-center text-sm font-medium text-white shadow-sm",
|
|
4018
|
+
onScroll: (event) => {
|
|
4019
|
+
const scroller = event.currentTarget;
|
|
4020
|
+
const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
|
|
4021
|
+
followRef.current = nearBottom;
|
|
4022
|
+
setFollowing(nearBottom);
|
|
4023
|
+
},
|
|
4024
|
+
children: cues.map((cue, index) => {
|
|
4025
|
+
const fromEnd = cues.length - 1 - index;
|
|
4026
|
+
const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
|
|
4027
|
+
const newest = fromEnd === 0;
|
|
4028
|
+
return /* @__PURE__ */ jsx(
|
|
4029
|
+
"p",
|
|
4030
|
+
{
|
|
4031
|
+
className: cn(
|
|
4032
|
+
"leading-5 break-words",
|
|
4033
|
+
!prefersReduced && "transition-opacity"
|
|
4034
|
+
),
|
|
4035
|
+
style: { opacity },
|
|
4036
|
+
"aria-live": newest ? "polite" : void 0,
|
|
4037
|
+
children: cue.text
|
|
4038
|
+
},
|
|
4039
|
+
cue.receivedAt
|
|
4040
|
+
);
|
|
4041
|
+
})
|
|
4042
|
+
}
|
|
4043
|
+
)
|
|
4044
|
+
] })
|
|
4045
|
+
}
|
|
4046
|
+
);
|
|
4047
|
+
}
|
|
3972
4048
|
var DEFAULT_LABELS3 = {
|
|
3973
4049
|
play: "Play",
|
|
3974
4050
|
pause: "Pause",
|
|
@@ -3997,7 +4073,8 @@ var DEFAULT_LABELS3 = {
|
|
|
3997
4073
|
captionsOff: "Off",
|
|
3998
4074
|
captionsEn: "English",
|
|
3999
4075
|
captionsEs: "Espa\xF1ol",
|
|
4000
|
-
captionsPt: "Portugu\xEAs"
|
|
4076
|
+
captionsPt: "Portugu\xEAs",
|
|
4077
|
+
captionsLatest: "Latest"
|
|
4001
4078
|
};
|
|
4002
4079
|
var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
4003
4080
|
var CONTROLS_HIDE_MS = 3e3;
|
|
@@ -4059,12 +4136,12 @@ function VideoPlayer({
|
|
|
4059
4136
|
liveCaptionsBaseUrl
|
|
4060
4137
|
}) {
|
|
4061
4138
|
const t = { ...DEFAULT_LABELS3, ...labels };
|
|
4062
|
-
const containerRef =
|
|
4063
|
-
const firstPlayFiredRef =
|
|
4064
|
-
const [userStarted, setUserStarted] =
|
|
4139
|
+
const containerRef = React9.useRef(null);
|
|
4140
|
+
const firstPlayFiredRef = React9.useRef(false);
|
|
4141
|
+
const [userStarted, setUserStarted] = React9.useState(false);
|
|
4065
4142
|
const active = autoPlay || !poster || userStarted;
|
|
4066
4143
|
const autoplayActive = autoPlay || userStarted;
|
|
4067
|
-
const handlePlayingChange =
|
|
4144
|
+
const handlePlayingChange = React9.useCallback(
|
|
4068
4145
|
(playing) => {
|
|
4069
4146
|
setIsPlaying(playing);
|
|
4070
4147
|
if (playing && !firstPlayFiredRef.current) {
|
|
@@ -4093,30 +4170,29 @@ function VideoPlayer({
|
|
|
4093
4170
|
onError,
|
|
4094
4171
|
onPlayingChange: handlePlayingChange
|
|
4095
4172
|
});
|
|
4096
|
-
const [isPlaying, setIsPlaying] =
|
|
4097
|
-
const [isMuted, setIsMuted] =
|
|
4098
|
-
const isMutedRef =
|
|
4173
|
+
const [isPlaying, setIsPlaying] = React9.useState(false);
|
|
4174
|
+
const [isMuted, setIsMuted] = React9.useState(muted);
|
|
4175
|
+
const isMutedRef = React9.useRef(isMuted);
|
|
4099
4176
|
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);
|
|
4177
|
+
const [volume, setVolume] = React9.useState(1);
|
|
4178
|
+
const [currentTime, setCurrentTime] = React9.useState(0);
|
|
4179
|
+
const [duration, setDuration] = React9.useState(0);
|
|
4180
|
+
const [buffered, setBuffered] = React9.useState(0);
|
|
4181
|
+
const [isFullscreen, setIsFullscreen] = React9.useState(false);
|
|
4182
|
+
const [pipActive, setPipActive] = React9.useState(false);
|
|
4183
|
+
const [controlsVisible, setControlsVisible] = React9.useState(true);
|
|
4184
|
+
const [playbackRate, setPlaybackRate] = React9.useState(1);
|
|
4185
|
+
const [openMenu, setOpenMenu] = React9.useState(null);
|
|
4186
|
+
const [captionLocale, setCaptionLocale] = React9.useState(defaultCaptionLocale ?? "off");
|
|
4187
|
+
const [captionCues, setCaptionCues] = React9.useState([]);
|
|
4188
|
+
const [liveCaptionCues, setLiveCaptionCues] = React9.useState([]);
|
|
4189
|
+
const [liveLagMs, setLiveLagMs] = React9.useState(null);
|
|
4190
|
+
const [behindLive, setBehindLive] = React9.useState(false);
|
|
4191
|
+
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9.useState(false);
|
|
4192
|
+
const hideTimerRef = React9.useRef(null);
|
|
4117
4193
|
const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
|
|
4118
4194
|
const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported;
|
|
4119
|
-
|
|
4195
|
+
React9.useEffect(() => {
|
|
4120
4196
|
const video = videoRef.current;
|
|
4121
4197
|
if (!video || !active) return;
|
|
4122
4198
|
const onTimeUpdate = () => {
|
|
@@ -4158,25 +4234,25 @@ function VideoPlayer({
|
|
|
4158
4234
|
video.removeEventListener("playing", onPlaying);
|
|
4159
4235
|
};
|
|
4160
4236
|
}, [videoRef, active, mode, liveCaptionsBaseUrl]);
|
|
4161
|
-
|
|
4237
|
+
React9.useLayoutEffect(() => {
|
|
4162
4238
|
const video = videoRef.current;
|
|
4163
4239
|
if (video) video.muted = isMuted;
|
|
4164
4240
|
}, [isMuted, active, videoRef]);
|
|
4165
|
-
|
|
4241
|
+
React9.useEffect(() => {
|
|
4166
4242
|
const video = videoRef.current;
|
|
4167
4243
|
if (!paused || !video || !isPlaying) return;
|
|
4168
4244
|
video.pause();
|
|
4169
4245
|
}, [paused, videoRef, isPlaying]);
|
|
4170
|
-
|
|
4246
|
+
React9.useEffect(() => {
|
|
4171
4247
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
4172
4248
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
4173
4249
|
}, [videoRef, active]);
|
|
4174
|
-
|
|
4250
|
+
React9.useEffect(() => {
|
|
4175
4251
|
const onFsChange = () => setIsFullscreen(document.fullscreenElement === containerRef.current);
|
|
4176
4252
|
document.addEventListener("fullscreenchange", onFsChange);
|
|
4177
4253
|
return () => document.removeEventListener("fullscreenchange", onFsChange);
|
|
4178
4254
|
}, []);
|
|
4179
|
-
|
|
4255
|
+
React9.useEffect(() => {
|
|
4180
4256
|
const video = asWebkitVideo(videoRef.current);
|
|
4181
4257
|
if (!video) return;
|
|
4182
4258
|
const onBegin = () => setIsFullscreen(true);
|
|
@@ -4188,7 +4264,7 @@ function VideoPlayer({
|
|
|
4188
4264
|
video.removeEventListener("webkitendfullscreen", onEnd);
|
|
4189
4265
|
};
|
|
4190
4266
|
}, [videoRef, active]);
|
|
4191
|
-
|
|
4267
|
+
React9.useEffect(() => {
|
|
4192
4268
|
const video = videoRef.current;
|
|
4193
4269
|
if (!video) return;
|
|
4194
4270
|
const onEnter = () => setPipActive(true);
|
|
@@ -4200,29 +4276,29 @@ function VideoPlayer({
|
|
|
4200
4276
|
video.removeEventListener("leavepictureinpicture", onLeave);
|
|
4201
4277
|
};
|
|
4202
4278
|
}, [videoRef]);
|
|
4203
|
-
const scheduleHide =
|
|
4279
|
+
const scheduleHide = React9.useCallback(() => {
|
|
4204
4280
|
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
4205
4281
|
hideTimerRef.current = setTimeout(() => {
|
|
4206
4282
|
setControlsVisible(false);
|
|
4207
4283
|
setOpenMenu(null);
|
|
4208
4284
|
}, CONTROLS_HIDE_MS);
|
|
4209
4285
|
}, []);
|
|
4210
|
-
const revealControls =
|
|
4286
|
+
const revealControls = React9.useCallback(() => {
|
|
4211
4287
|
setControlsVisible(true);
|
|
4212
4288
|
scheduleHide();
|
|
4213
4289
|
}, [scheduleHide]);
|
|
4214
|
-
|
|
4290
|
+
React9.useEffect(() => {
|
|
4215
4291
|
return () => {
|
|
4216
4292
|
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
4217
4293
|
};
|
|
4218
4294
|
}, []);
|
|
4219
|
-
|
|
4295
|
+
React9.useEffect(() => {
|
|
4220
4296
|
if (captionLocale === "off") {
|
|
4221
4297
|
setCaptionCues([]);
|
|
4222
4298
|
setLiveCaptionCues([]);
|
|
4223
|
-
liveCaptionLatchRef.current = null;
|
|
4224
4299
|
return;
|
|
4225
4300
|
}
|
|
4301
|
+
setLiveCaptionCues([]);
|
|
4226
4302
|
let cancelled = false;
|
|
4227
4303
|
const load = async () => {
|
|
4228
4304
|
const liveBase = liveCaptionsBaseUrl?.trim();
|
|
@@ -4230,7 +4306,9 @@ function VideoPlayer({
|
|
|
4230
4306
|
const loaded = await loadLiveCaptions(
|
|
4231
4307
|
liveCaptionsUrl(liveBase, captionLocale)
|
|
4232
4308
|
);
|
|
4233
|
-
if (!cancelled && loaded.ok)
|
|
4309
|
+
if (!cancelled && loaded.ok) {
|
|
4310
|
+
setLiveCaptionCues((prev) => mergeLiveCaptionCues(prev, loaded.cues));
|
|
4311
|
+
}
|
|
4234
4312
|
return;
|
|
4235
4313
|
}
|
|
4236
4314
|
const url = captionsVttUrlFromPlayback(src, captionLocale);
|
|
@@ -4249,20 +4327,8 @@ function VideoPlayer({
|
|
|
4249
4327
|
window.clearInterval(timer);
|
|
4250
4328
|
};
|
|
4251
4329
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4252
|
-
const
|
|
4253
|
-
const
|
|
4254
|
-
if (liveCaptionKeyRef.current !== liveCaptionKey) {
|
|
4255
|
-
liveCaptionKeyRef.current = liveCaptionKey;
|
|
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);
|
|
4330
|
+
const liveDueCues = liveCaptionsBaseUrl ? liveCuesDue(liveCaptionCues, Date.now(), liveLagMs) : [];
|
|
4331
|
+
const activeCaption = liveCaptionsBaseUrl ? null : captionAtTime(captionCues, currentTime);
|
|
4266
4332
|
function togglePlay() {
|
|
4267
4333
|
const video = videoRef.current;
|
|
4268
4334
|
if (!video) return;
|
|
@@ -4492,12 +4558,13 @@ function VideoPlayer({
|
|
|
4492
4558
|
] }),
|
|
4493
4559
|
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
4560
|
] }),
|
|
4495
|
-
|
|
4561
|
+
liveCaptionsBaseUrl && captionLocale !== "off" && /* @__PURE__ */ jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
|
|
4562
|
+
!liveCaptionsBaseUrl && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsx(
|
|
4496
4563
|
"div",
|
|
4497
4564
|
{
|
|
4498
4565
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4499
4566
|
"data-slot": "video-captions",
|
|
4500
|
-
children: /* @__PURE__ */ jsx("p", { className: "max-w-[90%] rounded-sm bg-black/70 px-3 py-1.5 text-center text-sm font-medium text-white shadow-sm", children: activeCaption.text })
|
|
4567
|
+
children: /* @__PURE__ */ jsx("p", { className: "line-clamp-2 max-w-[90%] break-words rounded-sm bg-black/70 px-3 py-1.5 text-center text-sm font-medium text-white shadow-sm", children: activeCaption.text })
|
|
4501
4568
|
}
|
|
4502
4569
|
),
|
|
4503
4570
|
active && /* @__PURE__ */ jsxs(
|
|
@@ -4785,16 +4852,16 @@ function videoInPictureInPicture(container) {
|
|
|
4785
4852
|
return container.contains(pip);
|
|
4786
4853
|
}
|
|
4787
4854
|
function useFeedExclusivePlayback(playbackId) {
|
|
4788
|
-
const containerRef =
|
|
4789
|
-
const [forcePaused, setForcePaused] =
|
|
4790
|
-
const requestPause =
|
|
4855
|
+
const containerRef = React9.useRef(null);
|
|
4856
|
+
const [forcePaused, setForcePaused] = React9.useState(false);
|
|
4857
|
+
const requestPause = React9.useCallback(() => {
|
|
4791
4858
|
if (videoInPictureInPicture(containerRef.current)) return;
|
|
4792
4859
|
setForcePaused(true);
|
|
4793
4860
|
}, []);
|
|
4794
|
-
|
|
4861
|
+
React9.useEffect(() => {
|
|
4795
4862
|
return registerFeedPlayer(playbackId, requestPause);
|
|
4796
4863
|
}, [playbackId, requestPause]);
|
|
4797
|
-
|
|
4864
|
+
React9.useEffect(() => {
|
|
4798
4865
|
const node = containerRef.current;
|
|
4799
4866
|
if (!node || typeof IntersectionObserver === "undefined") return;
|
|
4800
4867
|
const observer = new IntersectionObserver(
|
|
@@ -4810,14 +4877,14 @@ function useFeedExclusivePlayback(playbackId) {
|
|
|
4810
4877
|
observer.observe(node);
|
|
4811
4878
|
return () => observer.disconnect();
|
|
4812
4879
|
}, [requestPause]);
|
|
4813
|
-
|
|
4880
|
+
React9.useEffect(() => {
|
|
4814
4881
|
const onVisibility = () => {
|
|
4815
4882
|
if (document.hidden) requestPause();
|
|
4816
4883
|
};
|
|
4817
4884
|
document.addEventListener("visibilitychange", onVisibility);
|
|
4818
4885
|
return () => document.removeEventListener("visibilitychange", onVisibility);
|
|
4819
4886
|
}, [requestPause]);
|
|
4820
|
-
const onPlayingChange =
|
|
4887
|
+
const onPlayingChange = React9.useCallback(
|
|
4821
4888
|
(playing) => {
|
|
4822
4889
|
if (!playing) return;
|
|
4823
4890
|
setForcePaused(false);
|
|
@@ -4844,7 +4911,7 @@ function FeedVideoPlayer({
|
|
|
4844
4911
|
paused: exclusivePaused,
|
|
4845
4912
|
onPlayingChange: onExclusivePlayingChange
|
|
4846
4913
|
} = useFeedExclusivePlayback(playbackId);
|
|
4847
|
-
const handlePlayingChange =
|
|
4914
|
+
const handlePlayingChange = React9.useCallback(
|
|
4848
4915
|
(playing) => {
|
|
4849
4916
|
onExclusivePlayingChange(playing);
|
|
4850
4917
|
onPlayingChange?.(playing);
|
|
@@ -4871,8 +4938,8 @@ function FeedVideoPlayer({
|
|
|
4871
4938
|
);
|
|
4872
4939
|
}
|
|
4873
4940
|
function usePlaybackStats(statsUrl, { intervalMs = 15e3, enabled = true } = {}) {
|
|
4874
|
-
const [stats, setStats] =
|
|
4875
|
-
|
|
4941
|
+
const [stats, setStats] = React9.useState({});
|
|
4942
|
+
React9.useEffect(() => {
|
|
4876
4943
|
if (!statsUrl || !enabled) return;
|
|
4877
4944
|
let cancelled = false;
|
|
4878
4945
|
const controller = new AbortController();
|