-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Conversation
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 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; |
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.
So this prevents the hooks from being called multiple times? Because it seems like otherwise you'd call each hook vttjsLoadedHooks.length
times.
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.
Yup, it's to make sue that each of the vttjsloaded
hooks is only ever called the one time.
src/js/tracks/text-track.js
Outdated
|
||
track.tech_.on('vttjsloaded', loadHandler); | ||
track.tech_.on('vttjserror', () => { | ||
log.error(`vttjs failed to load, stopping trying to process ${track.src}`); |
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.
I think this error is a bit hard to understand, maybe "vttjs failed to load. Unable to process ${track.src}."
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.
you could even just use src
here too, I think.
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.
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) { |
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.
should this be a component or just an event target?
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.
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.
src/js/tracks/vtt.js
Outdated
*/ | ||
class VttLoader extends Component { | ||
constructor(player, options, ready) { | ||
const options_ = mergeOptions({createEl: false}, options); |
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.
I think this is named settings
in other places, this probably makes more sense, but for consistency we may want to do that.
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.
Makes sense to change. I just copied this from MediaLoader.
src/js/tracks/vtt.js
Outdated
* @event VttLoader#vttjsloaded | ||
* @type {EventTarget~Event} | ||
*/ | ||
this.trigger('vttjsloaded'); |
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.
Do we want to trigger this event here? seems linke we only listen for this on tech
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.
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.
src/js/tracks/vtt.js
Outdated
* @event VttLoader#vttjserror | ||
* @type {EventTarget~Event} | ||
*/ | ||
this.trigger('vttjserror'); |
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.
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) => { |
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.
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.
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.
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.
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. |
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. |
@brandonocasey @gesinger noticed that |
This isn't going to go in any time soon, closing. |
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.
It is now exported on
videojs
as an object with two properties, which are functions:get
andloaded
.Todos
videojs.vttjs
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.
@imbcmdth @gesinger @mjneil this is the start of exporting vttjs properly.