-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
refactor player.userActive() #4716
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,6 +318,9 @@ class Player extends Component { | |
// Init state hasStarted_ | ||
this.hasStarted_ = false; | ||
|
||
// Init state userActive_ | ||
this.userActive_ = false; | ||
|
||
// if the global option object was accidentally blown away by | ||
// someone, bail early with an informative error | ||
if (!this.options_ || | ||
|
@@ -2774,53 +2777,43 @@ class Player extends Component { | |
* The current value of userActive when getting | ||
*/ | ||
userActive(bool) { | ||
if (bool !== undefined) { | ||
bool = !!bool; | ||
if (bool !== this.userActive_) { | ||
this.userActive_ = bool; | ||
if (bool) { | ||
// If the user was inactive and is now active we want to reset the | ||
// inactivity timer | ||
this.userActivity_ = true; | ||
this.removeClass('vjs-user-inactive'); | ||
this.addClass('vjs-user-active'); | ||
/** | ||
* @event Player#useractive | ||
* @type {EventTarget~Event} | ||
*/ | ||
this.trigger('useractive'); | ||
} else { | ||
// We're switching the state to inactive manually, so erase any other | ||
// activity | ||
this.userActivity_ = false; | ||
|
||
// Chrome/Safari/IE have bugs where when you change the cursor it can | ||
// trigger a mousemove event. This causes an issue when you're hiding | ||
// the cursor when the user is inactive, and a mousemove signals user | ||
// activity. Making it impossible to go into inactive mode. Specifically | ||
// this happens in fullscreen when we really need to hide the cursor. | ||
// | ||
// When this gets resolved in ALL browsers it can be removed | ||
// https://code.google.com/p/chromium/issues/detail?id=103041 | ||
if (this.tech_) { | ||
this.tech_.one('mousemove', function(e) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
}); | ||
} | ||
if (bool === undefined) { | ||
return this.userActive_; | ||
} | ||
|
||
this.removeClass('vjs-user-active'); | ||
this.addClass('vjs-user-inactive'); | ||
/** | ||
* @event Player#userinactive | ||
* @type {EventTarget~Event} | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to preserve these JSDoc blocks. |
||
this.trigger('userinactive'); | ||
} | ||
} | ||
if (bool === this.userActive_) { | ||
return; | ||
} | ||
|
||
this.userActive_ = bool; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should cast this to a boolean like previously to make sure that things don't break silently |
||
|
||
if (this.userActive_) { | ||
this.userActivity_ = true; | ||
this.removeClass('vjs-user-inactive'); | ||
this.addClass('vjs-user-active'); | ||
this.trigger('useractive'); | ||
return; | ||
} | ||
return this.userActive_; | ||
|
||
// Chrome/Safari/IE have bugs where when you change the cursor it can | ||
// trigger a mousemove event. This causes an issue when you're hiding | ||
// the cursor when the user is inactive, and a mousemove signals user | ||
// activity. Making it impossible to go into inactive mode. Specifically | ||
// this happens in fullscreen when we really need to hide the cursor. | ||
// | ||
// When this gets resolved in ALL browsers it can be removed | ||
// https://code.google.com/p/chromium/issues/detail?id=103041 | ||
if (this.tech_) { | ||
this.tech_.one('mousemove', function(e) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
}); | ||
} | ||
|
||
this.userActivity_ = false; | ||
this.removeClass('vjs-user-active'); | ||
this.addClass('vjs-user-inactive'); | ||
this.trigger('userinactive'); | ||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to preserve these JSDoc blocks.