From 6de076222aca7005371e01768171efdc62ed8018 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sat, 25 Feb 2023 16:18:28 +0100 Subject: Avoid always resuming the end of the video --- .../player/shared/manager-options/manager-options-builder.ts | 1 + client/src/assets/player/shared/peertube/peertube-plugin.ts | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'client/src/assets/player/shared') diff --git a/client/src/assets/player/shared/manager-options/manager-options-builder.ts b/client/src/assets/player/shared/manager-options/manager-options-builder.ts index c820d637b..5d3ee4c4a 100644 --- a/client/src/assets/player/shared/manager-options/manager-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/manager-options-builder.ts @@ -35,6 +35,7 @@ export class ManagerOptionsBuilder { ...pick(commonOptions, [ 'videoViewUrl', + 'videoViewIntervalMs', 'authorizationHeader', 'startTime', 'videoDuration', diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts index ec8fbb320..b5f177f30 100644 --- a/client/src/assets/player/shared/peertube/peertube-plugin.ts +++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts @@ -27,9 +27,7 @@ class PeerTubePlugin extends Plugin { private readonly videoUUID: string private readonly startTime: number - private readonly CONSTANTS = { - USER_VIEW_VIDEO_INTERVAL: 5000 // Every 5 seconds, notify the user is watching the video - } + private readonly videoViewIntervalMs: number private videoCaptions: VideoJSCaption[] private defaultSubtitle: string @@ -48,6 +46,7 @@ class PeerTubePlugin extends Plugin { this.authorizationHeader = options.authorizationHeader this.videoUUID = options.videoUUID this.startTime = timeToInt(options.startTime) + this.videoViewIntervalMs = options.videoViewIntervalMs this.videoCaptions = options.videoCaptions this.initialInactivityTimeout = this.player.options_.inactivityTimeout @@ -188,7 +187,7 @@ class PeerTubePlugin extends Plugin { }) this.player.one('ended', () => { - const currentTime = Math.round(this.player.duration()) + const currentTime = Math.floor(this.player.duration()) lastCurrentTime = currentTime this.notifyUserIsWatching(currentTime, lastViewEvent) @@ -197,7 +196,7 @@ class PeerTubePlugin extends Plugin { }) this.videoViewInterval = setInterval(() => { - const currentTime = Math.round(this.player.currentTime()) + const currentTime = Math.floor(this.player.currentTime()) // No need to update if (currentTime === lastCurrentTime) return @@ -213,7 +212,7 @@ class PeerTubePlugin extends Plugin { if (!this.authorizationHeader()) { saveVideoWatchHistory(this.videoUUID, currentTime) } - }, this.CONSTANTS.USER_VIEW_VIDEO_INTERVAL) + }, this.videoViewIntervalMs) } private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) { -- cgit v1.2.3