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
|
// Add playback rate selection by adding rates
|
||||||
// 'playbackRates': [0.5, 1, 1.5, 2],
|
// 'playbackRates': [0.5, 1, 1.5, 2],
|
||||||
|
|
||||||
|
// default inactivity timeout
|
||||||
|
'inactivityTimeout': 2000,
|
||||||
|
|
||||||
// Included control sets
|
// Included control sets
|
||||||
'children': {
|
'children': {
|
||||||
'mediaLoader': {},
|
'mediaLoader': {},
|
||||||
|
@ -1502,16 +1502,19 @@ vjs.Player.prototype.listenForUserActivity = function(){
|
|||||||
// Clear any existing inactivity timeout to start the timer over
|
// Clear any existing inactivity timeout to start the timer over
|
||||||
clearTimeout(inactivityTimeout);
|
clearTimeout(inactivityTimeout);
|
||||||
|
|
||||||
// In X seconds, if no more activity has occurred the user will be
|
var timeout = this.options()['inactivityTimeout'];
|
||||||
// considered inactive
|
if (timeout > 0) {
|
||||||
inactivityTimeout = setTimeout(vjs.bind(this, function() {
|
// In <timeout> milliseconds, if no more activity has occurred the
|
||||||
// Protect against the case where the inactivityTimeout can trigger just
|
// user will be considered inactive
|
||||||
// before the next user activity is picked up by the activityCheck loop
|
inactivityTimeout = setTimeout(vjs.bind(this, function () {
|
||||||
// causing a flicker
|
// Protect against the case where the inactivityTimeout can trigger just
|
||||||
if (!this.userActivity_) {
|
// before the next user activity is picked up by the activityCheck loop
|
||||||
this.userActive(false);
|
// causing a flicker
|
||||||
}
|
if (!this.userActivity_) {
|
||||||
}), 2000);
|
this.userActive(false);
|
||||||
|
}
|
||||||
|
}), timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}), 250);
|
}), 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('controls'), '', 'controls attribute was set properly');
|
||||||
equal(el.getAttribute('webkit-playsinline'), '', 'webkit-playsinline 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