Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't remove vjs-waiting until time changes #5533

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,18 @@ class Player extends Component {
* @type {EventTarget~Event}
*/
this.trigger('waiting');
this.one('timeupdate', () => this.removeClass('vjs-waiting'));

// Browsers may emit a timeupdate event after a waiting event. In order to prevent
// premature removal of the waiting class, wait for the time to change.
const timeWhenWaiting = this.currentTime();
const timeUpdateListener = () => {
if (timeWhenWaiting !== this.currentTime()) {
this.removeClass('vjs-waiting');
this.off('timeupdate', timeUpdateListener);
}
};

this.on('timeupdate', timeUpdateListener);
}

/**
Expand Down
19 changes: 16 additions & 3 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,13 +1460,26 @@ QUnit.test('player#reset loads the first item in the techOrder and then techCall
assert.equal(techCallMethod, 'reset', 'we then reset the tech');
});

QUnit.test('Remove waiting class on timeupdate after tech waiting', function(assert) {
QUnit.test('Remove waiting class after tech waiting when timeupdate shows a time change', function(assert) {
const player = TestHelpers.makePlayer();

player.currentTime = () => 1;
player.tech_.trigger('waiting');
assert.ok(/vjs-waiting/.test(player.el().className), 'vjs-waiting is added to the player el on tech waiting');
assert.ok(
/vjs-waiting/.test(player.el().className),
'vjs-waiting is added to the player el on tech waiting'
);
player.trigger('timeupdate');
assert.ok(
/vjs-waiting/.test(player.el().className),
'vjs-waiting still exists on the player el when time hasn\'t changed on timeupdate'
);
player.currentTime = () => 2;
player.trigger('timeupdate');
assert.ok(!(/vjs-waiting/).test(player.el().className), 'vjs-waiting is removed from the player el on timeupdate');
assert.notOk(
(/vjs-waiting/).test(player.el().className),
'vjs-waiting removed from the player el when time has changed on timeupdate'
);
player.dispose();
});

Expand Down