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

Patch for video.js to prevent mousemove spam #331

Merged
merged 1 commit into from Mar 9, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 19 additions & 10 deletions js/vendor/video-js/video.dev.js
Expand Up @@ -3912,44 +3912,53 @@ vjs.Player.prototype.userActive = function(bool){
}; };


vjs.Player.prototype.listenForUserActivity = function(){ vjs.Player.prototype.listenForUserActivity = function(){
var onMouseActivity, onMouseDown, mouseInProgress, onMouseUp, var onActivity, onMouseMove, onMouseDown, mouseInProgress, onMouseUp,
activityCheck, inactivityTimeout; activityCheck, inactivityTimeout, lastMoveX, lastMoveY;


onMouseActivity = 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() { onMouseDown = function() {
onMouseActivity(); onActivity();
// For as long as the they are touching the device or have their mouse down, // 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. // 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 // So we want to continue to update that they are active
clearInterval(mouseInProgress); clearInterval(mouseInProgress);
// Setting userActivity=true now and setting the interval to the same time // Setting userActivity=true now and setting the interval to the same time
// as the activityCheck interval (250) should ensure we never miss the // as the activityCheck interval (250) should ensure we never miss the
// next activityCheck // next activityCheck
mouseInProgress = setInterval(vjs.bind(this, onMouseActivity), 250); mouseInProgress = setInterval(vjs.bind(this, onActivity), 250);
}; };


onMouseUp = function(event) { onMouseUp = function(event) {
onMouseActivity(); onActivity();
// Stop the interval that maintains activity if the mouse/touch is down // Stop the interval that maintains activity if the mouse/touch is down
clearInterval(mouseInProgress); clearInterval(mouseInProgress);
}; };


// Any mouse movement will be considered user activity // Any mouse movement will be considered user activity
this.on('mousedown', onMouseDown); this.on('mousedown', onMouseDown);
this.on('mousemove', onMouseActivity); this.on('mousemove', onMouseMove);
this.on('mouseup', onMouseUp); this.on('mouseup', onMouseUp);


// Listen for keyboard navigation // Listen for keyboard navigation
// Shouldn't need to use inProgress interval because of key repeat // Shouldn't need to use inProgress interval because of key repeat
this.on('keydown', onMouseActivity); this.on('keydown', onActivity);
this.on('keyup', onMouseActivity); this.on('keyup', onActivity);


// Consider any touch events that bubble up to be activity // Consider any touch events that bubble up to be activity
// Certain touches on the tech will be blocked from bubbling because they // Certain touches on the tech will be blocked from bubbling because they
// toggle controls // toggle controls
this.on('touchstart', onMouseDown); this.on('touchstart', onMouseDown);
this.on('touchmove', onMouseActivity); this.on('touchmove', onActivity);
this.on('touchend', onMouseUp); this.on('touchend', onMouseUp);
this.on('touchcancel', onMouseUp); this.on('touchcancel', onMouseUp);


Expand Down