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

fix: don't throttle duration change updates #4635

Merged
merged 8 commits into from Oct 31, 2017
Merged

Conversation

brandonocasey
Copy link
Contributor

@brandonocasey brandonocasey commented Sep 28, 2017

Description

Right now the durationchange event is throttled with the other two events, timeupdate and loadedmetadata. This means that only one of those events will trigger an update if they all occur within 25ms of each other.

This functionality makes sense for timeupdate or loadedmetadata as those should not indicate a time update (even though they often do).

For durationchange however it will always indicate a change in the duration, and we want to always update the display when it happens. Here is a scenario of how we could show duration incorrectly right now:

User is playing a video that has a postroll ad at the end. After the postroll ad their will be a timeupdate, and then a durationchange to signify that we are back in content. Then ended will fire, and no more events will happen.

The player will still show the duration of the ad, as the durationchange was eaten by the timeupdate that happened at nearly the same time.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though, there's a test failing.

@brandonocasey brandonocasey force-pushed the fix/duration-change branch 2 times, most recently from b31b49d to 44ab963 Compare October 20, 2017 21:17
@@ -48,7 +48,7 @@ class TimeDisplay extends Component {
'aria-live': 'off'
}, Dom.createEl('span', {
className: 'vjs-control-text',
textContent: this.localize(this.contentText_)
textContent: this.localize(this.controlText_)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a typo, I could arguable pull this into its own pr if we want, but this is one of the causes of the broken unit tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im actually not sure what is causing the failure on IE8, this must have just fixed IE9

@@ -63,7 +63,7 @@ class TimeDisplay extends Component {
* @private
*/
updateTextNode_() {
if (this.textNode_) {
if (this.textNode_ && this.contentEl_ && this.contentEl_.contains(this.textNode_)) {
this.contentEl_.removeChild(this.textNode_);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IE11 throws in request animation frames when trying to remove a DOM node from a container when the container does not have the node. Might only be an issue for our unit tests, but I fixed it here.

@brandonocasey brandonocasey added the needs: LGTM Needs an additional approval label Oct 20, 2017
const disposeFn = function() {
this.clearTimeout(timeoutId);
};
const disposeFn = () => this.clearTimeout(timeoutId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed a bit weird to me in a regular function we wouldn't have access to this.clearTimeout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we call the dispose handler with context as the component instance, so, it should have it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least, it should be. this is ok too.

const disposeFn = function() {
this.clearInterval(intervalId);
};
const disposeFn = () => this.clearInterval(intervalId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here as well

const disposeFn = function() {
this.clearTimeout(timeoutId);
};
const disposeFn = () => this.clearTimeout(timeoutId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we call the dispose handler with context as the component instance, so, it should have it.

const disposeFn = function() {
this.clearTimeout(timeoutId);
};
const disposeFn = () => this.clearTimeout(timeoutId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least, it should be. this is ok too.

return;
}

// ie8/9 don't support `el.contains` inside of setTimeout call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird

}

// ie8/9 don't support `el.contains` inside of setTimeout call.
if (this.textNode_ && this.textNode_.parentNode === this.contentEl_) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about just removing everything inside of contentEl_? It'll also fix an issue where if the page is translated in chrome using google translate, the text node will be wrapped in another element and this method will fail.
This could also just happen in a separate PR.

@@ -1239,9 +1239,7 @@ class Component {
fn = Fn.bind(this, fn);

const timeoutId = window.setTimeout(fn, timeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost commented saying that this should be changed to this.setTimeout before realizing what this line is for 😆

@gkatsev gkatsev added confirmed and removed needs: LGTM Needs an additional approval labels Oct 31, 2017
@gkatsev gkatsev merged commit 9cf9800 into master Oct 31, 2017
@gkatsev gkatsev deleted the fix/duration-change branch October 31, 2017 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants