Skip to content

Commit

Permalink
Reset the cached clientRect when media is attached (video-dev#5070)
Browse files Browse the repository at this point in the history
* Reset the cached clientRect when media is attached

* Add test for capLevelToPlayerSize event order independence
  • Loading branch information
littlespex authored Nov 29, 2022
1 parent d785f03 commit 4f01724
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/controller/cap-level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class CapLevelController implements ComponentAPI {
data: MediaAttachingData
) {
this.media = data.media instanceof HTMLVideoElement ? data.media : null;
this.clientRect = null;
}

protected onManifestParsed(
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/controller/cap-level-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,34 @@ describe('CapLevelController', function () {
expect(capLevelController.mediaWidth).to.equal(1280 * pixelRatio);
expect(capLevelController.mediaHeight).to.equal(720 * pixelRatio);
});

it('gets valid width and height when the media element is attached after onManifestParsed', function () {
hls = new Hls({ capLevelToPlayerSize: true });
capLevelController = new CapLevelController(hls);
capLevelController.onManifestParsed(Events.MANIFEST_PARSED, {
levels,
});

let bounds = capLevelController.getDimensions();
expect(bounds.width).to.equal(0);
expect(bounds.height).to.equal(0);
expect(capLevelController.mediaWidth).to.equal(0);
expect(capLevelController.mediaHeight).to.equal(0);

media.style.width = '1280px';
media.style.height = '720px';
document.querySelector('#test-fixture').appendChild(media);
capLevelController.onMediaAttaching(Events.MEDIA_ATTACHING, {
media,
});

const pixelRatio = capLevelController.contentScaleFactor;
bounds = capLevelController.getDimensions();
expect(bounds.width).to.equal(1280);
expect(bounds.height).to.equal(720);
expect(capLevelController.mediaWidth).to.equal(1280 * pixelRatio);
expect(capLevelController.mediaHeight).to.equal(720 * pixelRatio);
});
});

describe('initialization', function () {
Expand Down

0 comments on commit 4f01724

Please sign in to comment.