Skip to content

Commit

Permalink
fix: Make UITextDisplayer constructor backward compatible (#6532)
Browse files Browse the repository at this point in the history
Keep constructor backward compatible with earlier that had two
arguments, i.e. make the new third optional for existing applications.

Fixes #6531

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
  • Loading branch information
MichaelSweden and avelad committed May 6, 2024
1 parent a2f2635 commit d564be8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
goog.provide('shaka.text.UITextDisplayer');

goog.require('goog.asserts');
goog.require('shaka.Deprecate');
goog.require('shaka.text.Cue');
goog.require('shaka.text.CueRegion');
goog.require('shaka.util.Dom');
Expand Down Expand Up @@ -65,12 +66,22 @@ shaka.text.UITextDisplayer = class {

this.videoContainer_.appendChild(this.textContainer_);

if (!config || !config.captionsUpdatePeriod) {
shaka.Deprecate.deprecateFeature(5,
'UITextDisplayer w/ config',
'Please migrate to initializing UITextDisplayer with a config.');
}

/** @private {number} */
const updatePeriod = (config && config.captionsUpdatePeriod) ?
config.captionsUpdatePeriod : 0.25;

/** @private {shaka.util.Timer} */
this.captionsTimer_ = new shaka.util.Timer(() => {
if (!this.video_.paused) {
this.updateCaptions_();
}
}).tickEvery(config.captionsUpdatePeriod);
}).tickEvery(updatePeriod);

/**
* Maps cues to cue elements. Specifically points out the wrapper element of
Expand Down
7 changes: 7 additions & 0 deletions test/text/ui_text_displayer_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,11 @@ describe('UITextDisplayer', () => {

expect(videoContainer.childNodes.length).toBe(0);
});

it('Backward compatible UITextDisplayer constructor', () => {
// The third argument to UITextDisplayer constructor is new in v4.8.0.
// Test without, to support existing applications.
/** @suppress {checkTypes} */
textDisplayer = new shaka.text.UITextDisplayer(video, videoContainer);
});
});

0 comments on commit d564be8

Please sign in to comment.