Skip to content

Commit

Permalink
Yieldmo adapter: outstream support was added
Browse files Browse the repository at this point in the history
- New renderer based on prebid-outstream was added
- Config is passing thru Renderer.install
- OpenRTB playback API support added for outstream
  • Loading branch information
ym-abaranov committed Feb 9, 2021
1 parent 19b4885 commit 08fe448
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import * as utils from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { Renderer } from '../src/Renderer.js';
import includes from 'core-js-pure/features/array/includes';
import find from 'core-js-pure/features/array/find.js';

const BIDDER_CODE = 'yieldmo';
const CURRENCY = 'USD';
const TIME_TO_LIVE = 300;
const NET_REVENUE = true;
const BANNER_SERVER_ENDPOINT = 'https://ads.yieldmo.com/exchange/prebid';
const VIDEO_SERVER_ENDPOINT = 'https://ads.yieldmo.com/exchange/prebidvideo';
const OUTSTREAM_VIDEO_PLAYER_URL = 'https://prebid-outstream.yieldmo.com/bundle.js';
const OPENRTB_VIDEO_BIDPARAMS = ['placement', 'startdelay', 'skipafter',
'protocols', 'api', 'playbackmethod', 'maxduration', 'minduration', 'pos'];
const OPENRTB_VIDEO_SITEPARAMS = ['name', 'domain', 'cat', 'keywords'];
const localWindow = utils.getWindowTop();
const DEFAULT_PLAYBACK_METHOD = 2;
const VAST_TIMEOUT = 5000;

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -198,8 +201,9 @@ function createNewBannerBid(response) {
* @param bidRequest server request
*/
function createNewVideoBid(response, bidRequest) {
const imp = find((utils.deepAccess(bidRequest, 'data.imp') || []), imp => imp.id === response.impid);
return {
const imp = (utils.deepAccess(bidRequest, 'data.imp') || []).find(imp => imp.id === response.impid);

let result = {
requestId: imp.id,
cpm: response.price,
width: imp.video.w,
Expand All @@ -211,6 +215,52 @@ function createNewVideoBid(response, bidRequest) {
ttl: TIME_TO_LIVE,
vastXml: response.adm
};

const playbackmethodMap = [
{
preload: true,
mute: false,
autoPlay: true
},
{
preload: true,
mute: true,
autoPlay: true
}
];

if (imp.placement !== 1) {
const receivedPlaybackMethod = imp.video.playbackmethod[0] || DEFAULT_PLAYBACK_METHOD;
const playbackIdx = (receivedPlaybackMethod >= 1 && receivedPlaybackMethod <= 2)
? receivedPlaybackMethod - 1
: 0;

const renderer = Renderer.install({
url: OUTSTREAM_VIDEO_PLAYER_URL,
config: {
width: result.width,
height: result.height,
vastTimeout: VAST_TIMEOUT,
maxAllowedVastTagRedirects: 3,
allowVpaid: false,
autoPlay: true,
...playbackmethodMap[playbackIdx]
},
id: imp.tagid,
loaded: false,
});

renderer.setRender(function (bid) {
bid.renderer.push(() => {
const { id, config } = bid.renderer;
window.YMoutstreamPlayer(bid, id, config);
});
});

result.renderer = renderer;
}

return result;
}

/**
Expand Down Expand Up @@ -457,3 +507,4 @@ function validateVideoParams(bid) {
return false;
}
}

0 comments on commit 08fe448

Please sign in to comment.