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

Adding vtt.js's exports to window breaks addCue in Chrome #4093

Closed
justinanastos opened this issue Feb 15, 2017 · 10 comments
Closed

Adding vtt.js's exports to window breaks addCue in Chrome #4093

justinanastos opened this issue Feb 15, 2017 · 10 comments

Comments

@justinanastos
Copy link
Contributor

Description

In tech.js#addWebVttScript_, all of the exports from vtt.js are blindly added to window. This will break the ability to call Chrome's native TextTrack.prototype.addCue() because Chrome expects an instance of it's native VTTCue and not the vtt.js version.

This will effect all use cases of calling textTrack.addCue(). I found the issue while trying to restore text track functionality to videojs-contrib-dash in videojs/videojs-contrib-dash#135. The details of the error can be seen specifically in this comment videojs/videojs-contrib-dash#135 (comment).

Reduced Test Case

http://jsbin.com/tomegu/7/edit?html,js,output

The console will show the error thrown.

Results

Expected

I expect TextTrack.addCue(new VTTCue( ... )) to add cues.

Actual

Chrome will throw an error, shown below.

Error output

Uncaught TypeError: Failed to execute 'addCue' on 'TextTrack': parameter 1 is not of type 'TextTrackCue'.

Additional Information

versions

videojs

I haven't checked any versions besides v5.16, but the same code exists in master so I assume all of the version.

browsers

Chrome

OSes

Only tested on MacOS 10.12.3 (latest as of this writing)

plugins

None

Resolution

I propose that only values that do not exist on window are defined when iterating through vtt.js's exports.

This reduced test case shows a cue being added as expected when using the native VTTCue in Chrome.

http://jsbin.com/yelizon/5/edit?html,js,output

@gkatsev
Copy link
Member

gkatsev commented Feb 16, 2017

Yeah, that sounds like an issue. Historically, we haven't needed to handle this because either native tracks or emulated tracks would be used. The current proposed fix, unfortunately, will break emulated caption support, at least with the current version of vttjs that we're using. If it doesn't, let me know I'm wrong!
We already have an issue for updating vttjs (#3819) and we recently updated how vttjs is included. However, it seems like we need to spend some more time on this, potentially making vttjs be much more contained within tracks.

@justinanastos
Copy link
Contributor Author

justinanastos commented Feb 16, 2017

@gkatsev I'm minimally versed with emulated captions so please forgive the naive question: why would this break it? Is the shimmed VTTCue from vtt.js adding some functionality that doesn't exist natively anywhere?


Edit: Added anywhere to the end.

@gkatsev
Copy link
Member

gkatsev commented Feb 16, 2017

I believe that there's some extra stuff that's currently happening in there that isn't available natively for the features we support with emulated tracks. I do remember that it wasn't sufficient to use native cues at the time I implemented it. It's possible things have changed and we probably should verify. Maybe we would only want to do this for older browsers or something. Though, I think making vttjs more contained with our emulated tracks functionality sounds like a good move regardless.

@justinanastos
Copy link
Contributor Author

Thanks @gkatsev .

@gkatsev
Copy link
Member

gkatsev commented Feb 16, 2017

Thanks for looking into this @justinanastos.

@gkatsev
Copy link
Member

gkatsev commented Feb 16, 2017

I took a look today, I think the way everything is set up can be tweaked to fix the issue and also do it as a minor (so we can fix it in 5.x as well). I'll be working on this some more tomorrow.

@justinanastos
Copy link
Contributor Author

Awesome, any way I can help @gkatsev ?

@gkatsev
Copy link
Member

gkatsev commented Feb 17, 2017

I'll ping you when I have something ready to test, thanks @justinanastos.

@gkatsev
Copy link
Member

gkatsev commented Feb 21, 2017

@justinanastos hey, I have a PR open against our vttjs fork with updates (videojs/vtt.js#7), I also published it as a beta tag on npm [email protected]. If you can give it a shot, that would be awesome.

@gkatsev gkatsev mentioned this issue Feb 21, 2017
@gkatsev
Copy link
Member

gkatsev commented Feb 21, 2017

Just realized that we needed an extra piece here: #4115. Please try out that branch, it's currently including the pre-release of vttjs in the PR.

gkatsev added a commit that referenced this issue Feb 27, 2017
Update videojs-vtt.js and don't auto-export its versions of VTTCue globally.
When our TextTrack object is given a cue, if it's a native cue, wrap it in our emulated vttjs.VTTCue.

Fixes #4093.
gkatsev added a commit that referenced this issue Feb 27, 2017
Update videojs-vtt.js and don't auto-export its versions of VTTCue globally.
When our TextTrack object is given a cue, if it's a native cue, wrap it in our emulated vttjs.VTTCue.

Fixes #4093.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Feb 28, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 4, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 4, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 4, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 14, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 14, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 14, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 14, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
justinanastos added a commit to justinanastos/videojs-contrib-dash that referenced this issue Apr 14, 2017
The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.
forbesjo pushed a commit to videojs/videojs-contrib-dash that referenced this issue May 11, 2017
* Use dash controlled text tracks

As of video.js v5.14, video.js no longer supports native
subtitles on anything besides Safari. For Chrome, this means
there is *no* subtitle support with mpeg-dash. This will wait for
dash.js to load all the text tracks and then add them to video.js
if we're using a version that does not attempt to use native
subtitles. When the video.js menu is used to change captions,
we'll set the corresponding active text track in dash.

We *cannot* dynamically add text track cues to video.js beacuse
fragmented text tracks are loaded on the fly and there's no event
fired when they are loaded. Therefore, we must has dash to
natively display captions.

* Update README.md to describe `nativeCaptions` usage requirements

* Require [email protected]

The v5.18.0 release of video.js includes a fix for videojs/video.js#4093 with videojs/video.js#4131. This is neccessary for text tracks to work in Chrome.

* fixup! Use dash controlled text tracks

- Only set `textTrack.mode` for `captions` and `subtitles.
- Don't call the initial `updateActiveDashTextTrack` until after
  the `textTrack.mode`s have been set.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants