Skip to content

Commit 6a2b02a

Browse files
Álvaro Velad Galvánjoeyparrish
authored andcommitted
fix(ads): Add ResizeObserver to CS ad manager. (#3652)
Closes: #3638
1 parent 9920453 commit 6a2b02a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/ads/client_side_ad_manager.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ shaka.ads.ClientSideAdManager = class {
3232
/** @private {HTMLMediaElement} */
3333
this.video_ = video;
3434

35+
/** @private {ResizeObserver} */
36+
this.resizeObserver_ = null;
37+
3538
/** @private {number} */
3639
this.requestAdsStartTime_ = NaN;
3740

@@ -176,6 +179,16 @@ shaka.ads.ClientSideAdManager = class {
176179
this.video_.offsetHeight, viewMode);
177180
});
178181

182+
if ('ResizeObserver' in window) {
183+
this.resizeObserver_ = new ResizeObserver(() => {
184+
const viewMode = document.fullscreenElement ?
185+
google.ima.ViewMode.FULLSCREEN : google.ima.ViewMode.NORMAL;
186+
this.imaAdsManager_.resize(this.video_.offsetWidth,
187+
this.video_.offsetHeight, viewMode);
188+
});
189+
this.resizeObserver_.observe(this.video_);
190+
}
191+
179192
// Single video and overlay ads will start at this time
180193
// TODO (ismena): Need a better inderstanding of what this does.
181194
// The docs say it's called to 'start playing the ads,' but I haven't

0 commit comments

Comments
 (0)