diff options
Diffstat (limited to 'client/src/standalone/videos/embed.ts')
-rw-r--r-- | client/src/standalone/videos/embed.ts | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index cc4274b99..cffda2cc7 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts | |||
@@ -3,10 +3,18 @@ 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, ResultList, VideoDetails, VideoPlaylist, VideoPlaylistElement, VideoState } from '../../../../shared/models' | 6 | import { |
7 | HTMLServerConfig, | ||
8 | ResultList, | ||
9 | ServerErrorCode, | ||
10 | VideoDetails, | ||
11 | VideoPlaylist, | ||
12 | VideoPlaylistElement, | ||
13 | VideoState | ||
14 | } from '../../../../shared/models' | ||
7 | import { PeertubePlayerManager } from '../../assets/player' | 15 | import { PeertubePlayerManager } from '../../assets/player' |
8 | import { TranslationsManager } from '../../assets/player/translations-manager' | 16 | import { TranslationsManager } from '../../assets/player/translations-manager' |
9 | import { getParamString, logger, videoRequiresAuth } from '../../root-helpers' | 17 | import { getParamString, logger, videoRequiresFileToken } from '../../root-helpers' |
10 | import { PeerTubeEmbedApi } from './embed-api' | 18 | import { PeerTubeEmbedApi } from './embed-api' |
11 | import { | 19 | import { |
12 | AuthHTTP, | 20 | AuthHTTP, |
@@ -19,6 +27,7 @@ import { | |||
19 | VideoFetcher | 27 | VideoFetcher |
20 | } from './shared' | 28 | } from './shared' |
21 | import { PlayerHTML } from './shared/player-html' | 29 | import { PlayerHTML } from './shared/player-html' |
30 | import { PeerTubeServerError } from 'src/types' | ||
22 | 31 | ||
23 | export class PeerTubeEmbed { | 32 | export class PeerTubeEmbed { |
24 | player: videojs.Player | 33 | player: videojs.Player |
@@ -38,6 +47,8 @@ export class PeerTubeEmbed { | |||
38 | private readonly liveManager: LiveManager | 47 | private readonly liveManager: LiveManager |
39 | 48 | ||
40 | private playlistTracker: PlaylistTracker | 49 | private playlistTracker: PlaylistTracker |
50 | private videoPassword: string | ||
51 | private requiresPassword: boolean | ||
41 | 52 | ||
42 | constructor (videoWrapperId: string) { | 53 | constructor (videoWrapperId: string) { |
43 | logger.registerServerSending(window.location.origin) | 54 | logger.registerServerSending(window.location.origin) |
@@ -50,6 +61,7 @@ export class PeerTubeEmbed { | |||
50 | this.playerHTML = new PlayerHTML(videoWrapperId) | 61 | this.playerHTML = new PlayerHTML(videoWrapperId) |
51 | this.playerManagerOptions = new PlayerManagerOptions(this.playerHTML, this.videoFetcher, this.peertubePlugin) | 62 | this.playerManagerOptions = new PlayerManagerOptions(this.playerHTML, this.videoFetcher, this.peertubePlugin) |
52 | this.liveManager = new LiveManager(this.playerHTML) | 63 | this.liveManager = new LiveManager(this.playerHTML) |
64 | this.requiresPassword = false | ||
53 | 65 | ||
54 | try { | 66 | try { |
55 | this.config = JSON.parse((window as any)['PeerTubeServerConfig']) | 67 | this.config = JSON.parse((window as any)['PeerTubeServerConfig']) |
@@ -176,11 +188,13 @@ export class PeerTubeEmbed { | |||
176 | const { uuid, autoplayFromPreviousVideo, forceAutoplay } = options | 188 | const { uuid, autoplayFromPreviousVideo, forceAutoplay } = options |
177 | 189 | ||
178 | try { | 190 | try { |
179 | const { videoResponse, captionsPromise } = await this.videoFetcher.loadVideo(uuid) | 191 | const { videoResponse, captionsPromise } = await this.videoFetcher.loadVideo({ videoId: uuid, videoPassword: this.videoPassword }) |
180 | 192 | ||
181 | return this.buildVideoPlayer({ videoResponse, captionsPromise, autoplayFromPreviousVideo, forceAutoplay }) | 193 | return this.buildVideoPlayer({ videoResponse, captionsPromise, autoplayFromPreviousVideo, forceAutoplay }) |
182 | } catch (err) { | 194 | } catch (err) { |
183 | this.playerHTML.displayError(err.message, await this.translationsPromise) | 195 | |
196 | if (await this.handlePasswordError(err)) this.loadVideoAndBuildPlayer({ ...options }) | ||
197 | else this.playerHTML.displayError(err.message, await this.translationsPromise) | ||
184 | } | 198 | } |
185 | } | 199 | } |
186 | 200 | ||
@@ -205,8 +219,8 @@ export class PeerTubeEmbed { | |||
205 | ? await this.videoFetcher.loadLive(videoInfo) | 219 | ? await this.videoFetcher.loadLive(videoInfo) |
206 | : undefined | 220 | : undefined |
207 | 221 | ||
208 | const videoFileToken = videoRequiresAuth(videoInfo) | 222 | const videoFileToken = videoRequiresFileToken(videoInfo) |
209 | ? await this.videoFetcher.loadVideoToken(videoInfo) | 223 | ? await this.videoFetcher.loadVideoToken(videoInfo, this.videoPassword) |
210 | : undefined | 224 | : undefined |
211 | 225 | ||
212 | return { live, video: videoInfo, videoFileToken } | 226 | return { live, video: videoInfo, videoFileToken } |
@@ -232,6 +246,8 @@ export class PeerTubeEmbed { | |||
232 | 246 | ||
233 | authorizationHeader: () => this.http.getHeaderTokenValue(), | 247 | authorizationHeader: () => this.http.getHeaderTokenValue(), |
234 | videoFileToken: () => videoFileToken, | 248 | videoFileToken: () => videoFileToken, |
249 | videoPassword: () => this.videoPassword, | ||
250 | requiresPassword: this.requiresPassword, | ||
235 | 251 | ||
236 | onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer({ uuid, autoplayFromPreviousVideo: true, forceAutoplay: false }), | 252 | onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer({ uuid, autoplayFromPreviousVideo: true, forceAutoplay: false }), |
237 | 253 | ||
@@ -263,6 +279,7 @@ export class PeerTubeEmbed { | |||
263 | this.initializeApi() | 279 | this.initializeApi() |
264 | 280 | ||
265 | this.playerHTML.removePlaceholder() | 281 | this.playerHTML.removePlaceholder() |
282 | if (this.videoPassword) this.playerHTML.removeVideoPasswordBlock() | ||
266 | 283 | ||
267 | if (this.isPlaylistEmbed()) { | 284 | if (this.isPlaylistEmbed()) { |
268 | await this.buildPlayerPlaylistUpnext() | 285 | await this.buildPlayerPlaylistUpnext() |
@@ -401,6 +418,21 @@ export class PeerTubeEmbed { | |||
401 | (this.player.el() as HTMLElement).style.pointerEvents = 'none' | 418 | (this.player.el() as HTMLElement).style.pointerEvents = 'none' |
402 | } | 419 | } |
403 | 420 | ||
421 | private async handlePasswordError (err: PeerTubeServerError) { | ||
422 | let incorrectPassword: boolean = null | ||
423 | if (err.serverCode === ServerErrorCode.VIDEO_REQUIRES_PASSWORD) incorrectPassword = false | ||
424 | else if (err.serverCode === ServerErrorCode.INCORRECT_VIDEO_PASSWORD) incorrectPassword = true | ||
425 | |||
426 | if (incorrectPassword === null) return false | ||
427 | |||
428 | this.requiresPassword = true | ||
429 | this.videoPassword = await this.playerHTML.askVideoPassword({ | ||
430 | incorrectPassword, | ||
431 | translations: await this.translationsPromise | ||
432 | }) | ||
433 | return true | ||
434 | } | ||
435 | |||
404 | } | 436 | } |
405 | 437 | ||
406 | PeerTubeEmbed.main() | 438 | PeerTubeEmbed.main() |