From ccca846da8766a03274dc8b537a90891a3dc33a8 Mon Sep 17 00:00:00 2001 From: Grzegorz Blaszczyk Date: Fri, 15 Nov 2019 19:44:34 +0100 Subject: [PATCH] feat: resets pastSeekEnd_ variable. (#6249) * feat: resets pastSeekEnd_ when its value is much higher than seeking increment. * fixes unit tests --- src/js/live-tracker.js | 8 +++++++- test/unit/live-tracker.test.js | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/js/live-tracker.js b/src/js/live-tracker.js index 3463ff4079..13d684a0d2 100644 --- a/src/js/live-tracker.js +++ b/src/js/live-tracker.js @@ -88,7 +88,13 @@ class LiveTracker extends Component { this.trigger('seekableendchange'); } - this.pastSeekEnd_ = this.pastSeekEnd() + 0.03; + // we should reset pastSeekEnd when the value + // is much higher than seeking increment. + if (this.pastSeekEnd() > this.seekableIncrement_ * 1.5) { + this.pastSeekEnd_ = 0; + } else { + this.pastSeekEnd_ = this.pastSeekEnd() + 0.03; + } if (this.isBehind_() !== this.behindLiveEdge()) { this.behindLiveEdge_ = this.isBehind_(); diff --git a/test/unit/live-tracker.test.js b/test/unit/live-tracker.test.js index ac69e437bf..a0f42af0fc 100644 --- a/test/unit/live-tracker.test.js +++ b/test/unit/live-tracker.test.js @@ -68,9 +68,12 @@ QUnit.module('LiveTracker', () => { QUnit.test('Triggers liveedgechange when we fall behind and catch up', function(assert) { this.liveTracker.seekableIncrement_ = 6; + this.player.seekable = () => createTimeRanges(0, 20); this.player.trigger('timeupdate'); - this.player.currentTime = () => 0; - this.clock.tick(20000); + this.player.currentTime = () => 14; + this.clock.tick(6000); + this.player.seekable = () => createTimeRanges(0, 26); + this.clock.tick(1000); assert.equal(this.liveEdgeChanges, 1, 'should have one live edge change'); assert.ok(this.liveTracker.behindLiveEdge(), 'behind live edge'); @@ -99,6 +102,7 @@ QUnit.module('LiveTracker', () => { QUnit.test('seeks to live edge on seekableendchange', function(assert) { this.player.trigger('timeupdate'); + this.player.seekable = () => createTimeRanges(0, 6); this.liveTracker.seekableIncrement_ = 2; let currentTime = 0;