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

[PLAYER-4216] (PR 3 of 3) MainHtml5 closed captions refactor #333

Merged
merged 25 commits into from
Sep 12, 2018

Conversation

jpfranco
Copy link
Contributor

@jpfranco jpfranco commented Sep 7, 2018

Rewrote most of the closed captions implementation from scratch. The main issues that were addressed by these changes are the following:

  • Allowing captions to be switched via the native fullscreen UI on iOS
  • Allowing captions to be turned off via the native fullscreen UI on iOS
  • Keeping the player's UI in sync with the native fullscreen UI on iOS

These changes will also fix the following:

  • In-manifest/In-stream captions for VOD will now be available on supported platforms
  • Metadata text tracks will no longer show up in the UI
  • Text tracks will no longer be removed and re-added on each call to setClosedCaptions
  • VTT files will no longer be requested on each call to setClosedCaptions and when pausing and then resuming
  • More robust handling of multi closed captions for live

Note: I will create a separate PR for new unit tests, for now I only fixed the existing ones.

"@babel/preset-env", {
"targets": {
"ie": 11
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default Babel will transpile es6 syntax but it will not automatically add polyfills for APIs such as Array.prototype.filter or Object.assign. Eventually we should look for a way to load all polyfills in the core so that they are available for all plugins without including them on each script

@@ -0,0 +1,21 @@

const CONSTANTS = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deliberately left this out of html5-common since only MainHtml5 should be concerned with these values

expect(element.textTracks[0].mode).to.eql(OO.CONSTANTS.CLOSED_CAPTIONS.SHOWING);
});

it('should replace French text tracks by English text tracks for iOS versions < 10 ', function(){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This workaround was removed so these tests are no longer relevant

@@ -607,60 +598,6 @@ describe('main_html5 wrapper tests', function () {
expect(vtc.notifyParameters).to.eql([vtc.interface.EVENTS.CLOSED_CAPTION_CUE_CHANGED, ""]);
});

it('should notify CLOSED_CAPTION_CUE_CHANGED on \'timeupdate\' event in Firefox', function(){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This Firefox workaround was removed so these tests are no longer relevant

* @param {Object} metadata An object containing the properties to be merged with the existing object
* @return {Object} The updated metadata entry or undefined if there were no matches
*/
tryUpdateEntry(searchOptions, metadata = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this update the entry in this.textTracks? If not, should this function be renamed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the matched object reference from this.textTracks will be updated.

wrapper.setClosedCaptions(language, closedCaptions, params);
element.textTracks.onaddtrack();
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 have a listener for onaddtrack in our video plugin? I'm just curious how this is used for the unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is set up on the loadedmetadata event

* @param {TextTrackMap} textTrackMap A TextTrackMap that contains metadata for all of the video's TextTrack objects.
* @return {TextTrack} The first TextTrack object that matches the given key or undefined if there are no matches.
*/
findTrackByKey(languageOrId, textTrackMap = new TextTrackMap()) {
Copy link
Contributor

@aeng7 aeng7 Sep 7, 2018

Choose a reason for hiding this comment

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

Is it possible for two text tracks to have the same exact language key (like English for hard of hearing vs English subtitles)? If so, should this return all the tracks that have that key? Also, who is using this function. I tried searching this PR for findTrackByKey and coulnd't find a usage.

Edit: Nevermind, found out that the main_html5 source was minimized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch. I will have to tweak this in order to account for that scenario. This is called by executeSetClosedCaptions btw

* @return {Boolean} True if all tracks have 'disabled' mode, false otherwise
*/
areAllDisabled() {
const allDisabled = this.textTracks.reduce((result, trackMetadata) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be simpler to iterate through the textTracks and return once a non-disabled text track is found? I think .reduce will keep iterating through the textTracks even after a non-disabled text track is found. Though this is minor all things considered since textTracks won't be large.

Copy link
Contributor Author

@jpfranco jpfranco Sep 7, 2018

Choose a reason for hiding this comment

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

Given the small size of the data set I think reduce is the way to do this with the least amount of code. I can change this if you want, but I like this one-liner

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, I'm good. This is fine

let isFound = true;

for (let property in searchOptions) {
if (searchOptions[property] !== currentTrack[property]) {
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 need to do any hasOwnProperty checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, will add this but I don't think it's strictly necessary. The class controls the object creation and if someone passes a searchOptions object that inherits from something unexpected then that in itself would be a bigger issue.

id: textTrack.label
});

if (trackMetadata) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the trackMetadata isn't found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would just mean that either all external tracks have already been mapped or the addtrack event was triggered by an in-stream track addition. This call is meant to be idempotent so that it can be executed at any point in time

@aeng7
Copy link
Contributor

aeng7 commented Sep 11, 2018

LGTM

Copy link
Contributor

@dallen42 dallen42 left a comment

Choose a reason for hiding this comment

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

LGTM

@jpfranco jpfranco merged commit c891805 into master Sep 12, 2018
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.

4 participants