2018-05-31 09:35:01 +00:00
|
|
|
import { catchError } from 'rxjs/operators'
|
2018-07-17 15:06:34 +00:00
|
|
|
import { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
|
2017-06-16 12:32:15 +00:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router'
|
2018-03-01 12:57:29 +00:00
|
|
|
import { RedirectService } from '@app/core/routing/redirect.service'
|
2018-03-23 13:26:20 +00:00
|
|
|
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-07-13 16:21:19 +00:00
|
|
|
import { forkJoin, Subscription } from 'rxjs'
|
2017-12-11 16:36:46 +00:00
|
|
|
import * as videojs from 'video.js'
|
2018-01-09 14:40:46 +00:00
|
|
|
import 'videojs-hotkeys'
|
2018-03-19 16:16:34 +00:00
|
|
|
import * as WebTorrent from 'webtorrent'
|
2018-07-31 13:26:48 +00:00
|
|
|
import { UserVideoRateType, VideoPrivacy, VideoRateType, VideoState } from '../../../../../shared'
|
2017-10-06 08:40:09 +00:00
|
|
|
import '../../../assets/player/peertube-videojs-plugin'
|
2017-06-16 12:32:15 +00:00
|
|
|
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-12 18:04:58 +00:00
|
|
|
import { addContextMenu, getVideojsOptions, loadLocale } from '../../../assets/player/peertube-player'
|
2018-04-19 09:01:34 +00:00
|
|
|
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'
|
2018-07-13 16:21:19 +00:00
|
|
|
import { VideoCaptionService } from '@app/shared/video-caption'
|
|
|
|
import { VideoCaption } from '../../../../../shared/models/videos/video-caption.model'
|
2016-03-14 12:50:19 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-video-watch',
|
2016-09-19 20:49:31 +00:00
|
|
|
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 {
|
2018-02-28 14:33:45 +00:00
|
|
|
private static LOCAL_STORAGE_PRIVACY_CONCERN_KEY = 'video-watch-privacy-concern'
|
|
|
|
|
2017-10-19 12:58:28 +00:00
|
|
|
@ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
|
2017-06-16 12:32:15 +00:00
|
|
|
@ViewChild('videoShareModal') videoShareModal: VideoShareComponent
|
|
|
|
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent
|
2018-02-20 15:13:05 +00:00
|
|
|
@ViewChild('videoSupportModal') videoSupportModal: VideoSupportComponent
|
2017-06-16 12:32:15 +00:00
|
|
|
|
2018-01-07 13:48:10 +00:00
|
|
|
otherVideosDisplayed: Video[] = []
|
2017-12-06 16:15:59 +00:00
|
|
|
|
2017-06-16 12:32:15 +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
|
2017-11-28 14:40:53 +00:00
|
|
|
descriptionLoading = false
|
2017-10-30 19:26:06 +00:00
|
|
|
|
|
|
|
completeDescriptionShown = false
|
|
|
|
completeVideoDescription: string
|
|
|
|
shortVideoDescription: string
|
2017-10-26 13:01:47 +00:00
|
|
|
videoHTMLDescription = ''
|
2017-12-21 09:49:52 +00:00
|
|
|
likesBarTooltipText = ''
|
2018-03-08 11:01:55 +00:00
|
|
|
hasAlreadyAcceptedPrivacyConcern = false
|
2018-07-16 17:15:20 +00:00
|
|
|
remoteServerDown = false
|
2017-06-16 12:32:15 +00:00
|
|
|
|
2018-06-06 12:23:40 +00:00
|
|
|
private videojsLocaleLoaded = false
|
2018-01-08 09:46:41 +00:00
|
|
|
private otherVideos: Video[] = []
|
2017-06-16 12:32:15 +00:00
|
|
|
private paramsSub: Subscription
|
|
|
|
|
|
|
|
constructor (
|
2016-05-27 15:49:18 +00:00
|
|
|
private elementRef: ElementRef,
|
2018-07-17 15:06:34 +00:00
|
|
|
private changeDetector: ChangeDetectorRef,
|
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,
|
2017-01-27 15:14:11 +00:00
|
|
|
private authService: AuthService,
|
2018-04-19 09:01:34 +00:00
|
|
|
private serverService: ServerService,
|
2018-05-31 09:35:01 +00:00
|
|
|
private restExtractor: RestExtractor,
|
2017-10-26 13:01:47 +00:00
|
|
|
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-07-13 16:21:19 +00:00
|
|
|
private videoCaptionService: VideoCaptionService,
|
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()
|
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
ngOnInit () {
|
2018-03-23 13:26:20 +00:00
|
|
|
if (
|
|
|
|
WebTorrent.WEBRTC_SUPPORT === false ||
|
|
|
|
peertubeLocalStorage.getItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true'
|
|
|
|
) {
|
2018-03-07 16:35:30 +00:00
|
|
|
this.hasAlreadyAcceptedPrivacyConcern = true
|
|
|
|
}
|
|
|
|
|
2017-12-06 16:15:59 +00:00
|
|
|
this.videoService.getVideos({ currentPage: 1, itemsPerPage: 5 }, '-createdAt')
|
2018-06-12 18:04:58 +00:00
|
|
|
.subscribe(
|
|
|
|
data => {
|
|
|
|
this.otherVideos = data.videos
|
|
|
|
this.updateOtherVideosDisplayed()
|
|
|
|
},
|
2018-02-07 11:20:48 +00:00
|
|
|
|
2018-06-12 18:04:58 +00:00
|
|
|
err => console.error(err)
|
|
|
|
)
|
2017-12-06 16:15:59 +00:00
|
|
|
|
2017-01-29 17:35:19 +00:00
|
|
|
this.paramsSub = this.route.params.subscribe(routeParams => {
|
2018-06-12 18:04:58 +00:00
|
|
|
const uuid = routeParams[ 'uuid' ]
|
2018-05-31 09:35:01 +00:00
|
|
|
|
2018-04-16 22:49:04 +00:00
|
|
|
// Video did not change
|
2018-02-19 09:38:24 +00:00
|
|
|
if (this.video && this.video.uuid === uuid) return
|
2018-06-14 09:25:49 +00:00
|
|
|
|
|
|
|
if (this.player) this.player.pause()
|
|
|
|
|
2018-04-16 22:49:04 +00:00
|
|
|
// Video did change
|
2018-07-13 16:21:19 +00:00
|
|
|
forkJoin(
|
|
|
|
this.videoService.getVideo(uuid),
|
|
|
|
this.videoCaptionService.listCaptions(uuid)
|
|
|
|
)
|
|
|
|
.pipe(
|
|
|
|
catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
|
|
|
|
)
|
|
|
|
.subscribe(([ video, captionsResult ]) => {
|
|
|
|
const startTime = this.route.snapshot.queryParams.start
|
|
|
|
this.onVideoFetched(video, captionsResult.data, startTime)
|
|
|
|
.catch(err => this.handleError(err))
|
|
|
|
})
|
2017-06-16 12:32:15 +00:00
|
|
|
})
|
2016-11-04 15:04:50 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
ngOnDestroy () {
|
2018-04-03 16:06:58 +00:00
|
|
|
this.flushPlayer()
|
2016-11-08 20:17:17 +00:00
|
|
|
|
2017-01-29 17:35:19 +00:00
|
|
|
// Unsubscribe subscriptions
|
2017-06-16 12:32:15 +00:00
|
|
|
this.paramsSub.unsubscribe()
|
2016-03-14 12:50:19 +00:00
|
|
|
}
|
2016-03-14 21:16:43 +00:00
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
setLike () {
|
|
|
|
if (this.isUserLoggedIn() === false) return
|
2018-01-07 13:48:10 +00:00
|
|
|
if (this.userRating === 'like') {
|
|
|
|
// Already liked this video
|
|
|
|
this.setRating('none')
|
|
|
|
} else {
|
|
|
|
this.setRating('like')
|
|
|
|
}
|
2017-03-08 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
setDislike () {
|
|
|
|
if (this.isUserLoggedIn() === false) return
|
2018-01-07 13:48:10 +00:00
|
|
|
if (this.userRating === 'dislike') {
|
|
|
|
// Already disliked this video
|
|
|
|
this.setRating('none')
|
|
|
|
} else {
|
|
|
|
this.setRating('dislike')
|
|
|
|
}
|
2017-03-08 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 14:29:32 +00:00
|
|
|
async blacklistVideo (event: Event) {
|
2017-06-16 12:32:15 +00:00
|
|
|
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'))
|
2018-02-22 14:29:32 +00:00
|
|
|
if (res === false) return
|
2017-04-26 19:22:10 +00:00
|
|
|
|
2018-02-22 14:29:32 +00:00
|
|
|
this.videoBlacklistService.blacklistVideo(this.video.id)
|
2018-06-12 18:04:58 +00:00
|
|
|
.subscribe(
|
|
|
|
() => {
|
|
|
|
this.notificationsService.success(
|
|
|
|
this.i18n('Success'),
|
|
|
|
this.i18n('Video {{videoName}} had been blacklisted.', { videoName: this.video.name })
|
|
|
|
)
|
|
|
|
this.redirectService.redirectToHomepage()
|
|
|
|
},
|
|
|
|
|
|
|
|
error => this.notificationsService.error(this.i18n('Error'), error.message)
|
|
|
|
)
|
2017-04-26 19:22:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 19:26:06 +00:00
|
|
|
showMoreDescription () {
|
|
|
|
if (this.completeVideoDescription === undefined) {
|
|
|
|
return this.loadCompleteDescription()
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateVideoDescription(this.completeVideoDescription)
|
2017-11-28 14:40:53 +00:00
|
|
|
this.completeDescriptionShown = true
|
2017-10-30 19:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showLessDescription () {
|
|
|
|
this.updateVideoDescription(this.shortVideoDescription)
|
2017-11-28 14:40:53 +00:00
|
|
|
this.completeDescriptionShown = false
|
2017-10-30 19:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadCompleteDescription () {
|
2017-11-28 14:40:53 +00:00
|
|
|
this.descriptionLoading = true
|
|
|
|
|
2017-10-30 19:26:06 +00:00
|
|
|
this.videoService.loadCompleteDescription(this.video.descriptionPath)
|
2018-06-12 18:04:58 +00:00
|
|
|
.subscribe(
|
|
|
|
description => {
|
|
|
|
this.completeDescriptionShown = true
|
|
|
|
this.descriptionLoading = false
|
|
|
|
|
|
|
|
this.shortVideoDescription = this.video.description
|
|
|
|
this.completeVideoDescription = description
|
|
|
|
|
|
|
|
this.updateVideoDescription(this.completeVideoDescription)
|
|
|
|
},
|
|
|
|
|
|
|
|
error => {
|
|
|
|
this.descriptionLoading = false
|
|
|
|
this.notificationsService.error(this.i18n('Error'), error.message)
|
|
|
|
}
|
|
|
|
)
|
2017-10-30 19:26:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
showShareModal () {
|
|
|
|
this.videoShareModal.show()
|
2016-11-08 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 12:58:28 +00:00
|
|
|
showDownloadModal (event: Event) {
|
2017-06-16 12:32:15 +00:00
|
|
|
event.preventDefault()
|
2017-10-19 12:58:28 +00:00
|
|
|
this.videoDownloadModal.show()
|
2016-11-08 20:11:57 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +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())
|
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
isVideoBlacklistable () {
|
2017-12-12 13:41:59 +00:00
|
|
|
return this.video.isBlackistableBy(this.user)
|
2017-04-26 19:22:10 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 15:35:32 +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 []
|
|
|
|
|
2018-07-24 09:40:04 +00:00
|
|
|
return this.video.tags
|
2017-12-06 16:15:59 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 16:53:58 +00:00
|
|
|
isVideoRemovable () {
|
|
|
|
return this.video.isRemovableBy(this.authService.getUser())
|
|
|
|
}
|
|
|
|
|
2018-02-22 14:29:32 +00:00
|
|
|
async removeVideo (event: Event) {
|
2017-12-20 16:53:58 +00:00
|
|
|
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'))
|
2018-02-22 14:29:32 +00:00
|
|
|
if (res === false) return
|
2017-12-20 16:53:58 +00:00
|
|
|
|
2018-02-22 14:29:32 +00:00
|
|
|
this.videoService.removeVideo(this.video.id)
|
2018-06-12 18:04:58 +00:00
|
|
|
.subscribe(
|
|
|
|
status => {
|
|
|
|
this.notificationsService.success(
|
|
|
|
this.i18n('Success'),
|
|
|
|
this.i18n('Video {{videoName}} deleted.', { videoName: this.video.name })
|
|
|
|
)
|
|
|
|
|
|
|
|
// Go back to the video-list.
|
|
|
|
this.redirectService.redirectToHomepage()
|
|
|
|
},
|
|
|
|
|
|
|
|
error => this.notificationsService.error(this.i18n('Error'), error.message)
|
|
|
|
)
|
2017-12-20 16:53:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 11:01:55 +00:00
|
|
|
acceptedPrivacyConcern () {
|
2018-03-23 13:26:20 +00:00
|
|
|
peertubeLocalStorage.setItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true')
|
2018-03-08 11:01:55 +00:00
|
|
|
this.hasAlreadyAcceptedPrivacyConcern = true
|
|
|
|
}
|
|
|
|
|
2018-06-12 18:04:58 +00:00
|
|
|
isVideoToTranscode () {
|
|
|
|
return this.video && this.video.state.id === VideoState.TO_TRANSCODE
|
|
|
|
}
|
|
|
|
|
2018-08-03 07:43:00 +00:00
|
|
|
isVideoToImport () {
|
|
|
|
return this.video && this.video.state.id === VideoState.TO_IMPORT
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:52:15 +00:00
|
|
|
hasVideoScheduledPublication () {
|
|
|
|
return this.video && this.video.scheduledUpdate !== undefined
|
|
|
|
}
|
|
|
|
|
2017-10-30 19:26:06 +00:00
|
|
|
private updateVideoDescription (description: string) {
|
|
|
|
this.video.description = description
|
|
|
|
this.setVideoDescriptionHTML()
|
|
|
|
}
|
|
|
|
|
|
|
|
private setVideoDescriptionHTML () {
|
2018-02-20 15:13:05 +00:00
|
|
|
this.videoHTMLDescription = this.markdownService.textMarkdownToHTML(this.video.description)
|
2017-10-30 19:26:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 09:49:52 +00:00
|
|
|
private setVideoLikesBarTooltipText () {
|
2018-06-12 18:04:58 +00:00
|
|
|
this.likesBarTooltipText = this.i18n('{{likesNumber}} likes / {{dislikesNumber}} dislikes', {
|
|
|
|
likesNumber: this.video.likes,
|
|
|
|
dislikesNumber: this.video.dislikes
|
|
|
|
})
|
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
|
|
|
|
|
2018-07-16 17:15:20 +00:00
|
|
|
// Display a message in the video player instead of a notification
|
2018-07-17 12:44:19 +00:00
|
|
|
if (errorMessage.indexOf('from xs param') !== -1) {
|
2018-07-16 17:15:20 +00:00
|
|
|
this.flushPlayer()
|
|
|
|
this.remoteServerDown = true
|
2018-07-17 15:06:34 +00:00
|
|
|
this.changeDetector.detectChanges()
|
|
|
|
|
2018-07-16 17:15:20 +00:00
|
|
|
return
|
2017-07-23 09:07:30 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 17:15:20 +00:00
|
|
|
this.notificationsService.error(this.i18n('Error'), errorMessage)
|
2017-07-23 09:07:30 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
private checkUserRating () {
|
2017-03-08 20:35:43 +00:00
|
|
|
// Unlogged users do not have ratings
|
2017-06-16 12:32:15 +00:00
|
|
|
if (this.isUserLoggedIn() === false) return
|
2017-03-08 20:35:43 +00:00
|
|
|
|
|
|
|
this.videoService.getUserVideoRating(this.video.id)
|
2018-06-12 18:04:58 +00:00
|
|
|
.subscribe(
|
|
|
|
ratingObject => {
|
|
|
|
if (ratingObject) {
|
|
|
|
this.userRating = ratingObject.rating
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
err => this.notificationsService.error(this.i18n('Error'), err.message)
|
|
|
|
)
|
2017-03-08 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 16:21:19 +00:00
|
|
|
private async onVideoFetched (video: VideoDetails, videoCaptions: VideoCaption[], startTime = 0) {
|
2017-06-16 12:32:15 +00:00
|
|
|
this.video = video
|
2017-04-04 19:37:03 +00:00
|
|
|
|
2018-04-04 07:04:34 +00:00
|
|
|
// Re init attributes
|
|
|
|
this.descriptionLoading = false
|
|
|
|
this.completeDescriptionShown = false
|
2018-07-16 17:15:20 +00:00
|
|
|
this.remoteServerDown = false
|
2018-04-04 07:04:34 +00:00
|
|
|
|
2018-02-07 11:20:48 +00:00
|
|
|
this.updateOtherVideosDisplayed()
|
2018-01-07 13:48:10 +00:00
|
|
|
|
2018-04-19 09:01:34 +00:00
|
|
|
if (this.video.isVideoNSFWForUser(this.user, this.serverService.getConfig())) {
|
2018-02-28 14:33:45 +00:00
|
|
|
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')
|
2017-10-27 06:51:40 +00:00
|
|
|
)
|
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)
|
|
|
|
|
2018-07-13 16:21:19 +00:00
|
|
|
const playerCaptions = videoCaptions.map(c => ({
|
|
|
|
label: c.language.label,
|
|
|
|
language: c.language.id,
|
|
|
|
src: environment.apiUrl + c.captionPath
|
|
|
|
}))
|
|
|
|
|
2018-04-03 15:33:39 +00:00
|
|
|
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,
|
2018-07-13 16:21:19 +00:00
|
|
|
videoCaptions: playerCaptions,
|
2018-04-03 15:33:39 +00:00
|
|
|
playerElement: this.playerElement,
|
2018-06-18 07:42:16 +00:00
|
|
|
videoViewUrl: this.video.privacy.id !== VideoPrivacy.PRIVATE ? this.videoService.getVideoViewUrl(this.video.uuid) : null,
|
2018-04-03 15:33:39 +00:00
|
|
|
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
|
|
|
})
|
2017-10-06 08:40:09 +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-02-28 14:33:45 +00:00
|
|
|
})
|
2018-04-03 15:33:39 +00:00
|
|
|
})
|
2018-02-28 14:33:45 +00:00
|
|
|
|
|
|
|
this.setVideoDescriptionHTML()
|
|
|
|
this.setVideoLikesBarTooltipText()
|
|
|
|
|
|
|
|
this.setOpenGraphTags()
|
|
|
|
this.checkUserRating()
|
2017-04-04 19:37:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 13:48:10 +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)
|
2018-06-12 18:04:58 +00:00
|
|
|
.subscribe(
|
|
|
|
() => {
|
|
|
|
// Update the video like attribute
|
|
|
|
this.updateVideoRating(this.userRating, nextRating)
|
|
|
|
this.userRating = nextRating
|
|
|
|
},
|
|
|
|
|
|
|
|
err => this.notificationsService.error(this.i18n('Error'), err.message)
|
|
|
|
)
|
2018-01-07 13:48:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-17 09:28:11 +00:00
|
|
|
private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) {
|
2017-06-16 12:32:15 +00:00
|
|
|
let likesToIncrement = 0
|
|
|
|
let dislikesToIncrement = 0
|
2017-03-08 20:35:43 +00:00
|
|
|
|
|
|
|
if (oldRating) {
|
2017-06-16 12:32:15 +00:00
|
|
|
if (oldRating === 'like') likesToIncrement--
|
|
|
|
if (oldRating === 'dislike') dislikesToIncrement--
|
2017-03-08 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
if (newRating === 'like') likesToIncrement++
|
|
|
|
if (newRating === 'dislike') dislikesToIncrement++
|
2017-03-08 20:35:43 +00:00
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
this.video.likes += likesToIncrement
|
|
|
|
this.video.dislikes += dislikesToIncrement
|
2018-02-28 08:49:40 +00:00
|
|
|
|
2018-02-28 14:33:45 +00:00
|
|
|
this.video.buildLikeAndDislikePercents()
|
2018-02-28 08:49:40 +00:00
|
|
|
this.setVideoLikesBarTooltipText()
|
2017-03-08 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 11:20:48 +00:00
|
|
|
private updateOtherVideosDisplayed () {
|
2018-02-08 09:19:09 +00:00
|
|
|
if (this.video && this.otherVideos && this.otherVideos.length > 0) {
|
2018-02-07 11:20:48 +00:00
|
|
|
this.otherVideosDisplayed = this.otherVideos.filter(v => v.uuid !== this.video.uuid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
private setOpenGraphTags () {
|
|
|
|
this.metaService.setTitle(this.video.name)
|
2017-03-10 09:33:36 +00:00
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
this.metaService.setTag('og:type', 'video')
|
2016-11-04 16:37:44 +00:00
|
|
|
|
2017-06-16 12:32:15 +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
|
|
|
|
2017-06-16 12:32:15 +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
|
|
|
|
2017-07-12 10:19:39 +00:00
|
|
|
this.metaService.setTag('og:image', this.video.previewPath)
|
2016-11-04 16:37:44 +00:00
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
this.metaService.setTag('og:duration', this.video.duration.toString())
|
2016-11-04 16:37:44 +00:00
|
|
|
|
2017-06-16 12:32:15 +00:00
|
|
|
this.metaService.setTag('og:site_name', 'PeerTube')
|
2016-11-04 16:37:44 +00:00
|
|
|
|
2017-06-16 12:32:15 +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
|
|
|
|
2017-12-19 13:01:34 +00:00
|
|
|
private isAutoplay () {
|
2018-06-14 09:25:49 +00:00
|
|
|
// We'll jump to the thread id, so do not play the video
|
|
|
|
if (this.route.snapshot.params['threadId']) return false
|
|
|
|
|
|
|
|
// Otherwise true by default
|
2017-12-19 13:01:34 +00:00
|
|
|
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
|
|
|
}
|