1
0
Fork 0
peertube/client/src/app/videos/+video-watch/video-watch.component.ts

484 lines
15 KiB
TypeScript
Raw Normal View History

2018-05-31 09:35:01 +00:00
import { catchError } from 'rxjs/operators'
2018-06-06 12:23:40 +00:00
import { Component, ElementRef, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild, Inject } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
2018-03-01 12:57:29 +00:00
import { RedirectService } from '@app/core/routing/redirect.service'
import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
2018-02-20 15:13:05 +00:00
import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component'
2017-11-30 08:21:11 +00:00
import { MetaService } from '@ngx-meta/core'
import { NotificationsService } from 'angular2-notifications'
2018-05-15 09:55:51 +00:00
import { Subscription } from 'rxjs'
2017-12-11 16:36:46 +00:00
import * as videojs from 'video.js'
import 'videojs-hotkeys'
2018-03-19 16:16:34 +00:00
import * as WebTorrent from 'webtorrent'
2018-04-17 08:35:08 +00:00
import { UserVideoRateType, VideoRateType } from '../../../../../shared'
import '../../../assets/player/peertube-videojs-plugin'
import { AuthService, ConfirmService } from '../../core'
2018-05-31 09:35:01 +00:00
import { RestExtractor, VideoBlacklistService } from '../../shared'
2017-12-07 10:15:19 +00:00
import { VideoDetails } from '../../shared/video/video-details.model'
2017-12-06 16:15:59 +00:00
import { Video } from '../../shared/video/video.model'
2017-12-11 16:36:46 +00:00
import { VideoService } from '../../shared/video/video.service'
2017-12-01 17:56:26 +00:00
import { MarkdownService } from '../shared'
2017-12-27 15:11:53 +00:00
import { VideoDownloadComponent } from './modal/video-download.component'
import { VideoReportComponent } from './modal/video-report.component'
import { VideoShareComponent } from './modal/video-share.component'
2018-06-06 12:23:40 +00:00
import { getVideojsOptions, loadLocale, addContextMenu } from '../../../assets/player/peertube-player'
import { ServerService } from '@app/core'
2018-05-31 16:12:15 +00:00
import { I18n } from '@ngx-translate/i18n-polyfill'
2018-06-06 12:23:40 +00:00
import { environment } from '../../../environments/environment'
2018-06-06 15:37:13 +00:00
import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
2016-03-14 12:50:19 +00:00
@Component({
selector: 'my-video-watch',
templateUrl: './video-watch.component.html',
styleUrls: [ './video-watch.component.scss' ]
2016-03-14 12:50:19 +00:00
})
2016-07-08 15:15:14 +00:00
export class VideoWatchComponent implements OnInit, OnDestroy {
private static LOCAL_STORAGE_PRIVACY_CONCERN_KEY = 'video-watch-privacy-concern'
@ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
@ViewChild('videoShareModal') videoShareModal: VideoShareComponent
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent
2018-02-20 15:13:05 +00:00
@ViewChild('videoSupportModal') videoSupportModal: VideoSupportComponent
otherVideosDisplayed: Video[] = []
2017-12-06 16:15:59 +00:00
player: videojs.Player
2017-12-20 08:57:00 +00:00
playerElement: HTMLVideoElement
2017-06-17 09:28:11 +00:00
userRating: UserVideoRateType = null
2017-10-25 14:43:19 +00:00
video: VideoDetails = null
descriptionLoading = false
completeDescriptionShown = false
completeVideoDescription: string
shortVideoDescription: string
videoHTMLDescription = ''
2017-12-21 09:49:52 +00:00
likesBarTooltipText = ''
hasAlreadyAcceptedPrivacyConcern = false
2018-06-06 12:23:40 +00:00
private videojsLocaleLoaded = false
2018-01-08 09:46:41 +00:00
private otherVideos: Video[] = []
private paramsSub: Subscription
constructor (
2016-05-27 15:49:18 +00:00
private elementRef: ElementRef,
2016-07-08 15:15:14 +00:00
private route: ActivatedRoute,
2017-04-04 19:37:03 +00:00
private router: Router,
2016-05-31 20:39:36 +00:00
private videoService: VideoService,
2017-10-10 08:02:18 +00:00
private videoBlacklistService: VideoBlacklistService,
2017-04-04 19:37:03 +00:00
private confirmService: ConfirmService,
2016-11-04 16:37:44 +00:00
private metaService: MetaService,
private authService: AuthService,
private serverService: ServerService,
2018-05-31 09:35:01 +00:00
private restExtractor: RestExtractor,
private notificationsService: NotificationsService,
2018-01-10 16:36:35 +00:00
private markdownService: MarkdownService,
2018-03-01 12:57:29 +00:00
private zone: NgZone,
2018-05-31 16:12:15 +00:00
private redirectService: RedirectService,
2018-06-06 12:23:40 +00:00
private i18n: I18n,
@Inject(LOCALE_ID) private localeId: string
2016-05-31 20:39:36 +00:00
) {}
2016-03-14 12:50:19 +00:00
2017-12-12 13:41:59 +00:00
get user () {
return this.authService.getUser()
}
ngOnInit () {
if (
WebTorrent.WEBRTC_SUPPORT === false ||
peertubeLocalStorage.getItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true'
) {
this.hasAlreadyAcceptedPrivacyConcern = true
}
2017-12-06 16:15:59 +00:00
this.videoService.getVideos({ currentPage: 1, itemsPerPage: 5 }, '-createdAt')
.subscribe(
data => {
this.otherVideos = data.videos
this.updateOtherVideosDisplayed()
},
err => console.error(err)
2017-12-06 16:15:59 +00:00
)
this.paramsSub = this.route.params.subscribe(routeParams => {
2018-04-03 16:06:58 +00:00
if (this.player) {
2017-12-11 10:20:54 +00:00
this.player.pause()
}
2018-02-19 09:38:24 +00:00
const uuid = routeParams['uuid']
2018-05-31 09:35:01 +00:00
// Video did not change
2018-02-19 09:38:24 +00:00
if (this.video && this.video.uuid === uuid) return
// Video did change
2018-05-31 09:35:01 +00:00
this.videoService
.getVideo(uuid)
.pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])))
.subscribe(
video => {
const startTime = this.route.snapshot.queryParams.start
this.onVideoFetched(video, startTime)
.catch(err => this.handleError(err))
}
)
})
}
ngOnDestroy () {
2018-04-03 16:06:58 +00:00
this.flushPlayer()
2016-11-08 20:17:17 +00:00
// Unsubscribe subscriptions
this.paramsSub.unsubscribe()
2016-03-14 12:50:19 +00:00
}
2016-03-14 21:16:43 +00:00
setLike () {
if (this.isUserLoggedIn() === false) return
if (this.userRating === 'like') {
// Already liked this video
this.setRating('none')
} else {
this.setRating('like')
}
2017-03-08 20:35:43 +00:00
}
setDislike () {
if (this.isUserLoggedIn() === false) return
if (this.userRating === 'dislike') {
// Already disliked this video
this.setRating('none')
} else {
this.setRating('dislike')
}
2017-03-08 20:35:43 +00:00
}
async blacklistVideo (event: Event) {
event.preventDefault()
2017-04-26 19:42:36 +00:00
2018-05-31 16:12:15 +00:00
const res = await this.confirmService.confirm(this.i18n('Do you really want to blacklist this video?'), this.i18n('Blacklist'))
if (res === false) return
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
this.videoBlacklistService.blacklistVideo(this.video.id)
.subscribe(
status => {
2018-05-31 16:12:15 +00:00
this.notificationsService.success(
this.i18n('Success'),
2018-06-05 07:13:26 +00:00
this.i18n('Video {{videoName}} had been blacklisted.', { videoName: this.video.name })
2018-05-31 16:12:15 +00:00
)
2018-03-01 12:57:29 +00:00
this.redirectService.redirectToHomepage()
},
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
2018-05-31 16:12:15 +00:00
error => this.notificationsService.error(this.i18n('Error'), error.message)
)
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
showMoreDescription () {
if (this.completeVideoDescription === undefined) {
return this.loadCompleteDescription()
}
this.updateVideoDescription(this.completeVideoDescription)
this.completeDescriptionShown = true
}
showLessDescription () {
this.updateVideoDescription(this.shortVideoDescription)
this.completeDescriptionShown = false
}
loadCompleteDescription () {
this.descriptionLoading = true
this.videoService.loadCompleteDescription(this.video.descriptionPath)
.subscribe(
description => {
this.completeDescriptionShown = true
this.descriptionLoading = false
this.shortVideoDescription = this.video.description
this.completeVideoDescription = description
this.updateVideoDescription(this.completeVideoDescription)
},
error => {
this.descriptionLoading = false
2018-05-31 16:12:15 +00:00
this.notificationsService.error(this.i18n('Error'), error.message)
}
)
}
showReportModal (event: Event) {
event.preventDefault()
this.videoReportModal.show()
2017-01-20 18:22:15 +00:00
}
2018-02-20 15:13:05 +00:00
showSupportModal () {
this.videoSupportModal.show()
}
showShareModal () {
this.videoShareModal.show()
2016-11-08 20:11:57 +00:00
}
showDownloadModal (event: Event) {
event.preventDefault()
this.videoDownloadModal.show()
2016-11-08 20:11:57 +00:00
}
isUserLoggedIn () {
return this.authService.isLoggedIn()
2017-01-20 18:22:15 +00:00
}
2017-12-27 15:11:53 +00:00
isVideoUpdatable () {
return this.video.isUpdatableBy(this.authService.getUser())
}
isVideoBlacklistable () {
2017-12-12 13:41:59 +00:00
return this.video.isBlackistableBy(this.user)
Add ability for an administrator to remove any video (#61) * Add ability for an admin to remove every video on the pod. * Server: add BlacklistedVideos relation. * Server: Insert in BlacklistedVideos relation upon deletion of a video. * Server: Modify BlacklistedVideos schema to add Pod id information. * Server: Moving insertion of a blacklisted video from the `afterDestroy` hook into the process of deletion of a video. To avoid inserting a video when it is removed on its origin pod. When a video is removed on its origin pod, the `afterDestroy` hook is fire, but no request is made on the delete('/:videoId') interface. Hence, we insert into `BlacklistedVideos` only on request on delete('/:videoId') (if requirements for insertion are met). * Server: Add removeVideoFromBlacklist hook on deletion of a video. We are going to proceed in another way :). We will add a new route : /:videoId/blacklist to blacklist a video. We do not blacklist a video upon its deletion now (to distinguish a video blacklist from a regular video delete) When we blacklist a video, the video remains in the DB, so we don't have any concern about its update. It just doesn't appear in the video list. When we remove a video, we then have to remove it from the blacklist too. We could also remove a video from the blacklist to 'unremove' it and make it appear again in the video list (will be another feature). * Server: Add handler for new route post(/:videoId/blacklist) * Client: Add isBlacklistable method * Client: Update isRemovableBy method. * Client: Move 'Delete video' feature from the video-list to the video-watch module. * Server: Exclude blacklisted videos from the video list * Server: Use findAll() in BlacklistedVideos.list() method * Server: Fix addVideoToBlacklist function. * Client: Add blacklist feature. * Server: Use JavaScript Standard Style. * Server: In checkUserCanDeleteVideo, move the callback call inside the db callback function * Server: Modify BlacklistVideo relation * Server: Modifiy Videos methods. * Server: Add checkVideoIsBlacklistable method * Server: Rewrite addVideoToBlacklist method * Server: Fix checkVideoIsBlacklistable method * Server: Add return to addVideoToBlacklist method
2017-04-26 19:22:10 +00:00
}
getVideoPoster () {
if (!this.video) return ''
return this.video.previewUrl
}
2017-12-06 16:15:59 +00:00
getVideoTags () {
if (!this.video || Array.isArray(this.video.tags) === false) return []
return this.video.tags.join(', ')
}
isVideoRemovable () {
return this.video.isRemovableBy(this.authService.getUser())
}
async removeVideo (event: Event) {
event.preventDefault()
2018-05-31 16:12:15 +00:00
const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this video?'), this.i18n('Delete'))
if (res === false) return
this.videoService.removeVideo(this.video.id)
.subscribe(
status => {
2018-05-31 16:12:15 +00:00
this.notificationsService.success(
this.i18n('Success'),
2018-06-05 07:13:26 +00:00
this.i18n('Video {{videoName}} deleted.', { videoName: this.video.name })
2018-05-31 16:12:15 +00:00
)
// Go back to the video-list.
2018-03-01 12:57:29 +00:00
this.redirectService.redirectToHomepage()
},
2018-05-31 16:12:15 +00:00
error => this.notificationsService.error(this.i18n('Error'), error.message)
2017-12-21 09:49:52 +00:00
)
}
acceptedPrivacyConcern () {
peertubeLocalStorage.setItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true')
this.hasAlreadyAcceptedPrivacyConcern = true
}
private updateVideoDescription (description: string) {
this.video.description = description
this.setVideoDescriptionHTML()
}
private setVideoDescriptionHTML () {
2017-12-08 07:39:15 +00:00
if (!this.video.description) {
this.videoHTMLDescription = ''
return
}
2018-02-20 15:13:05 +00:00
this.videoHTMLDescription = this.markdownService.textMarkdownToHTML(this.video.description)
}
2017-12-21 09:49:52 +00:00
private setVideoLikesBarTooltipText () {
2018-05-31 16:12:15 +00:00
this.likesBarTooltipText = this.i18n(
2018-06-05 07:13:26 +00:00
'{{likesNumber}} likes / {{dislikesNumber}} dislikes',
{ likesNumber: this.video.likes, dislikesNumber: this.video.dislikes }
2018-05-31 16:12:15 +00:00
)
2017-12-21 09:49:52 +00:00
}
2017-07-23 09:07:30 +00:00
private handleError (err: any) {
const errorMessage: string = typeof err === 'string' ? err : err.message
2018-02-26 08:55:23 +00:00
if (!errorMessage) return
2017-07-23 09:07:30 +00:00
let message = ''
if (errorMessage.indexOf('http error') !== -1) {
2018-05-31 16:12:15 +00:00
message = this.i18n('Cannot fetch video from server, maybe down.')
2017-07-23 09:07:30 +00:00
} else {
message = errorMessage
}
2018-05-31 16:12:15 +00:00
this.notificationsService.error(this.i18n('Error'), message)
2017-07-23 09:07:30 +00:00
}
private checkUserRating () {
2017-03-08 20:35:43 +00:00
// Unlogged users do not have ratings
if (this.isUserLoggedIn() === false) return
2017-03-08 20:35:43 +00:00
this.videoService.getUserVideoRating(this.video.id)
.subscribe(
2017-06-20 18:20:09 +00:00
ratingObject => {
2017-03-08 20:35:43 +00:00
if (ratingObject) {
this.userRating = ratingObject.rating
2017-03-08 20:35:43 +00:00
}
},
2018-05-31 16:12:15 +00:00
err => this.notificationsService.error(this.i18n('Error'), err.message)
)
2017-03-08 20:35:43 +00:00
}
2018-04-05 15:06:59 +00:00
private async onVideoFetched (video: VideoDetails, startTime = 0) {
this.video = video
2017-04-04 19:37:03 +00:00
// Re init attributes
this.descriptionLoading = false
this.completeDescriptionShown = false
this.updateOtherVideosDisplayed()
if (this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())) {
const res = await this.confirmService.confirm(
2018-05-31 16:12:15 +00:00
this.i18n('This video contains mature or explicit content. Are you sure you want to watch it?'),
this.i18n('Mature or explicit content')
)
2018-03-01 12:57:29 +00:00
if (res === false) return this.redirectService.redirectToHomepage()
2017-04-04 19:37:03 +00:00
}
2018-04-03 16:06:58 +00:00
// Flush old player if needed
this.flushPlayer()
2018-04-03 15:33:39 +00:00
// Build video element, because videojs remove it on dispose
const playerElementWrapper = this.elementRef.nativeElement.querySelector('#video-element-wrapper')
this.playerElement = document.createElement('video')
this.playerElement.className = 'video-js vjs-peertube-skin'
2018-05-22 07:16:05 +00:00
this.playerElement.setAttribute('playsinline', 'true')
2018-04-03 15:33:39 +00:00
playerElementWrapper.appendChild(this.playerElement)
const videojsOptions = getVideojsOptions({
autoplay: this.isAutoplay(),
2018-04-03 16:06:58 +00:00
inactivityTimeout: 2500,
2018-04-03 15:33:39 +00:00
videoFiles: this.video.files,
playerElement: this.playerElement,
videoViewUrl: this.videoService.getVideoViewUrl(this.video.uuid),
videoDuration: this.video.duration,
enableHotkeys: true,
peertubeLink: false,
2018-04-05 15:06:59 +00:00
poster: this.video.previewUrl,
2018-06-11 14:49:56 +00:00
startTime,
theaterMode: true
2018-04-03 15:33:39 +00:00
})
2018-06-06 12:23:40 +00:00
if (this.videojsLocaleLoaded === false) {
2018-06-06 15:37:13 +00:00
await loadLocale(environment.apiUrl, videojs, isOnDevLocale() ? getDevLocale() : this.localeId)
2018-06-06 12:23:40 +00:00
this.videojsLocaleLoaded = true
}
2018-04-03 15:33:39 +00:00
const self = this
2018-06-06 12:23:40 +00:00
this.zone.runOutsideAngular(async () => {
2018-04-03 16:06:58 +00:00
videojs(this.playerElement, videojsOptions, function () {
2018-04-03 15:33:39 +00:00
self.player = this
this.on('customError', (event, data) => self.handleError(data.err))
2018-06-06 12:23:40 +00:00
addContextMenu(self.player, self.video.embedUrl)
})
2018-04-03 15:33:39 +00:00
})
this.setVideoDescriptionHTML()
this.setVideoLikesBarTooltipText()
this.setOpenGraphTags()
this.checkUserRating()
2017-04-04 19:37:03 +00:00
}
private setRating (nextRating) {
let method
switch (nextRating) {
case 'like':
method = this.videoService.setVideoLike
break
case 'dislike':
method = this.videoService.setVideoDislike
break
case 'none':
method = this.videoService.unsetVideoLike
break
}
method.call(this.videoService, this.video.id)
.subscribe(
() => {
// Update the video like attribute
this.updateVideoRating(this.userRating, nextRating)
this.userRating = nextRating
},
2018-05-31 16:12:15 +00:00
err => this.notificationsService.error(this.i18n('Error'), err.message)
)
}
2017-06-17 09:28:11 +00:00
private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) {
let likesToIncrement = 0
let dislikesToIncrement = 0
2017-03-08 20:35:43 +00:00
if (oldRating) {
if (oldRating === 'like') likesToIncrement--
if (oldRating === 'dislike') dislikesToIncrement--
2017-03-08 20:35:43 +00:00
}
if (newRating === 'like') likesToIncrement++
if (newRating === 'dislike') dislikesToIncrement++
2017-03-08 20:35:43 +00:00
this.video.likes += likesToIncrement
this.video.dislikes += dislikesToIncrement
2018-02-28 08:49:40 +00:00
this.video.buildLikeAndDislikePercents()
2018-02-28 08:49:40 +00:00
this.setVideoLikesBarTooltipText()
2017-03-08 20:35:43 +00:00
}
private updateOtherVideosDisplayed () {
2018-02-08 09:19:09 +00:00
if (this.video && this.otherVideos && this.otherVideos.length > 0) {
this.otherVideosDisplayed = this.otherVideos.filter(v => v.uuid !== this.video.uuid)
}
}
private setOpenGraphTags () {
this.metaService.setTitle(this.video.name)
2017-03-10 09:33:36 +00:00
this.metaService.setTag('og:type', 'video')
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:title', this.video.name)
this.metaService.setTag('name', this.video.name)
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:description', this.video.description)
this.metaService.setTag('description', this.video.description)
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:image', this.video.previewPath)
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:duration', this.video.duration.toString())
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:site_name', 'PeerTube')
2016-11-04 16:37:44 +00:00
this.metaService.setTag('og:url', window.location.href)
this.metaService.setTag('url', window.location.href)
2016-11-04 16:37:44 +00:00
}
2017-11-30 08:21:11 +00:00
private isAutoplay () {
// True by default
if (!this.user) return true
// Be sure the autoPlay is set to false
return this.user.autoPlayVideo !== false
}
2018-04-03 16:06:58 +00:00
private flushPlayer () {
// Remove player if it exists
if (this.player) {
this.player.dispose()
this.player = undefined
}
}
2016-03-14 12:50:19 +00:00
}