diff --git a/src/js/player.js b/src/js/player.js index 7e7eb22f2d..53f6c19efe 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -1294,13 +1294,22 @@ vjs.Player.prototype.userActive = function(bool){ }; vjs.Player.prototype.listenForUserActivity = function(){ - var onMouseActivity, onMouseDown, mouseInProgress, onMouseUp, - activityCheck, inactivityTimeout; + var onActivity, onMouseMove, onMouseDown, mouseInProgress, onMouseUp, + activityCheck, inactivityTimeout, lastMoveX, lastMoveY; - onMouseActivity = vjs.bind(this, this.reportUserActivity); + onActivity = vjs.bind(this, this.reportUserActivity); + + onMouseMove = function(e) { + // Prevent mousemove spamming + if(e.screenX != lastMoveX || e.screenY != lastMoveY) { + lastMoveX = e.screenX; + lastMoveY = e.screenY; + onActivity(); + } + }; onMouseDown = function() { - onMouseActivity(); + onActivity(); // For as long as the they are touching the device or have their mouse down, // we consider them active even if they're not moving their finger or mouse. // So we want to continue to update that they are active @@ -1308,24 +1317,24 @@ vjs.Player.prototype.listenForUserActivity = function(){ // Setting userActivity=true now and setting the interval to the same time // as the activityCheck interval (250) should ensure we never miss the // next activityCheck - mouseInProgress = setInterval(onMouseActivity, 250); + mouseInProgress = setInterval(onActivity, 250); }; onMouseUp = function(event) { - onMouseActivity(); + onActivity(); // Stop the interval that maintains activity if the mouse/touch is down clearInterval(mouseInProgress); }; // Any mouse movement will be considered user activity this.on('mousedown', onMouseDown); - this.on('mousemove', onMouseActivity); + this.on('mousemove', onMouseMove); this.on('mouseup', onMouseUp); // Listen for keyboard navigation // Shouldn't need to use inProgress interval because of key repeat - this.on('keydown', onMouseActivity); - this.on('keyup', onMouseActivity); + this.on('keydown', onActivity); + this.on('keyup', onActivity); // Run an interval every 250 milliseconds instead of stuffing everything into // the mousemove/touchmove function itself, to prevent performance degradation.