diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-04 13:40:02 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-03-09 09:23:10 +0100 |
commit | f443a74649174b2f9347c158e30f8ac7aa3e958a (patch) | |
tree | e423bc4e2307477bda4341037b7fa04ad10adae6 /client/src/standalone | |
parent | 01dd04cd5ab7b55d2a9af7d0ebf405bee9579b09 (diff) | |
download | PeerTube-f443a74649174b2f9347c158e30f8ac7aa3e958a.tar.gz PeerTube-f443a74649174b2f9347c158e30f8ac7aa3e958a.tar.zst PeerTube-f443a74649174b2f9347c158e30f8ac7aa3e958a.zip |
Add latency setting support
Diffstat (limited to 'client/src/standalone')
-rw-r--r-- | client/src/standalone/videos/embed.ts | 28 |
1 files changed, 23 insertions, 5 deletions
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' | |||
6 | import { | 6 | import { |
7 | HTMLServerConfig, | 7 | HTMLServerConfig, |
8 | HttpStatusCode, | 8 | HttpStatusCode, |
9 | LiveVideo, | ||
9 | OAuth2ErrorCode, | 10 | OAuth2ErrorCode, |
10 | ResultList, | 11 | ResultList, |
11 | UserRefreshToken, | 12 | UserRefreshToken, |
@@ -94,6 +95,10 @@ export class PeerTubeEmbed { | |||
94 | return window.location.origin + '/api/v1/videos/' + id | 95 | return window.location.origin + '/api/v1/videos/' + id |
95 | } | 96 | } |
96 | 97 | ||
98 | getLiveUrl (videoId: string) { | ||
99 | return window.location.origin + '/api/v1/videos/live/' + videoId | ||
100 | } | ||
101 | |||
97 | refreshFetch (url: string, options?: RequestInit) { | 102 | refreshFetch (url: string, options?: RequestInit) { |
98 | return fetch(url, options) | 103 | return fetch(url, options) |
99 | .then((res: Response) => { | 104 | .then((res: Response) => { |
@@ -166,6 +171,12 @@ export class PeerTubeEmbed { | |||
166 | return this.refreshFetch(this.getVideoUrl(videoId) + '/captions', { headers: this.headers }) | 171 | return this.refreshFetch(this.getVideoUrl(videoId) + '/captions', { headers: this.headers }) |
167 | } | 172 | } |
168 | 173 | ||
174 | loadWithLive (video: VideoDetails) { | ||
175 | return this.refreshFetch(this.getLiveUrl(video.uuid), { headers: this.headers }) | ||
176 | .then(res => res.json()) | ||
177 | .then((live: LiveVideo) => ({ video, live })) | ||
178 | } | ||
179 | |||
169 | loadPlaylistInfo (playlistId: string): Promise<Response> { | 180 | loadPlaylistInfo (playlistId: string): Promise<Response> { |
170 | return this.refreshFetch(this.getPlaylistUrl(playlistId), { headers: this.headers }) | 181 | return this.refreshFetch(this.getPlaylistUrl(playlistId), { headers: this.headers }) |
171 | } | 182 | } |
@@ -475,13 +486,15 @@ export class PeerTubeEmbed { | |||
475 | .then(res => res.json()) | 486 | .then(res => res.json()) |
476 | } | 487 | } |
477 | 488 | ||
478 | const videoInfoPromise = videoResponse.json() | 489 | const videoInfoPromise: Promise<{ video: VideoDetails, live?: LiveVideo }> = videoResponse.json() |
479 | .then((videoInfo: VideoDetails) => { | 490 | .then((videoInfo: VideoDetails) => { |
480 | this.loadParams(videoInfo) | 491 | this.loadParams(videoInfo) |
481 | 492 | ||
482 | if (!alreadyHadPlayer && !this.autoplay) this.loadPlaceholder(videoInfo) | 493 | if (!alreadyHadPlayer && !this.autoplay) this.buildPlaceholder(videoInfo) |
483 | 494 | ||
484 | return videoInfo | 495 | if (!videoInfo.isLive) return { video: videoInfo } |
496 | |||
497 | return this.loadWithLive(videoInfo) | ||
485 | }) | 498 | }) |
486 | 499 | ||
487 | const [ videoInfoTmp, serverTranslations, captionsResponse, PeertubePlayerManagerModule ] = await Promise.all([ | 500 | const [ videoInfoTmp, serverTranslations, captionsResponse, PeertubePlayerManagerModule ] = await Promise.all([ |
@@ -493,11 +506,15 @@ export class PeerTubeEmbed { | |||
493 | 506 | ||
494 | await this.loadPlugins(serverTranslations) | 507 | await this.loadPlugins(serverTranslations) |
495 | 508 | ||
496 | const videoInfo: VideoDetails = videoInfoTmp | 509 | const { video: videoInfo, live } = videoInfoTmp |
497 | 510 | ||
498 | const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager | 511 | const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager |
499 | const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse) | 512 | const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse) |
500 | 513 | ||
514 | const liveOptions = videoInfo.isLive | ||
515 | ? { latencyMode: live.latencyMode } | ||
516 | : undefined | ||
517 | |||
501 | const playlistPlugin = this.currentPlaylistElement | 518 | const playlistPlugin = this.currentPlaylistElement |
502 | ? { | 519 | ? { |
503 | elements: this.playlistElements, | 520 | elements: this.playlistElements, |
@@ -545,6 +562,7 @@ export class PeerTubeEmbed { | |||
545 | videoUUID: videoInfo.uuid, | 562 | videoUUID: videoInfo.uuid, |
546 | 563 | ||
547 | isLive: videoInfo.isLive, | 564 | isLive: videoInfo.isLive, |
565 | liveOptions, | ||
548 | 566 | ||
549 | playerElement: this.playerElement, | 567 | playerElement: this.playerElement, |
550 | onPlayerElementChange: (element: HTMLVideoElement) => { | 568 | onPlayerElementChange: (element: HTMLVideoElement) => { |
@@ -726,7 +744,7 @@ export class PeerTubeEmbed { | |||
726 | return [] | 744 | return [] |
727 | } | 745 | } |
728 | 746 | ||
729 | private loadPlaceholder (video: VideoDetails) { | 747 | private buildPlaceholder (video: VideoDetails) { |
730 | const placeholder = this.getPlaceholderElement() | 748 | const placeholder = this.getPlaceholderElement() |
731 | 749 | ||
732 | const url = window.location.origin + video.previewPath | 750 | const url = window.location.origin + video.previewPath |