Skip to content

Commit

Permalink
fix: Restart timeout monitor if playing when reinitialised (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
mister-ben authored and gkatsev committed May 2, 2018
1 parent 8d96f2a commit af868ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ const initPlugin = function(player, options) {
player.addClass('vjs-errors');
});

// if the plugin is re-initialised during playback, start the timeout handler.
if (!player.paused()) {
onPlayStartMonitor();
}

player.errors = reInitPlugin;
};

Expand Down
19 changes: 19 additions & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,25 @@ QUnit.test('progress clears player timeout errors', function(assert) {
assert.strictEqual(this.player.error(), null, 'error removed');
});

QUnit.test('reinitialising plugin during playback starts timeout handler', function(assert) {
let errors = 0;

this.player.on('error', function() {
errors++;
});
this.player.src(sources);
this.player.trigger('play');

// reinitialise while playing
this.player.errors();

this.clock.tick(45 * 1000);

assert.strictEqual(errors, 1, 'emitted an error');
assert.strictEqual(this.player.error().code, -2, 'error code is -2');
assert.strictEqual(this.player.error().type, 'PLAYER_ERR_TIMEOUT');
});

// safari 7 on OSX can emit stalls when playback is just fine
QUnit.test('stalling by itself is not an error', function(assert) {
this.player.src(sources);
Expand Down

0 comments on commit af868ed

Please sign in to comment.