diff options
Diffstat (limited to 'client/src/standalone/videos/embed.ts')
-rw-r--r-- | client/src/standalone/videos/embed.ts | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 451e54840..356f149c0 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts | |||
@@ -3,10 +3,10 @@ import '../../assets/player/shared/dock/peertube-dock-component' | |||
3 | import '../../assets/player/shared/dock/peertube-dock-plugin' | 3 | import '../../assets/player/shared/dock/peertube-dock-plugin' |
4 | import videojs from 'video.js' | 4 | import videojs from 'video.js' |
5 | import { peertubeTranslate } from '../../../../shared/core-utils/i18n' | 5 | import { peertubeTranslate } from '../../../../shared/core-utils/i18n' |
6 | import { HTMLServerConfig, LiveVideo, ResultList, VideoDetails, VideoPlaylist, VideoPlaylistElement } from '../../../../shared/models' | 6 | import { HTMLServerConfig, ResultList, VideoDetails, VideoPlaylist, VideoPlaylistElement } from '../../../../shared/models' |
7 | import { PeertubePlayerManager } from '../../assets/player' | 7 | import { PeertubePlayerManager } from '../../assets/player' |
8 | import { TranslationsManager } from '../../assets/player/translations-manager' | 8 | import { TranslationsManager } from '../../assets/player/translations-manager' |
9 | import { getParamString, logger } from '../../root-helpers' | 9 | import { getParamString, logger, videoRequiresAuth } from '../../root-helpers' |
10 | import { PeerTubeEmbedApi } from './embed-api' | 10 | import { PeerTubeEmbedApi } from './embed-api' |
11 | import { AuthHTTP, LiveManager, PeerTubePlugin, PlayerManagerOptions, PlaylistFetcher, PlaylistTracker, VideoFetcher } from './shared' | 11 | import { AuthHTTP, LiveManager, PeerTubePlugin, PlayerManagerOptions, PlaylistFetcher, PlaylistTracker, VideoFetcher } from './shared' |
12 | import { PlayerHTML } from './shared/player-html' | 12 | import { PlayerHTML } from './shared/player-html' |
@@ -117,6 +117,11 @@ export class PeerTubeEmbed { | |||
117 | 117 | ||
118 | private initializeApi () { | 118 | private initializeApi () { |
119 | if (this.playerManagerOptions.hasAPIEnabled()) { | 119 | if (this.playerManagerOptions.hasAPIEnabled()) { |
120 | if (this.api) { | ||
121 | this.api.reInit() | ||
122 | return | ||
123 | } | ||
124 | |||
120 | this.api = new PeerTubeEmbedApi(this) | 125 | this.api = new PeerTubeEmbedApi(this) |
121 | this.api.initialize() | 126 | this.api.initialize() |
122 | } | 127 | } |
@@ -167,22 +172,25 @@ export class PeerTubeEmbed { | |||
167 | private async buildVideoPlayer (videoResponse: Response, captionsPromise: Promise<Response>) { | 172 | private async buildVideoPlayer (videoResponse: Response, captionsPromise: Promise<Response>) { |
168 | const alreadyHadPlayer = this.resetPlayerElement() | 173 | const alreadyHadPlayer = this.resetPlayerElement() |
169 | 174 | ||
170 | const videoInfoPromise: Promise<{ video: VideoDetails, live?: LiveVideo }> = videoResponse.json() | 175 | const videoInfoPromise = videoResponse.json() |
171 | .then((videoInfo: VideoDetails) => { | 176 | .then(async (videoInfo: VideoDetails) => { |
172 | this.playerManagerOptions.loadParams(this.config, videoInfo) | 177 | this.playerManagerOptions.loadParams(this.config, videoInfo) |
173 | 178 | ||
174 | if (!alreadyHadPlayer && !this.playerManagerOptions.hasAutoplay()) { | 179 | if (!alreadyHadPlayer && !this.playerManagerOptions.hasAutoplay()) { |
175 | this.playerHTML.buildPlaceholder(videoInfo) | 180 | this.playerHTML.buildPlaceholder(videoInfo) |
176 | } | 181 | } |
182 | const live = videoInfo.isLive | ||
183 | ? await this.videoFetcher.loadLive(videoInfo) | ||
184 | : undefined | ||
177 | 185 | ||
178 | if (!videoInfo.isLive) { | 186 | const videoFileToken = videoRequiresAuth(videoInfo) |
179 | return { video: videoInfo } | 187 | ? await this.videoFetcher.loadVideoToken(videoInfo) |
180 | } | 188 | : undefined |
181 | 189 | ||
182 | return this.videoFetcher.loadVideoWithLive(videoInfo) | 190 | return { live, video: videoInfo, videoFileToken } |
183 | }) | 191 | }) |
184 | 192 | ||
185 | const [ { video, live }, translations, captionsResponse, PeertubePlayerManagerModule ] = await Promise.all([ | 193 | const [ { video, live, videoFileToken }, translations, captionsResponse, PeertubePlayerManagerModule ] = await Promise.all([ |
186 | videoInfoPromise, | 194 | videoInfoPromise, |
187 | this.translationsPromise, | 195 | this.translationsPromise, |
188 | captionsPromise, | 196 | captionsPromise, |
@@ -200,6 +208,9 @@ export class PeerTubeEmbed { | |||
200 | translations, | 208 | translations, |
201 | serverConfig: this.config, | 209 | serverConfig: this.config, |
202 | 210 | ||
211 | authorizationHeader: () => this.http.getHeaderTokenValue(), | ||
212 | videoFileToken: () => videoFileToken, | ||
213 | |||
203 | onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer(uuid), | 214 | onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer(uuid), |
204 | 215 | ||
205 | playlistTracker: this.playlistTracker, | 216 | playlistTracker: this.playlistTracker, |