Skip to content

Commit

Permalink
feat: resets pastSeekEnd_ variable. (#6249)
Browse files Browse the repository at this point in the history
* feat: resets pastSeekEnd_ when its value is much higher than seeking increment.

* fixes unit tests
  • Loading branch information
gjanblaszczyk authored and gkatsev committed Nov 15, 2019
1 parent 4f8c498 commit ccca846
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/js/live-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_();
Expand Down
8 changes: 6 additions & 2 deletions test/unit/live-tracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit ccca846

Please sign in to comment.