Skip to content

Commit

Permalink
use resizeObserver when available for resizing captions (#3437)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcunat committed Oct 21, 2020
1 parent 2d147d4 commit 4961649
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/streaming/text/TextTracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function TextTracks() {
fullscreenAttribute,
displayCCOnTop,
previousISDState,
topZIndex;
topZIndex,
resizeObserver;

function setup() {
logger = Debug(context).getInstance().getLogger(instance);
Expand Down Expand Up @@ -537,7 +538,14 @@ function TextTracks() {

if (track && track.renderingType === 'html') {
checkVideoSize.call(this, track, true);
videoSizeCheckInterval = setInterval(checkVideoSize.bind(this, track), 500);
if (window.ResizeObserver) {
resizeObserver = new window.ResizeObserver(() => {
checkVideoSize.call(this, track, true);
});
resizeObserver.observe(videoModel.getElement());
} else {
videoSizeCheckInterval = setInterval(checkVideoSize.bind(this, track), 500);
}
}
}

Expand Down Expand Up @@ -593,6 +601,10 @@ function TextTracks() {
clearInterval(videoSizeCheckInterval);
videoSizeCheckInterval = null;
}
if (resizeObserver && videoModel) {
resizeObserver.unobserve(videoModel.getElement());
resizeObserver = null;
}
currentTrackIdx = -1;
clearCaptionContainer.call(this);
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/streaming.text.TextController.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ describe('TextController', function () {
}
};
}
if (typeof window === 'undefined') {
global.window = {};
}
});

afterEach(function () {
if (typeof window !== 'undefined' && global !== window) {
delete global.document;
}
delete global.window;
});

beforeEach(function () {
Expand Down

0 comments on commit 4961649

Please sign in to comment.