Skip to content

Commit d09cd7e

Browse files
authored
fix(Ads): Fix unnecessary request when using VAST (#7660)
If the URL does not have an extension, using mimeType allows us to avoid having to make a HEAD type request
1 parent ef2c7eb commit d09cd7e

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

docs/tutorials/ad_monetization.md

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ adManager.addCustomInterstitial({
101101
startTime: 10,
102102
endTime: null,
103103
uri: 'YOUR_URL',
104+
mimeType: null,
104105
isSkippable: true,
105106
skipOffset: 10,
106107
canJump: false,
@@ -136,6 +137,7 @@ player.addEventListener('timelineregionadded', (e) => {
136137
startTime: event.startTime,
137138
endTime: event.endTime,
138139
uri: 'YOUR_URL',
140+
mimeType: null,
139141
isSkippable: false,
140142
skipOffset: null,
141143
skipFor: null,
@@ -171,6 +173,7 @@ adManager.addCustomInterstitial({
171173
startTime: 10,
172174
endTime: null,
173175
uri: 'YOUR_URL',
176+
mimeType: null,
174177
isSkippable: true,
175178
skipOffset: 10,
176179
canJump: false,

externs/shaka/ads.js

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ shaka.extern.AdCuePoint;
6363
* startTime: number,
6464
* endTime: ?number,
6565
* uri: string,
66+
* mimeType: ?string,
6667
* isSkippable: boolean,
6768
* skipOffset: ?number,
6869
* skipFor: ?number,
@@ -89,6 +90,8 @@ shaka.extern.AdCuePoint;
8990
* @property {string} uri
9091
* The uri of the interstitial, can be any type that
9192
* ShakaPlayer supports (either in MSE or src=)
93+
* @property {?string} mimeType
94+
* The mimeType of the interstitial if known.
9295
* @property {boolean} isSkippable
9396
* Indicate if the interstitial is skippable.
9497
* @property {?number} skipOffset

lib/ads/ad_utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ shaka.ads.Utils = class {
8080
startTime: startTime,
8181
endTime: null,
8282
uri: adUrl,
83+
mimeType: media.attributes['type'] || null,
8384
isSkippable: skipOffset != null,
8485
skipOffset,
8586
skipFor: null,

lib/ads/interstitial_ad_manager.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ shaka.ads.InterstitialAdManager = class {
181181
if (difference > 0 && difference <= 10) {
182182
if (!this.preloadManagerInterstitials_.has(interstitial)) {
183183
this.preloadManagerInterstitials_.set(
184-
interstitial, this.player_.preload(interstitial.uri));
184+
interstitial, this.player_.preload(
185+
interstitial.uri,
186+
/* startTime= */ null,
187+
interstitial.mimeType || undefined));
185188
}
186189
}
187190
}
@@ -333,6 +336,7 @@ shaka.ads.InterstitialAdManager = class {
333336
startTime: region.startTime,
334337
endTime: region.endTime,
335338
uri: alternativeMPDUri,
339+
mimeType: null,
336340
isSkippable: false,
337341
skipOffset: null,
338342
skipFor: null,
@@ -416,7 +420,10 @@ shaka.ads.InterstitialAdManager = class {
416420
if (shouldPreload) {
417421
if (!this.preloadManagerInterstitials_.has(interstitial)) {
418422
this.preloadManagerInterstitials_.set(
419-
interstitial, this.player_.preload(interstitial.uri));
423+
interstitial, this.player_.preload(
424+
interstitial.uri,
425+
/* startTime= */ null,
426+
interstitial.mimeType || undefined));
420427
}
421428
}
422429
}
@@ -779,10 +786,16 @@ shaka.ads.InterstitialAdManager = class {
779786
if (preloadManager) {
780787
await this.player_.load(preloadManager);
781788
} else {
782-
await this.player_.load(interstitial.uri);
789+
await this.player_.load(
790+
interstitial.uri,
791+
/* startTime= */ null,
792+
interstitial.mimeType || undefined);
783793
}
784794
} else {
785-
await this.player_.load(interstitial.uri);
795+
await this.player_.load(
796+
interstitial.uri,
797+
/* startTime= */ null,
798+
interstitial.mimeType || undefined);
786799
}
787800
if (interstitial.playoutLimit) {
788801
if (playoutLimitTimer) {
@@ -912,6 +925,7 @@ shaka.ads.InterstitialAdManager = class {
912925
startTime,
913926
endTime,
914927
uri,
928+
mimeType: null,
915929
isSkippable,
916930
skipOffset,
917931
skipFor,
@@ -964,6 +978,7 @@ shaka.ads.InterstitialAdManager = class {
964978
startTime,
965979
endTime,
966980
uri: asset['URI'],
981+
mimeType: null,
967982
isSkippable,
968983
skipOffset,
969984
skipFor,

0 commit comments

Comments
 (0)