Skip to content

Commit

Permalink
fix(FEC-7214, FEC-7217, FEC-7214): multiple request ads fix (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ziv authored Oct 3, 2017
1 parent 432af1f commit 7862373
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/ima.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,13 @@ export default class Ima extends BasePlugin {
}

/**
* TODO: Rethink on design and implementation.
* Plays ad on demand.
* @param {string} adTagUrl - The ad tag url to play.
* @returns {void}
*/
playAdNow(adTagUrl: string): void {
super.updateConfig({adTagUrl: adTagUrl});
this.loadPromise = Utils.Object.defer();
this.destroy();
this._addBindings();
this._initAdsLoader();
this._requestAds();
this.loadPromise.then(this._startAdsManager.bind(this));
this.logger.warn("playAdNow API is not implemented yet", adTagUrl);
}

/**
Expand Down Expand Up @@ -239,19 +234,6 @@ export default class Ima extends BasePlugin {
return this._nextPromise;
}

/**
* Updates the configuration of the plugin.
* @param {Object} update - The fully or partially updated configuration.
* @override
* @returns {void}
*/
updateConfig(update: Object): void {
super.updateConfig(update);
if (update.adTagUrl && this._stateMachine.is(State.LOADED)) {
this._requestAds();
}
}

/**
* Gets the state machine.
* @public
Expand Down
17 changes: 17 additions & 0 deletions test/src/ima.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ describe('Ima Plugin', function () {
player.play();
});

it('should call requestAds once', (done) => {
cuePoints = [0];
player = loadPlayerWithAds(targetId, {
adTagUrl: 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ar%3Dpreonly&cmsid=496&vid=short_onecue&correlator='
});
ima = player._pluginManager.get('ima');
const spy = sinon.spy(ima, "_requestAds");
player.addEventListener(player.Event.AD_LOADED, (e) => {
adPodIndex = e.payload.extraAdData.adPodInfo.podIndex;
spy.should.calledOnce;
});
player.addEventListener(player.Event.AD_STARTED, () => {
maybeDoneTest(cuePoints, adPodIndex, done);
});
player.play();
});

it('should play vmap-preroll-bumper', (done) => {
cuePoints = [0, 0];
player = loadPlayerWithAds(targetId, {
Expand Down

0 comments on commit 7862373

Please sign in to comment.