mirror of
https://github.com/videojs/video.js.git
synced 2024-12-27 02:43:45 +02:00
Merge branch 'issue-1408' of github.com:glencoesoftware/video.js into glencoesoftware-issue-1408
This commit is contained in:
commit
7c27add29d
@ -92,6 +92,9 @@ vjs.options = {
|
||||
// Add playback rate selection by adding rates
|
||||
// 'playbackRates': [0.5, 1, 1.5, 2],
|
||||
|
||||
// default inactivity timeout
|
||||
'inactivityTimeout': 2000,
|
||||
|
||||
// Included control sets
|
||||
'children': {
|
||||
'mediaLoader': {},
|
||||
|
@ -1502,16 +1502,19 @@ vjs.Player.prototype.listenForUserActivity = function(){
|
||||
// Clear any existing inactivity timeout to start the timer over
|
||||
clearTimeout(inactivityTimeout);
|
||||
|
||||
// In X seconds, if no more activity has occurred the user will be
|
||||
// considered inactive
|
||||
inactivityTimeout = setTimeout(vjs.bind(this, function() {
|
||||
var timeout = this.options()['inactivityTimeout'];
|
||||
if (timeout > 0) {
|
||||
// In <timeout> milliseconds, if no more activity has occurred the
|
||||
// user will be considered inactive
|
||||
inactivityTimeout = setTimeout(vjs.bind(this, function () {
|
||||
// Protect against the case where the inactivityTimeout can trigger just
|
||||
// before the next user activity is picked up by the activityCheck loop
|
||||
// causing a flicker
|
||||
if (!this.userActivity_) {
|
||||
this.userActive(false);
|
||||
}
|
||||
}), 2000);
|
||||
}), timeout);
|
||||
}
|
||||
}
|
||||
}), 250);
|
||||
|
||||
|
@ -518,3 +518,54 @@ test('should restore attributes from the original video tag when creating a new
|
||||
equal(el.getAttribute('controls'), '', 'controls attribute was set properly');
|
||||
equal(el.getAttribute('webkit-playsinline'), '', 'webkit-playsinline attribute was set properly');
|
||||
});
|
||||
|
||||
test('should honor default inactivity timeout', function() {
|
||||
var player, html5Mock;
|
||||
var clock = sinon.useFakeTimers();
|
||||
|
||||
// default timeout is 2000ms
|
||||
player = PlayerTest.makePlayer({});
|
||||
|
||||
equal(player.userActive(), true, 'User is active on creation');
|
||||
clock.tick(1800);
|
||||
equal(player.userActive(), true, 'User is still active');
|
||||
clock.tick(500);
|
||||
equal(player.userActive(), false, 'User is inactive after timeout expired');
|
||||
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
test('should honor configured inactivity timeout', function() {
|
||||
var player, html5Mock;
|
||||
var clock = sinon.useFakeTimers();
|
||||
|
||||
// default timeout is 2000ms, set to shorter 200ms
|
||||
player = PlayerTest.makePlayer({
|
||||
'inactivityTimeout': 200
|
||||
});
|
||||
|
||||
equal(player.userActive(), true, 'User is active on creation');
|
||||
clock.tick(150);
|
||||
equal(player.userActive(), true, 'User is still active');
|
||||
clock.tick(350);
|
||||
// make sure user is now inactive after 500ms
|
||||
equal(player.userActive(), false, 'User is inactive after timeout expired');
|
||||
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
test('should honor disabled inactivity timeout', function() {
|
||||
var player, html5Mock;
|
||||
var clock = sinon.useFakeTimers();
|
||||
|
||||
// default timeout is 2000ms, disable by setting to zero
|
||||
player = PlayerTest.makePlayer({
|
||||
'inactivityTimeout': 0
|
||||
});
|
||||
|
||||
equal(player.userActive(), true, 'User is active on creation');
|
||||
clock.tick(5000);
|
||||
equal(player.userActive(), true, 'User is still active');
|
||||
|
||||
clock.restore();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user