@livo-tv/blocks 1.5.0 → 1.6.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 +327 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +261 -93
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import * as
|
|
2
|
+
import * as React8 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, 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 = React8.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] = React8.useState(false);
|
|
2382
|
+
React8.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 = React8.useRef(null);
|
|
2400
|
+
const [playback, setPlayback] = React8.useState("pending");
|
|
2401
|
+
const [muted, setMuted] = React8.useState(true);
|
|
2402
|
+
const [audio, setAudio] = React8.useState("unknown");
|
|
2403
|
+
React8.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 = React8.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 = React8.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] = React8.useState(null);
|
|
2568
|
+
const [inView, setInView] = React8.useState(false);
|
|
2569
|
+
React8.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 = React8.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 = React8.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] = React8.useState(nowMs ?? Date.now());
|
|
3083
|
+
React8.useEffect(() => {
|
|
3084
3084
|
if (nowMs != null) {
|
|
3085
3085
|
setNow(nowMs);
|
|
3086
3086
|
return;
|
|
@@ -3175,6 +3175,187 @@ async function castHlsUrl(hlsUrl) {
|
|
|
3175
3175
|
await session.loadMedia(request);
|
|
3176
3176
|
}
|
|
3177
3177
|
|
|
3178
|
+
// src/components/video/seekPreview.ts
|
|
3179
|
+
var XYWH_RE = /#xywh=(\d+),(\d+),(\d+),(\d+)\s*$/;
|
|
3180
|
+
function thumbnailsVttUrlFromPlayback(src) {
|
|
3181
|
+
const trimmed = src.trim();
|
|
3182
|
+
if (!trimmed) return null;
|
|
3183
|
+
const replaced = trimmed.replace(
|
|
3184
|
+
/index\.m3u8(?:\?.*)?$/i,
|
|
3185
|
+
"thumbs/preview.vtt"
|
|
3186
|
+
);
|
|
3187
|
+
if (replaced === trimmed) return null;
|
|
3188
|
+
return replaced;
|
|
3189
|
+
}
|
|
3190
|
+
function parseVttTimestamp(value) {
|
|
3191
|
+
const parts = value.trim().split(":");
|
|
3192
|
+
if (parts.length === 3) {
|
|
3193
|
+
const hours = Number(parts[0]);
|
|
3194
|
+
const minutes = Number(parts[1]);
|
|
3195
|
+
const seconds2 = Number(parts[2]);
|
|
3196
|
+
if ([hours, minutes, seconds2].some((n) => Number.isNaN(n))) return 0;
|
|
3197
|
+
return hours * 3600 + minutes * 60 + seconds2;
|
|
3198
|
+
}
|
|
3199
|
+
if (parts.length === 2) {
|
|
3200
|
+
const minutes = Number(parts[0]);
|
|
3201
|
+
const seconds2 = Number(parts[1]);
|
|
3202
|
+
if ([minutes, seconds2].some((n) => Number.isNaN(n))) return 0;
|
|
3203
|
+
return minutes * 60 + seconds2;
|
|
3204
|
+
}
|
|
3205
|
+
const seconds = Number(value);
|
|
3206
|
+
return Number.isFinite(seconds) ? seconds : 0;
|
|
3207
|
+
}
|
|
3208
|
+
function parseThumbnailsVtt(text, vttUrl) {
|
|
3209
|
+
const cues = [];
|
|
3210
|
+
const blocks = text.replace(/^\uFEFF?WEBVTT[^\n]*\n/i, "").split(/\n\s*\n/);
|
|
3211
|
+
for (const block of blocks) {
|
|
3212
|
+
const lines = block.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
3213
|
+
const timing = lines.find((line) => line.includes("-->"));
|
|
3214
|
+
const payload = lines.find((line) => XYWH_RE.test(line));
|
|
3215
|
+
if (!timing || !payload) continue;
|
|
3216
|
+
const [startRaw, endRaw] = timing.split("-->").map((part) => part.trim());
|
|
3217
|
+
const match = payload.match(XYWH_RE);
|
|
3218
|
+
if (!startRaw || !endRaw || !match) continue;
|
|
3219
|
+
const spriteName = payload.slice(0, match.index);
|
|
3220
|
+
cues.push({
|
|
3221
|
+
start: parseVttTimestamp(startRaw),
|
|
3222
|
+
end: parseVttTimestamp(endRaw),
|
|
3223
|
+
spriteUrl: new URL(spriteName, vttUrl).toString(),
|
|
3224
|
+
x: Number(match[1]),
|
|
3225
|
+
y: Number(match[2]),
|
|
3226
|
+
width: Number(match[3]),
|
|
3227
|
+
height: Number(match[4])
|
|
3228
|
+
});
|
|
3229
|
+
}
|
|
3230
|
+
return cues;
|
|
3231
|
+
}
|
|
3232
|
+
function cueAtTime(cues, time) {
|
|
3233
|
+
if (cues.length === 0) return null;
|
|
3234
|
+
const hit = cues.find((cue) => time >= cue.start && time < cue.end);
|
|
3235
|
+
if (hit) return hit;
|
|
3236
|
+
const last = cues[cues.length - 1];
|
|
3237
|
+
if (last && time >= last.start) return last;
|
|
3238
|
+
return cues[0] ?? null;
|
|
3239
|
+
}
|
|
3240
|
+
function hoverTimeFromClientX(clientX, rect, duration) {
|
|
3241
|
+
if (rect.width <= 0 || duration <= 0) return 0;
|
|
3242
|
+
const ratio = Math.min(1, Math.max(0, (clientX - rect.left) / rect.width));
|
|
3243
|
+
return ratio * duration;
|
|
3244
|
+
}
|
|
3245
|
+
async function loadThumbnailsVtt(src) {
|
|
3246
|
+
const vttUrl = thumbnailsVttUrlFromPlayback(src);
|
|
3247
|
+
if (!vttUrl) return [];
|
|
3248
|
+
try {
|
|
3249
|
+
const response = await fetch(vttUrl);
|
|
3250
|
+
if (!response.ok) return [];
|
|
3251
|
+
const text = await response.text();
|
|
3252
|
+
return parseThumbnailsVtt(text, vttUrl);
|
|
3253
|
+
} catch {
|
|
3254
|
+
return [];
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
function SeekBar({
|
|
3258
|
+
src,
|
|
3259
|
+
duration,
|
|
3260
|
+
currentTime,
|
|
3261
|
+
buffered,
|
|
3262
|
+
onSeek,
|
|
3263
|
+
formatTime: formatTime2
|
|
3264
|
+
}) {
|
|
3265
|
+
const trackRef = React8.useRef(null);
|
|
3266
|
+
const [hoverTime, setHoverTime] = React8.useState(null);
|
|
3267
|
+
const [cues, setCues] = React8.useState(null);
|
|
3268
|
+
const loadedSrc = React8.useRef(null);
|
|
3269
|
+
React8.useEffect(() => {
|
|
3270
|
+
setCues(null);
|
|
3271
|
+
loadedSrc.current = null;
|
|
3272
|
+
}, [src]);
|
|
3273
|
+
const ensureCues = React8.useCallback(() => {
|
|
3274
|
+
if (loadedSrc.current === src) return;
|
|
3275
|
+
loadedSrc.current = src;
|
|
3276
|
+
void loadThumbnailsVtt(src).then((next) => {
|
|
3277
|
+
setCues(next);
|
|
3278
|
+
});
|
|
3279
|
+
}, [src]);
|
|
3280
|
+
const updateHover = React8.useCallback(
|
|
3281
|
+
(clientX) => {
|
|
3282
|
+
const rect = trackRef.current?.getBoundingClientRect();
|
|
3283
|
+
if (!rect) return;
|
|
3284
|
+
setHoverTime(hoverTimeFromClientX(clientX, rect, duration));
|
|
3285
|
+
},
|
|
3286
|
+
[duration]
|
|
3287
|
+
);
|
|
3288
|
+
const cue = hoverTime !== null && cues && cues.length > 0 ? cueAtTime(cues, hoverTime) : null;
|
|
3289
|
+
const hoverPercent = hoverTime !== null && duration > 0 ? Math.min(100, Math.max(0, hoverTime / duration * 100)) : 0;
|
|
3290
|
+
return /* @__PURE__ */ jsxs(
|
|
3291
|
+
"div",
|
|
3292
|
+
{
|
|
3293
|
+
ref: trackRef,
|
|
3294
|
+
className: "relative w-full",
|
|
3295
|
+
onPointerEnter: ensureCues,
|
|
3296
|
+
onPointerDown: (event) => {
|
|
3297
|
+
ensureCues();
|
|
3298
|
+
updateHover(event.clientX);
|
|
3299
|
+
},
|
|
3300
|
+
onPointerMove: (event) => {
|
|
3301
|
+
ensureCues();
|
|
3302
|
+
updateHover(event.clientX);
|
|
3303
|
+
},
|
|
3304
|
+
onPointerLeave: () => setHoverTime(null),
|
|
3305
|
+
onPointerUp: () => setHoverTime(null),
|
|
3306
|
+
children: [
|
|
3307
|
+
hoverTime !== null ? /* @__PURE__ */ jsxs(
|
|
3308
|
+
"div",
|
|
3309
|
+
{
|
|
3310
|
+
className: "pointer-events-none absolute bottom-full mb-2 flex flex-col items-center gap-1",
|
|
3311
|
+
style: { left: `${hoverPercent}%`, transform: "translateX(-50%)" },
|
|
3312
|
+
"data-slot": "seek-preview",
|
|
3313
|
+
children: [
|
|
3314
|
+
cue ? /* @__PURE__ */ jsx(
|
|
3315
|
+
"div",
|
|
3316
|
+
{
|
|
3317
|
+
"aria-hidden": "true",
|
|
3318
|
+
className: "overflow-hidden rounded border border-white/20 bg-black shadow-md",
|
|
3319
|
+
style: {
|
|
3320
|
+
width: cue.width,
|
|
3321
|
+
height: cue.height,
|
|
3322
|
+
backgroundImage: `url(${cue.spriteUrl})`,
|
|
3323
|
+
backgroundPosition: `-${cue.x}px -${cue.y}px`,
|
|
3324
|
+
backgroundRepeat: "no-repeat"
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
) : null,
|
|
3328
|
+
/* @__PURE__ */ jsx("span", { className: "rounded-full bg-black/80 px-1.5 py-0.5 text-[10px] tabular-nums text-white", children: formatTime2(hoverTime) })
|
|
3329
|
+
]
|
|
3330
|
+
}
|
|
3331
|
+
) : null,
|
|
3332
|
+
/* @__PURE__ */ jsx(
|
|
3333
|
+
Slider,
|
|
3334
|
+
{
|
|
3335
|
+
"aria-label": "Seek",
|
|
3336
|
+
min: 0,
|
|
3337
|
+
max: duration || 0,
|
|
3338
|
+
step: 0.1,
|
|
3339
|
+
value: [Math.min(currentTime, duration || 0)],
|
|
3340
|
+
onValueChange: (value) => onSeek(value[0] ?? 0),
|
|
3341
|
+
className: "w-full"
|
|
3342
|
+
}
|
|
3343
|
+
),
|
|
3344
|
+
duration > 0 && buffered > currentTime ? /* @__PURE__ */ jsx(
|
|
3345
|
+
"span",
|
|
3346
|
+
{
|
|
3347
|
+
"aria-hidden": "true",
|
|
3348
|
+
className: "pointer-events-none absolute top-1/2 left-0 h-1.5 -translate-y-1/2 rounded-full bg-white/25",
|
|
3349
|
+
style: {
|
|
3350
|
+
width: `${Math.min(buffered / duration * 100, 100)}%`
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
) : null
|
|
3354
|
+
]
|
|
3355
|
+
}
|
|
3356
|
+
);
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3178
3359
|
// src/components/video/hls-config.ts
|
|
3179
3360
|
function shouldRetryLiveEdge404(retryConfig, retryCount, _isTimeout, loaderResponse, defaultRetry) {
|
|
3180
3361
|
if (loaderResponse?.code === 404) {
|
|
@@ -3353,27 +3534,27 @@ function useHlsPlayback({
|
|
|
3353
3534
|
onError,
|
|
3354
3535
|
onPlayingChange
|
|
3355
3536
|
}) {
|
|
3356
|
-
const videoRef =
|
|
3357
|
-
const hlsRef =
|
|
3358
|
-
const [state, setState] =
|
|
3359
|
-
const [qualities, setQualities] =
|
|
3360
|
-
const [activeLevel, setActiveLevel] =
|
|
3361
|
-
const [autoplayState, setAutoplayState] =
|
|
3362
|
-
const [error, setError] =
|
|
3363
|
-
const [reloadKey, setReloadKey] =
|
|
3364
|
-
const onErrorRef =
|
|
3365
|
-
const onPlayingChangeRef =
|
|
3366
|
-
|
|
3537
|
+
const videoRef = React8.useRef(null);
|
|
3538
|
+
const hlsRef = React8.useRef(null);
|
|
3539
|
+
const [state, setState] = React8.useState("idle");
|
|
3540
|
+
const [qualities, setQualities] = React8.useState([]);
|
|
3541
|
+
const [activeLevel, setActiveLevel] = React8.useState(-1);
|
|
3542
|
+
const [autoplayState, setAutoplayState] = React8.useState("none");
|
|
3543
|
+
const [error, setError] = React8.useState(null);
|
|
3544
|
+
const [reloadKey, setReloadKey] = React8.useState(0);
|
|
3545
|
+
const onErrorRef = React8.useRef(onError);
|
|
3546
|
+
const onPlayingChangeRef = React8.useRef(onPlayingChange);
|
|
3547
|
+
React8.useEffect(() => {
|
|
3367
3548
|
onErrorRef.current = onError;
|
|
3368
3549
|
onPlayingChangeRef.current = onPlayingChange;
|
|
3369
3550
|
}, [onError, onPlayingChange]);
|
|
3370
|
-
const retry =
|
|
3551
|
+
const retry = React8.useCallback(() => {
|
|
3371
3552
|
setError(null);
|
|
3372
3553
|
setState("loading");
|
|
3373
3554
|
setAutoplayState("none");
|
|
3374
3555
|
setReloadKey((k) => k + 1);
|
|
3375
3556
|
}, []);
|
|
3376
|
-
|
|
3557
|
+
React8.useEffect(() => {
|
|
3377
3558
|
const media = videoRef.current;
|
|
3378
3559
|
if (!media || !src || !active) {
|
|
3379
3560
|
setState("idle");
|
|
@@ -3643,7 +3824,7 @@ function useHlsPlayback({
|
|
|
3643
3824
|
destroyHls();
|
|
3644
3825
|
};
|
|
3645
3826
|
}, [src, mode, active, autoPlay, muted, reloadKey]);
|
|
3646
|
-
const setLevel =
|
|
3827
|
+
const setLevel = React8.useCallback((index) => {
|
|
3647
3828
|
const hls = hlsRef.current;
|
|
3648
3829
|
if (!hls) return;
|
|
3649
3830
|
hls.nextLevel = index;
|
|
@@ -3729,12 +3910,12 @@ function VideoPlayer({
|
|
|
3729
3910
|
className
|
|
3730
3911
|
}) {
|
|
3731
3912
|
const t = { ...DEFAULT_LABELS3, ...labels };
|
|
3732
|
-
const containerRef =
|
|
3733
|
-
const firstPlayFiredRef =
|
|
3734
|
-
const [userStarted, setUserStarted] =
|
|
3913
|
+
const containerRef = React8.useRef(null);
|
|
3914
|
+
const firstPlayFiredRef = React8.useRef(false);
|
|
3915
|
+
const [userStarted, setUserStarted] = React8.useState(false);
|
|
3735
3916
|
const active = autoPlay || !poster || userStarted;
|
|
3736
3917
|
const autoplayActive = autoPlay || userStarted;
|
|
3737
|
-
const handlePlayingChange =
|
|
3918
|
+
const handlePlayingChange = React8.useCallback(
|
|
3738
3919
|
(playing) => {
|
|
3739
3920
|
setIsPlaying(playing);
|
|
3740
3921
|
if (playing && !firstPlayFiredRef.current) {
|
|
@@ -3763,25 +3944,25 @@ function VideoPlayer({
|
|
|
3763
3944
|
onError,
|
|
3764
3945
|
onPlayingChange: handlePlayingChange
|
|
3765
3946
|
});
|
|
3766
|
-
const [isPlaying, setIsPlaying] =
|
|
3767
|
-
const [isMuted, setIsMuted] =
|
|
3768
|
-
const [volume, setVolume] =
|
|
3769
|
-
const [currentTime, setCurrentTime] =
|
|
3770
|
-
const [duration, setDuration] =
|
|
3771
|
-
const [buffered, setBuffered] =
|
|
3772
|
-
const [isFullscreen, setIsFullscreen] =
|
|
3773
|
-
const [pipActive, setPipActive] =
|
|
3774
|
-
const [controlsVisible, setControlsVisible] =
|
|
3775
|
-
const [playbackRate, setPlaybackRate] =
|
|
3776
|
-
const [openMenu, setOpenMenu] =
|
|
3947
|
+
const [isPlaying, setIsPlaying] = React8.useState(false);
|
|
3948
|
+
const [isMuted, setIsMuted] = React8.useState(muted);
|
|
3949
|
+
const [volume, setVolume] = React8.useState(1);
|
|
3950
|
+
const [currentTime, setCurrentTime] = React8.useState(0);
|
|
3951
|
+
const [duration, setDuration] = React8.useState(0);
|
|
3952
|
+
const [buffered, setBuffered] = React8.useState(0);
|
|
3953
|
+
const [isFullscreen, setIsFullscreen] = React8.useState(false);
|
|
3954
|
+
const [pipActive, setPipActive] = React8.useState(false);
|
|
3955
|
+
const [controlsVisible, setControlsVisible] = React8.useState(true);
|
|
3956
|
+
const [playbackRate, setPlaybackRate] = React8.useState(1);
|
|
3957
|
+
const [openMenu, setOpenMenu] = React8.useState(
|
|
3777
3958
|
null
|
|
3778
3959
|
);
|
|
3779
|
-
const [behindLive, setBehindLive] =
|
|
3780
|
-
const [webkitFullscreenSupported, setWebkitFullscreenSupported] =
|
|
3781
|
-
const hideTimerRef =
|
|
3960
|
+
const [behindLive, setBehindLive] = React8.useState(false);
|
|
3961
|
+
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React8.useState(false);
|
|
3962
|
+
const hideTimerRef = React8.useRef(null);
|
|
3782
3963
|
const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
|
|
3783
3964
|
const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported;
|
|
3784
|
-
|
|
3965
|
+
React8.useEffect(() => {
|
|
3785
3966
|
const video = videoRef.current;
|
|
3786
3967
|
if (!video || !active) return;
|
|
3787
3968
|
const onTimeUpdate = () => {
|
|
@@ -3814,21 +3995,21 @@ function VideoPlayer({
|
|
|
3814
3995
|
video.removeEventListener("ratechange", onRate);
|
|
3815
3996
|
};
|
|
3816
3997
|
}, [videoRef, active, mode]);
|
|
3817
|
-
|
|
3998
|
+
React8.useEffect(() => {
|
|
3818
3999
|
const video = videoRef.current;
|
|
3819
4000
|
if (!paused || !video || !isPlaying) return;
|
|
3820
4001
|
video.pause();
|
|
3821
4002
|
}, [paused, videoRef, isPlaying]);
|
|
3822
|
-
|
|
4003
|
+
React8.useEffect(() => {
|
|
3823
4004
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
3824
4005
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
3825
4006
|
}, [videoRef, active]);
|
|
3826
|
-
|
|
4007
|
+
React8.useEffect(() => {
|
|
3827
4008
|
const onFsChange = () => setIsFullscreen(document.fullscreenElement === containerRef.current);
|
|
3828
4009
|
document.addEventListener("fullscreenchange", onFsChange);
|
|
3829
4010
|
return () => document.removeEventListener("fullscreenchange", onFsChange);
|
|
3830
4011
|
}, []);
|
|
3831
|
-
|
|
4012
|
+
React8.useEffect(() => {
|
|
3832
4013
|
const video = asWebkitVideo(videoRef.current);
|
|
3833
4014
|
if (!video) return;
|
|
3834
4015
|
const onBegin = () => setIsFullscreen(true);
|
|
@@ -3840,7 +4021,7 @@ function VideoPlayer({
|
|
|
3840
4021
|
video.removeEventListener("webkitendfullscreen", onEnd);
|
|
3841
4022
|
};
|
|
3842
4023
|
}, [videoRef, active]);
|
|
3843
|
-
|
|
4024
|
+
React8.useEffect(() => {
|
|
3844
4025
|
const video = videoRef.current;
|
|
3845
4026
|
if (!video) return;
|
|
3846
4027
|
const onEnter = () => setPipActive(true);
|
|
@@ -3852,18 +4033,18 @@ function VideoPlayer({
|
|
|
3852
4033
|
video.removeEventListener("leavepictureinpicture", onLeave);
|
|
3853
4034
|
};
|
|
3854
4035
|
}, [videoRef]);
|
|
3855
|
-
const scheduleHide =
|
|
4036
|
+
const scheduleHide = React8.useCallback(() => {
|
|
3856
4037
|
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
3857
4038
|
hideTimerRef.current = setTimeout(() => {
|
|
3858
4039
|
setControlsVisible(false);
|
|
3859
4040
|
setOpenMenu(null);
|
|
3860
4041
|
}, CONTROLS_HIDE_MS);
|
|
3861
4042
|
}, []);
|
|
3862
|
-
const revealControls =
|
|
4043
|
+
const revealControls = React8.useCallback(() => {
|
|
3863
4044
|
setControlsVisible(true);
|
|
3864
4045
|
scheduleHide();
|
|
3865
4046
|
}, [scheduleHide]);
|
|
3866
|
-
|
|
4047
|
+
React8.useEffect(() => {
|
|
3867
4048
|
return () => {
|
|
3868
4049
|
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
3869
4050
|
};
|
|
@@ -4105,30 +4286,17 @@ function VideoPlayer({
|
|
|
4105
4286
|
),
|
|
4106
4287
|
"data-slot": "video-controls",
|
|
4107
4288
|
children: [
|
|
4108
|
-
mode === "vod" && /* @__PURE__ */
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
}
|
|
4120
|
-
),
|
|
4121
|
-
duration > 0 && buffered > currentTime && /* @__PURE__ */ jsx(
|
|
4122
|
-
"span",
|
|
4123
|
-
{
|
|
4124
|
-
"aria-hidden": "true",
|
|
4125
|
-
className: "pointer-events-none absolute top-1/2 left-0 h-1.5 -translate-y-1/2 rounded-full bg-white/25",
|
|
4126
|
-
style: {
|
|
4127
|
-
width: `${Math.min(buffered / duration * 100, 100)}%`
|
|
4128
|
-
}
|
|
4129
|
-
}
|
|
4130
|
-
)
|
|
4131
|
-
] }),
|
|
4289
|
+
mode === "vod" && /* @__PURE__ */ jsx(
|
|
4290
|
+
SeekBar,
|
|
4291
|
+
{
|
|
4292
|
+
src,
|
|
4293
|
+
duration,
|
|
4294
|
+
currentTime,
|
|
4295
|
+
buffered,
|
|
4296
|
+
onSeek: seekTo,
|
|
4297
|
+
formatTime
|
|
4298
|
+
}
|
|
4299
|
+
),
|
|
4132
4300
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4133
4301
|
/* @__PURE__ */ jsx(
|
|
4134
4302
|
ControlButton,
|
|
@@ -4366,16 +4534,16 @@ function videoInPictureInPicture(container) {
|
|
|
4366
4534
|
return container.contains(pip);
|
|
4367
4535
|
}
|
|
4368
4536
|
function useFeedExclusivePlayback(playbackId) {
|
|
4369
|
-
const containerRef =
|
|
4370
|
-
const [forcePaused, setForcePaused] =
|
|
4371
|
-
const requestPause =
|
|
4537
|
+
const containerRef = React8.useRef(null);
|
|
4538
|
+
const [forcePaused, setForcePaused] = React8.useState(false);
|
|
4539
|
+
const requestPause = React8.useCallback(() => {
|
|
4372
4540
|
if (videoInPictureInPicture(containerRef.current)) return;
|
|
4373
4541
|
setForcePaused(true);
|
|
4374
4542
|
}, []);
|
|
4375
|
-
|
|
4543
|
+
React8.useEffect(() => {
|
|
4376
4544
|
return registerFeedPlayer(playbackId, requestPause);
|
|
4377
4545
|
}, [playbackId, requestPause]);
|
|
4378
|
-
|
|
4546
|
+
React8.useEffect(() => {
|
|
4379
4547
|
const node = containerRef.current;
|
|
4380
4548
|
if (!node || typeof IntersectionObserver === "undefined") return;
|
|
4381
4549
|
const observer = new IntersectionObserver(
|
|
@@ -4391,14 +4559,14 @@ function useFeedExclusivePlayback(playbackId) {
|
|
|
4391
4559
|
observer.observe(node);
|
|
4392
4560
|
return () => observer.disconnect();
|
|
4393
4561
|
}, [requestPause]);
|
|
4394
|
-
|
|
4562
|
+
React8.useEffect(() => {
|
|
4395
4563
|
const onVisibility = () => {
|
|
4396
4564
|
if (document.hidden) requestPause();
|
|
4397
4565
|
};
|
|
4398
4566
|
document.addEventListener("visibilitychange", onVisibility);
|
|
4399
4567
|
return () => document.removeEventListener("visibilitychange", onVisibility);
|
|
4400
4568
|
}, [requestPause]);
|
|
4401
|
-
const onPlayingChange =
|
|
4569
|
+
const onPlayingChange = React8.useCallback(
|
|
4402
4570
|
(playing) => {
|
|
4403
4571
|
if (!playing) return;
|
|
4404
4572
|
setForcePaused(false);
|
|
@@ -4425,7 +4593,7 @@ function FeedVideoPlayer({
|
|
|
4425
4593
|
paused: exclusivePaused,
|
|
4426
4594
|
onPlayingChange: onExclusivePlayingChange
|
|
4427
4595
|
} = useFeedExclusivePlayback(playbackId);
|
|
4428
|
-
const handlePlayingChange =
|
|
4596
|
+
const handlePlayingChange = React8.useCallback(
|
|
4429
4597
|
(playing) => {
|
|
4430
4598
|
onExclusivePlayingChange(playing);
|
|
4431
4599
|
onPlayingChange?.(playing);
|
|
@@ -4452,8 +4620,8 @@ function FeedVideoPlayer({
|
|
|
4452
4620
|
);
|
|
4453
4621
|
}
|
|
4454
4622
|
function usePlaybackStats(statsUrl, { intervalMs = 15e3, enabled = true } = {}) {
|
|
4455
|
-
const [stats, setStats] =
|
|
4456
|
-
|
|
4623
|
+
const [stats, setStats] = React8.useState({});
|
|
4624
|
+
React8.useEffect(() => {
|
|
4457
4625
|
if (!statsUrl || !enabled) return;
|
|
4458
4626
|
let cancelled = false;
|
|
4459
4627
|
const controller = new AbortController();
|