From d564be8e8903ca1e825303a1f3c1e8369b2a5297 Mon Sep 17 00:00:00 2001 From: MichaelSweden Date: Mon, 6 May 2024 10:11:20 +0200 Subject: [PATCH] fix: Make UITextDisplayer constructor backward compatible (#6532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep constructor backward compatible with earlier that had two arguments, i.e. make the new third optional for existing applications. Fixes https://github.com/shaka-project/shaka-player/issues/6531 --------- Co-authored-by: Álvaro Velad Galván --- lib/text/ui_text_displayer.js | 13 ++++++++++++- test/text/ui_text_displayer_unit.js | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index 95d5f6c4fd..7b33c48416 100644 --- a/lib/text/ui_text_displayer.js +++ b/lib/text/ui_text_displayer.js @@ -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'); @@ -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 diff --git a/test/text/ui_text_displayer_unit.js b/test/text/ui_text_displayer_unit.js index 9464ad3e2c..ddddf3b00d 100644 --- a/test/text/ui_text_displayer_unit.js +++ b/test/text/ui_text_displayer_unit.js @@ -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); + }); });