Skip to content

Commit

Permalink
feat: adds a request mode for ad requests
Browse files Browse the repository at this point in the history
onLoad: This is the default behaviour, ad requests are done when the player is ready

onPlay: New behaviour, Ad requests are only made once playback is initiated. This is necessary as some ad networks consider ad requests to be plays
  • Loading branch information
Tim Bielawski committed Jan 29, 2019
1 parent e0d59f5 commit 278556b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/controller.js
Expand Up @@ -86,6 +86,7 @@ Controller.IMA_DEFAULTS = {
adLabel: 'Advertisement',
adLabelNofN: 'of',
showControlsForJSAds: true,
requestMode: 'onLoad',
};

/**
Expand Down
5 changes: 5 additions & 0 deletions src/player-wrapper.js
Expand Up @@ -139,6 +139,11 @@ const PlayerWrapper = function(player, adsPluginSettings, controller) {
this.vjsPlayer.on('readyforpreroll', this.onReadyForPreroll.bind(this));
this.vjsPlayer.ready(this.onPlayerReady.bind(this));

if (this.controller.getSettings().requestMode === 'onPlay') {
this.vjsPlayer.one('play',
this.controller.requestAds.bind(this.controller));
}

this.vjsPlayer.ads(adsPluginSettings);
};

Expand Down
7 changes: 4 additions & 3 deletions src/sdk-impl.js
Expand Up @@ -553,9 +553,10 @@ SdkImpl.prototype.onPlayerReadyForPreroll = function() {
SdkImpl.prototype.onPlayerReady = function() {
this.initAdObjects();

if (this.controller.getSettings().adTagUrl ||
this.controller.getSettings().adsResponse) {
this.requestAds();
if ((this.controller.getSettings().adTagUrl ||
this.controller.getSettings().adsResponse) &&
this.controller.getSettings().requestMode === 'onLoad') {
this.requestAds();
}
};

Expand Down

0 comments on commit 278556b

Please sign in to comment.