]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/shared/peertube/peertube-plugin.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / shared / peertube / peertube-plugin.ts
index b5f177f3050b7afd7a61f84006cc443ab4360fc0..af21477491444b5192183a1b528d43f7ef89317b 100644 (file)
@@ -180,8 +180,10 @@ class PeerTubePlugin extends Plugin {
     })
 
     this.player.on('seeked', () => {
-      // Don't take into account small seek events
-      if (Math.abs(this.player.currentTime() - lastCurrentTime) < 3) return
+      const diff = Math.floor(this.player.currentTime()) - lastCurrentTime
+
+      // Don't take into account small forwards
+      if (diff > 0 && diff < 3) return
 
       lastViewEvent = 'seek'
     })
@@ -207,26 +209,20 @@ class PeerTubePlugin extends Plugin {
         .catch(err => logger.error('Cannot notify user is watching.', err))
 
       lastViewEvent = undefined
-
-      // Server won't save history, so save the video position in local storage
-      if (!this.authorizationHeader()) {
-        saveVideoWatchHistory(this.videoUUID, currentTime)
-      }
     }, this.videoViewIntervalMs)
   }
 
   private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {
-    if (!this.videoViewUrl) return Promise.resolve(undefined)
-
-    const body: VideoView = {
-      currentTime,
-      viewEvent
+    // Server won't save history, so save the video position in local storage
+    if (!this.authorizationHeader()) {
+      saveVideoWatchHistory(this.videoUUID, currentTime)
     }
 
-    const headers = new Headers({
-      'Content-type': 'application/json; charset=UTF-8'
-    })
+    if (!this.videoViewUrl) return Promise.resolve(true)
+
+    const body: VideoView = { currentTime, viewEvent }
 
+    const headers = new Headers({ 'Content-type': 'application/json; charset=UTF-8' })
     if (this.authorizationHeader()) headers.set('Authorization', this.authorizationHeader())
 
     return fetch(this.videoViewUrl, { method: 'POST', body: JSON.stringify(body), headers })