Skip to content

Commit

Permalink
improves additional data passed to the handler in AuctionInit and Auc…
Browse files Browse the repository at this point in the history
…tionEnd events (prebid#3168)
  • Loading branch information
Marco Masotti authored and Pedro López Jiménez committed Mar 18, 2019
1 parent 4c049c7 commit 8560526
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
31 changes: 25 additions & 6 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
let _bidderRequests = [];
let _bidsReceived = [];
let _auctionStart;
let _auctionEnd;
let _auctionId = utils.generateUUID();
let _auctionStatus;
let _callback = callback;
Expand All @@ -106,6 +107,22 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
function addBidRequests(bidderRequests) { _bidderRequests = _bidderRequests.concat(bidderRequests) };
function addBidReceived(bidsReceived) { _bidsReceived = _bidsReceived.concat(bidsReceived); }

function getProperties() {
return {
auctionId: _auctionId,
auctionStart: _auctionStart,
auctionEnd: _auctionEnd,
auctionStatus: _auctionStatus,
adUnits: _adUnits,
adUnitCodes: _adUnitCodes,
labels: _labels,
bidderRequests: _bidderRequests,
bidsReceived: _bidsReceived,
winningBids: _winningBids,
timeout: _timeout
};
}

function startAuctionTimer() {
const timedOut = true;
const timeoutCallback = executeCallback.bind(null, timedOut);
Expand All @@ -129,10 +146,17 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
}
}

<<<<<<< HEAD
events.emit(CONSTANTS.EVENTS.AUCTION_END, {auctionId: _auctionId, timedOut});

=======
>>>>>>> improves additional data passed to the handler in AuctionInit and AuctionEnd events (#3168)
try {
_auctionStatus = AUCTION_COMPLETED;
_auctionEnd = Date.now();

events.emit(CONSTANTS.EVENTS.AUCTION_END, getProperties());

const adUnitCodes = _adUnitCodes;
const bids = _bidsReceived
.filter(adUnitsFilter.bind(this, adUnitCodes))
Expand Down Expand Up @@ -185,12 +209,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})

_auctionStatus = AUCTION_IN_PROGRESS;

const auctionInit = {
timestamp: _auctionStart,
auctionId: _auctionId,
timeout: _timeout
};
events.emit(CONSTANTS.EVENTS.AUCTION_INIT, auctionInit);
events.emit(CONSTANTS.EVENTS.AUCTION_INIT, getProperties());

let callbacks = auctionCallbacks(auctionDone, this);
let boundObj = {
Expand Down
4 changes: 2 additions & 2 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1591,8 +1591,8 @@ describe('Unit: Prebid Module', function () {
describe('emit', function () {
it('should be able to emit event without arguments', function () {
var spyEventsEmit = sinon.spy(events, 'emit');
events.emit(CONSTANTS.EVENTS.AUCTION_END);
assert.ok(spyEventsEmit.calledWith('auctionEnd'));
events.emit(CONSTANTS.EVENTS.REQUEST_BIDS);
assert.ok(spyEventsEmit.calledWith('requestBids'));
events.emit.restore();
});
});
Expand Down

0 comments on commit 8560526

Please sign in to comment.