-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Always emulated text track list #2391
Conversation
TextTrackList has a couple of event listeners that users rely on. By emulated the TextTrackList we can hopefully eliminate some of the friction that can occur during tech changes around the text track event handlers.
When switching techs, we want to clear out the old text tracks and then restore them using the currently appropriate tracks.
Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED Commit: f198faa (Please note that this is a fully automated comment.) |
I'll tackle tests next but it's working for me when switching from html to flash and back. |
@@ -86,6 +87,12 @@ class Html5 extends Tech { | |||
* @method dispose | |||
*/ | |||
dispose() { | |||
let tt = this.el().textTracks; | |||
|
|||
tt.removeEventListener('change', Fn.bind(this, this.handleTextTrackChange)); |
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.
If el().textTracks
is a native list then I don't know if the Fn.bind is going to do what you want here. The remove-by-same-id only works with our internal event listeners. The native removeEventListener still looks for the same function.
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.
Yep, you're right. I keep getting more and more output when switching techs.
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 have a fix for this locally but for some odd reason it only wants to work when I'm setting through the code for removing the old text tracks...
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, the issue seems that if we remove the event listener in the same event tick as removing the track, we don't actually get the removetrack
event. Looking at the spec, it seems like the removetrack
events are queued to fire when tracks are removed, so, it makes sense for us to miss them.
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 believe the solution in this case really is a setTimeout around the removal of tracks. Either that or create a remove handler that gets added on addtrack
and bound to a particular track which then gets removed when that particular track gets removed. But I think that solution might be too clever.
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.
Could we queue our own removetrack event in that case? Seems like handling that asynchronously could get messy when switching to the new 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.
I just realized we could probably just clean out our emulated text track list manually. However, if we remove the event listener asynchronously, it works fine too. Or, we can have the removetrack
handler be smart and get added on addtrack
and removed on removetrack
if there are no longer any text tracks (which is what I tried to describe above).
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 like the idea of something simple and less async, but whatever you think
works best.
Sent from mobile
One question around tech changes but other than that looks really good to me. |
Add event listeners in the constructor. Remove event listeners in dispose. 'removetrack' listener needs to be removed asynchronously to make sure that we get all the events that are to be triggered.
I updated things. I currently see a weird issue where when you switch back to the html5 tech, to get the non-current-locale text tracks to show, you need to select it twice. Not sure what is going on there. |
Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED Commit: 6d75a25 (Please note that this is a fully automated comment.) |
I decided to not try and do anything asynchronous and just clear out our emulated text track list manually in dispose since nothing should be coming along across the tech switch from html5->flash |
Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED Commit: 486dc45 (Please note that this is a fully automated comment.) |
@@ -178,3 +178,48 @@ test('native source handler canHandleSource', function(){ | |||
// Reset test video canPlayType | |||
Html5.TEST_VID.canPlayType = origCPT; | |||
}); | |||
|
|||
if (Html5.supportsNativeTextTracks()) { |
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.
these only run if we are using and support native text tracks, so, I'm only running the tests in those browsers as well because it'll fail otherwise.
I think I may have fixed the issue that text tracks have had with safari in this PR. |
@@ -70,6 +70,7 @@ test('dispose removes the object element even before ready fires', function() { | |||
mockFlash.off = noop; | |||
mockFlash.trigger = noop; | |||
mockFlash.el_ = {}; | |||
mockFlash.textTracks = () => ([]); |
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 what was causing the issues in safari that we're seeing in master and elsewhere.
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.
Please can we fix this? How do we fix this?
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.
Oh, you did. Sweet. :)
Actually, looks like selecting the captions twice is caused by what #2412 fixes. |
@@ -0,0 +1,47 @@ | |||
let trackToJson = function(track) { |
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.
This function and file could use an explanatory comment.
Other than my documentation comment, LGTM |
2nd dmlap. Lgtm! |
Superseded by #2425 |
Fixes #2367