Skip to content

Commit

Permalink
fix(Ads): Fix unnecessary request when using VAST (#7660)
Browse files Browse the repository at this point in the history
If the URL does not have an extension, using mimeType allows us to avoid
having to make a HEAD type request
  • Loading branch information
avelad authored Nov 25, 2024
1 parent ef2c7eb commit d09cd7e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/tutorials/ad_monetization.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ adManager.addCustomInterstitial({
startTime: 10,
endTime: null,
uri: 'YOUR_URL',
mimeType: null,
isSkippable: true,
skipOffset: 10,
canJump: false,
Expand Down Expand Up @@ -136,6 +137,7 @@ player.addEventListener('timelineregionadded', (e) => {
startTime: event.startTime,
endTime: event.endTime,
uri: 'YOUR_URL',
mimeType: null,
isSkippable: false,
skipOffset: null,
skipFor: null,
Expand Down Expand Up @@ -171,6 +173,7 @@ adManager.addCustomInterstitial({
startTime: 10,
endTime: null,
uri: 'YOUR_URL',
mimeType: null,
isSkippable: true,
skipOffset: 10,
canJump: false,
Expand Down
3 changes: 3 additions & 0 deletions externs/shaka/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ shaka.extern.AdCuePoint;
* startTime: number,
* endTime: ?number,
* uri: string,
* mimeType: ?string,
* isSkippable: boolean,
* skipOffset: ?number,
* skipFor: ?number,
Expand All @@ -89,6 +90,8 @@ shaka.extern.AdCuePoint;
* @property {string} uri
* The uri of the interstitial, can be any type that
* ShakaPlayer supports (either in MSE or src=)
* @property {?string} mimeType
* The mimeType of the interstitial if known.
* @property {boolean} isSkippable
* Indicate if the interstitial is skippable.
* @property {?number} skipOffset
Expand Down
1 change: 1 addition & 0 deletions lib/ads/ad_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ shaka.ads.Utils = class {
startTime: startTime,
endTime: null,
uri: adUrl,
mimeType: media.attributes['type'] || null,
isSkippable: skipOffset != null,
skipOffset,
skipFor: null,
Expand Down
23 changes: 19 additions & 4 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ shaka.ads.InterstitialAdManager = class {
if (difference > 0 && difference <= 10) {
if (!this.preloadManagerInterstitials_.has(interstitial)) {
this.preloadManagerInterstitials_.set(
interstitial, this.player_.preload(interstitial.uri));
interstitial, this.player_.preload(
interstitial.uri,
/* startTime= */ null,
interstitial.mimeType || undefined));
}
}
}
Expand Down Expand Up @@ -333,6 +336,7 @@ shaka.ads.InterstitialAdManager = class {
startTime: region.startTime,
endTime: region.endTime,
uri: alternativeMPDUri,
mimeType: null,
isSkippable: false,
skipOffset: null,
skipFor: null,
Expand Down Expand Up @@ -416,7 +420,10 @@ shaka.ads.InterstitialAdManager = class {
if (shouldPreload) {
if (!this.preloadManagerInterstitials_.has(interstitial)) {
this.preloadManagerInterstitials_.set(
interstitial, this.player_.preload(interstitial.uri));
interstitial, this.player_.preload(
interstitial.uri,
/* startTime= */ null,
interstitial.mimeType || undefined));
}
}
}
Expand Down Expand Up @@ -779,10 +786,16 @@ shaka.ads.InterstitialAdManager = class {
if (preloadManager) {
await this.player_.load(preloadManager);
} else {
await this.player_.load(interstitial.uri);
await this.player_.load(
interstitial.uri,
/* startTime= */ null,
interstitial.mimeType || undefined);
}
} else {
await this.player_.load(interstitial.uri);
await this.player_.load(
interstitial.uri,
/* startTime= */ null,
interstitial.mimeType || undefined);
}
if (interstitial.playoutLimit) {
if (playoutLimitTimer) {
Expand Down Expand Up @@ -912,6 +925,7 @@ shaka.ads.InterstitialAdManager = class {
startTime,
endTime,
uri,
mimeType: null,
isSkippable,
skipOffset,
skipFor,
Expand Down Expand Up @@ -964,6 +978,7 @@ shaka.ads.InterstitialAdManager = class {
startTime,
endTime,
uri: asset['URI'],
mimeType: null,
isSkippable,
skipOffset,
skipFor,
Expand Down

0 comments on commit d09cd7e

Please sign in to comment.