]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-watch/video-watch.component.ts
Add ability for client to create server logs
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-watch / video-watch.component.ts
1 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
2 import { forkJoin, map, Observable, of, Subscription, switchMap } from 'rxjs'
3 import { VideoJsPlayer } from 'video.js'
4 import { PlatformLocation } from '@angular/common'
5 import { Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
6 import { ActivatedRoute, Router } from '@angular/router'
7 import {
8 AuthService,
9 AuthUser,
10 ConfirmService,
11 MetaService,
12 Notifier,
13 PeerTubeSocket,
14 PluginService,
15 RestExtractor,
16 ScreenService,
17 ServerService,
18 User,
19 UserService
20 } from '@app/core'
21 import { HooksService } from '@app/core/plugins/hooks.service'
22 import { isXPercentInViewport, scrollToTop } from '@app/helpers'
23 import { Video, VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
24 import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
25 import { LiveVideoService } from '@app/shared/shared-video-live'
26 import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
27 import { logger } from '@root-helpers/logger'
28 import { isP2PEnabled } from '@root-helpers/video'
29 import { timeToInt } from '@shared/core-utils'
30 import {
31 HTMLServerConfig,
32 HttpStatusCode,
33 LiveVideo,
34 PeerTubeProblemDocument,
35 ServerErrorCode,
36 VideoCaption,
37 VideoPrivacy,
38 VideoState
39 } from '@shared/models'
40 import {
41 CustomizationOptions,
42 P2PMediaLoaderOptions,
43 PeertubePlayerManager,
44 PeertubePlayerManagerOptions,
45 PlayerMode,
46 videojs
47 } from '../../../assets/player'
48 import { cleanupVideoWatch, getStoredTheater, getStoredVideoWatchHistory } from '../../../assets/player/peertube-player-local-storage'
49 import { environment } from '../../../environments/environment'
50 import { VideoWatchPlaylistComponent } from './shared'
51
52 type URLOptions = CustomizationOptions & { playerMode: PlayerMode }
53
54 @Component({
55 selector: 'my-video-watch',
56 templateUrl: './video-watch.component.html',
57 styleUrls: [ './video-watch.component.scss' ]
58 })
59 export class VideoWatchComponent implements OnInit, OnDestroy {
60 @ViewChild('videoWatchPlaylist', { static: true }) videoWatchPlaylist: VideoWatchPlaylistComponent
61 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
62
63 player: VideoJsPlayer
64 playerElement: HTMLVideoElement
65 playerPlaceholderImgSrc: string
66 theaterEnabled = false
67
68 video: VideoDetails = null
69 videoCaptions: VideoCaption[] = []
70 liveVideo: LiveVideo
71
72 playlistPosition: number
73 playlist: VideoPlaylist = null
74
75 remoteServerDown = false
76 noPlaylistVideoFound = false
77
78 private nextVideoUUID = ''
79 private nextVideoTitle = ''
80
81 private currentTime: number
82
83 private paramsSub: Subscription
84 private queryParamsSub: Subscription
85 private configSub: Subscription
86 private liveVideosSub: Subscription
87
88 private serverConfig: HTMLServerConfig
89
90 private hotkeys: Hotkey[] = []
91
92 constructor (
93 private elementRef: ElementRef,
94 private route: ActivatedRoute,
95 private router: Router,
96 private videoService: VideoService,
97 private playlistService: VideoPlaylistService,
98 private liveVideoService: LiveVideoService,
99 private confirmService: ConfirmService,
100 private metaService: MetaService,
101 private authService: AuthService,
102 private userService: UserService,
103 private serverService: ServerService,
104 private restExtractor: RestExtractor,
105 private notifier: Notifier,
106 private zone: NgZone,
107 private videoCaptionService: VideoCaptionService,
108 private hotkeysService: HotkeysService,
109 private hooks: HooksService,
110 private pluginService: PluginService,
111 private peertubeSocket: PeerTubeSocket,
112 private screenService: ScreenService,
113 private location: PlatformLocation,
114 @Inject(LOCALE_ID) private localeId: string
115 ) { }
116
117 get user () {
118 return this.authService.getUser()
119 }
120
121 get anonymousUser () {
122 return this.userService.getAnonymousUser()
123 }
124
125 ngOnInit () {
126 this.serverConfig = this.serverService.getHTMLConfig()
127
128 PeertubePlayerManager.initState()
129
130 this.loadRouteParams()
131 this.loadRouteQuery()
132
133 this.initHotkeys()
134
135 this.theaterEnabled = getStoredTheater()
136
137 this.hooks.runAction('action:video-watch.init', 'video-watch')
138
139 setTimeout(cleanupVideoWatch, 1500) // Run in timeout to ensure we're not blocking the UI
140 }
141
142 ngOnDestroy () {
143 this.flushPlayer()
144
145 // Unsubscribe subscriptions
146 if (this.paramsSub) this.paramsSub.unsubscribe()
147 if (this.queryParamsSub) this.queryParamsSub.unsubscribe()
148 if (this.configSub) this.configSub.unsubscribe()
149 if (this.liveVideosSub) this.liveVideosSub.unsubscribe()
150
151 // Unbind hotkeys
152 this.hotkeysService.remove(this.hotkeys)
153 }
154
155 getCurrentTime () {
156 return this.currentTime
157 }
158
159 getCurrentPlaylistPosition () {
160 return this.videoWatchPlaylist.currentPlaylistPosition
161 }
162
163 onRecommendations (videos: Video[]) {
164 if (videos.length === 0) return
165
166 // The recommended videos's first element should be the next video
167 const video = videos[0]
168 this.nextVideoUUID = video.uuid
169 this.nextVideoTitle = video.name
170 }
171
172 handleTimestampClicked (timestamp: number) {
173 if (!this.player || this.video.isLive) return
174
175 this.player.currentTime(timestamp)
176 scrollToTop()
177 }
178
179 onPlaylistVideoFound (videoId: string) {
180 this.loadVideo(videoId)
181 }
182
183 onPlaylistNoVideoFound () {
184 this.noPlaylistVideoFound = true
185 }
186
187 isUserLoggedIn () {
188 return this.authService.isLoggedIn()
189 }
190
191 isVideoBlur (video: Video) {
192 return video.isVideoNSFWForUser(this.user, this.serverConfig)
193 }
194
195 isChannelDisplayNameGeneric () {
196 const genericChannelDisplayName = [
197 `Main ${this.video.channel.ownerAccount.name} channel`,
198 `Default ${this.video.channel.ownerAccount.name} channel`
199 ]
200
201 return genericChannelDisplayName.includes(this.video.channel.displayName)
202 }
203
204 displayOtherVideosAsRow () {
205 // Use the same value as in the SASS file
206 return this.screenService.getWindowInnerWidth() <= 1100
207 }
208
209 private loadRouteParams () {
210 this.paramsSub = this.route.params.subscribe(routeParams => {
211 const videoId = routeParams['videoId']
212 if (videoId) return this.loadVideo(videoId)
213
214 const playlistId = routeParams['playlistId']
215 if (playlistId) return this.loadPlaylist(playlistId)
216 })
217 }
218
219 private loadRouteQuery () {
220 this.queryParamsSub = this.route.queryParams.subscribe(queryParams => {
221 // Handle the ?playlistPosition
222 const positionParam = queryParams['playlistPosition'] ?? 1
223
224 this.playlistPosition = positionParam === 'last'
225 ? -1 // Handle the "last" index
226 : parseInt(positionParam + '', 10)
227
228 if (isNaN(this.playlistPosition)) {
229 logger.error(`playlistPosition query param '${positionParam}' was parsed as NaN, defaulting to 1.`)
230 this.playlistPosition = 1
231 }
232
233 this.videoWatchPlaylist.updatePlaylistIndex(this.playlistPosition)
234
235 const start = queryParams['start']
236 if (this.player && start) this.player.currentTime(parseInt(start, 10))
237 })
238 }
239
240 private loadVideo (videoId: string) {
241 if (this.isSameElement(this.video, videoId)) return
242
243 if (this.player) this.player.pause()
244
245 const videoObs = this.hooks.wrapObsFun(
246 this.videoService.getVideo.bind(this.videoService),
247 { videoId },
248 'video-watch',
249 'filter:api.video-watch.video.get.params',
250 'filter:api.video-watch.video.get.result'
251 )
252
253 const videoAndLiveObs: Observable<{ video: VideoDetails, live?: LiveVideo }> = videoObs.pipe(
254 switchMap(video => {
255 if (!video.isLive) return of({ video })
256
257 return this.liveVideoService.getVideoLive(video.uuid)
258 .pipe(map(live => ({ live, video })))
259 })
260 )
261
262 forkJoin([
263 videoAndLiveObs,
264 this.videoCaptionService.listCaptions(videoId),
265 this.userService.getAnonymousOrLoggedUser()
266 ]).subscribe({
267 next: ([ { video, live }, captionsResult, loggedInOrAnonymousUser ]) => {
268 const queryParams = this.route.snapshot.queryParams
269
270 const urlOptions = {
271 resume: queryParams.resume,
272
273 startTime: queryParams.start,
274 stopTime: queryParams.stop,
275
276 muted: queryParams.muted,
277 loop: queryParams.loop,
278 subtitle: queryParams.subtitle,
279
280 playerMode: queryParams.mode,
281 peertubeLink: false
282 }
283
284 this.onVideoFetched({ video, live, videoCaptions: captionsResult.data, loggedInOrAnonymousUser, urlOptions })
285 .catch(err => this.handleGlobalError(err))
286 },
287
288 error: err => this.handleRequestError(err)
289 })
290 }
291
292 private loadPlaylist (playlistId: string) {
293 if (this.isSameElement(this.playlist, playlistId)) return
294
295 this.noPlaylistVideoFound = false
296
297 this.playlistService.getVideoPlaylist(playlistId)
298 .subscribe({
299 next: playlist => {
300 this.playlist = playlist
301
302 this.videoWatchPlaylist.loadPlaylistElements(playlist, !this.playlistPosition, this.playlistPosition)
303 },
304
305 error: err => this.handleRequestError(err)
306 })
307 }
308
309 private isSameElement (element: VideoDetails | VideoPlaylist, newId: string) {
310 if (!element) return false
311
312 return (element.id + '') === newId || element.uuid === newId || element.shortUUID === newId
313 }
314
315 private async handleRequestError (err: any) {
316 const errorBody = err.body as PeerTubeProblemDocument
317
318 if (errorBody?.code === ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS && errorBody.originUrl) {
319 const originUrl = errorBody.originUrl + (window.location.search ?? '')
320
321 const res = await this.confirmService.confirm(
322 // eslint-disable-next-line max-len
323 $localize`This video is not available on this instance. Do you want to be redirected on the origin instance: <a href="${originUrl}">${originUrl}</a>?`,
324 $localize`Redirection`
325 )
326
327 if (res === true) return window.location.href = originUrl
328 }
329
330 // If 400, 403 or 404, the video is private or blocked so redirect to 404
331 return this.restExtractor.redirectTo404IfNotFound(err, 'video', [
332 HttpStatusCode.BAD_REQUEST_400,
333 HttpStatusCode.FORBIDDEN_403,
334 HttpStatusCode.NOT_FOUND_404
335 ])
336 }
337
338 private handleGlobalError (err: any) {
339 const errorMessage: string = typeof err === 'string' ? err : err.message
340 if (!errorMessage) return
341
342 // Display a message in the video player instead of a notification
343 if (errorMessage.includes('from xs param')) {
344 this.flushPlayer()
345 this.remoteServerDown = true
346
347 return
348 }
349
350 this.notifier.error(errorMessage)
351 }
352
353 private async onVideoFetched (options: {
354 video: VideoDetails
355 live: LiveVideo
356 videoCaptions: VideoCaption[]
357 urlOptions: URLOptions
358 loggedInOrAnonymousUser: User
359 }) {
360 const { video, live, videoCaptions, urlOptions, loggedInOrAnonymousUser } = options
361
362 this.subscribeToLiveEventsIfNeeded(this.video, video)
363
364 this.video = video
365 this.videoCaptions = videoCaptions
366 this.liveVideo = live
367
368 // Re init attributes
369 this.playerPlaceholderImgSrc = undefined
370 this.remoteServerDown = false
371 this.currentTime = undefined
372
373 if (this.isVideoBlur(this.video)) {
374 const res = await this.confirmService.confirm(
375 $localize`This video contains mature or explicit content. Are you sure you want to watch it?`,
376 $localize`Mature or explicit content`
377 )
378 if (res === false) return this.location.back()
379 }
380
381 this.buildPlayer(urlOptions, loggedInOrAnonymousUser)
382 .catch(err => logger.error('Cannot build the player', err))
383
384 this.setOpenGraphTags()
385
386 const hookOptions = {
387 videojs,
388 video: this.video,
389 playlist: this.playlist
390 }
391 this.hooks.runAction('action:video-watch.video.loaded', 'video-watch', hookOptions)
392 }
393
394 private async buildPlayer (urlOptions: URLOptions, loggedInOrAnonymousUser: User) {
395 // Flush old player if needed
396 this.flushPlayer()
397
398 const videoState = this.video.state.id
399 if (videoState === VideoState.LIVE_ENDED || videoState === VideoState.WAITING_FOR_LIVE) {
400 this.playerPlaceholderImgSrc = this.video.previewPath
401 return
402 }
403
404 // Build video element, because videojs removes it on dispose
405 const playerElementWrapper = this.elementRef.nativeElement.querySelector('#videojs-wrapper')
406 this.playerElement = document.createElement('video')
407 this.playerElement.className = 'video-js vjs-peertube-skin'
408 this.playerElement.setAttribute('playsinline', 'true')
409 playerElementWrapper.appendChild(this.playerElement)
410
411 const params = {
412 video: this.video,
413 videoCaptions: this.videoCaptions,
414 liveVideo: this.liveVideo,
415 urlOptions,
416 loggedInOrAnonymousUser,
417 user: this.user
418 }
419 const { playerMode, playerOptions } = await this.hooks.wrapFun(
420 this.buildPlayerManagerOptions.bind(this),
421 params,
422 'video-watch',
423 'filter:internal.video-watch.player.build-options.params',
424 'filter:internal.video-watch.player.build-options.result'
425 )
426
427 this.zone.runOutsideAngular(async () => {
428 this.player = await PeertubePlayerManager.initialize(playerMode, playerOptions, player => this.player = player)
429
430 this.player.on('customError', (_e, data: any) => {
431 this.zone.run(() => this.handleGlobalError(data.err))
432 })
433
434 this.player.on('timeupdate', () => {
435 // Don't need to trigger angular change for this variable, that is sent to children components on click
436 this.currentTime = Math.floor(this.player.currentTime())
437 })
438
439 /**
440 * condition: true to make the upnext functionality trigger, false to disable the upnext functionality
441 * go to the next video in 'condition()' if you don't want of the timer.
442 * next: function triggered at the end of the timer.
443 * suspended: function used at each click of the timer checking if we need to reset progress
444 * and wait until suspended becomes truthy again.
445 */
446 this.player.upnext({
447 timeout: 5000, // 5s
448
449 headText: $localize`Up Next`,
450 cancelText: $localize`Cancel`,
451 suspendedText: $localize`Autoplay is suspended`,
452
453 getTitle: () => this.nextVideoTitle,
454
455 next: () => this.zone.run(() => this.playNextVideoInAngularZone()),
456 condition: () => {
457 if (!this.playlist) return this.isAutoPlayNext()
458
459 // Don't wait timeout to play the next playlist video
460 if (this.isPlaylistAutoPlayNext()) {
461 this.playNextVideoInAngularZone()
462 return undefined
463 }
464
465 return false
466 },
467
468 suspended: () => {
469 return (
470 !isXPercentInViewport(this.player.el() as HTMLElement, 80) ||
471 !document.getElementById('content').contains(document.activeElement)
472 )
473 }
474 })
475
476 this.player.one('stopped', () => {
477 if (this.playlist && this.isPlaylistAutoPlayNext()) {
478 this.playNextVideoInAngularZone()
479 }
480 })
481
482 this.player.one('ended', () => {
483 if (this.video.isLive) {
484 this.zone.run(() => this.video.state.id = VideoState.LIVE_ENDED)
485 }
486 })
487
488 this.player.on('theaterChange', (_: any, enabled: boolean) => {
489 this.zone.run(() => this.theaterEnabled = enabled)
490 })
491
492 this.hooks.runAction('action:video-watch.player.loaded', 'video-watch', {
493 player: this.player,
494 playlist: this.playlist,
495 playlistPosition: this.playlistPosition,
496 videojs,
497 video: this.video
498 })
499 })
500 }
501
502 private hasNextVideo () {
503 if (this.playlist) {
504 return this.videoWatchPlaylist.hasNextVideo()
505 }
506
507 return true
508 }
509
510 private playNextVideoInAngularZone () {
511 if (this.playlist) {
512 this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
513 return
514 }
515
516 if (this.nextVideoUUID) {
517 this.router.navigate([ '/w', this.nextVideoUUID ])
518 }
519 }
520
521 private isAutoplay () {
522 // We'll jump to the thread id, so do not play the video
523 if (this.route.snapshot.params['threadId']) return false
524
525 // Otherwise true by default
526 if (!this.user) return true
527
528 // Be sure the autoPlay is set to false
529 return this.user.autoPlayVideo !== false
530 }
531
532 private isAutoPlayNext () {
533 return (
534 (this.user?.autoPlayNextVideo) ||
535 this.anonymousUser.autoPlayNextVideo
536 )
537 }
538
539 private isPlaylistAutoPlayNext () {
540 return (
541 (this.user?.autoPlayNextVideoPlaylist) ||
542 this.anonymousUser.autoPlayNextVideoPlaylist
543 )
544 }
545
546 private flushPlayer () {
547 // Remove player if it exists
548 if (!this.player) return
549
550 try {
551 this.player.dispose()
552 this.player = undefined
553 } catch (err) {
554 logger.error('Cannot dispose player.', err)
555 }
556 }
557
558 private buildPlayerManagerOptions (params: {
559 video: VideoDetails
560 liveVideo: LiveVideo
561 videoCaptions: VideoCaption[]
562 urlOptions: CustomizationOptions & { playerMode: PlayerMode }
563 loggedInOrAnonymousUser: User
564 user?: AuthUser // Keep for plugins
565 }) {
566 const { video, liveVideo, videoCaptions, urlOptions, loggedInOrAnonymousUser } = params
567
568 const getStartTime = () => {
569 const byUrl = urlOptions.startTime !== undefined
570 const byHistory = video.userHistory && (!this.playlist || urlOptions.resume !== undefined)
571 const byLocalStorage = getStoredVideoWatchHistory(video.uuid)
572
573 if (byUrl) return timeToInt(urlOptions.startTime)
574 if (byHistory) return video.userHistory.currentTime
575 if (byLocalStorage) return byLocalStorage.duration
576
577 return 0
578 }
579
580 let startTime = getStartTime()
581
582 // If we are at the end of the video, reset the timer
583 if (video.duration - startTime <= 1) startTime = 0
584
585 const playerCaptions = videoCaptions.map(c => ({
586 label: c.language.label,
587 language: c.language.id,
588 src: environment.apiUrl + c.captionPath
589 }))
590
591 const liveOptions = video.isLive
592 ? { latencyMode: liveVideo.latencyMode }
593 : undefined
594
595 const options: PeertubePlayerManagerOptions = {
596 common: {
597 autoplay: this.isAutoplay(),
598 p2pEnabled: isP2PEnabled(video, this.serverConfig, loggedInOrAnonymousUser.p2pEnabled),
599
600 hasNextVideo: () => this.hasNextVideo(),
601 nextVideo: () => this.playNextVideoInAngularZone(),
602
603 playerElement: this.playerElement,
604 onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
605
606 videoDuration: video.duration,
607 enableHotkeys: true,
608 inactivityTimeout: 2500,
609 poster: video.previewUrl,
610
611 startTime,
612 stopTime: urlOptions.stopTime,
613 controlBar: urlOptions.controlBar,
614 controls: urlOptions.controls,
615 muted: urlOptions.muted,
616 loop: urlOptions.loop,
617 subtitle: urlOptions.subtitle,
618
619 peertubeLink: urlOptions.peertubeLink,
620
621 theaterButton: true,
622 captions: videoCaptions.length !== 0,
623
624 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
625 ? this.videoService.getVideoViewUrl(video.uuid)
626 : null,
627 authorizationHeader: this.authService.getRequestHeaderValue(),
628
629 embedUrl: video.embedUrl,
630 embedTitle: video.name,
631 instanceName: this.serverConfig.instance.name,
632
633 isLive: video.isLive,
634 liveOptions,
635
636 language: this.localeId,
637
638 serverUrl: environment.apiUrl,
639
640 videoCaptions: playerCaptions,
641
642 videoShortUUID: video.shortUUID,
643 videoUUID: video.uuid,
644
645 errorNotifier: (message: string) => this.notifier.error(message)
646 },
647
648 webtorrent: {
649 videoFiles: video.files
650 },
651
652 pluginsManager: this.pluginService.getPluginsManager()
653 }
654
655 // Only set this if we're in a playlist
656 if (this.playlist) {
657 options.common.hasPreviousVideo = () => this.videoWatchPlaylist.hasPreviousVideo()
658
659 options.common.previousVideo = () => {
660 this.zone.run(() => this.videoWatchPlaylist.navigateToPreviousPlaylistVideo())
661 }
662 }
663
664 let mode: PlayerMode
665
666 if (urlOptions.playerMode) {
667 if (urlOptions.playerMode === 'p2p-media-loader') mode = 'p2p-media-loader'
668 else mode = 'webtorrent'
669 } else {
670 if (video.hasHlsPlaylist()) mode = 'p2p-media-loader'
671 else mode = 'webtorrent'
672 }
673
674 // p2p-media-loader needs TextEncoder, fallback on WebTorrent if not available
675 if (typeof TextEncoder === 'undefined') {
676 mode = 'webtorrent'
677 }
678
679 if (mode === 'p2p-media-loader') {
680 const hlsPlaylist = video.getHlsPlaylist()
681
682 const p2pMediaLoader = {
683 playlistUrl: hlsPlaylist.playlistUrl,
684 segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
685 redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
686 trackerAnnounce: video.trackerUrls,
687 videoFiles: hlsPlaylist.files
688 } as P2PMediaLoaderOptions
689
690 Object.assign(options, { p2pMediaLoader })
691 }
692
693 return { playerMode: mode, playerOptions: options }
694 }
695
696 private async subscribeToLiveEventsIfNeeded (oldVideo: VideoDetails, newVideo: VideoDetails) {
697 if (!this.liveVideosSub) {
698 this.liveVideosSub = this.buildLiveEventsSubscription()
699 }
700
701 if (oldVideo && oldVideo.id !== newVideo.id) {
702 this.peertubeSocket.unsubscribeLiveVideos(oldVideo.id)
703 }
704
705 if (!newVideo.isLive) return
706
707 await this.peertubeSocket.subscribeToLiveVideosSocket(newVideo.id)
708 }
709
710 private buildLiveEventsSubscription () {
711 return this.peertubeSocket.getLiveVideosObservable()
712 .subscribe(({ type, payload }) => {
713 if (type === 'state-change') return this.handleLiveStateChange(payload.state)
714 if (type === 'views-change') return this.handleLiveViewsChange(payload.viewers)
715 })
716 }
717
718 private handleLiveStateChange (newState: VideoState) {
719 if (newState !== VideoState.PUBLISHED) return
720
721 logger.info('Loading video after live update.')
722
723 const videoUUID = this.video.uuid
724
725 // Reset to force refresh the video
726 this.video = undefined
727 this.loadVideo(videoUUID)
728 }
729
730 private handleLiveViewsChange (newViewers: number) {
731 if (!this.video) {
732 logger.error('Cannot update video live views because video is no defined.')
733 return
734 }
735
736 logger.info('Updating live views.')
737
738 this.video.viewers = newViewers
739 }
740
741 private initHotkeys () {
742 this.hotkeys = [
743 // These hotkeys are managed by the player
744 new Hotkey('f', e => e, undefined, $localize`Enter/exit fullscreen`),
745 new Hotkey('space', e => e, undefined, $localize`Play/Pause the video`),
746 new Hotkey('m', e => e, undefined, $localize`Mute/unmute the video`),
747
748 new Hotkey('0-9', e => e, undefined, $localize`Skip to a percentage of the video: 0 is 0% and 9 is 90%`),
749
750 new Hotkey('up', e => e, undefined, $localize`Increase the volume`),
751 new Hotkey('down', e => e, undefined, $localize`Decrease the volume`),
752
753 new Hotkey('right', e => e, undefined, $localize`Seek the video forward`),
754 new Hotkey('left', e => e, undefined, $localize`Seek the video backward`),
755
756 new Hotkey('>', e => e, undefined, $localize`Increase playback rate`),
757 new Hotkey('<', e => e, undefined, $localize`Decrease playback rate`),
758
759 new Hotkey(',', e => e, undefined, $localize`Navigate in the video to the previous frame`),
760 new Hotkey('.', e => e, undefined, $localize`Navigate in the video to the next frame`),
761
762 new Hotkey('t', e => {
763 this.theaterEnabled = !this.theaterEnabled
764 return false
765 }, undefined, $localize`Toggle theater mode`)
766 ]
767
768 if (this.isUserLoggedIn()) {
769 this.hotkeys = this.hotkeys.concat([
770 new Hotkey('shift+s', () => {
771 if (this.subscribeButton.isSubscribedToAll()) this.subscribeButton.unsubscribe()
772 else this.subscribeButton.subscribe()
773
774 return false
775 }, undefined, $localize`Subscribe to the account`)
776 ])
777 }
778
779 this.hotkeysService.add(this.hotkeys)
780 }
781
782 private setOpenGraphTags () {
783 this.metaService.setTitle(this.video.name)
784
785 this.metaService.setTag('og:type', 'video')
786
787 this.metaService.setTag('og:title', this.video.name)
788 this.metaService.setTag('name', this.video.name)
789
790 this.metaService.setTag('og:description', this.video.description)
791 this.metaService.setTag('description', this.video.description)
792
793 this.metaService.setTag('og:image', this.video.previewPath)
794
795 this.metaService.setTag('og:duration', this.video.duration.toString())
796
797 this.metaService.setTag('og:site_name', 'PeerTube')
798
799 this.metaService.setTag('og:url', window.location.href)
800 this.metaService.setTag('url', window.location.href)
801 }
802 }