mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +02:00
Add latency setting support
This commit is contained in:
parent
01dd04cd5a
commit
f443a74649
42 changed files with 516 additions and 81 deletions
|
@ -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<Response> {
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue