import { Directive, EventEmitter, Input, OnInit, Output } from '@angular/core'
+import 'rxjs/add/operator/debounceTime'
import 'rxjs/add/operator/distinct'
+import 'rxjs/add/operator/filter'
+import 'rxjs/add/operator/map'
import 'rxjs/add/operator/startWith'
import { fromEvent } from 'rxjs/observable/fromEvent'
private restService: RestService
) {}
+ getVideoViewUrl (uuid: string) {
+ return VideoService.BASE_VIDEO_URL + uuid + '/views'
+ }
+
getVideo (uuid: string): Observable<VideoDetails> {
return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid)
.map(videoHash => new VideoDetails(videoHash))
}
viewVideo (uuid: string): Observable<VideoDetails> {
- return this.authHttp.post(VideoService.BASE_VIDEO_URL + uuid + '/views', {})
+ return this.authHttp.post(this.getVideoViewUrl(uuid), {})
.map(this.restExtractor.extractDataBool)
.catch(this.restExtractor.handleError)
}
peertube: {
videoFiles: this.video.files,
playerElement: this.playerElement,
- peerTubeLink: false
+ peerTubeLink: false,
+ videoViewUrl: this.videoService.getVideoViewUrl(this.video.uuid)
},
hotkeys: {
enableVolumeScroll: false
})
})
} else {
- this.player.peertube().setVideoFiles(this.video.files)
+ this.player.peertube().setVideoFiles(this.video.files, this.videoService.getVideoViewUrl(this.video.uuid))
}
this.setVideoDescriptionHTML()
this.setOpenGraphTags()
this.checkUserRating()
-
- this.prepareViewAdd()
}
)
}
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
// Big thanks to: https://github.com/kmoskwiak/videojs-resolution-switcher
+import { VideoService } from '@app/shared/video/video.service'
import * as videojs from 'video.js'
import * as WebTorrent from 'webtorrent'
import { VideoFile } from '../../../../shared/models/videos/video.model'
videoFiles: VideoFile[]
playerElement: HTMLVideoElement
peerTubeLink: boolean
+ videoViewUrl: string
}
// https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
private videoFiles: VideoFile[]
private torrent: WebTorrent.Torrent
private autoplay = false
+ private videoViewUrl: string
+ private videoViewInterval
constructor (player: videojs.Player, options: PeertubePluginOptions) {
super(player, options)
this.player.options_.autoplay = false
this.videoFiles = options.videoFiles
+ this.videoViewUrl = options.videoViewUrl
// Hack to "simulate" src link in video.js >= 6
// Without this, we can't play the video after pausing it
this.player.ready(() => {
this.initializePlayer(options)
this.runTorrentInfoScheduler()
+ this.prepareRunViewAdd()
})
}
}
}
- setVideoFiles (files: VideoFile[]) {
+ setVideoFiles (files: VideoFile[], videoViewUrl: string) {
+ this.videoViewUrl = videoViewUrl
this.videoFiles = files
+ // Re run view add for the new video
+ this.prepareRunViewAdd()
this.updateVideoFile(undefined, () => this.player.play())
}
}, 1000)
}
+ private prepareRunViewAdd () {
+ if (this.player.readyState() < 1) {
+ return this.player.one('loadedmetadata', () => this.runViewAdd())
+ }
+
+ this.runViewAdd()
+ }
+
+ private runViewAdd () {
+ this.clearVideoViewInterval()
+
+ // After 30 seconds (or 3/4 of the video), add a view to the video
+ let minSecondsToView = 30
+
+ const duration = this.player.duration()
+ if (duration < minSecondsToView) minSecondsToView = (duration * 3) / 4
+
+ let secondsViewed = 0
+ this.videoViewInterval = setInterval(() => {
+ if (this.player && !this.player.paused()) {
+ secondsViewed += 1
+
+ if (secondsViewed > minSecondsToView) {
+ this.clearVideoViewInterval()
+
+ this.addViewToVideo().catch(err => console.error(err))
+ }
+ }
+ }, 1000)
+ }
+
+ private clearVideoViewInterval () {
+ if (this.videoViewInterval !== undefined) {
+ clearInterval(this.videoViewInterval)
+ this.videoViewInterval = undefined
+ }
+ }
+
+ private addViewToVideo () {
+ return fetch(this.videoViewUrl, { method: 'POST' })
+ }
+
private handleError (err: Error | string) {
return this.player.trigger('customError', { err })
}
.vjs-big-play-button {
outline: 0;
- font-size: 8em;
+ font-size: 7em;
- $big-play-width: 3em;
- $big-play-height: 1.5em;
+ $big-play-width: 1.5em;
+ $big-play-height: 1em;
border: 0;
border-radius: 0.3em;
left: 50%;
top: 50%;
+ width: $big-play-width;
+ height: $big-play-height;
+ line-height: $big-play-height;
margin-left: -($big-play-width / 2);
margin-top: -($big-play-height / 2);
- background-color: transparent !important;
+ transition: opacity 0.5s;
&::-moz-focus-inner {
border: 0;
transition: text-shadow 0.3s;
}
- &:hover .vjs-icon-placeholder::before {
- text-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
+ &:hover {
+ opacity: 0.9;
+
+ .vjs-icon-placeholder::before {
+ text-shadow: 0 0 1px rgba(255, 255, 255, 0.8);
+ }
}
}
import 'videojs-dock/dist/videojs-dock.es.js'
import { VideoDetails } from '../../../../shared'
+function getVideoUrl (id: string) {
+ return window.location.origin + '/api/v1/videos/' + videoId
+}
+
async function loadVideoInfo (videoId: string): Promise<VideoDetails> {
- const response = await fetch(window.location.origin + '/api/v1/videos/' + videoId)
+ const response = await fetch(getVideoUrl(videoId))
return response.json()
}
peertube: {
videoFiles: videoInfo.files,
playerElement: videoElement,
- peerTubeLink: true
+ peerTubeLink: true,
+ videoViewUrl: getVideoUrl(videoId) + '/views'
},
hotkeys: {
enableVolumeScroll: false
tags: videoInfo.tags.slice(0, 5),
privacy: VideoPrivacy.PUBLIC,
fixture: videoPath,
- thumbnailfile
+ thumbnailfile,
+ previewfile: thumbnailfile
}
console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)