diff options
Diffstat (limited to 'client/src/app/+videos/+video-watch/video-watch.component.ts')
-rw-r--r-- | client/src/app/+videos/+video-watch/video-watch.component.ts | 64 |
1 files changed, 38 insertions, 26 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 fd61bcbf0..d542f243c 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' | 1 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' |
2 | import { forkJoin, Subscription } from 'rxjs' | 2 | import { forkJoin, Subscription } from 'rxjs' |
3 | import { isP2PEnabled } from 'src/assets/player/utils' | ||
3 | import { PlatformLocation } from '@angular/common' | 4 | import { PlatformLocation } from '@angular/common' |
4 | import { Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' | 5 | import { Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' |
5 | import { ActivatedRoute, Router } from '@angular/router' | 6 | import { ActivatedRoute, Router } from '@angular/router' |
@@ -14,6 +15,7 @@ import { | |||
14 | RestExtractor, | 15 | RestExtractor, |
15 | ScreenService, | 16 | ScreenService, |
16 | ServerService, | 17 | ServerService, |
18 | User, | ||
17 | UserService | 19 | UserService |
18 | } from '@app/core' | 20 | } from '@app/core' |
19 | import { HooksService } from '@app/core/plugins/hooks.service' | 21 | import { HooksService } from '@app/core/plugins/hooks.service' |
@@ -237,31 +239,34 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
237 | 'filter:api.video-watch.video.get.result' | 239 | 'filter:api.video-watch.video.get.result' |
238 | ) | 240 | ) |
239 | 241 | ||
240 | forkJoin([ videoObs, this.videoCaptionService.listCaptions(videoId) ]) | 242 | forkJoin([ |
241 | .subscribe({ | 243 | videoObs, |
242 | next: ([ video, captionsResult ]) => { | 244 | this.videoCaptionService.listCaptions(videoId), |
243 | const queryParams = this.route.snapshot.queryParams | 245 | this.userService.getAnonymousOrLoggedUser() |
246 | ]).subscribe({ | ||
247 | next: ([ video, captionsResult, loggedInOrAnonymousUser ]) => { | ||
248 | const queryParams = this.route.snapshot.queryParams | ||
244 | 249 | ||
245 | const urlOptions = { | 250 | const urlOptions = { |
246 | resume: queryParams.resume, | 251 | resume: queryParams.resume, |
247 | 252 | ||
248 | startTime: queryParams.start, | 253 | startTime: queryParams.start, |
249 | stopTime: queryParams.stop, | 254 | stopTime: queryParams.stop, |
250 | 255 | ||
251 | muted: queryParams.muted, | 256 | muted: queryParams.muted, |
252 | loop: queryParams.loop, | 257 | loop: queryParams.loop, |
253 | subtitle: queryParams.subtitle, | 258 | subtitle: queryParams.subtitle, |
254 | 259 | ||
255 | playerMode: queryParams.mode, | 260 | playerMode: queryParams.mode, |
256 | peertubeLink: false | 261 | peertubeLink: false |
257 | } | 262 | } |
258 | 263 | ||
259 | this.onVideoFetched(video, captionsResult.data, urlOptions) | 264 | this.onVideoFetched({ video, videoCaptions: captionsResult.data, loggedInOrAnonymousUser, urlOptions }) |
260 | .catch(err => this.handleGlobalError(err)) | 265 | .catch(err => this.handleGlobalError(err)) |
261 | }, | 266 | }, |
262 | 267 | ||
263 | error: err => this.handleRequestError(err) | 268 | error: err => this.handleRequestError(err) |
264 | }) | 269 | }) |
265 | } | 270 | } |
266 | 271 | ||
267 | private loadPlaylist (playlistId: string) { | 272 | private loadPlaylist (playlistId: string) { |
@@ -323,11 +328,14 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
323 | this.notifier.error(errorMessage) | 328 | this.notifier.error(errorMessage) |
324 | } | 329 | } |
325 | 330 | ||
326 | private async onVideoFetched ( | 331 | private async onVideoFetched (options: { |
327 | video: VideoDetails, | 332 | video: VideoDetails |
328 | videoCaptions: VideoCaption[], | 333 | videoCaptions: VideoCaption[] |
329 | urlOptions: URLOptions | 334 | urlOptions: URLOptions |
330 | ) { | 335 | loggedInOrAnonymousUser: User |
336 | }) { | ||
337 | const { video, videoCaptions, urlOptions, loggedInOrAnonymousUser } = options | ||
338 | |||
331 | this.subscribeToLiveEventsIfNeeded(this.video, video) | 339 | this.subscribeToLiveEventsIfNeeded(this.video, video) |
332 | 340 | ||
333 | this.video = video | 341 | this.video = video |
@@ -346,7 +354,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
346 | if (res === false) return this.location.back() | 354 | if (res === false) return this.location.back() |
347 | } | 355 | } |
348 | 356 | ||
349 | this.buildPlayer(urlOptions) | 357 | this.buildPlayer(urlOptions, loggedInOrAnonymousUser) |
350 | .catch(err => console.error('Cannot build the player', err)) | 358 | .catch(err => console.error('Cannot build the player', err)) |
351 | 359 | ||
352 | this.setOpenGraphTags() | 360 | this.setOpenGraphTags() |
@@ -359,7 +367,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
359 | this.hooks.runAction('action:video-watch.video.loaded', 'video-watch', hookOptions) | 367 | this.hooks.runAction('action:video-watch.video.loaded', 'video-watch', hookOptions) |
360 | } | 368 | } |
361 | 369 | ||
362 | private async buildPlayer (urlOptions: URLOptions) { | 370 | private async buildPlayer (urlOptions: URLOptions, loggedInOrAnonymousUser: User) { |
363 | // Flush old player if needed | 371 | // Flush old player if needed |
364 | this.flushPlayer() | 372 | this.flushPlayer() |
365 | 373 | ||
@@ -380,6 +388,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
380 | video: this.video, | 388 | video: this.video, |
381 | videoCaptions: this.videoCaptions, | 389 | videoCaptions: this.videoCaptions, |
382 | urlOptions, | 390 | urlOptions, |
391 | loggedInOrAnonymousUser, | ||
383 | user: this.user | 392 | user: this.user |
384 | } | 393 | } |
385 | const { playerMode, playerOptions } = await this.hooks.wrapFun( | 394 | const { playerMode, playerOptions } = await this.hooks.wrapFun( |
@@ -517,9 +526,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
517 | video: VideoDetails | 526 | video: VideoDetails |
518 | videoCaptions: VideoCaption[] | 527 | videoCaptions: VideoCaption[] |
519 | urlOptions: CustomizationOptions & { playerMode: PlayerMode } | 528 | urlOptions: CustomizationOptions & { playerMode: PlayerMode } |
529 | loggedInOrAnonymousUser: User | ||
520 | user?: AuthUser | 530 | user?: AuthUser |
521 | }) { | 531 | }) { |
522 | const { video, videoCaptions, urlOptions, user } = params | 532 | const { video, videoCaptions, urlOptions, loggedInOrAnonymousUser, user } = params |
523 | 533 | ||
524 | const getStartTime = () => { | 534 | const getStartTime = () => { |
525 | const byUrl = urlOptions.startTime !== undefined | 535 | const byUrl = urlOptions.startTime !== undefined |
@@ -547,6 +557,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
547 | const options: PeertubePlayerManagerOptions = { | 557 | const options: PeertubePlayerManagerOptions = { |
548 | common: { | 558 | common: { |
549 | autoplay: this.isAutoplay(), | 559 | autoplay: this.isAutoplay(), |
560 | p2pEnabled: isP2PEnabled(video, this.serverConfig, loggedInOrAnonymousUser.p2pEnabled), | ||
561 | |||
550 | nextVideo: () => this.playNextVideoInAngularZone(), | 562 | nextVideo: () => this.playNextVideoInAngularZone(), |
551 | 563 | ||
552 | playerElement: this.playerElement, | 564 | playerElement: this.playerElement, |