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

fix: TextTrackMenuItem components should not disable text tracks of different kind(s). #5741

Merged
merged 4 commits into from
Jan 10, 2019

Conversation

misteroneill
Copy link
Member

Description

While investigating a non-public issue, I happened to notice that metadata tracks were being disabled when switching captions languages. Upon investigation, I found this code, which is the culprit. It will disable any track that's not the selected track.

Specific Changes proposed

Instead of disabling all tracks when switching, only disable tracks of the appropriate kind(s).

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Unit Tests updated or fixed
  • Reviewed by Two Core Contributors

super.handleClick(event);

if (!tracks) {
return;
}

// Determine the relevant kind(s) of tracks for this component.
const kinds = (referenceTrack.kinds || [referenceTrack.kind]).filter(Boolean);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be good to note that we also filter out any invalid kinds in a comment.


// If this text track is the component's track and it is not showing,
// set it to showing.
if (track === referenceTrack) {
if (track.mode !== 'showing') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it belongs in the setter for mode in TextTrack if its not already there. Not that we have to change it in this pr.

Copy link
Member

Choose a reason for hiding this comment

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

it's theoretically possible (and maybe eventually we will) to have multiple tracks enabled at the same time, while we disallow it via the UI, we shouldn't limit it if people want to enable multiple items directly via the API.

Copy link
Member

Choose a reason for hiding this comment

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

it's possible I misread your comment. Do you mean verifying that if we set the mode to the same thing it'll be a no-op?

super.handleClick(event);

if (!tracks) {
return;
}

// Determine the relevant kind(s) of tracks for this component.
const kinds = (referenceTrack.kinds || [referenceTrack.kind]).filter(Boolean);
Copy link
Contributor

Choose a reason for hiding this comment

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

After looking at the tests I was going to suggest that we add a tests for a track with multiple kinds. Then I looked at the HTML5 video spec and our track implementation and it seems like kinds isn't actually a thing. Only kind should ever exist. Perhaps we can keep it for now but add some code about deprecating this usage?

Copy link
Member

Choose a reason for hiding this comment

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

kinds is a thing that was added for the combined subtitles/captions menu, it should be considered an implementation detail and not used outside of Video.js internals.

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, it might have been good to name it in a way that was more obviously an implementation detail because that confused me at first, too. Oh well.

@brandonocasey
Copy link
Contributor

also I chuckled at the TDD commit 👍

@gkatsev
Copy link
Member

gkatsev commented Jan 9, 2019

protip: push the test without the change first to see it fail 🙂


QUnit.module('TextTrackMenuItem', {
beforeEach(assert) {
this.clock = sinon.useFakeTimers();
Copy link
Member

Choose a reason for hiding this comment

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

is clock used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't seem so. Copy/paste!


const foo = this.player.addTextTrack('captions', 'foo', 'en');

const fooItem = new TextTrackMenuItem(this.player, {
Copy link
Member

Choose a reason for hiding this comment

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

this isn't cleaned up/disposed.

Copy link
Member

Choose a reason for hiding this comment

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

fooItem and barItem below aren't cleaned up either.

Copy link
Member Author

Choose a reason for hiding this comment

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

Won't they be disposed with the player in the afterEach?

Copy link
Member

Choose a reason for hiding this comment

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

this object is never added to a menu/the player, so it won't get disposed automatically. It's probably not a huge deal but best to clean up as much as we can to reduce any potential memory leak issues with tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, right.

@misteroneill
Copy link
Member Author

It is a separate commit, but you can trust me that it failed. 😉

@gkatsev gkatsev added this to the 7.4.x milestone Jan 10, 2019
@gkatsev
Copy link
Member

gkatsev commented Jan 10, 2019

I can confirm that tests pass :)

@gkatsev
Copy link
Member

gkatsev commented Jan 10, 2019

Also, tested it locally and works great.

@gkatsev gkatsev merged commit b27f713 into master Jan 10, 2019
@gkatsev gkatsev deleted the fix/off-captions branch January 10, 2019 19:24
gkatsev pushed a commit that referenced this pull request Jan 10, 2019
gkatsev pushed a commit that referenced this pull request May 24, 2019
gkatsev pushed a commit to gkatsev/video.js that referenced this pull request Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants