Skip to content

Commit

Permalink
fix: Remove useless deprecation in UITextDisplayer and add some guard…
Browse files Browse the repository at this point in the history
…s in SimpleTextDisplayer (#7805)

Fixes #7803
  • Loading branch information
avelad authored Dec 24, 2024
1 parent ae34b68 commit fd78ec4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
3 changes: 1 addition & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -6554,9 +6554,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
const Platform = shaka.util.Platform;
if (this.videoContainer_ &&
(!Platform.safariVersion() || document.fullscreenEnabled)) {
const latestConfig = this.getConfiguration();
return new shaka.text.UITextDisplayer(
this.video_, this.videoContainer_, latestConfig.textDisplayer);
this.video_, this.videoContainer_);
} else {
// eslint-disable-next-line no-restricted-syntax
if (HTMLMediaElement.prototype.addTextTrack) {
Expand Down
10 changes: 9 additions & 1 deletion lib/text/simple_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ shaka.text.SimpleTextDisplayer = class {
* @export
*/
append(cues) {
if (!this.textTrack_) {
return;
}
const flattenedCues = shaka.text.Utils.getCuesToFlatten(cues);

// Convert cues.
Expand Down Expand Up @@ -178,6 +181,9 @@ shaka.text.SimpleTextDisplayer = class {
* @export
*/
isTextVisible() {
if (!this.textTrack_) {
return false;
}
return this.textTrack_.mode == 'showing';
}

Expand All @@ -186,7 +192,9 @@ shaka.text.SimpleTextDisplayer = class {
* @export
*/
setTextVisibility(on) {
this.textTrack_.mode = on ? 'showing' : 'hidden';
if (this.textTrack_) {
this.textTrack_.mode = on ? 'showing' : 'hidden';
}
}

/**
Expand Down
16 changes: 2 additions & 14 deletions lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
goog.provide('shaka.text.UITextDisplayer');

goog.require('goog.asserts');
goog.require('shaka.Deprecate');
goog.require('shaka.log');
goog.require('shaka.text.Cue');
goog.require('shaka.text.CueRegion');
Expand All @@ -31,9 +30,8 @@ shaka.text.UITextDisplayer = class {
* Constructor.
* @param {HTMLMediaElement} video
* @param {HTMLElement} videoContainer
* @param {shaka.extern.TextDisplayerConfiguration} config
*/
constructor(video, videoContainer, config) {
constructor(video, videoContainer) {
goog.asserts.assert(videoContainer, 'videoContainer should be valid.');

if (!document.fullscreenEnabled) {
Expand Down Expand Up @@ -74,22 +72,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;

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

/**
* Maps cues to cue elements. Specifically points out the wrapper element of
Expand Down
4 changes: 1 addition & 3 deletions test/test/util/layout_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ shaka.test.DomTextLayoutTests = class extends shaka.test.TextLayoutTests {
/** @override */
recreateTextDisplayer() {
this.textDisplayer = new shaka.text.UITextDisplayer(
/** @type {!HTMLMediaElement} */(this.mockVideo),
this.videoContainer,
{captionsUpdatePeriod: 0.25});
/** @type {!HTMLMediaElement} */(this.mockVideo), this.videoContainer);
this.textDisplayer.setTextVisibility(true);
}

Expand Down
3 changes: 1 addition & 2 deletions test/text/ui_text_displayer_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ describe('UITextDisplayer', () => {

beforeEach(() => {
video.currentTime = 0;
textDisplayer = new shaka.text.UITextDisplayer(
video, videoContainer, {captionsUpdatePeriod: 0.25});
textDisplayer = new shaka.text.UITextDisplayer(video, videoContainer);
});

afterEach(async () => {
Expand Down

0 comments on commit fd78ec4

Please sign in to comment.