aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+videos')
-rw-r--r--client/src/app/+videos/+video-watch/video-watch.component.ts53
1 files changed, 37 insertions, 16 deletions
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index 9ae6f9f12..b3818c8de 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -20,12 +20,12 @@ import {
20} from '@app/core' 20} from '@app/core'
21import { HooksService } from '@app/core/plugins/hooks.service' 21import { HooksService } from '@app/core/plugins/hooks.service'
22import { isXPercentInViewport, scrollToTop } from '@app/helpers' 22import { isXPercentInViewport, scrollToTop } from '@app/helpers'
23import { Video, VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main' 23import { Video, VideoCaptionService, VideoDetails, VideoFileTokenService, VideoService } from '@app/shared/shared-main'
24import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' 24import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
25import { LiveVideoService } from '@app/shared/shared-video-live' 25import { LiveVideoService } from '@app/shared/shared-video-live'
26import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' 26import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
27import { logger } from '@root-helpers/logger' 27import { logger } from '@root-helpers/logger'
28import { isP2PEnabled } from '@root-helpers/video' 28import { isP2PEnabled, videoRequiresAuth } from '@root-helpers/video'
29import { timeToInt } from '@shared/core-utils' 29import { timeToInt } from '@shared/core-utils'
30import { 30import {
31 HTMLServerConfig, 31 HTMLServerConfig,
@@ -78,6 +78,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
78 private nextVideoUUID = '' 78 private nextVideoUUID = ''
79 private nextVideoTitle = '' 79 private nextVideoTitle = ''
80 80
81 private videoFileToken: string
82
81 private currentTime: number 83 private currentTime: number
82 84
83 private paramsSub: Subscription 85 private paramsSub: Subscription
@@ -110,6 +112,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
110 private pluginService: PluginService, 112 private pluginService: PluginService,
111 private peertubeSocket: PeerTubeSocket, 113 private peertubeSocket: PeerTubeSocket,
112 private screenService: ScreenService, 114 private screenService: ScreenService,
115 private videoFileTokenService: VideoFileTokenService,
113 private location: PlatformLocation, 116 private location: PlatformLocation,
114 @Inject(LOCALE_ID) private localeId: string 117 @Inject(LOCALE_ID) private localeId: string
115 ) { } 118 ) { }
@@ -252,12 +255,19 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
252 'filter:api.video-watch.video.get.result' 255 'filter:api.video-watch.video.get.result'
253 ) 256 )
254 257
255 const videoAndLiveObs: Observable<{ video: VideoDetails, live?: LiveVideo }> = videoObs.pipe( 258 const videoAndLiveObs: Observable<{ video: VideoDetails, live?: LiveVideo, videoFileToken?: string }> = videoObs.pipe(
256 switchMap(video => { 259 switchMap(video => {
257 if (!video.isLive) return of({ video }) 260 if (!video.isLive) return of({ video, live: undefined })
258 261
259 return this.liveVideoService.getVideoLive(video.uuid) 262 return this.liveVideoService.getVideoLive(video.uuid)
260 .pipe(map(live => ({ live, video }))) 263 .pipe(map(live => ({ live, video })))
264 }),
265
266 switchMap(({ video, live }) => {
267 if (!videoRequiresAuth(video)) return of({ video, live, videoFileToken: undefined })
268
269 return this.videoFileTokenService.getVideoFileToken(video.uuid)
270 .pipe(map(({ token }) => ({ video, live, videoFileToken: token })))
261 }) 271 })
262 ) 272 )
263 273
@@ -266,7 +276,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
266 this.videoCaptionService.listCaptions(videoId), 276 this.videoCaptionService.listCaptions(videoId),
267 this.userService.getAnonymousOrLoggedUser() 277 this.userService.getAnonymousOrLoggedUser()
268 ]).subscribe({ 278 ]).subscribe({
269 next: ([ { video, live }, captionsResult, loggedInOrAnonymousUser ]) => { 279 next: ([ { video, live, videoFileToken }, captionsResult, loggedInOrAnonymousUser ]) => {
270 const queryParams = this.route.snapshot.queryParams 280 const queryParams = this.route.snapshot.queryParams
271 281
272 const urlOptions = { 282 const urlOptions = {
@@ -283,7 +293,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
283 peertubeLink: false 293 peertubeLink: false
284 } 294 }
285 295
286 this.onVideoFetched({ video, live, videoCaptions: captionsResult.data, loggedInOrAnonymousUser, urlOptions }) 296 this.onVideoFetched({ video, live, videoCaptions: captionsResult.data, videoFileToken, loggedInOrAnonymousUser, urlOptions })
287 .catch(err => this.handleGlobalError(err)) 297 .catch(err => this.handleGlobalError(err))
288 }, 298 },
289 299
@@ -356,16 +366,19 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
356 video: VideoDetails 366 video: VideoDetails
357 live: LiveVideo 367 live: LiveVideo
358 videoCaptions: VideoCaption[] 368 videoCaptions: VideoCaption[]
369 videoFileToken: string
370
359 urlOptions: URLOptions 371 urlOptions: URLOptions
360 loggedInOrAnonymousUser: User 372 loggedInOrAnonymousUser: User
361 }) { 373 }) {
362 const { video, live, videoCaptions, urlOptions, loggedInOrAnonymousUser } = options 374 const { video, live, videoCaptions, urlOptions, videoFileToken, loggedInOrAnonymousUser } = options
363 375
364 this.subscribeToLiveEventsIfNeeded(this.video, video) 376 this.subscribeToLiveEventsIfNeeded(this.video, video)
365 377
366 this.video = video 378 this.video = video
367 this.videoCaptions = videoCaptions 379 this.videoCaptions = videoCaptions
368 this.liveVideo = live 380 this.liveVideo = live
381 this.videoFileToken = videoFileToken
369 382
370 // Re init attributes 383 // Re init attributes
371 this.playerPlaceholderImgSrc = undefined 384 this.playerPlaceholderImgSrc = undefined
@@ -414,6 +427,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
414 video: this.video, 427 video: this.video,
415 videoCaptions: this.videoCaptions, 428 videoCaptions: this.videoCaptions,
416 liveVideo: this.liveVideo, 429 liveVideo: this.liveVideo,
430 videoFileToken: this.videoFileToken,
417 urlOptions, 431 urlOptions,
418 loggedInOrAnonymousUser, 432 loggedInOrAnonymousUser,
419 user: this.user 433 user: this.user
@@ -561,11 +575,15 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
561 video: VideoDetails 575 video: VideoDetails
562 liveVideo: LiveVideo 576 liveVideo: LiveVideo
563 videoCaptions: VideoCaption[] 577 videoCaptions: VideoCaption[]
578
579 videoFileToken: string
580
564 urlOptions: CustomizationOptions & { playerMode: PlayerMode } 581 urlOptions: CustomizationOptions & { playerMode: PlayerMode }
582
565 loggedInOrAnonymousUser: User 583 loggedInOrAnonymousUser: User
566 user?: AuthUser // Keep for plugins 584 user?: AuthUser // Keep for plugins
567 }) { 585 }) {
568 const { video, liveVideo, videoCaptions, urlOptions, loggedInOrAnonymousUser } = params 586 const { video, liveVideo, videoCaptions, videoFileToken, urlOptions, loggedInOrAnonymousUser } = params
569 587
570 const getStartTime = () => { 588 const getStartTime = () => {
571 const byUrl = urlOptions.startTime !== undefined 589 const byUrl = urlOptions.startTime !== undefined
@@ -623,13 +641,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
623 theaterButton: true, 641 theaterButton: true,
624 captions: videoCaptions.length !== 0, 642 captions: videoCaptions.length !== 0,
625 643
626 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
627 ? this.videoService.getVideoViewUrl(video.uuid)
628 : null,
629 authorizationHeader: this.authService.getRequestHeaderValue(),
630
631 metricsUrl: environment.apiUrl + '/api/v1/metrics/playback',
632
633 embedUrl: video.embedUrl, 644 embedUrl: video.embedUrl,
634 embedTitle: video.name, 645 embedTitle: video.name,
635 instanceName: this.serverConfig.instance.name, 646 instanceName: this.serverConfig.instance.name,
@@ -639,7 +650,17 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
639 650
640 language: this.localeId, 651 language: this.localeId,
641 652
642 serverUrl: environment.apiUrl, 653 metricsUrl: environment.apiUrl + '/api/v1/metrics/playback',
654
655 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
656 ? this.videoService.getVideoViewUrl(video.uuid)
657 : null,
658 authorizationHeader: () => this.authService.getRequestHeaderValue(),
659
660 serverUrl: environment.originServerUrl,
661
662 videoFileToken: () => videoFileToken,
663 requiresAuth: videoRequiresAuth(video),
643 664
644 videoCaptions: playerCaptions, 665 videoCaptions: playerCaptions,
645 666