diff options
-rw-r--r-- | client/src/standalone/videos/embed.ts | 24 | ||||
-rw-r--r-- | client/src/standalone/videos/shared/player-manager-options.ts | 24 | ||||
-rw-r--r-- | client/src/standalone/videos/shared/video-fetcher.ts | 13 |
3 files changed, 53 insertions, 8 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index cffda2cc7..6e37ce193 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import './embed.scss' | 1 | import './embed.scss' |
2 | import '../../assets/player/shared/dock/peertube-dock-component' | 2 | 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 { PeerTubeServerError } from 'src/types' | ||
4 | import videojs from 'video.js' | 5 | import videojs from 'video.js' |
5 | import { peertubeTranslate } from '../../../../shared/core-utils/i18n' | 6 | import { peertubeTranslate } from '../../../../shared/core-utils/i18n' |
6 | import { | 7 | import { |
@@ -27,7 +28,6 @@ import { | |||
27 | VideoFetcher | 28 | VideoFetcher |
28 | } from './shared' | 29 | } from './shared' |
29 | import { PlayerHTML } from './shared/player-html' | 30 | import { PlayerHTML } from './shared/player-html' |
30 | import { PeerTubeServerError } from 'src/types' | ||
31 | 31 | ||
32 | export class PeerTubeEmbed { | 32 | export class PeerTubeEmbed { |
33 | player: videojs.Player | 33 | player: videojs.Player |
@@ -188,9 +188,13 @@ export class PeerTubeEmbed { | |||
188 | const { uuid, autoplayFromPreviousVideo, forceAutoplay } = options | 188 | const { uuid, autoplayFromPreviousVideo, forceAutoplay } = options |
189 | 189 | ||
190 | try { | 190 | try { |
191 | const { videoResponse, captionsPromise } = await this.videoFetcher.loadVideo({ videoId: uuid, videoPassword: this.videoPassword }) | 191 | const { |
192 | videoResponse, | ||
193 | captionsPromise, | ||
194 | storyboardsPromise | ||
195 | } = await this.videoFetcher.loadVideo({ videoId: uuid, videoPassword: this.videoPassword }) | ||
192 | 196 | ||
193 | return this.buildVideoPlayer({ videoResponse, captionsPromise, autoplayFromPreviousVideo, forceAutoplay }) | 197 | return this.buildVideoPlayer({ videoResponse, captionsPromise, storyboardsPromise, autoplayFromPreviousVideo, forceAutoplay }) |
194 | } catch (err) { | 198 | } catch (err) { |
195 | 199 | ||
196 | if (await this.handlePasswordError(err)) this.loadVideoAndBuildPlayer({ ...options }) | 200 | if (await this.handlePasswordError(err)) this.loadVideoAndBuildPlayer({ ...options }) |
@@ -200,11 +204,12 @@ export class PeerTubeEmbed { | |||
200 | 204 | ||
201 | private async buildVideoPlayer (options: { | 205 | private async buildVideoPlayer (options: { |
202 | videoResponse: Response | 206 | videoResponse: Response |
207 | storyboardsPromise: Promise<Response> | ||
203 | captionsPromise: Promise<Response> | 208 | captionsPromise: Promise<Response> |
204 | autoplayFromPreviousVideo: boolean | 209 | autoplayFromPreviousVideo: boolean |
205 | forceAutoplay: boolean | 210 | forceAutoplay: boolean |
206 | }) { | 211 | }) { |
207 | const { videoResponse, captionsPromise, autoplayFromPreviousVideo, forceAutoplay } = options | 212 | const { videoResponse, captionsPromise, storyboardsPromise, autoplayFromPreviousVideo, forceAutoplay } = options |
208 | 213 | ||
209 | this.resetPlayerElement() | 214 | this.resetPlayerElement() |
210 | 215 | ||
@@ -226,10 +231,17 @@ export class PeerTubeEmbed { | |||
226 | return { live, video: videoInfo, videoFileToken } | 231 | return { live, video: videoInfo, videoFileToken } |
227 | }) | 232 | }) |
228 | 233 | ||
229 | const [ { video, live, videoFileToken }, translations, captionsResponse, PeertubePlayerManagerModule ] = await Promise.all([ | 234 | const [ |
235 | { video, live, videoFileToken }, | ||
236 | translations, | ||
237 | captionsResponse, | ||
238 | storyboardsResponse, | ||
239 | PeertubePlayerManagerModule | ||
240 | ] = await Promise.all([ | ||
230 | videoInfoPromise, | 241 | videoInfoPromise, |
231 | this.translationsPromise, | 242 | this.translationsPromise, |
232 | captionsPromise, | 243 | captionsPromise, |
244 | storyboardsPromise, | ||
233 | this.PeertubePlayerManagerModulePromise | 245 | this.PeertubePlayerManagerModulePromise |
234 | ]) | 246 | ]) |
235 | 247 | ||
@@ -244,6 +256,8 @@ export class PeerTubeEmbed { | |||
244 | translations, | 256 | translations, |
245 | serverConfig: this.config, | 257 | serverConfig: this.config, |
246 | 258 | ||
259 | storyboardsResponse, | ||
260 | |||
247 | authorizationHeader: () => this.http.getHeaderTokenValue(), | 261 | authorizationHeader: () => this.http.getHeaderTokenValue(), |
248 | videoFileToken: () => videoFileToken, | 262 | videoFileToken: () => videoFileToken, |
249 | videoPassword: () => this.videoPassword, | 263 | videoPassword: () => this.videoPassword, |
diff --git a/client/src/standalone/videos/shared/player-manager-options.ts b/client/src/standalone/videos/shared/player-manager-options.ts index 587516410..3c7521bc2 100644 --- a/client/src/standalone/videos/shared/player-manager-options.ts +++ b/client/src/standalone/videos/shared/player-manager-options.ts | |||
@@ -2,6 +2,7 @@ import { peertubeTranslate } from '../../../../../shared/core-utils/i18n' | |||
2 | import { | 2 | import { |
3 | HTMLServerConfig, | 3 | HTMLServerConfig, |
4 | LiveVideo, | 4 | LiveVideo, |
5 | Storyboard, | ||
5 | Video, | 6 | Video, |
6 | VideoCaption, | 7 | VideoCaption, |
7 | VideoDetails, | 8 | VideoDetails, |
@@ -155,6 +156,9 @@ export class PlayerManagerOptions { | |||
155 | async getPlayerOptions (options: { | 156 | async getPlayerOptions (options: { |
156 | video: VideoDetails | 157 | video: VideoDetails |
157 | captionsResponse: Response | 158 | captionsResponse: Response |
159 | |||
160 | storyboardsResponse: Response | ||
161 | |||
158 | live?: LiveVideo | 162 | live?: LiveVideo |
159 | 163 | ||
160 | forceAutoplay: boolean | 164 | forceAutoplay: boolean |
@@ -187,11 +191,15 @@ export class PlayerManagerOptions { | |||
187 | forceAutoplay, | 191 | forceAutoplay, |
188 | playlistTracker, | 192 | playlistTracker, |
189 | live, | 193 | live, |
194 | storyboardsResponse, | ||
190 | authorizationHeader, | 195 | authorizationHeader, |
191 | serverConfig | 196 | serverConfig |
192 | } = options | 197 | } = options |
193 | 198 | ||
194 | const videoCaptions = await this.buildCaptions(captionsResponse, translations) | 199 | const [ videoCaptions, storyboard ] = await Promise.all([ |
200 | this.buildCaptions(captionsResponse, translations), | ||
201 | this.buildStoryboard(storyboardsResponse) | ||
202 | ]) | ||
195 | 203 | ||
196 | const playerOptions: PeertubePlayerManagerOptions = { | 204 | const playerOptions: PeertubePlayerManagerOptions = { |
197 | common: { | 205 | common: { |
@@ -210,6 +218,8 @@ export class PlayerManagerOptions { | |||
210 | captions: videoCaptions.length !== 0, | 218 | captions: videoCaptions.length !== 0, |
211 | subtitle: this.subtitle, | 219 | subtitle: this.subtitle, |
212 | 220 | ||
221 | storyboard, | ||
222 | |||
213 | startTime: playlistTracker | 223 | startTime: playlistTracker |
214 | ? playlistTracker.getCurrentElement().startTimestamp | 224 | ? playlistTracker.getCurrentElement().startTimestamp |
215 | : this.startTime, | 225 | : this.startTime, |
@@ -286,6 +296,18 @@ export class PlayerManagerOptions { | |||
286 | } | 296 | } |
287 | } | 297 | } |
288 | 298 | ||
299 | private async buildStoryboard (storyboardsResponse: Response) { | ||
300 | const { storyboards } = await storyboardsResponse.json() as { storyboards: Storyboard[] } | ||
301 | if (!storyboards || storyboards.length === 0) return undefined | ||
302 | |||
303 | return { | ||
304 | url: window.location.origin + storyboards[0].storyboardPath, | ||
305 | height: storyboards[0].spriteHeight, | ||
306 | width: storyboards[0].spriteWidth, | ||
307 | interval: storyboards[0].spriteDuration | ||
308 | } | ||
309 | } | ||
310 | |||
289 | private buildPlaylistOptions (options: { | 311 | private buildPlaylistOptions (options: { |
290 | playlistTracker?: PlaylistTracker | 312 | playlistTracker?: PlaylistTracker |
291 | playNextPlaylistVideo?: () => any | 313 | playNextPlaylistVideo?: () => any |
diff --git a/client/src/standalone/videos/shared/video-fetcher.ts b/client/src/standalone/videos/shared/video-fetcher.ts index 76ba0a3ed..d52730b83 100644 --- a/client/src/standalone/videos/shared/video-fetcher.ts +++ b/client/src/standalone/videos/shared/video-fetcher.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { PeerTubeServerError } from '../../../types' | 1 | import { PeerTubeServerError } from '../../../types' |
2 | import { HttpStatusCode, LiveVideo, VideoDetails, VideoToken } from '../../../../../shared/models' | 2 | import { HttpStatusCode, LiveVideo, Storyboard, VideoDetails, VideoToken } from '../../../../../shared/models' |
3 | import { logger } from '../../../root-helpers' | 3 | import { logger } from '../../../root-helpers' |
4 | import { AuthHTTP } from './auth-http' | 4 | import { AuthHTTP } from './auth-http' |
5 | 5 | ||
@@ -36,8 +36,9 @@ export class VideoFetcher { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | const captionsPromise = this.loadVideoCaptions({ videoId, videoPassword }) | 38 | const captionsPromise = this.loadVideoCaptions({ videoId, videoPassword }) |
39 | const storyboardsPromise = this.loadStoryboards(videoId) | ||
39 | 40 | ||
40 | return { captionsPromise, videoResponse } | 41 | return { captionsPromise, storyboardsPromise, videoResponse } |
41 | } | 42 | } |
42 | 43 | ||
43 | loadLive (video: VideoDetails) { | 44 | loadLive (video: VideoDetails) { |
@@ -71,6 +72,14 @@ export class VideoFetcher { | |||
71 | return window.location.origin + '/api/v1/videos/live/' + videoId | 72 | return window.location.origin + '/api/v1/videos/live/' + videoId |
72 | } | 73 | } |
73 | 74 | ||
75 | private loadStoryboards (videoUUID: string): Promise<Response> { | ||
76 | return this.http.fetch(this.getStoryboardsUrl(videoUUID), { optionalAuth: true }) | ||
77 | } | ||
78 | |||
79 | private getStoryboardsUrl (videoId: string) { | ||
80 | return window.location.origin + '/api/v1/videos/' + videoId + '/storyboards' | ||
81 | } | ||
82 | |||
74 | private getVideoTokenUrl (id: string) { | 83 | private getVideoTokenUrl (id: string) { |
75 | return this.getVideoUrl(id) + '/token' | 84 | return this.getVideoUrl(id) + '/token' |
76 | } | 85 | } |