X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fpeertube-plugin.ts;h=919b7c2398cc0a338da3a797f07fe2063003666b;hb=171efc48e67498406feb6d7873b3482b41505515;hp=a5a706420c6b146ac17aa66140e794e441f37de1;hpb=72efdda586489bf59ac7df12ff9e75a926f1f048;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts index a5a706420..919b7c239 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/peertube-plugin.ts @@ -1,20 +1,17 @@ -import videojs from 'video.js' import './videojs-components/settings-menu-button' -import { - PeerTubePluginOptions, - ResolutionUpdateData, - UserWatching, - VideoJSCaption -} from './peertube-videojs-typings' -import { isMobile, timeToInt } from './utils' +import videojs from 'video.js' +import { timeToInt } from '@shared/core-utils' import { getStoredLastSubtitle, getStoredMute, getStoredVolume, saveLastSubtitle, saveMuteInStore, + saveVideoWatchHistory, saveVolumeInStore } from './peertube-player-local-storage' +import { PeerTubePluginOptions, ResolutionUpdateData, UserWatching, VideoJSCaption } from './peertube-videojs-typings' +import { isMobile } from './utils' const Plugin = videojs.getPlugin('plugin') @@ -32,6 +29,8 @@ class PeerTubePlugin extends Plugin { private userWatchingVideoInterval: any private lastResolutionChange: ResolutionUpdateData + private isLive: boolean + private menuOpened = false private mouseInControlBar = false private readonly savedInactivityTimeout: number @@ -42,6 +41,7 @@ class PeerTubePlugin extends Plugin { this.videoViewUrl = options.videoViewUrl this.videoDuration = options.videoDuration this.videoCaptions = options.videoCaptions + this.isLive = options.isLive this.savedInactivityTimeout = player.options_.inactivityTimeout @@ -117,7 +117,7 @@ class PeerTubePlugin extends Plugin { this.initializePlayer() this.runViewAdd() - if (options.userWatching) this.runUserWatchVideo(options.userWatching) + this.runUserWatchVideo(options.userWatching, options.videoUUID) }) } @@ -152,7 +152,9 @@ class PeerTubePlugin extends Plugin { // After 30 seconds (or 3/4 of the video), add a view to the video let minSecondsToView = 30 - if (this.videoDuration < minSecondsToView) minSecondsToView = (this.videoDuration * 3) / 4 + if (!this.isLive && this.videoDuration < minSecondsToView) { + minSecondsToView = (this.videoDuration * 3) / 4 + } let secondsViewed = 0 this.videoViewInterval = setInterval(() => { @@ -160,7 +162,12 @@ class PeerTubePlugin extends Plugin { secondsViewed += 1 if (secondsViewed > minSecondsToView) { - this.clearVideoViewInterval() + // Restart the loop if this is a live + if (this.isLive) { + secondsViewed = 0 + } else { + this.clearVideoViewInterval() + } this.addViewToVideo().catch(err => console.error(err)) } @@ -168,7 +175,7 @@ class PeerTubePlugin extends Plugin { }, 1000) } - private runUserWatchVideo (options: UserWatching) { + private runUserWatchVideo (options: UserWatching, videoUUID: string) { let lastCurrentTime = 0 this.userWatchingVideoInterval = setInterval(() => { @@ -177,8 +184,12 @@ class PeerTubePlugin extends Plugin { if (currentTime - lastCurrentTime >= 1) { lastCurrentTime = currentTime - this.notifyUserIsWatching(currentTime, options.url, options.authorizationHeader) - .catch(err => console.error('Cannot notify user is watching.', err)) + if (options) { + this.notifyUserIsWatching(currentTime, options.url, options.authorizationHeader) + .catch(err => console.error('Cannot notify user is watching.', err)) + } else { + saveVideoWatchHistory(videoUUID, currentTime) + } } }, this.CONSTANTS.USER_WATCHING_VIDEO_INTERVAL) } @@ -233,12 +244,20 @@ class PeerTubePlugin extends Plugin { } private alterInactivity () { - if (this.menuOpened || this.mouseInControlBar) { + if (this.menuOpened) { this.player.options_.inactivityTimeout = this.savedInactivityTimeout return } - this.player.options_.inactivityTimeout = 1 + if (!this.mouseInControlBar && !this.isTouchEnabled()) { + this.player.options_.inactivityTimeout = 1 + } + } + + private isTouchEnabled () { + return ('ontouchstart' in window) || + navigator.maxTouchPoints > 0 || + navigator.msMaxTouchPoints > 0 } private initCaptions () {