From 16cd996f2f9baa50283720af4dae1eb501a79b60 Mon Sep 17 00:00:00 2001 From: Anton Baranov Date: Tue, 9 Feb 2021 10:08:59 -0800 Subject: [PATCH] Multiple changes was added - New renderer based on prebid-outstream was added - Config is passing thru Renderer.install - OpenRTB playback API support added for outstream --- modules/yieldmoBidAdapter.js | 57 ++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index c1151617ac44..2b5715fcc9dc 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -1,8 +1,8 @@ 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'; @@ -10,10 +10,13 @@ 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, @@ -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, @@ -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; } /** @@ -457,3 +507,4 @@ function validateVideoParams(bid) { return false; } } +