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