Better view handling with looped videos
This commit is contained in:
parent
9ee467b9cd
commit
01b3396c80
2 changed files with 36 additions and 7 deletions
|
@ -298,12 +298,9 @@ class PeerTubePlugin extends Plugin {
|
||||||
|
|
||||||
let lastCurrentTime = startTime
|
let lastCurrentTime = startTime
|
||||||
let lastViewEvent: VideoViewEvent
|
let lastViewEvent: VideoViewEvent
|
||||||
let ended = false // player.ended() is too "slow", so handle ended manually
|
let ended = false // player.ended() is too "slow", so store ended state manually
|
||||||
|
|
||||||
if (this.videoViewInterval) clearInterval(this.videoViewInterval)
|
this.disableUserViewing()
|
||||||
if (this.videoViewOnPlayHandler) this.player.off('play', this.videoViewOnPlayHandler)
|
|
||||||
if (this.videoViewOnSeekedHandler) this.player.off('seeked', this.videoViewOnSeekedHandler)
|
|
||||||
if (this.videoViewOnEndedHandler) this.player.off('ended', this.videoViewOnEndedHandler)
|
|
||||||
|
|
||||||
this.videoViewOnPlayHandler = () => {
|
this.videoViewOnPlayHandler = () => {
|
||||||
debugLogger('Notify user is watching on play: ' + startTime)
|
debugLogger('Notify user is watching on play: ' + startTime)
|
||||||
|
@ -318,7 +315,14 @@ class PeerTubePlugin extends Plugin {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const diff = Math.floor(this.player.currentTime()) - lastCurrentTime
|
const currentTime = Math.floor(this.player.currentTime())
|
||||||
|
if (currentTime === 0 && this.player.loop()) {
|
||||||
|
debugLogger('Disabling viewing notification after first video loop.')
|
||||||
|
this.disableUserViewing()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const diff = currentTime - lastCurrentTime
|
||||||
|
|
||||||
// Don't take into account small forwards
|
// Don't take into account small forwards
|
||||||
if (diff > 0 && diff < 3) return
|
if (diff > 0 && diff < 3) return
|
||||||
|
@ -366,6 +370,28 @@ class PeerTubePlugin extends Plugin {
|
||||||
}, this.options.videoViewIntervalMs)
|
}, this.options.videoViewIntervalMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private disableUserViewing () {
|
||||||
|
if (this.videoViewInterval) {
|
||||||
|
clearInterval(this.videoViewInterval)
|
||||||
|
this.videoViewInterval = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.videoViewOnPlayHandler) {
|
||||||
|
this.player.off('play', this.videoViewOnPlayHandler)
|
||||||
|
this.videoViewOnPlayHandler = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.videoViewOnSeekedHandler) {
|
||||||
|
this.player.off('seeked', this.videoViewOnSeekedHandler)
|
||||||
|
this.videoViewOnSeekedHandler = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.videoViewOnEndedHandler) {
|
||||||
|
this.player.off('ended', this.videoViewOnEndedHandler)
|
||||||
|
this.videoViewOnEndedHandler = undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {
|
private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {
|
||||||
// Server won't save history, so save the video position in local storage
|
// Server won't save history, so save the video position in local storage
|
||||||
if (!this.authorizationHeader()) {
|
if (!this.authorizationHeader()) {
|
||||||
|
|
|
@ -65,7 +65,10 @@ export class VideoViewerStats {
|
||||||
let stats: LocalViewerStats = await this.getLocalVideoViewer({ sessionId, videoId: video.id })
|
let stats: LocalViewerStats = await this.getLocalVideoViewer({ sessionId, videoId: video.id })
|
||||||
|
|
||||||
if (stats && stats.watchSections.length >= MAX_LOCAL_VIEWER_WATCH_SECTIONS) {
|
if (stats && stats.watchSections.length >= MAX_LOCAL_VIEWER_WATCH_SECTIONS) {
|
||||||
logger.warn('Too much watch section to store for a viewer, skipping this one', { currentTime, viewEvent, ...lTags(video.uuid) })
|
logger.warn(
|
||||||
|
'Too much watch section to store for a viewer, skipping this one',
|
||||||
|
{ sessionId, currentTime, viewEvent, ...lTags(video.uuid) }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue