Skip to content

Commit

Permalink
Merge pull request googleads#859 from tv2/feature/prevent_ad_playing
Browse files Browse the repository at this point in the history
Added option to prevent ad playing after content start
  • Loading branch information
Kiro705 authored Feb 24, 2020
2 parents bad7344 + f589fc2 commit 5fc5193
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ the previous snippet. A summary of all settings follows:
| vastLoadTimeout | number | Override for default VAST load timeout in milliseconds for a single wrapper. The default timeout is 5000ms. |
| vpaidAllowed | boolean | **DEPRECATED**, please use vpaidMode. |
| vpaidMode | VpaidMode(5) | VPAID Mode. Defaults to ENABLED. This setting,overrides vpaidAllowed. |
| preventLateAdStart | boolean | Prevent ads from starting after the content has started if an adtimeout occurred (preroll, midroll, postroll). The default value is false


(1) [IMA SDK Docs](//developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsRenderingSettings)
Expand Down
8 changes: 8 additions & 0 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Controller.IMA_DEFAULTS = {
adLabelNofN: 'of',
showControlsForJSAds: true,
requestMode: 'onLoad',
preventLateAdStart: false,
};

/**
Expand Down Expand Up @@ -490,6 +491,13 @@ Controller.prototype.onPlayerReadyForPreroll = function() {
this.sdkImpl.onPlayerReadyForPreroll();
};

/**
* Called if the ad times out.
*/
Controller.prototype.onAdTimeout = function() {
this.sdkImpl.onAdTimeout();
};


/**
* Called when the player is ready.
Expand Down
7 changes: 7 additions & 0 deletions src/player-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const PlayerWrapper = function(player, adsPluginSettings, controller) {
this.vjsPlayer.on('contentended', this.boundContentEndedListener);
this.vjsPlayer.on('dispose', this.playerDisposedListener.bind(this));
this.vjsPlayer.on('readyforpreroll', this.onReadyForPreroll.bind(this));
this.vjsPlayer.on('adtimeout', this.onAdTimeout.bind(this));
this.vjsPlayer.ready(this.onPlayerReady.bind(this));

if (this.controller.getSettings().requestMode === 'onPlay') {
Expand Down Expand Up @@ -270,6 +271,12 @@ PlayerWrapper.prototype.onReadyForPreroll = function() {
this.controller.onPlayerReadyForPreroll();
};

/**
* Detects if the ad has timed out.
*/
PlayerWrapper.prototype.onAdTimeout = function() {
this.controller.onAdTimeout();
};

/**
* Called when the player fires its 'ready' event.
Expand Down
18 changes: 17 additions & 1 deletion src/sdk-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ const SdkImpl = function(controller) {
*/
this.contentCompleteCalled = false;

/**
* True if the ad has timed out.
*/
this.isAdTimedOut = false;

/**
* Stores the dimensions for the ads manager.
*/
Expand Down Expand Up @@ -301,7 +306,14 @@ SdkImpl.prototype.onAdsManagerLoaded = function(adsManagerLoadedEvent) {
this.initAdsManager();
}

this.controller.onAdsReady();
const {preventLateAdStart} = this.controller.getSettings();

if (!preventLateAdStart) {
this.controller.onAdsReady();
} else if (preventLateAdStart &&
!this.isAdTimedOut) {
this.controller.onAdsReady();
}

if (this.controller.getSettings().adsManagerLoadedCallback) {
this.controller.getSettings().adsManagerLoadedCallback();
Expand Down Expand Up @@ -558,6 +570,10 @@ SdkImpl.prototype.onPlayerReadyForPreroll = function() {
}
};

SdkImpl.prototype.onAdTimeout = function() {
this.isAdTimedOut = true;
};

SdkImpl.prototype.onPlayerReady = function() {
this.initAdObjects();

Expand Down

0 comments on commit 5fc5193

Please sign in to comment.