Lazy load static objects
[oweals/peertube.git] / client / src / app / videos / +video-watch / video-watch.component.ts
1 import { catchError } from 'rxjs/operators'
2 import { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { RedirectService } from '@app/core/routing/redirect.service'
5 import { peertubeLocalStorage, peertubeSessionStorage } from '@app/shared/misc/peertube-web-storage'
6 import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component'
7 import { MetaService } from '@ngx-meta/core'
8 import { AuthUser, Notifier, ServerService } from '@app/core'
9 import { forkJoin, Observable, Subscription } from 'rxjs'
10 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
11 import { ServerConfig, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '../../../../../shared'
12 import { AuthService, ConfirmService } from '../../core'
13 import { RestExtractor, VideoBlacklistService } from '../../shared'
14 import { VideoDetails } from '../../shared/video/video-details.model'
15 import { VideoService } from '../../shared/video/video.service'
16 import { VideoShareComponent } from './modal/video-share.component'
17 import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component'
18 import { I18n } from '@ngx-translate/i18n-polyfill'
19 import { environment } from '../../../environments/environment'
20 import { VideoCaptionService } from '@app/shared/video-caption'
21 import { MarkdownService } from '@app/shared/renderer'
22 import {
23   videojs,
24   CustomizationOptions,
25   P2PMediaLoaderOptions,
26   PeertubePlayerManager,
27   PeertubePlayerManagerOptions,
28   PlayerMode
29 } from '../../../assets/player/peertube-player-manager'
30 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
31 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
32 import { Video } from '@app/shared/video/video.model'
33 import { isWebRTCDisabled, timeToInt } from '../../../assets/player/utils'
34 import { VideoWatchPlaylistComponent } from '@app/videos/+video-watch/video-watch-playlist.component'
35 import { getStoredTheater } from '../../../assets/player/peertube-player-local-storage'
36 import { PluginService } from '@app/core/plugins/plugin.service'
37 import { HooksService } from '@app/core/plugins/hooks.service'
38 import { PlatformLocation } from '@angular/common'
39 import { RecommendedVideosComponent } from '../recommendations/recommended-videos.component'
40 import { scrollToTop } from '@app/shared/misc/utils'
41
42 @Component({
43   selector: 'my-video-watch',
44   templateUrl: './video-watch.component.html',
45   styleUrls: [ './video-watch.component.scss' ]
46 })
47 export class VideoWatchComponent implements OnInit, OnDestroy {
48   private static LOCAL_STORAGE_PRIVACY_CONCERN_KEY = 'video-watch-privacy-concern'
49
50   @ViewChild('videoWatchPlaylist', { static: true }) videoWatchPlaylist: VideoWatchPlaylistComponent
51   @ViewChild('videoShareModal', { static: false }) videoShareModal: VideoShareComponent
52   @ViewChild('videoSupportModal', { static: false }) videoSupportModal: VideoSupportComponent
53   @ViewChild('subscribeButton', { static: false }) subscribeButton: SubscribeButtonComponent
54
55   player: any
56   playerElement: HTMLVideoElement
57   theaterEnabled = false
58   userRating: UserVideoRateType = null
59   descriptionLoading = false
60
61   video: VideoDetails = null
62   videoCaptions: VideoCaption[] = []
63
64   playlist: VideoPlaylist = null
65
66   completeDescriptionShown = false
67   completeVideoDescription: string
68   shortVideoDescription: string
69   videoHTMLDescription = ''
70   likesBarTooltipText = ''
71   hasAlreadyAcceptedPrivacyConcern = false
72   remoteServerDown = false
73   hotkeys: Hotkey[] = []
74
75   tooltipLike = ''
76   tooltipDislike = ''
77   tooltipSupport = ''
78   tooltipSaveToPlaylist = ''
79
80   private nextVideoUuid = ''
81   private nextVideoTitle = ''
82   private currentTime: number
83   private paramsSub: Subscription
84   private queryParamsSub: Subscription
85   private configSub: Subscription
86
87   private serverConfig: ServerConfig
88
89   constructor (
90     private elementRef: ElementRef,
91     private changeDetector: ChangeDetectorRef,
92     private route: ActivatedRoute,
93     private router: Router,
94     private videoService: VideoService,
95     private playlistService: VideoPlaylistService,
96     private videoBlacklistService: VideoBlacklistService,
97     private confirmService: ConfirmService,
98     private metaService: MetaService,
99     private authService: AuthService,
100     private serverService: ServerService,
101     private restExtractor: RestExtractor,
102     private notifier: Notifier,
103     private pluginService: PluginService,
104     private markdownService: MarkdownService,
105     private zone: NgZone,
106     private redirectService: RedirectService,
107     private videoCaptionService: VideoCaptionService,
108     private i18n: I18n,
109     private hotkeysService: HotkeysService,
110     private hooks: HooksService,
111     private location: PlatformLocation,
112     @Inject(LOCALE_ID) private localeId: string
113   ) {
114     this.tooltipLike = this.i18n('Like this video')
115     this.tooltipDislike = this.i18n('Dislike this video')
116     this.tooltipSupport = this.i18n('Support options for this video')
117     this.tooltipSaveToPlaylist = this.i18n('Save to playlist')
118   }
119
120   get user () {
121     return this.authService.getUser()
122   }
123
124   async ngOnInit () {
125     this.serverConfig = this.serverService.getTmpConfig()
126
127     this.configSub = this.serverService.getConfig()
128         .subscribe(config => {
129           this.serverConfig = config
130
131           if (
132             isWebRTCDisabled() ||
133             this.serverConfig.tracker.enabled === false ||
134             peertubeLocalStorage.getItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true'
135           ) {
136             this.hasAlreadyAcceptedPrivacyConcern = true
137           }
138         })
139
140     this.paramsSub = this.route.params.subscribe(routeParams => {
141       const videoId = routeParams[ 'videoId' ]
142       if (videoId) this.loadVideo(videoId)
143
144       const playlistId = routeParams[ 'playlistId' ]
145       if (playlistId) this.loadPlaylist(playlistId)
146     })
147
148     this.queryParamsSub = this.route.queryParams.subscribe(async queryParams => {
149       const videoId = queryParams[ 'videoId' ]
150       if (videoId) await this.loadVideo(videoId)
151
152       const start = queryParams[ 'start' ]
153       if (this.player && start) this.player.currentTime(parseInt(start, 10))
154     })
155
156     this.initHotkeys()
157
158     this.theaterEnabled = getStoredTheater()
159
160     this.hooks.runAction('action:video-watch.init', 'video-watch')
161   }
162
163   ngOnDestroy () {
164     this.flushPlayer()
165
166     // Unsubscribe subscriptions
167     if (this.paramsSub) this.paramsSub.unsubscribe()
168     if (this.queryParamsSub) this.queryParamsSub.unsubscribe()
169
170     // Unbind hotkeys
171     this.hotkeysService.remove(this.hotkeys)
172   }
173
174   setLike () {
175     if (this.isUserLoggedIn() === false) return
176
177     // Already liked this video
178     if (this.userRating === 'like') this.setRating('none')
179     else this.setRating('like')
180   }
181
182   setDislike () {
183     if (this.isUserLoggedIn() === false) return
184
185     // Already disliked this video
186     if (this.userRating === 'dislike') this.setRating('none')
187     else this.setRating('dislike')
188   }
189
190   getRatePopoverText () {
191     if (this.isUserLoggedIn()) return undefined
192
193     return this.i18n('You need to be connected to rate this content.')
194   }
195
196   showMoreDescription () {
197     if (this.completeVideoDescription === undefined) {
198       return this.loadCompleteDescription()
199     }
200
201     this.updateVideoDescription(this.completeVideoDescription)
202     this.completeDescriptionShown = true
203   }
204
205   showLessDescription () {
206     this.updateVideoDescription(this.shortVideoDescription)
207     this.completeDescriptionShown = false
208   }
209
210   loadCompleteDescription () {
211     this.descriptionLoading = true
212
213     this.videoService.loadCompleteDescription(this.video.descriptionPath)
214         .subscribe(
215           description => {
216             this.completeDescriptionShown = true
217             this.descriptionLoading = false
218
219             this.shortVideoDescription = this.video.description
220             this.completeVideoDescription = description
221
222             this.updateVideoDescription(this.completeVideoDescription)
223           },
224
225           error => {
226             this.descriptionLoading = false
227             this.notifier.error(error.message)
228           }
229         )
230   }
231
232   showSupportModal () {
233     this.pausePlayer()
234
235     this.videoSupportModal.show()
236   }
237
238   showShareModal () {
239     this.pausePlayer()
240
241     this.videoShareModal.show(this.currentTime)
242   }
243
244   isUserLoggedIn () {
245     return this.authService.isLoggedIn()
246   }
247
248   getVideoTags () {
249     if (!this.video || Array.isArray(this.video.tags) === false) return []
250
251     return this.video.tags
252   }
253
254   onRecommendations (videos: Video[]) {
255     if (videos.length > 0) {
256       // The recommended videos's first element should be the next video
257       const video = videos[0]
258       this.nextVideoUuid = video.uuid
259       this.nextVideoTitle = video.name
260     }
261   }
262
263   onModalOpened () {
264     this.pausePlayer()
265   }
266
267   onVideoRemoved () {
268     this.redirectService.redirectToHomepage()
269   }
270
271   acceptedPrivacyConcern () {
272     peertubeLocalStorage.setItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true')
273     this.hasAlreadyAcceptedPrivacyConcern = true
274   }
275
276   isVideoToTranscode () {
277     return this.video && this.video.state.id === VideoState.TO_TRANSCODE
278   }
279
280   isVideoToImport () {
281     return this.video && this.video.state.id === VideoState.TO_IMPORT
282   }
283
284   hasVideoScheduledPublication () {
285     return this.video && this.video.scheduledUpdate !== undefined
286   }
287
288   isVideoBlur (video: Video) {
289     return video.isVideoNSFWForUser(this.user, this.serverConfig)
290   }
291
292   isAutoPlayEnabled () {
293     return (
294       (this.user && this.user.autoPlayNextVideo) ||
295       peertubeSessionStorage.getItem(RecommendedVideosComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true'
296     )
297   }
298
299   handleTimestampClicked (timestamp: number) {
300     if (this.player) this.player.currentTime(timestamp)
301     scrollToTop()
302   }
303
304   isPlaylistAutoPlayEnabled () {
305     return (
306       (this.user && this.user.autoPlayNextVideoPlaylist) ||
307       peertubeSessionStorage.getItem(VideoWatchPlaylistComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) === 'true'
308     )
309   }
310
311   private loadVideo (videoId: string) {
312     // Video did not change
313     if (this.video && this.video.uuid === videoId) return
314
315     if (this.player) this.player.pause()
316
317     const videoObs = this.hooks.wrapObsFun(
318       this.videoService.getVideo.bind(this.videoService),
319       { videoId },
320       'video-watch',
321       'filter:api.video-watch.video.get.params',
322       'filter:api.video-watch.video.get.result'
323     )
324
325     // Video did change
326     forkJoin([
327       videoObs,
328       this.videoCaptionService.listCaptions(videoId)
329     ])
330       .pipe(
331         // If 401, the video is private or blacklisted so redirect to 404
332         catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
333       )
334       .subscribe(([ video, captionsResult ]) => {
335         const queryParams = this.route.snapshot.queryParams
336
337         const urlOptions = {
338           startTime: queryParams.start,
339           stopTime: queryParams.stop,
340
341           muted: queryParams.muted,
342           loop: queryParams.loop,
343           subtitle: queryParams.subtitle,
344
345           playerMode: queryParams.mode,
346           peertubeLink: false
347         }
348
349         this.onVideoFetched(video, captionsResult.data, urlOptions)
350             .catch(err => this.handleError(err))
351       })
352   }
353
354   private loadPlaylist (playlistId: string) {
355     // Playlist did not change
356     if (this.playlist && this.playlist.uuid === playlistId) return
357
358     this.playlistService.getVideoPlaylist(playlistId)
359       .pipe(
360         // If 401, the video is private or blacklisted so redirect to 404
361         catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
362       )
363       .subscribe(playlist => {
364         this.playlist = playlist
365
366         const videoId = this.route.snapshot.queryParams['videoId']
367         this.videoWatchPlaylist.loadPlaylistElements(playlist, !videoId)
368       })
369   }
370
371   private updateVideoDescription (description: string) {
372     this.video.description = description
373     this.setVideoDescriptionHTML()
374       .catch(err => console.error(err))
375   }
376
377   private async setVideoDescriptionHTML () {
378     const html = await this.markdownService.textMarkdownToHTML(this.video.description)
379     this.videoHTMLDescription = await this.markdownService.processVideoTimestamps(html)
380   }
381
382   private setVideoLikesBarTooltipText () {
383     this.likesBarTooltipText = this.i18n('{{likesNumber}} likes / {{dislikesNumber}} dislikes', {
384       likesNumber: this.video.likes,
385       dislikesNumber: this.video.dislikes
386     })
387   }
388
389   private handleError (err: any) {
390     const errorMessage: string = typeof err === 'string' ? err : err.message
391     if (!errorMessage) return
392
393     // Display a message in the video player instead of a notification
394     if (errorMessage.indexOf('from xs param') !== -1) {
395       this.flushPlayer()
396       this.remoteServerDown = true
397       this.changeDetector.detectChanges()
398
399       return
400     }
401
402     this.notifier.error(errorMessage)
403   }
404
405   private checkUserRating () {
406     // Unlogged users do not have ratings
407     if (this.isUserLoggedIn() === false) return
408
409     this.videoService.getUserVideoRating(this.video.id)
410         .subscribe(
411           ratingObject => {
412             if (ratingObject) {
413               this.userRating = ratingObject.rating
414             }
415           },
416
417           err => this.notifier.error(err.message)
418         )
419   }
420
421   private async onVideoFetched (
422     video: VideoDetails,
423     videoCaptions: VideoCaption[],
424     urlOptions: CustomizationOptions & { playerMode: PlayerMode }
425   ) {
426     this.video = video
427     this.videoCaptions = videoCaptions
428
429     // Re init attributes
430     this.descriptionLoading = false
431     this.completeDescriptionShown = false
432     this.remoteServerDown = false
433     this.currentTime = undefined
434
435     this.videoWatchPlaylist.updatePlaylistIndex(video)
436
437     if (this.isVideoBlur(this.video)) {
438       const res = await this.confirmService.confirm(
439         this.i18n('This video contains mature or explicit content. Are you sure you want to watch it?'),
440         this.i18n('Mature or explicit content')
441       )
442       if (res === false) return this.location.back()
443     }
444
445     // Flush old player if needed
446     this.flushPlayer()
447
448     // Build video element, because videojs removes it on dispose
449     const playerElementWrapper = this.elementRef.nativeElement.querySelector('#videojs-wrapper')
450     this.playerElement = document.createElement('video')
451     this.playerElement.className = 'video-js vjs-peertube-skin'
452     this.playerElement.setAttribute('playsinline', 'true')
453     playerElementWrapper.appendChild(this.playerElement)
454
455     const params = {
456       video: this.video,
457       videoCaptions,
458       urlOptions,
459       user: this.user
460     }
461     const { playerMode, playerOptions } = await this.hooks.wrapFun(
462       this.buildPlayerManagerOptions.bind(this),
463       params,
464       'video-watch',
465       'filter:internal.video-watch.player.build-options.params',
466       'filter:internal.video-watch.player.build-options.result'
467     )
468
469     this.zone.runOutsideAngular(async () => {
470       this.player = await PeertubePlayerManager.initialize(playerMode, playerOptions, player => this.player = player)
471       this.player.focus()
472
473       this.player.on('customError', ({ err }: { err: any }) => this.handleError(err))
474
475       this.player.on('timeupdate', () => {
476         this.currentTime = Math.floor(this.player.currentTime())
477       })
478
479       /**
480        * replaces this.player.one('ended')
481        * define 'condition(next)' to return true to wait, false to stop
482        */
483       this.player.upnext({
484         timeout: 10000, // 10s
485         headText: this.i18n('Up Next'),
486         cancelText: this.i18n('Cancel'),
487         getTitle: () => this.nextVideoTitle,
488         next: () => this.zone.run(() => this.autoplayNext()),
489         condition: () => {
490           if (this.playlist) {
491             if (this.isPlaylistAutoPlayEnabled()) {
492               // upnext will not trigger, and instead the next video will play immediately
493               this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
494             }
495           } else if (this.isAutoPlayEnabled()) {
496             return true // upnext will trigger
497           }
498           return false // upnext will not trigger, and instead leave the video stopping
499         }
500       })
501
502       this.player.one('stopped', () => {
503         if (this.playlist) {
504           if (this.isPlaylistAutoPlayEnabled()) this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
505         }
506       })
507
508       this.player.on('theaterChange', (_: any, enabled: boolean) => {
509         this.zone.run(() => this.theaterEnabled = enabled)
510       })
511
512       this.hooks.runAction('action:video-watch.player.loaded', 'video-watch', { player: this.player })
513     })
514
515     this.setVideoDescriptionHTML()
516     this.setVideoLikesBarTooltipText()
517
518     this.setOpenGraphTags()
519     this.checkUserRating()
520
521     this.hooks.runAction('action:video-watch.video.loaded', 'video-watch', { videojs })
522   }
523
524   private autoplayNext () {
525     if (this.nextVideoUuid) {
526       this.router.navigate([ '/videos/watch', this.nextVideoUuid ])
527     }
528   }
529
530   private setRating (nextRating: UserVideoRateType) {
531     const ratingMethods: { [id in UserVideoRateType]: (id: number) => Observable<any> } = {
532       like: this.videoService.setVideoLike,
533       dislike: this.videoService.setVideoDislike,
534       none: this.videoService.unsetVideoLike
535     }
536
537     ratingMethods[nextRating].call(this.videoService, this.video.id)
538           .subscribe(
539             () => {
540               // Update the video like attribute
541               this.updateVideoRating(this.userRating, nextRating)
542               this.userRating = nextRating
543             },
544
545             (err: { message: string }) => this.notifier.error(err.message)
546           )
547   }
548
549   private updateVideoRating (oldRating: UserVideoRateType, newRating: UserVideoRateType) {
550     let likesToIncrement = 0
551     let dislikesToIncrement = 0
552
553     if (oldRating) {
554       if (oldRating === 'like') likesToIncrement--
555       if (oldRating === 'dislike') dislikesToIncrement--
556     }
557
558     if (newRating === 'like') likesToIncrement++
559     if (newRating === 'dislike') dislikesToIncrement++
560
561     this.video.likes += likesToIncrement
562     this.video.dislikes += dislikesToIncrement
563
564     this.video.buildLikeAndDislikePercents()
565     this.setVideoLikesBarTooltipText()
566   }
567
568   private setOpenGraphTags () {
569     this.metaService.setTitle(this.video.name)
570
571     this.metaService.setTag('og:type', 'video')
572
573     this.metaService.setTag('og:title', this.video.name)
574     this.metaService.setTag('name', this.video.name)
575
576     this.metaService.setTag('og:description', this.video.description)
577     this.metaService.setTag('description', this.video.description)
578
579     this.metaService.setTag('og:image', this.video.previewPath)
580
581     this.metaService.setTag('og:duration', this.video.duration.toString())
582
583     this.metaService.setTag('og:site_name', 'PeerTube')
584
585     this.metaService.setTag('og:url', window.location.href)
586     this.metaService.setTag('url', window.location.href)
587   }
588
589   private isAutoplay () {
590     // We'll jump to the thread id, so do not play the video
591     if (this.route.snapshot.params['threadId']) return false
592
593     // Otherwise true by default
594     if (!this.user) return true
595
596     // Be sure the autoPlay is set to false
597     return this.user.autoPlayVideo !== false
598   }
599
600   private flushPlayer () {
601     // Remove player if it exists
602     if (this.player) {
603       try {
604         this.player.dispose()
605         this.player = undefined
606       } catch (err) {
607         console.error('Cannot dispose player.', err)
608       }
609     }
610   }
611
612   private buildPlayerManagerOptions (params: {
613     video: VideoDetails,
614     videoCaptions: VideoCaption[],
615     urlOptions: CustomizationOptions & { playerMode: PlayerMode },
616     user?: AuthUser
617   }) {
618     const { video, videoCaptions, urlOptions, user } = params
619     const getStartTime = () => {
620       const byUrl = urlOptions.startTime !== undefined
621       const byHistory = video.userHistory && !this.playlist
622
623       if (byUrl) {
624         return timeToInt(urlOptions.startTime)
625       } else if (byHistory) {
626         return video.userHistory.currentTime
627       } else {
628         return 0
629       }
630     }
631
632     let startTime = getStartTime()
633     // If we are at the end of the video, reset the timer
634     if (video.duration - startTime <= 1) startTime = 0
635
636     const playerCaptions = videoCaptions.map(c => ({
637       label: c.language.label,
638       language: c.language.id,
639       src: environment.apiUrl + c.captionPath
640     }))
641
642     const options: PeertubePlayerManagerOptions = {
643       common: {
644         autoplay: this.isAutoplay(),
645
646         playerElement: this.playerElement,
647         onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
648
649         videoDuration: video.duration,
650         enableHotkeys: true,
651         inactivityTimeout: 2500,
652         poster: video.previewUrl,
653
654         startTime,
655         stopTime: urlOptions.stopTime,
656         controls: urlOptions.controls,
657         muted: urlOptions.muted,
658         loop: urlOptions.loop,
659         subtitle: urlOptions.subtitle,
660
661         peertubeLink: urlOptions.peertubeLink,
662
663         theaterButton: true,
664         captions: videoCaptions.length !== 0,
665
666         videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
667           ? this.videoService.getVideoViewUrl(video.uuid)
668           : null,
669         embedUrl: video.embedUrl,
670
671         language: this.localeId,
672
673         userWatching: user && user.videosHistoryEnabled === true ? {
674           url: this.videoService.getUserWatchingVideoUrl(video.uuid),
675           authorizationHeader: this.authService.getRequestHeaderValue()
676         } : undefined,
677
678         serverUrl: environment.apiUrl,
679
680         videoCaptions: playerCaptions
681       },
682
683       webtorrent: {
684         videoFiles: video.files
685       }
686     }
687
688     let mode: PlayerMode
689
690     if (urlOptions.playerMode) {
691       if (urlOptions.playerMode === 'p2p-media-loader') mode = 'p2p-media-loader'
692       else mode = 'webtorrent'
693     } else {
694       if (video.hasHlsPlaylist()) mode = 'p2p-media-loader'
695       else mode = 'webtorrent'
696     }
697
698     if (mode === 'p2p-media-loader') {
699       const hlsPlaylist = video.getHlsPlaylist()
700
701       const p2pMediaLoader = {
702         playlistUrl: hlsPlaylist.playlistUrl,
703         segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
704         redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
705         trackerAnnounce: video.trackerUrls,
706         videoFiles: hlsPlaylist.files
707       } as P2PMediaLoaderOptions
708
709       Object.assign(options, { p2pMediaLoader })
710     }
711
712     return { playerMode: mode, playerOptions: options }
713   }
714
715   private pausePlayer () {
716     if (!this.player) return
717
718     this.player.pause()
719   }
720
721   private initHotkeys () {
722     this.hotkeys = [
723       // These hotkeys are managed by the player
724       new Hotkey('f', e => e, undefined, this.i18n('Enter/exit fullscreen (requires player focus)')),
725       new Hotkey('space', e => e, undefined, this.i18n('Play/Pause the video (requires player focus)')),
726       new Hotkey('m', e => e, undefined, this.i18n('Mute/unmute the video (requires player focus)')),
727
728       new Hotkey('0-9', e => e, undefined, this.i18n('Skip to a percentage of the video: 0 is 0% and 9 is 90% (requires player focus)')),
729
730       new Hotkey('up', e => e, undefined, this.i18n('Increase the volume (requires player focus)')),
731       new Hotkey('down', e => e, undefined, this.i18n('Decrease the volume (requires player focus)')),
732
733       new Hotkey('right', e => e, undefined, this.i18n('Seek the video forward (requires player focus)')),
734       new Hotkey('left', e => e, undefined, this.i18n('Seek the video backward (requires player focus)')),
735
736       new Hotkey('>', e => e, undefined, this.i18n('Increase playback rate (requires player focus)')),
737       new Hotkey('<', e => e, undefined, this.i18n('Decrease playback rate (requires player focus)')),
738
739       new Hotkey('.', e => e, undefined, this.i18n('Navigate in the video frame by frame (requires player focus)'))
740     ]
741
742     if (this.isUserLoggedIn()) {
743       this.hotkeys = this.hotkeys.concat([
744         new Hotkey('shift+l', () => {
745           this.setLike()
746           return false
747         }, undefined, this.i18n('Like the video')),
748
749         new Hotkey('shift+d', () => {
750           this.setDislike()
751           return false
752         }, undefined, this.i18n('Dislike the video')),
753
754         new Hotkey('shift+s', () => {
755           this.subscribeButton.subscribed ? this.subscribeButton.unsubscribe() : this.subscribeButton.subscribe()
756           return false
757         }, undefined, this.i18n('Subscribe to the account'))
758       ])
759     }
760
761     this.hotkeysService.add(this.hotkeys)
762   }
763 }