Skip to content

Commit

Permalink
fix(Ads): Allow play interstitials on iOS fullscreen (#7538)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Nov 6, 2024
1 parent 5dea918 commit 84ae806
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ shaka.ads.InterstitialAdManager = class {
* @param {function(!shaka.util.FakeEvent)} onEvent
*/
constructor(adContainer, basePlayer, baseVideo, onEvent) {
/** @private {?shaka.extern.AdsConfiguration} */
this.config_ = null;

/** @private {HTMLElement} */
this.adContainer_ = adContainer;

Expand Down Expand Up @@ -197,11 +200,26 @@ shaka.ads.InterstitialAdManager = class {
* @param {shaka.extern.AdsConfiguration} config
*/
configure(config) {
if (!this.adContainer_ ||
this.usingBaseVideo_ != config.supportsMultipleMediaElements) {
this.config_ = config;
}

/**
* @private
*/
determineIfUsingBaseVideo_() {
if (!this.adContainer_ || !this.config_ || this.playingAd_) {
return;
}
let supportsMultipleMediaElements =
this.config_.supportsMultipleMediaElements;
const video = /** @type {HTMLVideoElement} */(this.baseVideo_);
if (video.webkitSupportsFullscreen && video.webkitDisplayingFullscreen) {
supportsMultipleMediaElements = false;
}
if (this.usingBaseVideo_ != supportsMultipleMediaElements) {
return;
}
this.usingBaseVideo_ = !config.supportsMultipleMediaElements;
this.usingBaseVideo_ = !supportsMultipleMediaElements;
if (this.usingBaseVideo_) {
this.video_ = this.baseVideo_;
if (this.adVideo_) {
Expand Down Expand Up @@ -491,6 +509,7 @@ shaka.ads.InterstitialAdManager = class {
*/
async setupAd_(interstitial, sequenceLength, adPosition, initialTime,
oncePlayed = 0) {
this.determineIfUsingBaseVideo_();
goog.asserts.assert(this.video_, 'Must have video');

this.lastPlayedAd_ = interstitial;
Expand Down Expand Up @@ -618,6 +637,7 @@ shaka.ads.InterstitialAdManager = class {
this.baseVideo_.play();
}
}
this.determineIfUsingBaseVideo_();
}
};
const error = async (e) => {
Expand Down

0 comments on commit 84ae806

Please sign in to comment.