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

feat(VttLoader): a better way of loading vtt.js #4258

Closed
wants to merge 15 commits into from
Closed

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Apr 5, 2017

This is the first commit in that feature. Still needs to be exposed
properly on video.js. Also, vtt.js needs to be updated so that the
WebVTT object is properly available on the vttjs object in the CDN
version of the file.
Afterwards, parseCues in TextTrack should be updated to use the new way
of getting vttjs.

This also means that if vttjs is being loaded via script, it won't load until a player is initialized and it is using a tech that requires emulated text tracks. So, if a player loads and only requests native text tracks, it won't ever try to load vttjs.
It also means that a user can disable loading of vttjs if using the novtt script by requesting that the component be unavailable.

const player = videojs('vid', {
  vttLoader: false
});

It is now exported on videojs as an object with two properties, which are functions: get and loaded.

if (videojs.vttjs.loaded()) {
  const vttjs = videojs.vttjs.get();
  /* use vttjs */
}

Todos

  • expose vttjs on videojs object as videojs.vttjs
  • add videojs hooks for vttjsloaded
    this is so because vttjs isn't really a per-player thing. The only events aren't going away but should be considered deprecated.
  • if loaded vttjs via script, check to see if it has loaded previously.
  • Tests!!!
  • port to 5.x branch

@imbcmdth @gesinger @mjneil this is the start of exporting vttjs properly.

@gkatsev
Copy link
Member Author

gkatsev commented Apr 6, 2017

This requires vttjs updated with this PR: videojs/vtt.js#12


vttjsLoadedHooks.forEach((hookFn) => hookFn(vttjs));
// we notified the listeners, now clear them out
vttjsLoadedHooks.length = 0;
Copy link
Member

Choose a reason for hiding this comment

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

So this prevents the hooks from being called multiple times? Because it seems like otherwise you'd call each hook vttjsLoadedHooks.length times.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, it's to make sue that each of the vttjsloaded hooks is only ever called the one time.


track.tech_.on('vttjsloaded', loadHandler);
track.tech_.on('vttjserror', () => {
log.error(`vttjs failed to load, stopping trying to process ${track.src}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this error is a bit hard to understand, maybe "vttjs failed to load. Unable to process ${track.src}."

Copy link
Contributor

Choose a reason for hiding this comment

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

you could even just use src here too, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably a good change, though, it's been around for a while now :P

* @fires VttLoader#vttjserror
*/
class VttLoader extends Component {
constructor(player, options, ready) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be a component or just an event target?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having it be a component gives us a lot of things for free. For example, the ability to turn off the inclusion of vttjs when using the novtt build.
There's also precedent with the MediaLoader.

*/
class VttLoader extends Component {
constructor(player, options, ready) {
const options_ = mergeOptions({createEl: false}, options);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is named settings in other places, this probably makes more sense, but for consistency we may want to do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense to change. I just copied this from MediaLoader.

* @event VttLoader#vttjsloaded
* @type {EventTarget~Event}
*/
this.trigger('vttjsloaded');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to trigger this event here? seems linke we only listen for this on tech

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we probably don't need it. I was thinking that maybe users can get the instance and listen to it but with the hooks feature it's redundant.

* @event VttLoader#vttjserror
* @type {EventTarget~Event}
*/
this.trigger('vttjserror');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to trigger this event here? seems linke we only listen for this on tech

@@ -147,6 +148,15 @@ videojs.hooks_ = {};
*/
videojs.hooks = function(type, fn) {
videojs.hooks_[type] = videojs.hooks_[type] || [];
if (fn && type === 'vttjsloaded') {
vttjsOnLoad((vttjs) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The onload function seems a bit weird in the vttjsloader module. Maybe we should just move all the logic for that here? I don't think that it would be used anywhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

it can't be outside of vttjsloader because only that module knows if and when vttjs has loaded. Keeping it there, I think, it good because it contains all (except this little bit, but this mostly deals with hooks) the things that work with loading vttjs.

@brandonocasey
Copy link
Contributor

So fas this LGTM in my tests, we will have to release videojs-vtt.js and update the package.json here to get this to work.

@brandonocasey
Copy link
Contributor

So everything except for ie8 work, I don't know if we are doing work to support ie8 anymore anyway. This LGTM if thats the case. IE8 may have broken from another change, I can't even get videos to play.

@gkatsev
Copy link
Member Author

gkatsev commented Apr 25, 2017

@brandonocasey @gesinger noticed that grunt connect isn't serving the swf up correctly anymore. If you can change the local sandbox to point to the cdn (or delete the override setting) it potentially should work, assuming that's the issue.

@gkatsev
Copy link
Member Author

gkatsev commented Mar 29, 2018

This isn't going to go in any time soon, closing.

@gkatsev gkatsev closed this Mar 29, 2018
@gkatsev gkatsev deleted the videojs-vttjs branch March 29, 2018 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants