From f443a74649174b2f9347c158e30f8ac7aa3e958a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Mar 2022 13:40:02 +0100 Subject: Add latency setting support --- client/src/standalone/videos/embed.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'client/src/standalone') diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 38ff39890..9e4d87911 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -6,6 +6,7 @@ import { peertubeTranslate } from '../../../../shared/core-utils/i18n' import { HTMLServerConfig, HttpStatusCode, + LiveVideo, OAuth2ErrorCode, ResultList, UserRefreshToken, @@ -94,6 +95,10 @@ export class PeerTubeEmbed { return window.location.origin + '/api/v1/videos/' + id } + getLiveUrl (videoId: string) { + return window.location.origin + '/api/v1/videos/live/' + videoId + } + refreshFetch (url: string, options?: RequestInit) { return fetch(url, options) .then((res: Response) => { @@ -166,6 +171,12 @@ export class PeerTubeEmbed { return this.refreshFetch(this.getVideoUrl(videoId) + '/captions', { headers: this.headers }) } + loadWithLive (video: VideoDetails) { + return this.refreshFetch(this.getLiveUrl(video.uuid), { headers: this.headers }) + .then(res => res.json()) + .then((live: LiveVideo) => ({ video, live })) + } + loadPlaylistInfo (playlistId: string): Promise { return this.refreshFetch(this.getPlaylistUrl(playlistId), { headers: this.headers }) } @@ -475,13 +486,15 @@ export class PeerTubeEmbed { .then(res => res.json()) } - const videoInfoPromise = videoResponse.json() + const videoInfoPromise: Promise<{ video: VideoDetails, live?: LiveVideo }> = videoResponse.json() .then((videoInfo: VideoDetails) => { this.loadParams(videoInfo) - if (!alreadyHadPlayer && !this.autoplay) this.loadPlaceholder(videoInfo) + if (!alreadyHadPlayer && !this.autoplay) this.buildPlaceholder(videoInfo) - return videoInfo + if (!videoInfo.isLive) return { video: videoInfo } + + return this.loadWithLive(videoInfo) }) const [ videoInfoTmp, serverTranslations, captionsResponse, PeertubePlayerManagerModule ] = await Promise.all([ @@ -493,11 +506,15 @@ export class PeerTubeEmbed { await this.loadPlugins(serverTranslations) - const videoInfo: VideoDetails = videoInfoTmp + const { video: videoInfo, live } = videoInfoTmp const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse) + const liveOptions = videoInfo.isLive + ? { latencyMode: live.latencyMode } + : undefined + const playlistPlugin = this.currentPlaylistElement ? { elements: this.playlistElements, @@ -545,6 +562,7 @@ export class PeerTubeEmbed { videoUUID: videoInfo.uuid, isLive: videoInfo.isLive, + liveOptions, playerElement: this.playerElement, onPlayerElementChange: (element: HTMLVideoElement) => { @@ -726,7 +744,7 @@ export class PeerTubeEmbed { return [] } - private loadPlaceholder (video: VideoDetails) { + private buildPlaceholder (video: VideoDetails) { const placeholder = this.getPlaceholderElement() const url = window.location.origin + video.previewPath -- cgit v1.2.3