Skip to content

Commit

Permalink
fix(ads): Add ResizeObserver to CS ad manager. (#3652)
Browse files Browse the repository at this point in the history
Closes: #3638
  • Loading branch information
Álvaro Velad Galván authored Sep 22, 2021
1 parent 52d68a2 commit 2bdc326
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/ads/client_side_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ shaka.ads.ClientSideAdManager = class {
/** @private {HTMLMediaElement} */
this.video_ = video;

/** @private {ResizeObserver} */
this.resizeObserver_ = null;

/** @private {number} */
this.requestAdsStartTime_ = NaN;

Expand Down Expand Up @@ -180,6 +183,16 @@ shaka.ads.ClientSideAdManager = class {
this.video_.offsetHeight, viewMode);
});

if ('ResizeObserver' in window) {
this.resizeObserver_ = new ResizeObserver(() => {
const viewMode = document.fullscreenElement ?
google.ima.ViewMode.FULLSCREEN : google.ima.ViewMode.NORMAL;
this.imaAdsManager_.resize(this.video_.offsetWidth,
this.video_.offsetHeight, viewMode);
});
this.resizeObserver_.observe(this.video_);
}

// Single video and overlay ads will start at this time
// TODO (ismena): Need a better inderstanding of what this does.
// The docs say it's called to 'start playing the ads,' but I haven't
Expand Down

0 comments on commit 2bdc326

Please sign in to comment.