@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.d.cts
CHANGED
|
@@ -930,6 +930,11 @@ interface VideoPlayerProps {
|
|
|
930
930
|
className?: string;
|
|
931
931
|
/** Optional initial CC language. Defaults to Off. UI locale / `?lang=` do not enable captions. */
|
|
932
932
|
defaultCaptionLocale?: CaptionLocale;
|
|
933
|
+
/**
|
|
934
|
+
* When false, hide the CC menu and do not attach sidecar or live caption
|
|
935
|
+
* tracks. Defaults to true so existing callers keep current behavior.
|
|
936
|
+
*/
|
|
937
|
+
captionsEnabled?: boolean;
|
|
933
938
|
/** Live poll base, e.g. `https://api.livo.tv/public/streams/{id}/captions`. */
|
|
934
939
|
liveCaptionsBaseUrl?: string | null;
|
|
935
940
|
}
|
|
@@ -942,7 +947,7 @@ interface VideoPlayerProps {
|
|
|
942
947
|
*
|
|
943
948
|
* hls.js is a peer dependency loaded on demand; see {@link useHlsPlayback}.
|
|
944
949
|
*/
|
|
945
|
-
declare function VideoPlayer({ src, mode, poster, autoPlay, muted, stats, labels, showQualitySelector, paused, onPlayingChange, onFirstPlay, onError, onPlaybackProgress, onRebuffer, onQualityChange, fit, className, defaultCaptionLocale, liveCaptionsBaseUrl, }: VideoPlayerProps): React.JSX.Element;
|
|
950
|
+
declare function VideoPlayer({ src, mode, poster, autoPlay, muted, stats, labels, showQualitySelector, paused, onPlayingChange, onFirstPlay, onError, onPlaybackProgress, onRebuffer, onQualityChange, fit, className, defaultCaptionLocale, captionsEnabled, liveCaptionsBaseUrl, }: VideoPlayerProps): React.JSX.Element;
|
|
946
951
|
|
|
947
952
|
interface FeedVideoPlayerProps extends VideoPlayerProps {
|
|
948
953
|
/** Stable id for exclusive playback (typically the feed post id). */
|
package/dist/index.d.ts
CHANGED
|
@@ -930,6 +930,11 @@ interface VideoPlayerProps {
|
|
|
930
930
|
className?: string;
|
|
931
931
|
/** Optional initial CC language. Defaults to Off. UI locale / `?lang=` do not enable captions. */
|
|
932
932
|
defaultCaptionLocale?: CaptionLocale;
|
|
933
|
+
/**
|
|
934
|
+
* When false, hide the CC menu and do not attach sidecar or live caption
|
|
935
|
+
* tracks. Defaults to true so existing callers keep current behavior.
|
|
936
|
+
*/
|
|
937
|
+
captionsEnabled?: boolean;
|
|
933
938
|
/** Live poll base, e.g. `https://api.livo.tv/public/streams/{id}/captions`. */
|
|
934
939
|
liveCaptionsBaseUrl?: string | null;
|
|
935
940
|
}
|
|
@@ -942,7 +947,7 @@ interface VideoPlayerProps {
|
|
|
942
947
|
*
|
|
943
948
|
* hls.js is a peer dependency loaded on demand; see {@link useHlsPlayback}.
|
|
944
949
|
*/
|
|
945
|
-
declare function VideoPlayer({ src, mode, poster, autoPlay, muted, stats, labels, showQualitySelector, paused, onPlayingChange, onFirstPlay, onError, onPlaybackProgress, onRebuffer, onQualityChange, fit, className, defaultCaptionLocale, liveCaptionsBaseUrl, }: VideoPlayerProps): React.JSX.Element;
|
|
950
|
+
declare function VideoPlayer({ src, mode, poster, autoPlay, muted, stats, labels, showQualitySelector, paused, onPlayingChange, onFirstPlay, onError, onPlaybackProgress, onRebuffer, onQualityChange, fit, className, defaultCaptionLocale, captionsEnabled, liveCaptionsBaseUrl, }: VideoPlayerProps): React.JSX.Element;
|
|
946
951
|
|
|
947
952
|
interface FeedVideoPlayerProps extends VideoPlayerProps {
|
|
948
953
|
/** Stable id for exclusive playback (typically the feed post id). */
|
package/dist/index.js
CHANGED
|
@@ -5752,6 +5752,14 @@ var VIDEO_MEDIA_STYLE = `
|
|
|
5752
5752
|
display: none !important;
|
|
5753
5753
|
}
|
|
5754
5754
|
`;
|
|
5755
|
+
function hasCaptionSource(mode, src, liveCaptionsBaseUrl) {
|
|
5756
|
+
if (mode === "live") {
|
|
5757
|
+
return Boolean(liveCaptionsBaseUrl?.trim());
|
|
5758
|
+
}
|
|
5759
|
+
return CAPTION_LOCALES.some(
|
|
5760
|
+
(locale) => captionsVttUrlFromPlayback(src, locale) != null
|
|
5761
|
+
);
|
|
5762
|
+
}
|
|
5755
5763
|
function captionLocaleLabel(locale, labels) {
|
|
5756
5764
|
switch (locale) {
|
|
5757
5765
|
case "en":
|
|
@@ -5795,6 +5803,7 @@ function VideoPlayer({
|
|
|
5795
5803
|
fit = "aspect-video",
|
|
5796
5804
|
className,
|
|
5797
5805
|
defaultCaptionLocale,
|
|
5806
|
+
captionsEnabled = true,
|
|
5798
5807
|
liveCaptionsBaseUrl
|
|
5799
5808
|
}) {
|
|
5800
5809
|
const t = { ...DEFAULT_LABELS3, ...labels };
|
|
@@ -5842,6 +5851,9 @@ function VideoPlayer({
|
|
|
5842
5851
|
onRebuffer,
|
|
5843
5852
|
onQualityChange
|
|
5844
5853
|
});
|
|
5854
|
+
const liveCaptionPollUrl = liveCaptionsBaseUrl?.trim() || void 0;
|
|
5855
|
+
const showCaptionsMenu = captionsEnabled && hasCaptionSource(mode, src, liveCaptionPollUrl);
|
|
5856
|
+
const activeLiveCaptionsBaseUrl = showCaptionsMenu ? liveCaptionPollUrl : void 0;
|
|
5845
5857
|
const [isPlaying, setIsPlaying] = React11.useState(false);
|
|
5846
5858
|
const [isMuted, setIsMuted] = React11.useState(muted);
|
|
5847
5859
|
const isMutedRef = React11.useRef(isMuted);
|
|
@@ -5872,6 +5884,7 @@ function VideoPlayer({
|
|
|
5872
5884
|
const [cssFullscreen, setCssFullscreen] = React11.useState(false);
|
|
5873
5885
|
const [webkitNativeFs, setWebkitNativeFs] = React11.useState(false);
|
|
5874
5886
|
const hideTimerRef = React11.useRef(null);
|
|
5887
|
+
const lastPointerTypeRef = React11.useRef("mouse");
|
|
5875
5888
|
const liveCaptionCuesRef = React11.useRef(liveCaptionCues);
|
|
5876
5889
|
const liveLagMsRef = React11.useRef(liveLagMs);
|
|
5877
5890
|
const compactChromeRef = React11.useRef(compactChrome);
|
|
@@ -5927,7 +5940,7 @@ function VideoPlayer({
|
|
|
5927
5940
|
const edge = video.seekable.end(video.seekable.length - 1);
|
|
5928
5941
|
const lagSeconds = edge - video.currentTime;
|
|
5929
5942
|
setBehindLive(lagSeconds > LIVE_EDGE_THRESHOLD_S);
|
|
5930
|
-
if (
|
|
5943
|
+
if (activeLiveCaptionsBaseUrl) {
|
|
5931
5944
|
setLiveLagMs((prev) => stabilizeLiveLagMs(prev, lagSeconds * 1e3));
|
|
5932
5945
|
}
|
|
5933
5946
|
}
|
|
@@ -5958,7 +5971,7 @@ function VideoPlayer({
|
|
|
5958
5971
|
video.removeEventListener("ratechange", onRate);
|
|
5959
5972
|
video.removeEventListener("playing", onPlaying);
|
|
5960
5973
|
};
|
|
5961
|
-
}, [videoRef, active, effectiveMode,
|
|
5974
|
+
}, [videoRef, active, effectiveMode, activeLiveCaptionsBaseUrl]);
|
|
5962
5975
|
React11.useLayoutEffect(() => {
|
|
5963
5976
|
const video = videoRef.current;
|
|
5964
5977
|
if (video) video.muted = isMuted;
|
|
@@ -6072,7 +6085,7 @@ function VideoPlayer({
|
|
|
6072
6085
|
};
|
|
6073
6086
|
}, []);
|
|
6074
6087
|
React11.useEffect(() => {
|
|
6075
|
-
if (captionLocale === "off") {
|
|
6088
|
+
if (captionLocale === "off" || !showCaptionsMenu) {
|
|
6076
6089
|
setCaptionCues([]);
|
|
6077
6090
|
setLiveCaptionCues([]);
|
|
6078
6091
|
return;
|
|
@@ -6080,7 +6093,7 @@ function VideoPlayer({
|
|
|
6080
6093
|
setLiveCaptionCues([]);
|
|
6081
6094
|
let cancelled = false;
|
|
6082
6095
|
const load = async () => {
|
|
6083
|
-
const liveBase =
|
|
6096
|
+
const liveBase = activeLiveCaptionsBaseUrl;
|
|
6084
6097
|
if (liveBase) {
|
|
6085
6098
|
const loaded = await loadLiveCaptions(
|
|
6086
6099
|
liveCaptionsUrl(liveBase, captionLocale)
|
|
@@ -6099,15 +6112,15 @@ function VideoPlayer({
|
|
|
6099
6112
|
if (!cancelled) setCaptionCues(cues);
|
|
6100
6113
|
};
|
|
6101
6114
|
void load();
|
|
6102
|
-
if (!
|
|
6115
|
+
if (!activeLiveCaptionsBaseUrl) return;
|
|
6103
6116
|
const timer = window.setInterval(() => void load(), 2e3);
|
|
6104
6117
|
return () => {
|
|
6105
6118
|
cancelled = true;
|
|
6106
6119
|
window.clearInterval(timer);
|
|
6107
6120
|
};
|
|
6108
|
-
}, [captionLocale,
|
|
6121
|
+
}, [captionLocale, activeLiveCaptionsBaseUrl, showCaptionsMenu, src]);
|
|
6109
6122
|
React11.useEffect(() => {
|
|
6110
|
-
if (!
|
|
6123
|
+
if (!activeLiveCaptionsBaseUrl || captionLocale === "off") {
|
|
6111
6124
|
setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
|
|
6112
6125
|
return;
|
|
6113
6126
|
}
|
|
@@ -6125,12 +6138,12 @@ function VideoPlayer({
|
|
|
6125
6138
|
tick();
|
|
6126
6139
|
const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
|
|
6127
6140
|
return () => window.clearInterval(timer);
|
|
6128
|
-
}, [
|
|
6141
|
+
}, [activeLiveCaptionsBaseUrl, captionLocale]);
|
|
6129
6142
|
const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
|
|
6130
|
-
const captionScreen =
|
|
6143
|
+
const captionScreen = activeLiveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
|
|
6131
6144
|
React11.useEffect(() => {
|
|
6132
6145
|
const video = videoRef.current;
|
|
6133
|
-
if (!video || !
|
|
6146
|
+
if (!video || !activeLiveCaptionsBaseUrl) return;
|
|
6134
6147
|
try {
|
|
6135
6148
|
ensureLiveSubtitleTracks(video, {
|
|
6136
6149
|
en: t.captionsEn,
|
|
@@ -6144,7 +6157,7 @@ function VideoPlayer({
|
|
|
6144
6157
|
}, [
|
|
6145
6158
|
videoRef,
|
|
6146
6159
|
active,
|
|
6147
|
-
|
|
6160
|
+
activeLiveCaptionsBaseUrl,
|
|
6148
6161
|
captionLocale,
|
|
6149
6162
|
t.captionsEn,
|
|
6150
6163
|
t.captionsEs,
|
|
@@ -6168,10 +6181,10 @@ function VideoPlayer({
|
|
|
6168
6181
|
setCaptionLocale(showing);
|
|
6169
6182
|
};
|
|
6170
6183
|
return listenTextTracksChange(video.textTracks, onChange);
|
|
6171
|
-
}, [videoRef, active, src,
|
|
6184
|
+
}, [videoRef, active, src, activeLiveCaptionsBaseUrl]);
|
|
6172
6185
|
React11.useEffect(() => {
|
|
6173
6186
|
const video = videoRef.current;
|
|
6174
|
-
if (!video || captionLocale === "off" || !
|
|
6187
|
+
if (!video || captionLocale === "off" || !activeLiveCaptionsBaseUrl) return;
|
|
6175
6188
|
const track = findSubtitleTrack(video, captionLocale);
|
|
6176
6189
|
if (!track) return;
|
|
6177
6190
|
const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
|
|
@@ -6181,7 +6194,7 @@ function VideoPlayer({
|
|
|
6181
6194
|
livePlayout.screen?.text ?? "",
|
|
6182
6195
|
remaining
|
|
6183
6196
|
);
|
|
6184
|
-
}, [livePlayout, captionLocale,
|
|
6197
|
+
}, [livePlayout, captionLocale, activeLiveCaptionsBaseUrl]);
|
|
6185
6198
|
function togglePlay() {
|
|
6186
6199
|
const video = videoRef.current;
|
|
6187
6200
|
if (!video) return;
|
|
@@ -6282,6 +6295,20 @@ function VideoPlayer({
|
|
|
6282
6295
|
return next;
|
|
6283
6296
|
});
|
|
6284
6297
|
}
|
|
6298
|
+
function recordPointerType(e) {
|
|
6299
|
+
lastPointerTypeRef.current = e.pointerType;
|
|
6300
|
+
}
|
|
6301
|
+
function handlePointerMove(e) {
|
|
6302
|
+
if (e.pointerType === "mouse") lastPointerTypeRef.current = "mouse";
|
|
6303
|
+
}
|
|
6304
|
+
function handleMouseMove() {
|
|
6305
|
+
if (lastPointerTypeRef.current === "touch") return;
|
|
6306
|
+
revealControls();
|
|
6307
|
+
}
|
|
6308
|
+
function handleMouseLeave() {
|
|
6309
|
+
if (lastPointerTypeRef.current === "touch") return;
|
|
6310
|
+
if (isPlaying) setControlsVisible(false);
|
|
6311
|
+
}
|
|
6285
6312
|
function handleKeyDown(e) {
|
|
6286
6313
|
if (!active) return;
|
|
6287
6314
|
switch (e.key) {
|
|
@@ -6365,10 +6392,10 @@ function VideoPlayer({
|
|
|
6365
6392
|
cssFullscreen && "fixed inset-0 z-50 h-dvh w-dvw rounded-none",
|
|
6366
6393
|
className
|
|
6367
6394
|
),
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6395
|
+
onPointerDown: recordPointerType,
|
|
6396
|
+
onPointerMove: handlePointerMove,
|
|
6397
|
+
onMouseMove: handleMouseMove,
|
|
6398
|
+
onMouseLeave: handleMouseLeave,
|
|
6372
6399
|
onKeyDown: handleKeyDown,
|
|
6373
6400
|
tabIndex: 0,
|
|
6374
6401
|
role: "region",
|
|
@@ -6384,7 +6411,7 @@ function VideoPlayer({
|
|
|
6384
6411
|
className: "livo-video-player-media h-full w-full bg-black object-contain",
|
|
6385
6412
|
onClick: active ? toggleControls : void 0,
|
|
6386
6413
|
poster,
|
|
6387
|
-
children: !
|
|
6414
|
+
children: showCaptionsMenu && !activeLiveCaptionsBaseUrl ? CAPTION_LOCALES.map((locale) => {
|
|
6388
6415
|
const url = captionsVttUrlFromPlayback(src, locale);
|
|
6389
6416
|
if (!url) return null;
|
|
6390
6417
|
return /* @__PURE__ */ jsx(
|
|
@@ -6533,7 +6560,7 @@ function VideoPlayer({
|
|
|
6533
6560
|
),
|
|
6534
6561
|
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1", children: [
|
|
6535
6562
|
!compactChrome && effectiveMode === "vod" && typeof stats?.views === "number" && /* @__PURE__ */ jsx("span", { className: "mr-1 text-xs", children: t.formatViews ? t.formatViews(stats.views) : `${stats.views} views` }),
|
|
6536
|
-
/* @__PURE__ */ jsxs(
|
|
6563
|
+
showCaptionsMenu && /* @__PURE__ */ jsxs(
|
|
6537
6564
|
MenuControl,
|
|
6538
6565
|
{
|
|
6539
6566
|
label: t.captions,
|