-import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'
+import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
+import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component'
import { MetaService } from '@ngx-meta/core'
import { NotificationsService } from 'angular2-notifications'
import { Observable } from 'rxjs/Observable'
import { Subscription } from 'rxjs/Subscription'
import * as videojs from 'video.js'
+import 'videojs-hotkeys'
import { UserVideoRateType, VideoRateType } from '../../../../../shared'
import '../../../assets/player/peertube-videojs-plugin'
import { AuthService, ConfirmService } from '../../core'
@ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
@ViewChild('videoShareModal') videoShareModal: VideoShareComponent
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent
+ @ViewChild('videoSupportModal') videoSupportModal: VideoSupportComponent
otherVideosDisplayed: Video[] = []
error = false
- loading = false
player: videojs.Player
playerElement: HTMLVideoElement
userRating: UserVideoRateType = null
private metaService: MetaService,
private authService: AuthService,
private notificationsService: NotificationsService,
- private markdownService: MarkdownService
+ private markdownService: MarkdownService,
+ private zone: NgZone
) {}
get user () {
ngOnInit () {
this.videoService.getVideos({ currentPage: 1, itemsPerPage: 5 }, '-createdAt')
.subscribe(
- data => this.otherVideos = data.videos,
+ data => {
+ this.otherVideos = data.videos
+ this.updateOtherVideosDisplayed()
+ },
+
err => console.error(err)
)
this.player.pause()
}
- let uuid = routeParams['uuid']
+ const uuid = routeParams['uuid']
+ // Video did not changed
+ if (this.video && this.video.uuid === uuid) return
+
this.videoService.getVideo(uuid).subscribe(
video => this.onVideoFetched(video),
this.videoReportModal.show()
}
+ showSupportModal () {
+ this.videoSupportModal.show()
+ }
+
showShareModal () {
this.videoShareModal.show()
}
return Account.GET_ACCOUNT_AVATAR_URL(this.video.account)
}
+ getVideoPoster () {
+ if (!this.video) return ''
+
+ return this.video.previewUrl
+ }
+
getVideoTags () {
if (!this.video || Array.isArray(this.video.tags) === false) return []
return
}
- this.videoHTMLDescription = this.markdownService.markdownToHTML(this.video.description)
+ this.videoHTMLDescription = this.markdownService.textMarkdownToHTML(this.video.description)
}
private setVideoLikesBarTooltipText () {
private onVideoFetched (video: VideoDetails) {
this.video = video
- if (this.otherVideos.length > 0) {
- this.otherVideosDisplayed = this.otherVideos.filter(v => v.uuid !== this.video.uuid)
- }
+ this.updateOtherVideosDisplayed()
let observable
if (this.video.isVideoNSFWForUser(this.user)) {
peertube: {
videoFiles: this.video.files,
playerElement: this.playerElement,
- peerTubeLink: false
+ peerTubeLink: false,
+ videoViewUrl: this.videoService.getVideoViewUrl(this.video.uuid),
+ videoDuration: this.video.duration
+ },
+ hotkeys: {
+ enableVolumeScroll: false
}
}
}
this.videoPlayerLoaded = true
const self = this
- videojs(this.playerElement, videojsOptions, function () {
- self.player = this
- this.on('customError', (event, data) => {
- self.handleError(data.err)
+ this.zone.runOutsideAngular(() => {
+ videojs(this.playerElement, videojsOptions, function () {
+ self.player = this
+ this.on('customError', (event, data) => {
+ self.handleError(data.err)
+ })
})
})
} else {
- (this.player as any).setVideoFiles(this.video.files)
+ const videoViewUrl = this.videoService.getVideoViewUrl(this.video.uuid)
+ this.player.peertube().setVideoFiles(this.video.files, videoViewUrl, this.video.duration)
}
this.setVideoDescriptionHTML()
this.setOpenGraphTags()
this.checkUserRating()
-
- this.prepareViewAdd()
}
)
}
this.video.dislikes += dislikesToIncrement
}
+ private updateOtherVideosDisplayed () {
+ 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)
this.metaService.setTag('url', window.location.href)
}
- private prepareViewAdd () {
- // After 30 seconds (or 3/4 of the video), increment add a view
- let viewTimeoutSeconds = 30
- if (this.video.duration < viewTimeoutSeconds) viewTimeoutSeconds = (this.video.duration * 3) / 4
-
- setTimeout(() => {
- this.videoService
- .viewVideo(this.video.uuid)
- .subscribe()
-
- }, viewTimeoutSeconds * 1000)
- }
-
private isAutoplay () {
// True by default
if (!this.user) return true