Skip to content

Commit

Permalink
fix(Ads): Avoid adding custom interstitials without URI (#7696)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Nov 29, 2024
1 parent b2673fd commit 743b451
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,18 @@ shaka.ads.InterstitialAdManager = class {
addInterstitials(interstitials) {
let cuepointsChanged = false;
for (const interstitial of interstitials) {
if (!interstitial.uri) {
shaka.log.alwaysWarn('Missing URL in interstitial', interstitial);
continue;
}
const interstitialId = interstitial.id || JSON.stringify(interstitial);
if (this.interstitialIds_.has(interstitialId)) {
continue;
}
if (interstitial.loop && !interstitial.overlay) {
shaka.log.alwaysWarn('Loop is only supported in overlay interstitials',
interstitial);
}
if (!interstitial.overlay) {
cuepointsChanged = true;
}
Expand Down
26 changes: 26 additions & 0 deletions test/ads/interstitial_ad_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,32 @@ describe('Interstitial Ad manager', () => {
expect(onEventSpy).toHaveBeenCalledWith(
jasmine.objectContaining(eventValue1));
});

it('ignore invalid interstitial', async () => {
// It is not valid because it does not have an interstitial URL
const interstitial = {
id: null,
startTime: 10,
endTime: null,
uri: '',
mimeType: null,
isSkippable: true,
skipOffset: 10,
skipFor: null,
canJump: false,
resumeOffset: null,
playoutLimit: null,
once: true,
pre: false,
post: false,
timelineRange: false,
loop: false,
overlay: null,
};
await interstitialAdManager.addInterstitials([interstitial]);

expect(onEventSpy).not.toHaveBeenCalled();
});
});

describe('VAST', () => {
Expand Down

0 comments on commit 743b451

Please sign in to comment.