]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-watch/video-watch.component.ts
Add channel hooks
[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 this.video = undefined
246
247 const videoObs = this.hooks.wrapObsFun(
248 this.videoService.getVideo.bind(this.videoService),
249 { videoId },
250 'video-watch',
251 'filter:api.video-watch.video.get.params',
252 'filter:api.video-watch.video.get.result'
253 )
254
255 const videoAndLiveObs: Observable<{ video: VideoDetails, live?: LiveVideo }> = videoObs.pipe(
256 switchMap(video => {
257 if (!video.isLive) return of({ video })
258
259 return this.liveVideoService.getVideoLive(video.uuid)
260 .pipe(map(live => ({ live, video })))
261 })
262 )
263
264 forkJoin([
265 videoAndLiveObs,
266 this.videoCaptionService.listCaptions(videoId),
267 this.userService.getAnonymousOrLoggedUser()
268 ]).subscribe({
269 next: ([ { video, live }, captionsResult, loggedInOrAnonymousUser ]) => {
270 const queryParams = this.route.snapshot.queryParams
271
272 const urlOptions = {
273 resume: queryParams.resume,
274
275 startTime: queryParams.start,
276 stopTime: queryParams.stop,
277
278 muted: queryParams.muted,
279 loop: queryParams.loop,
280 subtitle: queryParams.subtitle,
281
282 playerMode: queryParams.mode,
283 peertubeLink: false
284 }
285
286 this.onVideoFetched({ video, live, videoCaptions: captionsResult.data, loggedInOrAnonymousUser, urlOptions })
287 .catch(err => this.handleGlobalError(err))
288 },
289
290 error: err => this.handleRequestError(err)
291 })
292 }
293
294 private loadPlaylist (playlistId: string) {
295 if (this.isSameElement(this.playlist, playlistId)) return
296
297 this.noPlaylistVideoFound = false
298
299 this.playlistService.getVideoPlaylist(playlistId)
300 .subscribe({
301 next: playlist => {
302 this.playlist = playlist
303
304 this.videoWatchPlaylist.loadPlaylistElements(playlist, !this.playlistPosition, this.playlistPosition)
305 },
306
307 error: err => this.handleRequestError(err)
308 })
309 }
310
311 private isSameElement (element: VideoDetails | VideoPlaylist, newId: string) {
312 if (!element) return false
313
314 return (element.id + '') === newId || element.uuid === newId || element.shortUUID === newId
315 }
316
317 private async handleRequestError (err: any) {
318 const errorBody = err.body as PeerTubeProblemDocument
319
320 if (errorBody?.code === ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS && errorBody.originUrl) {
321 const originUrl = errorBody.originUrl + (window.location.search ?? '')
322
323 const res = await this.confirmService.confirm(
324 // eslint-disable-next-line max-len
325 $localize`This video is not available on this instance. Do you want to be redirected on the origin instance: <a href="${originUrl}">${originUrl}</a>?`,
326 $localize`Redirection`
327 )
328
329 if (res === true) return window.location.href = originUrl
330 }
331
332 // If 400, 403 or 404, the video is private or blocked so redirect to 404
333 return this.restExtractor.redirectTo404IfNotFound(err, 'video', [
334 HttpStatusCode.BAD_REQUEST_400,
335 HttpStatusCode.FORBIDDEN_403,
336 HttpStatusCode.NOT_FOUND_404
337 ])
338 }
339
340 private handleGlobalError (err: any) {
341 const errorMessage: string = typeof err === 'string' ? err : err.message
342 if (!errorMessage) return
343
344 // Display a message in the video player instead of a notification
345 if (errorMessage.includes('from xs param')) {
346 this.flushPlayer()
347 this.remoteServerDown = true
348
349 return
350 }
351
352 this.notifier.error(errorMessage)
353 }
354
355 private async onVideoFetched (options: {
356 video: VideoDetails
357 live: LiveVideo
358 videoCaptions: VideoCaption[]
359 urlOptions: URLOptions
360 loggedInOrAnonymousUser: User
361 }) {
362 const { video, live, videoCaptions, urlOptions, loggedInOrAnonymousUser } = options
363
364 this.subscribeToLiveEventsIfNeeded(this.video, video)
365
366 this.video = video
367 this.videoCaptions = videoCaptions
368 this.liveVideo = live
369
370 // Re init attributes
371 this.playerPlaceholderImgSrc = undefined
372 this.remoteServerDown = false
373 this.currentTime = undefined
374
375 if (this.isVideoBlur(this.video)) {
376 const res = await this.confirmService.confirm(
377 $localize`This video contains mature or explicit content. Are you sure you want to watch it?`,
378 $localize`Mature or explicit content`
379 )
380 if (res === false) return this.location.back()
381 }
382
383 this.buildPlayer(urlOptions, loggedInOrAnonymousUser)
384 .catch(err => logger.error('Cannot build the player', err))
385
386 this.setOpenGraphTags()
387
388 const hookOptions = {
389 videojs,
390 video: this.video,
391 playlist: this.playlist
392 }
393 this.hooks.runAction('action:video-watch.video.loaded', 'video-watch', hookOptions)
394 }
395
396 private async buildPlayer (urlOptions: URLOptions, loggedInOrAnonymousUser: User) {
397 // Flush old player if needed
398 this.flushPlayer()
399
400 const videoState = this.video.state.id
401 if (videoState === VideoState.LIVE_ENDED || videoState === VideoState.WAITING_FOR_LIVE) {
402 this.playerPlaceholderImgSrc = this.video.previewPath
403 return
404 }
405
406 // Build video element, because videojs removes it on dispose
407 const playerElementWrapper = this.elementRef.nativeElement.querySelector('#videojs-wrapper')
408 this.playerElement = document.createElement('video')
409 this.playerElement.className = 'video-js vjs-peertube-skin'
410 this.playerElement.setAttribute('playsinline', 'true')
411 playerElementWrapper.appendChild(this.playerElement)
412
413 const params = {
414 video: this.video,
415 videoCaptions: this.videoCaptions,
416 liveVideo: this.liveVideo,
417 urlOptions,
418 loggedInOrAnonymousUser,
419 user: this.user
420 }
421 const { playerMode, playerOptions } = await this.hooks.wrapFun(
422 this.buildPlayerManagerOptions.bind(this),
423 params,
424 'video-watch',
425 'filter:internal.video-watch.player.build-options.params',
426 'filter:internal.video-watch.player.build-options.result'
427 )
428
429 this.zone.runOutsideAngular(async () => {
430 this.player = await PeertubePlayerManager.initialize(playerMode, playerOptions, player => this.player = player)
431
432 this.player.on('customError', (_e, data: any) => {
433 this.zone.run(() => this.handleGlobalError(data.err))
434 })
435
436 this.player.on('timeupdate', () => {
437 // Don't need to trigger angular change for this variable, that is sent to children components on click
438 this.currentTime = Math.floor(this.player.currentTime())
439 })
440
441 /**
442 * condition: true to make the upnext functionality trigger, false to disable the upnext functionality
443 * go to the next video in 'condition()' if you don't want of the timer.
444 * next: function triggered at the end of the timer.
445 * suspended: function used at each click of the timer checking if we need to reset progress
446 * and wait until suspended becomes truthy again.
447 */
448 this.player.upnext({
449 timeout: 5000, // 5s
450
451 headText: $localize`Up Next`,
452 cancelText: $localize`Cancel`,
453 suspendedText: $localize`Autoplay is suspended`,
454
455 getTitle: () => this.nextVideoTitle,
456
457 next: () => this.zone.run(() => this.playNextVideoInAngularZone()),
458 condition: () => {
459 if (!this.playlist) return this.isAutoPlayNext()
460
461 // Don't wait timeout to play the next playlist video
462 if (this.isPlaylistAutoPlayNext()) {
463 this.playNextVideoInAngularZone()
464 return undefined
465 }
466
467 return false
468 },
469
470 suspended: () => {
471 return (
472 !isXPercentInViewport(this.player.el() as HTMLElement, 80) ||
473 !document.getElementById('content').contains(document.activeElement)
474 )
475 }
476 })
477
478 this.player.one('stopped', () => {
479 if (this.playlist && this.isPlaylistAutoPlayNext()) {
480 this.playNextVideoInAngularZone()
481 }
482 })
483
484 this.player.one('ended', () => {
485 if (this.video.isLive) {
486 this.zone.run(() => this.video.state.id = VideoState.LIVE_ENDED)
487 }
488 })
489
490 this.player.on('theaterChange', (_: any, enabled: boolean) => {
491 this.zone.run(() => this.theaterEnabled = enabled)
492 })
493
494 this.hooks.runAction('action:video-watch.player.loaded', 'video-watch', {
495 player: this.player,
496 playlist: this.playlist,
497 playlistPosition: this.playlistPosition,
498 videojs,
499 video: this.video
500 })
501 })
502 }
503
504 private hasNextVideo () {
505 if (this.playlist) {
506 return this.videoWatchPlaylist.hasNextVideo()
507 }
508
509 return true
510 }
511
512 private playNextVideoInAngularZone () {
513 if (this.playlist) {
514 this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
515 return
516 }
517
518 if (this.nextVideoUUID) {
519 this.router.navigate([ '/w', this.nextVideoUUID ])
520 }
521 }
522
523 private isAutoplay () {
524 // We'll jump to the thread id, so do not play the video
525 if (this.route.snapshot.params['threadId']) return false
526
527 // Otherwise true by default
528 if (!this.user) return true
529
530 // Be sure the autoPlay is set to false
531 return this.user.autoPlayVideo !== false
532 }
533
534 private isAutoPlayNext () {
535 return (
536 (this.user?.autoPlayNextVideo) ||
537 this.anonymousUser.autoPlayNextVideo
538 )
539 }
540
541 private isPlaylistAutoPlayNext () {
542 return (
543 (this.user?.autoPlayNextVideoPlaylist) ||
544 this.anonymousUser.autoPlayNextVideoPlaylist
545 )
546 }
547
548 private flushPlayer () {
549 // Remove player if it exists
550 if (!this.player) return
551
552 try {
553 this.player.dispose()
554 this.player = undefined
555 } catch (err) {
556 logger.error('Cannot dispose player.', err)
557 }
558 }
559
560 private buildPlayerManagerOptions (params: {
561 video: VideoDetails
562 liveVideo: LiveVideo
563 videoCaptions: VideoCaption[]
564 urlOptions: CustomizationOptions & { playerMode: PlayerMode }
565 loggedInOrAnonymousUser: User
566 user?: AuthUser // Keep for plugins
567 }) {
568 const { video, liveVideo, videoCaptions, urlOptions, loggedInOrAnonymousUser } = params
569
570 const getStartTime = () => {
571 const byUrl = urlOptions.startTime !== undefined
572 const byHistory = video.userHistory && (!this.playlist || urlOptions.resume !== undefined)
573 const byLocalStorage = getStoredVideoWatchHistory(video.uuid)
574
575 if (byUrl) return timeToInt(urlOptions.startTime)
576 if (byHistory) return video.userHistory.currentTime
577 if (byLocalStorage) return byLocalStorage.duration
578
579 return 0
580 }
581
582 let startTime = getStartTime()
583
584 // If we are at the end of the video, reset the timer
585 if (video.duration - startTime <= 1) startTime = 0
586
587 const playerCaptions = videoCaptions.map(c => ({
588 label: c.language.label,
589 language: c.language.id,
590 src: environment.apiUrl + c.captionPath
591 }))
592
593 const liveOptions = video.isLive
594 ? { latencyMode: liveVideo.latencyMode }
595 : undefined
596
597 const options: PeertubePlayerManagerOptions = {
598 common: {
599 autoplay: this.isAutoplay(),
600 p2pEnabled: isP2PEnabled(video, this.serverConfig, loggedInOrAnonymousUser.p2pEnabled),
601
602 hasNextVideo: () => this.hasNextVideo(),
603 nextVideo: () => this.playNextVideoInAngularZone(),
604
605 playerElement: this.playerElement,
606 onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
607
608 videoDuration: video.duration,
609 enableHotkeys: true,
610 inactivityTimeout: 2500,
611 poster: video.previewUrl,
612
613 startTime,
614 stopTime: urlOptions.stopTime,
615 controlBar: urlOptions.controlBar,
616 controls: urlOptions.controls,
617 muted: urlOptions.muted,
618 loop: urlOptions.loop,
619 subtitle: urlOptions.subtitle,
620
621 peertubeLink: urlOptions.peertubeLink,
622
623 theaterButton: true,
624 captions: videoCaptions.length !== 0,
625
626 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
627 ? this.videoService.getVideoViewUrl(video.uuid)
628 : null,
629 authorizationHeader: this.authService.getRequestHeaderValue(),
630
631 embedUrl: video.embedUrl,
632 embedTitle: video.name,
633 instanceName: this.serverConfig.instance.name,
634
635 isLive: video.isLive,
636 liveOptions,
637
638 language: this.localeId,
639
640 serverUrl: environment.apiUrl,
641
642 videoCaptions: playerCaptions,
643
644 videoShortUUID: video.shortUUID,
645 videoUUID: video.uuid,
646
647 errorNotifier: (message: string) => this.notifier.error(message)
648 },
649
650 webtorrent: {
651 videoFiles: video.files
652 },
653
654 pluginsManager: this.pluginService.getPluginsManager()
655 }
656
657 // Only set this if we're in a playlist
658 if (this.playlist) {
659 options.common.hasPreviousVideo = () => this.videoWatchPlaylist.hasPreviousVideo()
660
661 options.common.previousVideo = () => {
662 this.zone.run(() => this.videoWatchPlaylist.navigateToPreviousPlaylistVideo())
663 }
664 }
665
666 let mode: PlayerMode
667
668 if (urlOptions.playerMode) {
669 if (urlOptions.playerMode === 'p2p-media-loader') mode = 'p2p-media-loader'
670 else mode = 'webtorrent'
671 } else {
672 if (video.hasHlsPlaylist()) mode = 'p2p-media-loader'
673 else mode = 'webtorrent'
674 }
675
676 // p2p-media-loader needs TextEncoder, fallback on WebTorrent if not available
677 if (typeof TextEncoder === 'undefined') {
678 mode = 'webtorrent'
679 }
680
681 if (mode === 'p2p-media-loader') {
682 const hlsPlaylist = video.getHlsPlaylist()
683
684 const p2pMediaLoader = {
685 playlistUrl: hlsPlaylist.playlistUrl,
686 segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
687 redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
688 trackerAnnounce: video.trackerUrls,
689 videoFiles: hlsPlaylist.files
690 } as P2PMediaLoaderOptions
691
692 Object.assign(options, { p2pMediaLoader })
693 }
694
695 return { playerMode: mode, playerOptions: options }
696 }
697
698 private async subscribeToLiveEventsIfNeeded (oldVideo: VideoDetails, newVideo: VideoDetails) {
699 if (!this.liveVideosSub) {
700 this.liveVideosSub = this.buildLiveEventsSubscription()
701 }
702
703 if (oldVideo && oldVideo.id !== newVideo.id) {
704 this.peertubeSocket.unsubscribeLiveVideos(oldVideo.id)
705 }
706
707 if (!newVideo.isLive) return
708
709 await this.peertubeSocket.subscribeToLiveVideosSocket(newVideo.id)
710 }
711
712 private buildLiveEventsSubscription () {
713 return this.peertubeSocket.getLiveVideosObservable()
714 .subscribe(({ type, payload }) => {
715 if (type === 'state-change') return this.handleLiveStateChange(payload.state)
716 if (type === 'views-change') return this.handleLiveViewsChange(payload.viewers)
717 })
718 }
719
720 private handleLiveStateChange (newState: VideoState) {
721 if (newState !== VideoState.PUBLISHED) return
722
723 logger.info('Loading video after live update.')
724
725 const videoUUID = this.video.uuid
726
727 // Reset to force refresh the video
728 this.video = undefined
729 this.loadVideo(videoUUID)
730 }
731
732 private handleLiveViewsChange (newViewers: number) {
733 if (!this.video) {
734 logger.error('Cannot update video live views because video is no defined.')
735 return
736 }
737
738 logger.info('Updating live views.')
739
740 this.video.viewers = newViewers
741 }
742
743 private initHotkeys () {
744 this.hotkeys = [
745 // These hotkeys are managed by the player
746 new Hotkey('f', e => e, undefined, $localize`Enter/exit fullscreen`),
747 new Hotkey('space', e => e, undefined, $localize`Play/Pause the video`),
748 new Hotkey('m', e => e, undefined, $localize`Mute/unmute the video`),
749
750 new Hotkey('0-9', e => e, undefined, $localize`Skip to a percentage of the video: 0 is 0% and 9 is 90%`),
751
752 new Hotkey('up', e => e, undefined, $localize`Increase the volume`),
753 new Hotkey('down', e => e, undefined, $localize`Decrease the volume`),
754
755 new Hotkey('right', e => e, undefined, $localize`Seek the video forward`),
756 new Hotkey('left', e => e, undefined, $localize`Seek the video backward`),
757
758 new Hotkey('>', e => e, undefined, $localize`Increase playback rate`),
759 new Hotkey('<', e => e, undefined, $localize`Decrease playback rate`),
760
761 new Hotkey(',', e => e, undefined, $localize`Navigate in the video to the previous frame`),
762 new Hotkey('.', e => e, undefined, $localize`Navigate in the video to the next frame`),
763
764 new Hotkey('t', e => {
765 this.theaterEnabled = !this.theaterEnabled
766 return false
767 }, undefined, $localize`Toggle theater mode`)
768 ]
769
770 if (this.isUserLoggedIn()) {
771 this.hotkeys = this.hotkeys.concat([
772 new Hotkey('shift+s', () => {
773 if (this.subscribeButton.isSubscribedToAll()) this.subscribeButton.unsubscribe()
774 else this.subscribeButton.subscribe()
775
776 return false
777 }, undefined, $localize`Subscribe to the account`)
778 ])
779 }
780
781 this.hotkeysService.add(this.hotkeys)
782 }
783
784 private setOpenGraphTags () {
785 this.metaService.setTitle(this.video.name)
786
787 this.metaService.setTag('og:type', 'video')
788
789 this.metaService.setTag('og:title', this.video.name)
790 this.metaService.setTag('name', this.video.name)
791
792 this.metaService.setTag('og:description', this.video.description)
793 this.metaService.setTag('description', this.video.description)
794
795 this.metaService.setTag('og:image', this.video.previewPath)
796
797 this.metaService.setTag('og:duration', this.video.duration.toString())
798
799 this.metaService.setTag('og:site_name', 'PeerTube')
800
801 this.metaService.setTag('og:url', window.location.href)
802 this.metaService.setTag('url', window.location.href)
803 }
804 }