Skip to content

Commit

Permalink
feat(Ads): Populate getAdId and getMediaUrl for interstitials (#7922)
Browse files Browse the repository at this point in the history
Close #7920
  • Loading branch information
avelad authored Jan 22, 2025
1 parent 0df53d2 commit 1a6a0db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
25 changes: 13 additions & 12 deletions lib/ads/interstitial_ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ goog.provide('shaka.ads.InterstitialAd');
shaka.ads.InterstitialAd = class {
/**
* @param {HTMLMediaElement} video
* @param {boolean} isSkippable
* @param {?number} skipOffset
* @param {?number} skipFor
* @param {shaka.extern.AdInterstitial} interstitial
* @param {function()} onSkip
* @param {number} sequenceLength
* @param {number} adPosition
* @param {boolean} isUsingAnotherMediaElement
* @param {?shaka.extern.AdInterstitialOverlay} overlay
*/
constructor(video, isSkippable, skipOffset, skipFor, onSkip,
sequenceLength, adPosition, isUsingAnotherMediaElement, overlay) {
constructor(video, interstitial, onSkip, sequenceLength, adPosition,
isUsingAnotherMediaElement) {
/** @private {HTMLMediaElement} */
this.video_ = video;

/** @private {shaka.extern.AdInterstitial} */
this.interstitial_ = interstitial;

/** @private {boolean} */
this.isSkippable_ = isSkippable;
this.isSkippable_ = interstitial.isSkippable;

/** @private {?number} */
this.skipOffset_ = isSkippable ? skipOffset || 0 : skipOffset;
this.skipOffset_ = interstitial.isSkippable ?
interstitial.skipOffset || 0 : interstitial.skipOffset;

/** @private {?number} */
this.skipFor_ = skipFor;
this.skipFor_ = interstitial.skipFor;

/** @private {function()} */
this.onSkip_ = onSkip;
Expand All @@ -50,7 +51,7 @@ shaka.ads.InterstitialAd = class {
this.isUsingAnotherMediaElement_ = isUsingAnotherMediaElement;

/** @private {?shaka.extern.AdInterstitialOverlay} */
this.overlay_ = overlay;
this.overlay_ = interstitial.overlay;
}

/**
Expand Down Expand Up @@ -288,7 +289,7 @@ shaka.ads.InterstitialAd = class {
* @export
*/
getAdId() {
return '';
return this.interstitial_.id || '';
}

/**
Expand All @@ -312,7 +313,7 @@ shaka.ads.InterstitialAd = class {
* @export
*/
getMediaUrl() {
return null;
return this.interstitial_.uri;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ shaka.ads.InterstitialAdManager = class {
}
};

const ad = new shaka.ads.InterstitialStaticAd(sequenceLength, adPosition,
interstitial.overlay == null);
const ad = new shaka.ads.InterstitialStaticAd(
interstitial, sequenceLength, adPosition);

this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_STARTED,
Expand Down Expand Up @@ -1009,9 +1009,8 @@ shaka.ads.InterstitialAdManager = class {
};

const ad = new shaka.ads.InterstitialAd(this.video_,
interstitial.isSkippable, interstitial.skipOffset,
interstitial.skipFor, this.lastOnSkip_, sequenceLength, adPosition,
!this.usingBaseVideo_, interstitial.overlay);
interstitial, this.lastOnSkip_, sequenceLength, adPosition,
!this.usingBaseVideo_);
if (!this.usingBaseVideo_) {
ad.setMuted(this.baseVideo_.muted);
ad.setVolume(this.baseVideo_.volume);
Expand Down
13 changes: 8 additions & 5 deletions lib/ads/interstitial_static_ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ goog.provide('shaka.ads.InterstitialStaticAd');
*/
shaka.ads.InterstitialStaticAd = class {
/**
* @param {shaka.extern.AdInterstitial} interstitial
* @param {number} sequenceLength
* @param {number} adPosition
* @param {boolean} isLinear
*/
constructor(sequenceLength, adPosition, isLinear) {
constructor(interstitial, sequenceLength, adPosition) {
/** @private {shaka.extern.AdInterstitial} */
this.interstitial_ = interstitial;

/** @private {number} */
this.sequenceLength_ = sequenceLength;

/** @private {number} */
this.adPosition_ = adPosition;

/** @private {boolean} */
this.isLinear_ = isLinear;
this.isLinear_ = interstitial.overlay == null;
}

/**
Expand Down Expand Up @@ -243,7 +246,7 @@ shaka.ads.InterstitialStaticAd = class {
* @export
*/
getAdId() {
return '';
return this.interstitial_.id || '';
}

/**
Expand All @@ -267,7 +270,7 @@ shaka.ads.InterstitialStaticAd = class {
* @export
*/
getMediaUrl() {
return null;
return this.interstitial_.uri;
}

/**
Expand Down

0 comments on commit 1a6a0db

Please sign in to comment.