From 6247fe72a117bd2f97f2394a4a85dd0a18c91c46 Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Tue, 16 Jan 2018 11:12:36 -0800 Subject: [PATCH] Determine when to trigger callback based on bid response --- src/adapters/bidderFactory.js | 12 +++++++++--- src/auction.js | 18 +++--------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/adapters/bidderFactory.js b/src/adapters/bidderFactory.js index ed3cc28db32..10315241c40 100644 --- a/src/adapters/bidderFactory.js +++ b/src/adapters/bidderFactory.js @@ -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); } @@ -281,7 +287,7 @@ export function newBidder(spec) { addBidUsingRequestMap(bids); } } - onResponse(); + onResponse(bids); function addBidUsingRequestMap(bid) { const bidRequest = bidRequestMap[bid.requestId]; diff --git a/src/auction.js b/src/auction.js index 186ba62a7a4..368334e701f 100644 --- a/src/auction.js +++ b/src/auction.js @@ -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'; @@ -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); }