From a34ca5c380b4105354cb6a725aa98352dce60e58 Mon Sep 17 00:00:00 2001 From: MichaelSweden Date: Sat, 4 May 2024 14:56:15 +0200 Subject: [PATCH 1/2] fix: Make UITextDisplayer constructor backward compatible 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 --- lib/text/ui_text_displayer.js | 6 +++++- test/text/ui_text_displayer_unit.js | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index 95d5f6c4fd..8f659cf5fd 100644 --- a/lib/text/ui_text_displayer.js +++ b/lib/text/ui_text_displayer.js @@ -65,12 +65,16 @@ shaka.text.UITextDisplayer = class { this.videoContainer_.appendChild(this.textContainer_); + /** @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); + }); }); From 142935c007a9ab8e16e63d84df2c68071379c161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Velad=20Galva=CC=81n?= Date: Mon, 6 May 2024 09:21:29 +0200 Subject: [PATCH 2/2] Add deprecate message --- lib/text/ui_text_displayer.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index 8f659cf5fd..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,6 +66,12 @@ 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;