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

move timeout back into parseCues #3181

Closed
wants to merge 14 commits into from

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Mar 15, 2016

Description

Make sure that vttjs has finished loading before proceeding with parsing cues.

Specific Changes proposed

Specifically, move the code that does a setTimeout from loadTrack back into parseCues. Make parseCues into an asynchronous loop waiting till vttjs has loaded.

Requirements Checklist

  • Feature implemented / Bug fixed
  • Reviewed by one Core Contributors

@gkatsev
Copy link
Member Author

gkatsev commented Mar 15, 2016

Going to see if I can add a test for this so it won't happen again :)

@gkatsev
Copy link
Member Author

gkatsev commented Mar 15, 2016

@chemoish can you review this one? You probably know the most about how tracks load next to me.

@gkatsev gkatsev added patch This PR can be added to a patch release. needs: LGTM Needs one or more additional approvals labels Mar 15, 2016
@chemoish
Copy link
Member

Does video.js have pub sub or anything we can leverage to listen to events?

I would prefer…

if (!window['WebVTT'] && this.el().parentNode != null) {
  let script = document.createElement('script');
  script.src = this.options_['vtt.js'] || '../node_modules/videojs-vtt.js/dist/vtt.js';
  script.onload = function () {
    console.log('load vtt.js');
  };
  this.el().parentNode.appendChild(script);
  window['WebVTT'] = true;
}

Instead of having a setTimeout.


Also, can't remember the influence of…

// NOTE: this is only used for the alt/video.novtt.js build


Also, should it be pointing to vtt.min.js?

// Make sure that vttjs has loaded, otherwise, wait till it finished loading
// NOTE: this is only used for the alt/video.novtt.js build
if (typeof window.WebVTT !== 'function') {
return window.setTimeout(function() {
Copy link
Member

Choose a reason for hiding this comment

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

If window.WebVTT never loads, this is infinite loop?

script.src = this.options_['vtt.js'] || '../node_modules/videojs-vtt.js/dist/vtt.js'; still seems fragile (hence the question).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it would. It should have a retry count, I guess.
Maybe changing it to send an event we can listen to is a better way of doing it, I'll see if I can do it quickly, I'd like to get this change in as quickly as possible.

@chemoish
Copy link
Member

@gkatsev since this is a patch I am ok with this going in and fixing it later to support retry or pubsub.

I didn't step through the tests, but LGTM.

return window.setTimeout(function() {
parseCues(srcContent, track, retry);
}, 100);
}
Copy link
Member

Choose a reason for hiding this comment

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

Is 400ms enough time to wait? Is there any guarantee that will be enough time on slow connections or heavily loaded pages?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure, I guess on really slow pages or really slow connections, it will die.
Maybe we want up to 10 retries?

Copy link
Member

Choose a reason for hiding this comment

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

Add // TODO: listen to onload event or similar (:

Copy link
Member Author

Choose a reason for hiding this comment

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

I could also have it do incremental back-off, 100 for first, 200 for second, 400 for 3rd, 800 for second. Total would be 1.5s.
Assuming we don't just do the onload.

Copy link
Member Author

Choose a reason for hiding this comment

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

@chemoish looks like it's not as urgent as other things, so, I'll spend time making it wait for vttjs to load instead of retrying :)

@gkatsev
Copy link
Member Author

gkatsev commented Mar 17, 2016

Updated the code to wait for the load event of the script and have loadTrack delay parseCues until such an event. What's left is to have those event handlers be removed if the script fails to load and also test updates.

let offSpyCall = testTech.off.getCall(0);

ok(errorSpyCall.calledWithMatch('vttjs failed to load, stopping trying to process'),
'we logged the correct error after 3 timeouts');
Copy link
Member

Choose a reason for hiding this comment

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

This message is outdated

@dmlap
Copy link
Member

dmlap commented Mar 17, 2016

Other than the update to the test message, LGTM

@gkatsev gkatsev added confirmed and removed needs: LGTM Needs one or more additional approvals labels Mar 17, 2016
@gkatsev gkatsev closed this in e2c8c12 Mar 17, 2016
@gkatsev gkatsev deleted the fix-vttjs-loading branch March 17, 2016 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed patch This PR can be added to a patch release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants