diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts index 7aff312f7..85174a652 100644 --- a/client/src/assets/player/shared/peertube/peertube-plugin.ts +++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts @@ -298,12 +298,9 @@ class PeerTubePlugin extends Plugin { let lastCurrentTime = startTime 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) - 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.disableUserViewing() this.videoViewOnPlayHandler = () => { debugLogger('Notify user is watching on play: ' + startTime) @@ -318,7 +315,14 @@ class PeerTubePlugin extends Plugin { 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 if (diff > 0 && diff < 3) return @@ -366,6 +370,28 @@ class PeerTubePlugin extends Plugin { }, 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) { // Server won't save history, so save the video position in local storage if (!this.authorizationHeader()) { diff --git a/server/core/lib/views/shared/video-viewer-stats.ts b/server/core/lib/views/shared/video-viewer-stats.ts index a5cbf1b9b..2b9bfc012 100644 --- a/server/core/lib/views/shared/video-viewer-stats.ts +++ b/server/core/lib/views/shared/video-viewer-stats.ts @@ -65,7 +65,10 @@ export class VideoViewerStats { let stats: LocalViewerStats = await this.getLocalVideoViewer({ sessionId, videoId: video.id }) 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 }