Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Patch for video.js to prevent mousemove spam #331

Merged
merged 1 commit into from

4 participants

@download13

On certain platforms (including node-webkit on Windows7 64-bit it seems) mousemove events are spammed whether or not the mouse has actually moved. This prevents the video player UI from being hidden since it always thinks the user is moving the mouse.

This is a patch for video.js that filters out the false mousemove events. I've already sent it as a PR to the video.js people, but until they make a decision this is a stopgap measure.

I'm not sure what causes it. Someone on StackExchange said that Webkit firing phantom mousemove events might have something to do with preventing a machine going into standby. The odd thing is that it only happens when the cursor is positioned over certain content. For example, events are not fired if the cursor is positioned over the #header element when selecting a movie, but almost anywhere else will result in a constant stream of mousemoves.

The point is, this seems to fix it for now. Ideally, it should be fixed in Webkit (assuming that's where the problem is from).

@download13 download13 Patch for video.js to prevent mousemove spam
On certain platforms (including node-webkit on Windows7 64-bit it seems) mousemove events are spammed whether or not the mouse has actually moved. This prevents the video player UI from being hidden since it always thinks the user is moving the mouse.

This is a patch for video.js that filter out the false mousemove events. I've already sent it as a PR to the video.js people, but until they make a decision this is a stopgap measure.

I'm not sure what causes it. Someone on StackExchange said that Webkit firing phantom mousemove events might have something to do with preventing a machine going into standby. The odd thing is that it only happens when the cursor is positioned over certain content. For example, events are not fired if the cursor is positioned over the #header element when selecting a movie, but almost anywhere else will result in a constant stream of mousemoves.

The point is, this seems to fix it for now. Ideally, it should be fixed in Webkit (assuming that's where the problem is from).
0f368b1
@Patineta Patineta merged commit 54e0759 into popcorn-time:master
@Patineta

That's a great find! We got one report of this previously, but as it seems to happen on very specific platforms and we couldn't replicate it, this should help with that. Thanks for the fix!

@h3ku

Thanks for this, not big problem, but make this little bit perfect.

Thanks!! i was waiting for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2014
  1. @download13

    Patch for video.js to prevent mousemove spam

    download13 authored
    On certain platforms (including node-webkit on Windows7 64-bit it seems) mousemove events are spammed whether or not the mouse has actually moved. This prevents the video player UI from being hidden since it always thinks the user is moving the mouse.
    
    This is a patch for video.js that filter out the false mousemove events. I've already sent it as a PR to the video.js people, but until they make a decision this is a stopgap measure.
    
    I'm not sure what causes it. Someone on StackExchange said that Webkit firing phantom mousemove events might have something to do with preventing a machine going into standby. The odd thing is that it only happens when the cursor is positioned over certain content. For example, events are not fired if the cursor is positioned over the #header element when selecting a movie, but almost anywhere else will result in a constant stream of mousemoves.
    
    The point is, this seems to fix it for now. Ideally, it should be fixed in Webkit (assuming that's where the problem is from).
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 10 deletions.
  1. +19 −10 js/vendor/video-js/video.dev.js
View
29 js/vendor/video-js/video.dev.js
@@ -3912,13 +3912,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 = 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
@@ -3926,30 +3935,30 @@ 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(vjs.bind(this, onMouseActivity), 250);
+ mouseInProgress = setInterval(vjs.bind(this, 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);
// Consider any touch events that bubble up to be activity
// Certain touches on the tech will be blocked from bubbling because they
// toggle controls
this.on('touchstart', onMouseDown);
- this.on('touchmove', onMouseActivity);
+ this.on('touchmove', onActivity);
this.on('touchend', onMouseUp);
this.on('touchcancel', onMouseUp);
Something went wrong with that request. Please try again.