Skip to content

Commit

Permalink
Determine when to trigger callback based on bid response
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlane committed Jan 16, 2018
1 parent 40bdbdd commit 6247fe7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
12 changes: 9 additions & 3 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@ export function newBidder(spec) {
// After all the responses have come back, call done() and
// register any required usersync pixels.
const responses = [];
function afterAllResponses() {
done();
function afterAllResponses(bids) {
const videoBid = bids && bids[0] && bids[0].mediaType && bids[0].mediaType === 'video';
const cacheEnabled = config.getConfig('cache.url');

// video bids with cache enabled need to be cached first before they are considered done
if (!(videoBid && cacheEnabled)) {
done();
}
registerSyncs(responses);
}

Expand Down Expand Up @@ -281,7 +287,7 @@ export function newBidder(spec) {
addBidUsingRequestMap(bids);
}
}
onResponse();
onResponse(bids);

function addBidUsingRequestMap(bid) {
const bidRequest = bidRequestMap[bid.requestId];
Expand Down
18 changes: 3 additions & 15 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import { Renderer } from 'src/Renderer';
import { config } from 'src/config';
import { userSync } from 'src/userSync';
import { createHook } from 'src/hook';
import { videoAdUnit } from 'src/video';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';

Expand Down Expand Up @@ -153,20 +152,9 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
return innerBidRequestId === bidRequest.bidderRequestId;
});

const nonVideoBid = request.bids.filter(videoAdUnit).length === 0;
const videoBid = request.bids.filter(videoAdUnit).length > 0;
const videoBidNoCache = videoBid && !config.getConfig('cache.url');
const videoBidWithCache = videoBid && config.getConfig('cache.url');

// video bids with cache enabled need to be cached first before saying they are done
if (!videoBidWithCache) {
request.doneCbCallCount += 1;
}

// in case of mediaType video and prebidCache enabled, call bidsBackHandler after cache is stored.
if (nonVideoBid || videoBidNoCache) {
bidsBackAll()
}
// this is done for cache-enabled video bids in tryAddVideoBids, after the cache is stored
request.doneCbCallCount += 1;
bidsBackAll();
}, 1);
}

Expand Down

0 comments on commit 6247fe7

Please sign in to comment.