]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/video-watch.component.ts
Autoplay next recommended video (#2137)
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / video-watch.component.ts
CommitLineData
e972e046 1import { catchError } from 'rxjs/operators'
3b492bff 2import { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
df98563e 3import { ActivatedRoute, Router } from '@angular/router'
901637bb 4import { RedirectService } from '@app/core/routing/redirect.service'
0bd78bf3 5import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
07fa4c97 6import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component'
1f3e9fec 7import { MetaService } from '@ngx-meta/core'
f8b2c1b4 8import { Notifier, ServerService } from '@app/core'
4c72c1cd 9import { forkJoin, Observable, Subscription } from 'rxjs'
20d21199 10import { Hotkey, HotkeysService } from 'angular2-hotkeys'
72675ebe 11import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '../../../../../shared'
df98563e 12import { AuthService, ConfirmService } from '../../core'
a51bad1a 13import { RestExtractor, VideoBlacklistService } from '../../shared'
ff249f49 14import { VideoDetails } from '../../shared/video/video-details.model'
63c4db6d 15import { VideoService } from '../../shared/video/video.service'
4635f59d 16import { VideoShareComponent } from './modal/video-share.component'
20d21199 17import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component'
989e526a 18import { I18n } from '@ngx-translate/i18n-polyfill'
e945b184 19import { environment } from '../../../environments/environment'
16f7022b 20import { VideoCaptionService } from '@app/shared/video-caption'
1506307f 21import { MarkdownService } from '@app/shared/renderer'
6ec0b75b 22import {
5efab546 23 CustomizationOptions,
6ec0b75b
C
24 P2PMediaLoaderOptions,
25 PeertubePlayerManager,
26 PeertubePlayerManagerOptions,
597a9266 27 PlayerMode
6ec0b75b 28} from '../../../assets/player/peertube-player-manager'
e2f01c47
C
29import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
30import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
e2f01c47 31import { Video } from '@app/shared/video/video.model'
5efab546 32import { isWebRTCDisabled, timeToInt } from '../../../assets/player/utils'
72675ebe 33import { VideoWatchPlaylistComponent } from '@app/videos/+video-watch/video-watch-playlist.component'
011e1e6b 34import { getStoredTheater } from '../../../assets/player/peertube-player-local-storage'
18a6f04c 35import { PluginService } from '@app/core/plugins/plugin.service'
93cae479 36import { HooksService } from '@app/core/plugins/hooks.service'
60c2bc80 37import { PlatformLocation } from '@angular/common'
6aa54148 38import { randomInt } from '@shared/core-utils/miscs/miscs'
dc8bc31b 39
dc8bc31b
C
40@Component({
41 selector: 'my-video-watch',
ec8d8440
C
42 templateUrl: './video-watch.component.html',
43 styleUrls: [ './video-watch.component.scss' ]
dc8bc31b 44})
0629423c 45export class VideoWatchComponent implements OnInit, OnDestroy {
22b59e80
C
46 private static LOCAL_STORAGE_PRIVACY_CONCERN_KEY = 'video-watch-privacy-concern'
47
f36da21e
C
48 @ViewChild('videoWatchPlaylist', { static: true }) videoWatchPlaylist: VideoWatchPlaylistComponent
49 @ViewChild('videoShareModal', { static: false }) videoShareModal: VideoShareComponent
50 @ViewChild('videoSupportModal', { static: false }) videoSupportModal: VideoSupportComponent
51 @ViewChild('subscribeButton', { static: false }) subscribeButton: SubscribeButtonComponent
df98563e 52
2adfc7ea 53 player: any
0826c92d 54 playerElement: HTMLVideoElement
9a18a625 55 theaterEnabled = false
154898b0 56 userRating: UserVideoRateType = null
80958c78 57 descriptionLoading = false
2de96f4d 58
2f4c784a
C
59 video: VideoDetails = null
60 videoCaptions: VideoCaption[] = []
61
e2f01c47 62 playlist: VideoPlaylist = null
e2f01c47 63
2de96f4d
C
64 completeDescriptionShown = false
65 completeVideoDescription: string
66 shortVideoDescription: string
9d9597df 67 videoHTMLDescription = ''
e9189001 68 likesBarTooltipText = ''
73e09f27 69 hasAlreadyAcceptedPrivacyConcern = false
6d88de72 70 remoteServerDown = false
20d21199 71 hotkeys: Hotkey[]
df98563e 72
6aa54148 73 private nextVideoUuid = ''
f0a39880 74 private currentTime: number
df98563e 75 private paramsSub: Subscription
e2f01c47 76 private queryParamsSub: Subscription
31b6ddf8 77 private configSub: Subscription
df98563e
C
78
79 constructor (
4fd8aa32 80 private elementRef: ElementRef,
3b492bff 81 private changeDetector: ChangeDetectorRef,
0629423c 82 private route: ActivatedRoute,
92fb909c 83 private router: Router,
d3ef341a 84 private videoService: VideoService,
e2f01c47 85 private playlistService: VideoPlaylistService,
35bf0c83 86 private videoBlacklistService: VideoBlacklistService,
92fb909c 87 private confirmService: ConfirmService,
3ec343a4 88 private metaService: MetaService,
7ddd02c9 89 private authService: AuthService,
0883b324 90 private serverService: ServerService,
a51bad1a 91 private restExtractor: RestExtractor,
f8b2c1b4 92 private notifier: Notifier,
18a6f04c 93 private pluginService: PluginService,
7ae71355 94 private markdownService: MarkdownService,
901637bb 95 private zone: NgZone,
989e526a 96 private redirectService: RedirectService,
16f7022b 97 private videoCaptionService: VideoCaptionService,
e945b184 98 private i18n: I18n,
20d21199 99 private hotkeysService: HotkeysService,
93cae479 100 private hooks: HooksService,
60c2bc80 101 private location: PlatformLocation,
e945b184 102 @Inject(LOCALE_ID) private localeId: string
d3ef341a 103 ) {}
dc8bc31b 104
b2731bff
C
105 get user () {
106 return this.authService.getUser()
107 }
108
18a6f04c 109 async ngOnInit () {
31b6ddf8
C
110 this.configSub = this.serverService.configLoaded
111 .subscribe(() => {
112 if (
113 isWebRTCDisabled() ||
114 this.serverService.getConfig().tracker.enabled === false ||
115 peertubeLocalStorage.getItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true'
116 ) {
117 this.hasAlreadyAcceptedPrivacyConcern = true
118 }
119 })
2b3b76ab 120
13fc89f4 121 this.paramsSub = this.route.params.subscribe(routeParams => {
e2f01c47
C
122 const videoId = routeParams[ 'videoId' ]
123 if (videoId) this.loadVideo(videoId)
a51bad1a 124
e2f01c47
C
125 const playlistId = routeParams[ 'playlistId' ]
126 if (playlistId) this.loadPlaylist(playlistId)
127 })
bf079b7b 128
e2f01c47
C
129 this.queryParamsSub = this.route.queryParams.subscribe(queryParams => {
130 const videoId = queryParams[ 'videoId' ]
131 if (videoId) this.loadVideo(videoId)
df98563e 132 })
20d21199 133
1c8ddbfa 134 this.initHotkeys()
011e1e6b
C
135
136 this.theaterEnabled = getStoredTheater()
18a6f04c 137
c9e3eeed 138 this.hooks.runAction('action:video-watch.init', 'video-watch')
d1992b93
C
139 }
140
df98563e 141 ngOnDestroy () {
09edde40 142 this.flushPlayer()
067e3f84 143
13fc89f4 144 // Unsubscribe subscriptions
e2f01c47
C
145 if (this.paramsSub) this.paramsSub.unsubscribe()
146 if (this.queryParamsSub) this.queryParamsSub.unsubscribe()
20d21199
RK
147
148 // Unbind hotkeys
149 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
dc8bc31b 150 }
98b01bac 151
df98563e
C
152 setLike () {
153 if (this.isUserLoggedIn() === false) return
4c72c1cd
C
154
155 // Already liked this video
156 if (this.userRating === 'like') this.setRating('none')
157 else this.setRating('like')
d38b8281
C
158 }
159
df98563e
C
160 setDislike () {
161 if (this.isUserLoggedIn() === false) return
4c72c1cd
C
162
163 // Already disliked this video
164 if (this.userRating === 'dislike') this.setRating('none')
165 else this.setRating('dislike')
d38b8281
C
166 }
167
2de96f4d 168 showMoreDescription () {
2de96f4d
C
169 if (this.completeVideoDescription === undefined) {
170 return this.loadCompleteDescription()
171 }
172
173 this.updateVideoDescription(this.completeVideoDescription)
80958c78 174 this.completeDescriptionShown = true
2de96f4d
C
175 }
176
177 showLessDescription () {
2de96f4d 178 this.updateVideoDescription(this.shortVideoDescription)
80958c78 179 this.completeDescriptionShown = false
2de96f4d
C
180 }
181
182 loadCompleteDescription () {
80958c78
C
183 this.descriptionLoading = true
184
2de96f4d 185 this.videoService.loadCompleteDescription(this.video.descriptionPath)
2186386c
C
186 .subscribe(
187 description => {
188 this.completeDescriptionShown = true
189 this.descriptionLoading = false
190
191 this.shortVideoDescription = this.video.description
192 this.completeVideoDescription = description
193
194 this.updateVideoDescription(this.completeVideoDescription)
195 },
196
197 error => {
198 this.descriptionLoading = false
f8b2c1b4 199 this.notifier.error(error.message)
2186386c
C
200 }
201 )
2de96f4d
C
202 }
203
07fa4c97
C
204 showSupportModal () {
205 this.videoSupportModal.show()
206 }
207
df98563e 208 showShareModal () {
f0a39880 209 this.videoShareModal.show(this.currentTime)
99cc4f49
C
210 }
211
df98563e
C
212 isUserLoggedIn () {
213 return this.authService.isLoggedIn()
4f8c0eb0
C
214 }
215
b1fa3eba
C
216 getVideoTags () {
217 if (!this.video || Array.isArray(this.video.tags) === false) return []
218
4278710d 219 return this.video.tags
b1fa3eba
C
220 }
221
6aa54148
L
222 onRecommendations (videos: Video[]) {
223 if (videos.length > 0) {
224 // Pick a random video until the recommendations are improved
225 this.nextVideoUuid = videos[randomInt(0,videos.length - 1)].uuid
226 }
227 }
228
3a0fb65c
C
229 onVideoRemoved () {
230 this.redirectService.redirectToHomepage()
6725d05c
C
231 }
232
73e09f27 233 acceptedPrivacyConcern () {
0bd78bf3 234 peertubeLocalStorage.setItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true')
73e09f27
C
235 this.hasAlreadyAcceptedPrivacyConcern = true
236 }
237
2186386c
C
238 isVideoToTranscode () {
239 return this.video && this.video.state.id === VideoState.TO_TRANSCODE
240 }
241
516df59b
C
242 isVideoToImport () {
243 return this.video && this.video.state.id === VideoState.TO_IMPORT
244 }
245
bbe0f064
C
246 hasVideoScheduledPublication () {
247 return this.video && this.video.scheduledUpdate !== undefined
248 }
249
e2f01c47
C
250 isVideoBlur (video: Video) {
251 return video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
252 }
253
e2f01c47
C
254 private loadVideo (videoId: string) {
255 // Video did not change
256 if (this.video && this.video.uuid === videoId) return
257
258 if (this.player) this.player.pause()
259
93cae479
C
260 const videoObs = this.hooks.wrapObsFun(
261 this.videoService.getVideo.bind(this.videoService),
262 { videoId },
263 'video-watch',
264 'filter:api.video-watch.video.get.params',
265 'filter:api.video-watch.video.get.result'
266 )
267
e2f01c47 268 // Video did change
c8861d5d 269 forkJoin([
93cae479 270 videoObs,
e2f01c47 271 this.videoCaptionService.listCaptions(videoId)
c8861d5d 272 ])
e2f01c47
C
273 .pipe(
274 // If 401, the video is private or blacklisted so redirect to 404
275 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
276 )
277 .subscribe(([ video, captionsResult ]) => {
278 const queryParams = this.route.snapshot.queryParams
e2f01c47 279
4c72c1cd
C
280 const urlOptions = {
281 startTime: queryParams.start,
282 stopTime: queryParams.stop,
5efab546
C
283
284 muted: queryParams.muted,
285 loop: queryParams.loop,
4c72c1cd 286 subtitle: queryParams.subtitle,
5efab546
C
287
288 playerMode: queryParams.mode,
289 peertubeLink: false
4c72c1cd
C
290 }
291
292 this.onVideoFetched(video, captionsResult.data, urlOptions)
e2f01c47
C
293 .catch(err => this.handleError(err))
294 })
295 }
296
297 private loadPlaylist (playlistId: string) {
298 // Playlist did not change
299 if (this.playlist && this.playlist.uuid === playlistId) return
300
301 this.playlistService.getVideoPlaylist(playlistId)
302 .pipe(
303 // If 401, the video is private or blacklisted so redirect to 404
304 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
305 )
306 .subscribe(playlist => {
307 this.playlist = playlist
308
309 const videoId = this.route.snapshot.queryParams['videoId']
72675ebe 310 this.videoWatchPlaylist.loadPlaylistElements(playlist, !videoId)
e2f01c47
C
311 })
312 }
313
2de96f4d
C
314 private updateVideoDescription (description: string) {
315 this.video.description = description
316 this.setVideoDescriptionHTML()
4c72c1cd 317 .catch(err => console.error(err))
2de96f4d
C
318 }
319
41d71344
C
320 private async setVideoDescriptionHTML () {
321 this.videoHTMLDescription = await this.markdownService.textMarkdownToHTML(this.video.description)
2de96f4d
C
322 }
323
e9189001 324 private setVideoLikesBarTooltipText () {
2186386c
C
325 this.likesBarTooltipText = this.i18n('{{likesNumber}} likes / {{dislikesNumber}} dislikes', {
326 likesNumber: this.video.likes,
327 dislikesNumber: this.video.dislikes
328 })
e9189001
C
329 }
330
0c31c33d
C
331 private handleError (err: any) {
332 const errorMessage: string = typeof err === 'string' ? err : err.message
bf5685f0
C
333 if (!errorMessage) return
334
6d88de72 335 // Display a message in the video player instead of a notification
0f7fedc3 336 if (errorMessage.indexOf('from xs param') !== -1) {
6d88de72
C
337 this.flushPlayer()
338 this.remoteServerDown = true
3b492bff
C
339 this.changeDetector.detectChanges()
340
6d88de72 341 return
0c31c33d
C
342 }
343
f8b2c1b4 344 this.notifier.error(errorMessage)
0c31c33d
C
345 }
346
df98563e 347 private checkUserRating () {
d38b8281 348 // Unlogged users do not have ratings
df98563e 349 if (this.isUserLoggedIn() === false) return
d38b8281
C
350
351 this.videoService.getUserVideoRating(this.video.id)
2186386c
C
352 .subscribe(
353 ratingObject => {
354 if (ratingObject) {
355 this.userRating = ratingObject.rating
356 }
357 },
358
f8b2c1b4 359 err => this.notifier.error(err.message)
2186386c 360 )
d38b8281
C
361 }
362
597a9266
C
363 private async onVideoFetched (
364 video: VideoDetails,
365 videoCaptions: VideoCaption[],
5efab546 366 urlOptions: CustomizationOptions & { playerMode: PlayerMode }
597a9266 367 ) {
df98563e 368 this.video = video
2f4c784a 369 this.videoCaptions = videoCaptions
92fb909c 370
c448d412
C
371 // Re init attributes
372 this.descriptionLoading = false
373 this.completeDescriptionShown = false
6d88de72 374 this.remoteServerDown = false
f0a39880 375 this.currentTime = undefined
c448d412 376
72675ebe 377 this.videoWatchPlaylist.updatePlaylistIndex(video)
e2f01c47 378
5efab546 379 let startTime = timeToInt(urlOptions.startTime) || (this.video.userHistory ? this.video.userHistory.currentTime : 0)
43483d12 380 // If we are at the end of the video, reset the timer
6e46de09
C
381 if (this.video.duration - startTime <= 1) startTime = 0
382
e2f01c47 383 if (this.isVideoBlur(this.video)) {
22b59e80 384 const res = await this.confirmService.confirm(
989e526a
C
385 this.i18n('This video contains mature or explicit content. Are you sure you want to watch it?'),
386 this.i18n('Mature or explicit content')
d6e32a2e 387 )
60c2bc80 388 if (res === false) return this.location.back()
92fb909c
C
389 }
390
09edde40
C
391 // Flush old player if needed
392 this.flushPlayer()
b891f9bc 393
60c2bc80 394 // Build video element, because videojs removes it on dispose
e2f01c47 395 const playerElementWrapper = this.elementRef.nativeElement.querySelector('#videojs-wrapper')
b891f9bc
C
396 this.playerElement = document.createElement('video')
397 this.playerElement.className = 'video-js vjs-peertube-skin'
e7eb5b39 398 this.playerElement.setAttribute('playsinline', 'true')
b891f9bc
C
399 playerElementWrapper.appendChild(this.playerElement)
400
16f7022b
C
401 const playerCaptions = videoCaptions.map(c => ({
402 label: c.language.label,
403 language: c.language.id,
404 src: environment.apiUrl + c.captionPath
405 }))
406
6ec0b75b 407 const options: PeertubePlayerManagerOptions = {
2adfc7ea
C
408 common: {
409 autoplay: this.isAutoplay(),
6ec0b75b 410
2adfc7ea 411 playerElement: this.playerElement,
6ec0b75b
C
412 onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
413
2adfc7ea
C
414 videoDuration: this.video.duration,
415 enableHotkeys: true,
416 inactivityTimeout: 2500,
417 poster: this.video.previewUrl,
5efab546 418
2adfc7ea 419 startTime,
f0a39880 420 stopTime: urlOptions.stopTime,
5efab546
C
421 controls: urlOptions.controls,
422 muted: urlOptions.muted,
423 loop: urlOptions.loop,
424 subtitle: urlOptions.subtitle,
425
426 peertubeLink: urlOptions.peertubeLink,
2adfc7ea
C
427
428 theaterMode: true,
429 captions: videoCaptions.length !== 0,
2adfc7ea 430
4c72c1cd
C
431 videoViewUrl: this.video.privacy.id !== VideoPrivacy.PRIVATE
432 ? this.videoService.getVideoViewUrl(this.video.uuid)
433 : null,
2adfc7ea
C
434 embedUrl: this.video.embedUrl,
435
436 language: this.localeId,
437
2adfc7ea
C
438 userWatching: this.user && this.user.videosHistoryEnabled === true ? {
439 url: this.videoService.getUserWatchingVideoUrl(this.video.uuid),
440 authorizationHeader: this.authService.getRequestHeaderValue()
441 } : undefined,
aa8b6df4 442
2adfc7ea
C
443 serverUrl: environment.apiUrl,
444
445 videoCaptions: playerCaptions
6ec0b75b
C
446 },
447
448 webtorrent: {
449 videoFiles: this.video.files
09209296 450 }
e945b184
C
451 }
452
65659166
C
453 let mode: PlayerMode
454
455 if (urlOptions.playerMode) {
456 if (urlOptions.playerMode === 'p2p-media-loader') mode = 'p2p-media-loader'
457 else mode = 'webtorrent'
458 } else {
459 if (this.video.hasHlsPlaylist()) mode = 'p2p-media-loader'
460 else mode = 'webtorrent'
461 }
597a9266
C
462
463 if (mode === 'p2p-media-loader') {
464 const hlsPlaylist = this.video.getHlsPlaylist()
e945b184 465
09209296
C
466 const p2pMediaLoader = {
467 playlistUrl: hlsPlaylist.playlistUrl,
468 segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
469 redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
470 trackerAnnounce: this.video.trackerUrls,
2adfc7ea 471 videoFiles: this.video.files
09209296
C
472 } as P2PMediaLoaderOptions
473
474 Object.assign(options, { p2pMediaLoader })
e945b184
C
475 }
476
e945b184 477 this.zone.runOutsideAngular(async () => {
bfbd9128 478 this.player = await PeertubePlayerManager.initialize(mode, options, player => this.player = player)
9a18a625 479
2adfc7ea 480 this.player.on('customError', ({ err }: { err: any }) => this.handleError(err))
f0a39880
C
481
482 this.player.on('timeupdate', () => {
483 this.currentTime = Math.floor(this.player.currentTime())
484 })
e2f01c47
C
485
486 this.player.one('ended', () => {
487 if (this.playlist) {
72675ebe 488 this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
6aa54148
L
489 } else if (this.user && this.user.autoPlayNextVideo) {
490 this.zone.run(() => this.autoplayNext())
e2f01c47
C
491 }
492 })
493
494 this.player.one('stopped', () => {
495 if (this.playlist) {
72675ebe 496 this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
e2f01c47
C
497 }
498 })
9a18a625
C
499
500 this.player.on('theaterChange', (_: any, enabled: boolean) => {
501 this.zone.run(() => this.theaterEnabled = enabled)
502 })
b891f9bc 503 })
22b59e80
C
504
505 this.setVideoDescriptionHTML()
506 this.setVideoLikesBarTooltipText()
507
508 this.setOpenGraphTags()
509 this.checkUserRating()
93cae479 510
c9e3eeed 511 this.hooks.runAction('action:video-watch.video.loaded', 'video-watch')
92fb909c
C
512 }
513
6aa54148
L
514 private autoplayNext () {
515 if (this.nextVideoUuid) {
516 this.router.navigate([ '/videos/watch', this.nextVideoUuid ])
517 }
518 }
519
5c6d985f 520 private setRating (nextRating: UserVideoRateType) {
4c72c1cd
C
521 const ratingMethods: { [id in UserVideoRateType]: (id: number) => Observable<any> } = {
522 like: this.videoService.setVideoLike,
523 dislike: this.videoService.setVideoDislike,
524 none: this.videoService.unsetVideoLike
57a49263
BB
525 }
526
4c72c1cd 527 ratingMethods[nextRating].call(this.videoService, this.video.id)
2186386c
C
528 .subscribe(
529 () => {
530 // Update the video like attribute
531 this.updateVideoRating(this.userRating, nextRating)
532 this.userRating = nextRating
533 },
534
f8b2c1b4 535 (err: { message: string }) => this.notifier.error(err.message)
2186386c 536 )
57a49263
BB
537 }
538
5c6d985f 539 private updateVideoRating (oldRating: UserVideoRateType, newRating: UserVideoRateType) {
df98563e
C
540 let likesToIncrement = 0
541 let dislikesToIncrement = 0
d38b8281
C
542
543 if (oldRating) {
df98563e
C
544 if (oldRating === 'like') likesToIncrement--
545 if (oldRating === 'dislike') dislikesToIncrement--
d38b8281
C
546 }
547
df98563e
C
548 if (newRating === 'like') likesToIncrement++
549 if (newRating === 'dislike') dislikesToIncrement++
d38b8281 550
df98563e
C
551 this.video.likes += likesToIncrement
552 this.video.dislikes += dislikesToIncrement
20b40b19 553
22b59e80 554 this.video.buildLikeAndDislikePercents()
20b40b19 555 this.setVideoLikesBarTooltipText()
d38b8281
C
556 }
557
df98563e
C
558 private setOpenGraphTags () {
559 this.metaService.setTitle(this.video.name)
758b996d 560
df98563e 561 this.metaService.setTag('og:type', 'video')
3ec343a4 562
df98563e
C
563 this.metaService.setTag('og:title', this.video.name)
564 this.metaService.setTag('name', this.video.name)
3ec343a4 565
df98563e
C
566 this.metaService.setTag('og:description', this.video.description)
567 this.metaService.setTag('description', this.video.description)
3ec343a4 568
d38309c3 569 this.metaService.setTag('og:image', this.video.previewPath)
3ec343a4 570
df98563e 571 this.metaService.setTag('og:duration', this.video.duration.toString())
3ec343a4 572
df98563e 573 this.metaService.setTag('og:site_name', 'PeerTube')
3ec343a4 574
df98563e
C
575 this.metaService.setTag('og:url', window.location.href)
576 this.metaService.setTag('url', window.location.href)
3ec343a4 577 }
1f3e9fec 578
d4c6a3b9 579 private isAutoplay () {
bf079b7b
C
580 // We'll jump to the thread id, so do not play the video
581 if (this.route.snapshot.params['threadId']) return false
582
583 // Otherwise true by default
d4c6a3b9
C
584 if (!this.user) return true
585
586 // Be sure the autoPlay is set to false
587 return this.user.autoPlayVideo !== false
588 }
09edde40
C
589
590 private flushPlayer () {
591 // Remove player if it exists
592 if (this.player) {
536598cf
C
593 try {
594 this.player.dispose()
595 this.player = undefined
596 } catch (err) {
597 console.error('Cannot dispose player.', err)
598 }
09edde40
C
599 }
600 }
1c8ddbfa
C
601
602 private initHotkeys () {
603 this.hotkeys = [
4c72c1cd 604 new Hotkey('shift+l', () => {
1c8ddbfa
C
605 this.setLike()
606 return false
607 }, undefined, this.i18n('Like the video')),
4c72c1cd
C
608
609 new Hotkey('shift+d', () => {
1c8ddbfa
C
610 this.setDislike()
611 return false
612 }, undefined, this.i18n('Dislike the video')),
4c72c1cd
C
613
614 new Hotkey('shift+s', () => {
615 this.subscribeButton.subscribed ? this.subscribeButton.unsubscribe() : this.subscribeButton.subscribe()
1c8ddbfa
C
616 return false
617 }, undefined, this.i18n('Subscribe to the account'))
618 ]
619 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
620 }
dc8bc31b 621}