Skip to content

Commit

Permalink
chore(Ads): Simplify quartile management in Interstitials (#7689)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Nov 28, 2024
1 parent ed13c8b commit 1236c2d
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@ shaka.ads.InterstitialAdManager = class {
this.onEvent_(new shaka.util.FakeEvent(
shaka.ads.Utils.AD_SKIP_STATE_CHANGED));
}
const eventsSent = new Set();
this.adEventManager_.listenOnce(this.player_, 'error', error);
this.adEventManager_.listen(this.video_, 'timeupdate', () => {
const duration = this.video_.duration;
Expand All @@ -743,23 +742,21 @@ shaka.ads.InterstitialAdManager = class {
new shaka.util.FakeEvent(shaka.ads.Utils.AD_SKIP_STATE_CHANGED));
}
prevCanSkipNow = currentCanSkipNow;
const currentPercent = 100 * this.video_.currentTime / duration;
if (currentPercent >= 25 && !eventsSent.has('firstquartile')) {
updateBaseVideoTime();
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_FIRST_QUARTILE));
eventsSent.add('firstquartile');
} else if (currentPercent >= 50 && !eventsSent.has('midpoint')) {
updateBaseVideoTime();
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_MIDPOINT));
eventsSent.add('midpoint');
} else if (currentPercent >= 75 && !eventsSent.has('thirdquartile')) {
updateBaseVideoTime();
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_THIRD_QUARTILE));
eventsSent.add('thirdquartile');
}
});
this.adEventManager_.listenOnce(this.player_, 'firstquartile', () => {
updateBaseVideoTime();
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_FIRST_QUARTILE));
});
this.adEventManager_.listenOnce(this.player_, 'midpoint', () => {
updateBaseVideoTime();
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_MIDPOINT));
});
this.adEventManager_.listenOnce(this.player_, 'thirdquartile', () => {
updateBaseVideoTime();
this.onEvent_(
new shaka.util.FakeEvent(shaka.ads.Utils.AD_THIRD_QUARTILE));
});
this.adEventManager_.listenOnce(this.player_, 'complete', complete);
this.adEventManager_.listen(this.video_, 'play', () => {
Expand Down

0 comments on commit 1236c2d

Please sign in to comment.