Skip to content

Commit

Permalink
Add outstream renderer to Beachfront adapter (#2403)
Browse files Browse the repository at this point in the history
* Added renderer to bidder adapter

* Start playback immediately

* Fix test case
  • Loading branch information
jsalis authored and jsnellbaker committed Apr 17, 2018
1 parent 1b29d1f commit bddef91
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
29 changes: 29 additions & 0 deletions modules/beachfrontBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { Renderer } from 'src/Renderer';
import { VIDEO, BANNER } from 'src/mediaTypes';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';

const ADAPTER_VERSION = '1.1';
const ADAPTER_NAME = 'BFIO_PREBID';
const OUTSTREAM = 'outstream';

export const VIDEO_ENDPOINT = '//reachms.bfmio.com/bid.json?exchange_id=';
export const BANNER_ENDPOINT = '//display.bfmio.com/prebid_display';
export const OUTSTREAM_SRC = '//player-cdn.beachfrontmedia.com/playerapi/loader/outstream.js';

export const VIDEO_TARGETING = ['mimes'];
export const DEFAULT_MIMES = ['video/mp4', 'application/javascript'];
Expand Down Expand Up @@ -53,6 +56,7 @@ export const spec = {
return [];
}
let size = getFirstSize(bidRequest);
let context = utils.deepAccess(bidRequest, 'mediaTypes.video.context');
return {
requestId: bidRequest.bidId,
bidderCode: spec.code,
Expand All @@ -61,6 +65,7 @@ export const spec = {
width: size.w,
height: size.h,
creativeId: response.cmpId,
renderer: context === OUTSTREAM ? createRenderer(bidRequest) : null,
mediaType: VIDEO,
currency: 'USD',
netRevenue: true,
Expand Down Expand Up @@ -91,6 +96,30 @@ export const spec = {
}
};

function createRenderer(bidRequest) {
const renderer = Renderer.install({
id: bidRequest.bidId,
url: OUTSTREAM_SRC,
loaded: false
});

renderer.setRender(outstreamRender);

return renderer;
}

function outstreamRender(bid) {
bid.renderer.push(() => {
window.Beachfront.Player(bid.adUnitCode, {
ad_tag_url: bid.vastUrl,
width: bid.width,
height: bid.height,
expand_in_view: false,
collapse_on_complete: true
});
});
}

function getSizes(bid) {
return utils.parseSizesInput(bid.sizes).map(size => {
let [ width, height ] = size.split('x');
Expand Down
18 changes: 17 additions & 1 deletion test/spec/modules/beachfrontBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec, VIDEO_ENDPOINT, BANNER_ENDPOINT, DEFAULT_MIMES } from 'modules/beachfrontBidAdapter';
import { spec, VIDEO_ENDPOINT, BANNER_ENDPOINT, OUTSTREAM_SRC, DEFAULT_MIMES } from 'modules/beachfrontBidAdapter';
import * as utils from 'src/utils';

describe('BeachfrontAdapter', () => {
Expand Down Expand Up @@ -267,12 +267,28 @@ describe('BeachfrontAdapter', () => {
vastUrl: serverResponse.url,
width: width,
height: height,
renderer: null,
mediaType: 'video',
currency: 'USD',
netRevenue: true,
ttl: 300
});
});

it('should return a renderer for outstream video bids', () => {
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: { context: 'outstream' } };
const serverResponse = {
bidPrice: 5.00,
url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da',
cmpId: '123abc'
};
const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest });
expect(bidResponse.renderer).to.deep.contain({
id: bidRequest.bidId,
url: OUTSTREAM_SRC
});
});
});

describe('for banner bids', () => {
Expand Down

0 comments on commit bddef91

Please sign in to comment.