@livo-tv/blocks 1.30.2 → 1.31.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 +28 -16
- 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 +28 -16
- 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);
|
|
@@ -5927,7 +5939,7 @@ function VideoPlayer({
|
|
|
5927
5939
|
const edge = video.seekable.end(video.seekable.length - 1);
|
|
5928
5940
|
const lagSeconds = edge - video.currentTime;
|
|
5929
5941
|
setBehindLive(lagSeconds > LIVE_EDGE_THRESHOLD_S);
|
|
5930
|
-
if (
|
|
5942
|
+
if (activeLiveCaptionsBaseUrl) {
|
|
5931
5943
|
setLiveLagMs((prev) => stabilizeLiveLagMs(prev, lagSeconds * 1e3));
|
|
5932
5944
|
}
|
|
5933
5945
|
}
|
|
@@ -5958,7 +5970,7 @@ function VideoPlayer({
|
|
|
5958
5970
|
video.removeEventListener("ratechange", onRate);
|
|
5959
5971
|
video.removeEventListener("playing", onPlaying);
|
|
5960
5972
|
};
|
|
5961
|
-
}, [videoRef, active, effectiveMode,
|
|
5973
|
+
}, [videoRef, active, effectiveMode, activeLiveCaptionsBaseUrl]);
|
|
5962
5974
|
React11.useLayoutEffect(() => {
|
|
5963
5975
|
const video = videoRef.current;
|
|
5964
5976
|
if (video) video.muted = isMuted;
|
|
@@ -6072,7 +6084,7 @@ function VideoPlayer({
|
|
|
6072
6084
|
};
|
|
6073
6085
|
}, []);
|
|
6074
6086
|
React11.useEffect(() => {
|
|
6075
|
-
if (captionLocale === "off") {
|
|
6087
|
+
if (captionLocale === "off" || !showCaptionsMenu) {
|
|
6076
6088
|
setCaptionCues([]);
|
|
6077
6089
|
setLiveCaptionCues([]);
|
|
6078
6090
|
return;
|
|
@@ -6080,7 +6092,7 @@ function VideoPlayer({
|
|
|
6080
6092
|
setLiveCaptionCues([]);
|
|
6081
6093
|
let cancelled = false;
|
|
6082
6094
|
const load = async () => {
|
|
6083
|
-
const liveBase =
|
|
6095
|
+
const liveBase = activeLiveCaptionsBaseUrl;
|
|
6084
6096
|
if (liveBase) {
|
|
6085
6097
|
const loaded = await loadLiveCaptions(
|
|
6086
6098
|
liveCaptionsUrl(liveBase, captionLocale)
|
|
@@ -6099,15 +6111,15 @@ function VideoPlayer({
|
|
|
6099
6111
|
if (!cancelled) setCaptionCues(cues);
|
|
6100
6112
|
};
|
|
6101
6113
|
void load();
|
|
6102
|
-
if (!
|
|
6114
|
+
if (!activeLiveCaptionsBaseUrl) return;
|
|
6103
6115
|
const timer = window.setInterval(() => void load(), 2e3);
|
|
6104
6116
|
return () => {
|
|
6105
6117
|
cancelled = true;
|
|
6106
6118
|
window.clearInterval(timer);
|
|
6107
6119
|
};
|
|
6108
|
-
}, [captionLocale,
|
|
6120
|
+
}, [captionLocale, activeLiveCaptionsBaseUrl, showCaptionsMenu, src]);
|
|
6109
6121
|
React11.useEffect(() => {
|
|
6110
|
-
if (!
|
|
6122
|
+
if (!activeLiveCaptionsBaseUrl || captionLocale === "off") {
|
|
6111
6123
|
setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
|
|
6112
6124
|
return;
|
|
6113
6125
|
}
|
|
@@ -6125,12 +6137,12 @@ function VideoPlayer({
|
|
|
6125
6137
|
tick();
|
|
6126
6138
|
const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
|
|
6127
6139
|
return () => window.clearInterval(timer);
|
|
6128
|
-
}, [
|
|
6140
|
+
}, [activeLiveCaptionsBaseUrl, captionLocale]);
|
|
6129
6141
|
const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
|
|
6130
|
-
const captionScreen =
|
|
6142
|
+
const captionScreen = activeLiveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
|
|
6131
6143
|
React11.useEffect(() => {
|
|
6132
6144
|
const video = videoRef.current;
|
|
6133
|
-
if (!video || !
|
|
6145
|
+
if (!video || !activeLiveCaptionsBaseUrl) return;
|
|
6134
6146
|
try {
|
|
6135
6147
|
ensureLiveSubtitleTracks(video, {
|
|
6136
6148
|
en: t.captionsEn,
|
|
@@ -6144,7 +6156,7 @@ function VideoPlayer({
|
|
|
6144
6156
|
}, [
|
|
6145
6157
|
videoRef,
|
|
6146
6158
|
active,
|
|
6147
|
-
|
|
6159
|
+
activeLiveCaptionsBaseUrl,
|
|
6148
6160
|
captionLocale,
|
|
6149
6161
|
t.captionsEn,
|
|
6150
6162
|
t.captionsEs,
|
|
@@ -6168,10 +6180,10 @@ function VideoPlayer({
|
|
|
6168
6180
|
setCaptionLocale(showing);
|
|
6169
6181
|
};
|
|
6170
6182
|
return listenTextTracksChange(video.textTracks, onChange);
|
|
6171
|
-
}, [videoRef, active, src,
|
|
6183
|
+
}, [videoRef, active, src, activeLiveCaptionsBaseUrl]);
|
|
6172
6184
|
React11.useEffect(() => {
|
|
6173
6185
|
const video = videoRef.current;
|
|
6174
|
-
if (!video || captionLocale === "off" || !
|
|
6186
|
+
if (!video || captionLocale === "off" || !activeLiveCaptionsBaseUrl) return;
|
|
6175
6187
|
const track = findSubtitleTrack(video, captionLocale);
|
|
6176
6188
|
if (!track) return;
|
|
6177
6189
|
const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
|
|
@@ -6181,7 +6193,7 @@ function VideoPlayer({
|
|
|
6181
6193
|
livePlayout.screen?.text ?? "",
|
|
6182
6194
|
remaining
|
|
6183
6195
|
);
|
|
6184
|
-
}, [livePlayout, captionLocale,
|
|
6196
|
+
}, [livePlayout, captionLocale, activeLiveCaptionsBaseUrl]);
|
|
6185
6197
|
function togglePlay() {
|
|
6186
6198
|
const video = videoRef.current;
|
|
6187
6199
|
if (!video) return;
|
|
@@ -6384,7 +6396,7 @@ function VideoPlayer({
|
|
|
6384
6396
|
className: "livo-video-player-media h-full w-full bg-black object-contain",
|
|
6385
6397
|
onClick: active ? toggleControls : void 0,
|
|
6386
6398
|
poster,
|
|
6387
|
-
children: !
|
|
6399
|
+
children: showCaptionsMenu && !activeLiveCaptionsBaseUrl ? CAPTION_LOCALES.map((locale) => {
|
|
6388
6400
|
const url = captionsVttUrlFromPlayback(src, locale);
|
|
6389
6401
|
if (!url) return null;
|
|
6390
6402
|
return /* @__PURE__ */ jsx(
|
|
@@ -6533,7 +6545,7 @@ function VideoPlayer({
|
|
|
6533
6545
|
),
|
|
6534
6546
|
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1", children: [
|
|
6535
6547
|
!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(
|
|
6548
|
+
showCaptionsMenu && /* @__PURE__ */ jsxs(
|
|
6537
6549
|
MenuControl,
|
|
6538
6550
|
{
|
|
6539
6551
|
label: t.captions,
|