-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
"@babel/preset-env", { | ||
"targets": { | ||
"ie": 11 |
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.
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 = { |
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.
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(){ |
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 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(){ |
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 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 = {}) { |
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.
Does this update the entry in this.textTracks
? If not, should this function be renamed?
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.
Yes, the matched object reference from this.textTracks
will be updated.
wrapper.setClosedCaptions(language, closedCaptions, params); | ||
element.textTracks.onaddtrack(); |
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 have a listener for onaddtrack in our video plugin? I'm just curious how this is used for the unit tests.
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 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()) { |
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.
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.
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.
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) => |
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.
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.
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.
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
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.
Nope, I'm good. This is fine
let isFound = true; | ||
|
||
for (let property in searchOptions) { | ||
if (searchOptions[property] !== currentTrack[property]) { |
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 need to do any hasOwnProperty
checks?
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.
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) { |
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.
What happens if the trackMetadata isn't found?
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 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
LGTM |
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.
LGTM
Rewrote most of the closed captions implementation from scratch. The main issues that were addressed by these changes are the following:
These changes will also fix the following:
setClosedCaptions
setClosedCaptions
and when pausing and then resumingNote: I will create a separate PR for new unit tests, for now I only fixed the existing ones.