mirror of
https://github.com/videojs/video.js.git
synced 2025-02-16 12:23:54 +02:00
refactor: player.listenForUserActivity_() (#4719)
This commit is contained in:
parent
95d7832b0e
commit
c16fedf26d
@ -2920,31 +2920,36 @@ class Player extends Component {
|
|||||||
|
|
||||||
this.setInterval(function() {
|
this.setInterval(function() {
|
||||||
// Check to see if mouse/touch activity has happened
|
// Check to see if mouse/touch activity has happened
|
||||||
if (this.userActivity_) {
|
if (!this.userActivity_) {
|
||||||
// Reset the activity tracker
|
return;
|
||||||
this.userActivity_ = false;
|
|
||||||
|
|
||||||
// If the user state was inactive, set the state to active
|
|
||||||
this.userActive(true);
|
|
||||||
|
|
||||||
// Clear any existing inactivity timeout to start the timer over
|
|
||||||
this.clearTimeout(inactivityTimeout);
|
|
||||||
|
|
||||||
const timeout = this.options_.inactivityTimeout;
|
|
||||||
|
|
||||||
if (timeout > 0) {
|
|
||||||
// In <timeout> milliseconds, if no more activity has occurred the
|
|
||||||
// user will be considered inactive
|
|
||||||
inactivityTimeout = this.setTimeout(function() {
|
|
||||||
// Protect against the case where the inactivityTimeout can trigger just
|
|
||||||
// before the next user activity is picked up by the activity check loop
|
|
||||||
// causing a flicker
|
|
||||||
if (!this.userActivity_) {
|
|
||||||
this.userActive(false);
|
|
||||||
}
|
|
||||||
}, timeout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the activity tracker
|
||||||
|
this.userActivity_ = false;
|
||||||
|
|
||||||
|
// If the user state was inactive, set the state to active
|
||||||
|
this.userActive(true);
|
||||||
|
|
||||||
|
// Clear any existing inactivity timeout to start the timer over
|
||||||
|
this.clearTimeout(inactivityTimeout);
|
||||||
|
|
||||||
|
const timeout = this.options_.inactivityTimeout;
|
||||||
|
|
||||||
|
if (timeout <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In <timeout> milliseconds, if no more activity has occurred the
|
||||||
|
// user will be considered inactive
|
||||||
|
inactivityTimeout = this.setTimeout(function() {
|
||||||
|
// Protect against the case where the inactivityTimeout can trigger just
|
||||||
|
// before the next user activity is picked up by the activity check loop
|
||||||
|
// causing a flicker
|
||||||
|
if (!this.userActivity_) {
|
||||||
|
this.userActive(false);
|
||||||
|
}
|
||||||
|
}, timeout);
|
||||||
|
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user