@livo-tv/blocks 1.30.2 → 1.32.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 +47 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +47 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5778,6 +5778,14 @@ var VIDEO_MEDIA_STYLE = `
|
|
|
5778
5778
|
display: none !important;
|
|
5779
5779
|
}
|
|
5780
5780
|
`;
|
|
5781
|
+
function hasCaptionSource(mode, src, liveCaptionsBaseUrl) {
|
|
5782
|
+
if (mode === "live") {
|
|
5783
|
+
return Boolean(liveCaptionsBaseUrl?.trim());
|
|
5784
|
+
}
|
|
5785
|
+
return CAPTION_LOCALES.some(
|
|
5786
|
+
(locale) => captionsVttUrlFromPlayback(src, locale) != null
|
|
5787
|
+
);
|
|
5788
|
+
}
|
|
5781
5789
|
function captionLocaleLabel(locale, labels) {
|
|
5782
5790
|
switch (locale) {
|
|
5783
5791
|
case "en":
|
|
@@ -5821,6 +5829,7 @@ function VideoPlayer({
|
|
|
5821
5829
|
fit = "aspect-video",
|
|
5822
5830
|
className,
|
|
5823
5831
|
defaultCaptionLocale,
|
|
5832
|
+
captionsEnabled = true,
|
|
5824
5833
|
liveCaptionsBaseUrl
|
|
5825
5834
|
}) {
|
|
5826
5835
|
const t = { ...DEFAULT_LABELS3, ...labels };
|
|
@@ -5868,6 +5877,9 @@ function VideoPlayer({
|
|
|
5868
5877
|
onRebuffer,
|
|
5869
5878
|
onQualityChange
|
|
5870
5879
|
});
|
|
5880
|
+
const liveCaptionPollUrl = liveCaptionsBaseUrl?.trim() || void 0;
|
|
5881
|
+
const showCaptionsMenu = captionsEnabled && hasCaptionSource(mode, src, liveCaptionPollUrl);
|
|
5882
|
+
const activeLiveCaptionsBaseUrl = showCaptionsMenu ? liveCaptionPollUrl : void 0;
|
|
5871
5883
|
const [isPlaying, setIsPlaying] = React11__namespace.useState(false);
|
|
5872
5884
|
const [isMuted, setIsMuted] = React11__namespace.useState(muted);
|
|
5873
5885
|
const isMutedRef = React11__namespace.useRef(isMuted);
|
|
@@ -5898,6 +5910,7 @@ function VideoPlayer({
|
|
|
5898
5910
|
const [cssFullscreen, setCssFullscreen] = React11__namespace.useState(false);
|
|
5899
5911
|
const [webkitNativeFs, setWebkitNativeFs] = React11__namespace.useState(false);
|
|
5900
5912
|
const hideTimerRef = React11__namespace.useRef(null);
|
|
5913
|
+
const lastPointerTypeRef = React11__namespace.useRef("mouse");
|
|
5901
5914
|
const liveCaptionCuesRef = React11__namespace.useRef(liveCaptionCues);
|
|
5902
5915
|
const liveLagMsRef = React11__namespace.useRef(liveLagMs);
|
|
5903
5916
|
const compactChromeRef = React11__namespace.useRef(compactChrome);
|
|
@@ -5953,7 +5966,7 @@ function VideoPlayer({
|
|
|
5953
5966
|
const edge = video.seekable.end(video.seekable.length - 1);
|
|
5954
5967
|
const lagSeconds = edge - video.currentTime;
|
|
5955
5968
|
setBehindLive(lagSeconds > LIVE_EDGE_THRESHOLD_S);
|
|
5956
|
-
if (
|
|
5969
|
+
if (activeLiveCaptionsBaseUrl) {
|
|
5957
5970
|
setLiveLagMs((prev) => stabilizeLiveLagMs(prev, lagSeconds * 1e3));
|
|
5958
5971
|
}
|
|
5959
5972
|
}
|
|
@@ -5984,7 +5997,7 @@ function VideoPlayer({
|
|
|
5984
5997
|
video.removeEventListener("ratechange", onRate);
|
|
5985
5998
|
video.removeEventListener("playing", onPlaying);
|
|
5986
5999
|
};
|
|
5987
|
-
}, [videoRef, active, effectiveMode,
|
|
6000
|
+
}, [videoRef, active, effectiveMode, activeLiveCaptionsBaseUrl]);
|
|
5988
6001
|
React11__namespace.useLayoutEffect(() => {
|
|
5989
6002
|
const video = videoRef.current;
|
|
5990
6003
|
if (video) video.muted = isMuted;
|
|
@@ -6098,7 +6111,7 @@ function VideoPlayer({
|
|
|
6098
6111
|
};
|
|
6099
6112
|
}, []);
|
|
6100
6113
|
React11__namespace.useEffect(() => {
|
|
6101
|
-
if (captionLocale === "off") {
|
|
6114
|
+
if (captionLocale === "off" || !showCaptionsMenu) {
|
|
6102
6115
|
setCaptionCues([]);
|
|
6103
6116
|
setLiveCaptionCues([]);
|
|
6104
6117
|
return;
|
|
@@ -6106,7 +6119,7 @@ function VideoPlayer({
|
|
|
6106
6119
|
setLiveCaptionCues([]);
|
|
6107
6120
|
let cancelled = false;
|
|
6108
6121
|
const load = async () => {
|
|
6109
|
-
const liveBase =
|
|
6122
|
+
const liveBase = activeLiveCaptionsBaseUrl;
|
|
6110
6123
|
if (liveBase) {
|
|
6111
6124
|
const loaded = await loadLiveCaptions(
|
|
6112
6125
|
liveCaptionsUrl(liveBase, captionLocale)
|
|
@@ -6125,15 +6138,15 @@ function VideoPlayer({
|
|
|
6125
6138
|
if (!cancelled) setCaptionCues(cues);
|
|
6126
6139
|
};
|
|
6127
6140
|
void load();
|
|
6128
|
-
if (!
|
|
6141
|
+
if (!activeLiveCaptionsBaseUrl) return;
|
|
6129
6142
|
const timer = window.setInterval(() => void load(), 2e3);
|
|
6130
6143
|
return () => {
|
|
6131
6144
|
cancelled = true;
|
|
6132
6145
|
window.clearInterval(timer);
|
|
6133
6146
|
};
|
|
6134
|
-
}, [captionLocale,
|
|
6147
|
+
}, [captionLocale, activeLiveCaptionsBaseUrl, showCaptionsMenu, src]);
|
|
6135
6148
|
React11__namespace.useEffect(() => {
|
|
6136
|
-
if (!
|
|
6149
|
+
if (!activeLiveCaptionsBaseUrl || captionLocale === "off") {
|
|
6137
6150
|
setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
|
|
6138
6151
|
return;
|
|
6139
6152
|
}
|
|
@@ -6151,12 +6164,12 @@ function VideoPlayer({
|
|
|
6151
6164
|
tick();
|
|
6152
6165
|
const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
|
|
6153
6166
|
return () => window.clearInterval(timer);
|
|
6154
|
-
}, [
|
|
6167
|
+
}, [activeLiveCaptionsBaseUrl, captionLocale]);
|
|
6155
6168
|
const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
|
|
6156
|
-
const captionScreen =
|
|
6169
|
+
const captionScreen = activeLiveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
|
|
6157
6170
|
React11__namespace.useEffect(() => {
|
|
6158
6171
|
const video = videoRef.current;
|
|
6159
|
-
if (!video || !
|
|
6172
|
+
if (!video || !activeLiveCaptionsBaseUrl) return;
|
|
6160
6173
|
try {
|
|
6161
6174
|
ensureLiveSubtitleTracks(video, {
|
|
6162
6175
|
en: t.captionsEn,
|
|
@@ -6170,7 +6183,7 @@ function VideoPlayer({
|
|
|
6170
6183
|
}, [
|
|
6171
6184
|
videoRef,
|
|
6172
6185
|
active,
|
|
6173
|
-
|
|
6186
|
+
activeLiveCaptionsBaseUrl,
|
|
6174
6187
|
captionLocale,
|
|
6175
6188
|
t.captionsEn,
|
|
6176
6189
|
t.captionsEs,
|
|
@@ -6194,10 +6207,10 @@ function VideoPlayer({
|
|
|
6194
6207
|
setCaptionLocale(showing);
|
|
6195
6208
|
};
|
|
6196
6209
|
return listenTextTracksChange(video.textTracks, onChange);
|
|
6197
|
-
}, [videoRef, active, src,
|
|
6210
|
+
}, [videoRef, active, src, activeLiveCaptionsBaseUrl]);
|
|
6198
6211
|
React11__namespace.useEffect(() => {
|
|
6199
6212
|
const video = videoRef.current;
|
|
6200
|
-
if (!video || captionLocale === "off" || !
|
|
6213
|
+
if (!video || captionLocale === "off" || !activeLiveCaptionsBaseUrl) return;
|
|
6201
6214
|
const track = findSubtitleTrack(video, captionLocale);
|
|
6202
6215
|
if (!track) return;
|
|
6203
6216
|
const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
|
|
@@ -6207,7 +6220,7 @@ function VideoPlayer({
|
|
|
6207
6220
|
livePlayout.screen?.text ?? "",
|
|
6208
6221
|
remaining
|
|
6209
6222
|
);
|
|
6210
|
-
}, [livePlayout, captionLocale,
|
|
6223
|
+
}, [livePlayout, captionLocale, activeLiveCaptionsBaseUrl]);
|
|
6211
6224
|
function togglePlay() {
|
|
6212
6225
|
const video = videoRef.current;
|
|
6213
6226
|
if (!video) return;
|
|
@@ -6308,6 +6321,20 @@ function VideoPlayer({
|
|
|
6308
6321
|
return next;
|
|
6309
6322
|
});
|
|
6310
6323
|
}
|
|
6324
|
+
function recordPointerType(e) {
|
|
6325
|
+
lastPointerTypeRef.current = e.pointerType;
|
|
6326
|
+
}
|
|
6327
|
+
function handlePointerMove(e) {
|
|
6328
|
+
if (e.pointerType === "mouse") lastPointerTypeRef.current = "mouse";
|
|
6329
|
+
}
|
|
6330
|
+
function handleMouseMove() {
|
|
6331
|
+
if (lastPointerTypeRef.current === "touch") return;
|
|
6332
|
+
revealControls();
|
|
6333
|
+
}
|
|
6334
|
+
function handleMouseLeave() {
|
|
6335
|
+
if (lastPointerTypeRef.current === "touch") return;
|
|
6336
|
+
if (isPlaying) setControlsVisible(false);
|
|
6337
|
+
}
|
|
6311
6338
|
function handleKeyDown(e) {
|
|
6312
6339
|
if (!active) return;
|
|
6313
6340
|
switch (e.key) {
|
|
@@ -6391,10 +6418,10 @@ function VideoPlayer({
|
|
|
6391
6418
|
cssFullscreen && "fixed inset-0 z-50 h-dvh w-dvw rounded-none",
|
|
6392
6419
|
className
|
|
6393
6420
|
),
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6421
|
+
onPointerDown: recordPointerType,
|
|
6422
|
+
onPointerMove: handlePointerMove,
|
|
6423
|
+
onMouseMove: handleMouseMove,
|
|
6424
|
+
onMouseLeave: handleMouseLeave,
|
|
6398
6425
|
onKeyDown: handleKeyDown,
|
|
6399
6426
|
tabIndex: 0,
|
|
6400
6427
|
role: "region",
|
|
@@ -6410,7 +6437,7 @@ function VideoPlayer({
|
|
|
6410
6437
|
className: "livo-video-player-media h-full w-full bg-black object-contain",
|
|
6411
6438
|
onClick: active ? toggleControls : void 0,
|
|
6412
6439
|
poster,
|
|
6413
|
-
children: !
|
|
6440
|
+
children: showCaptionsMenu && !activeLiveCaptionsBaseUrl ? CAPTION_LOCALES.map((locale) => {
|
|
6414
6441
|
const url = captionsVttUrlFromPlayback(src, locale);
|
|
6415
6442
|
if (!url) return null;
|
|
6416
6443
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -6559,7 +6586,7 @@ function VideoPlayer({
|
|
|
6559
6586
|
),
|
|
6560
6587
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1", children: [
|
|
6561
6588
|
!compactChrome && effectiveMode === "vod" && typeof stats?.views === "number" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-1 text-xs", children: t.formatViews ? t.formatViews(stats.views) : `${stats.views} views` }),
|
|
6562
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6589
|
+
showCaptionsMenu && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6563
6590
|
MenuControl,
|
|
6564
6591
|
{
|
|
6565
6592
|
label: t.captions,
|