Skip to content

Commit

Permalink
video handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mlequain committed Jul 9, 2024
1 parent 38fc385 commit 23cfd86
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
77 changes: 72 additions & 5 deletions modules/mediaConsortiumBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {BANNER} from '../src/mediaTypes.js'
import {BANNER, VIDEO} from '../src/mediaTypes.js'
import {registerBidder} from '../src/adapters/bidderFactory.js'
import {replaceAuctionPrice, generateUUID, isPlainObject, isArray} from '../src/utils.js'
import {replaceAuctionPrice, generateUUID, isPlainObject, isArray, logWarn, deepClone} from '../src/utils.js'
import { Renderer } from '../src/Renderer.js'
import { OUTSTREAM } from '../src/video.js'

const BIDDER_CODE = 'MediaConsortium'

const SYNC_ENDPOINT = 'https://relay.hubvisor.io/v1/sync/big'
const AUCTION_ENDPOINT = 'https://relay.hubvisor.io/v1/auction/big'

const XANDR_OUTSTREAM_RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js';

export const OPTIMIZATIONS_STORAGE_KEY = 'media_consortium_optimizations'

const SYNC_TYPES = {
Expand All @@ -17,7 +23,7 @@ export const spec = {
version: '0.0.1',
code: BIDDER_CODE,
gvlid: 1112,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid(bid) {
return true
},
Expand All @@ -43,7 +49,19 @@ export const spec = {
}
}

return acc.concat({id: bidId, adUnitCode, mediaTypes})
let finalizedMediatypes = deepClone(mediaTypes)

if (mediaTypes.video && mediaTypes.video.context !== OUTSTREAM) {
logWarn(`Filtering video request for adUnitCode ${adUnitCode} because context is not ${OUTSTREAM}`)

if (Object.keys(finalizedMediatypes).length > 1) {
delete finalizedMediatypes.video
} else {
return acc
}
}

return acc.concat({id: bidId, adUnitCode, mediaTypes: finalizedMediatypes})
}, [])

if (!impressions.length) {
Expand Down Expand Up @@ -128,7 +146,7 @@ export const spec = {

const markupWithMacroReplaced = replaceAuctionPrice(markup, cpm)

return {
const formattedBid = {
requestId: impressionId,
cpm,
currency,
Expand All @@ -142,6 +160,20 @@ export const spec = {
ad: markupWithMacroReplaced,
adUrl: null
}

if (mediaType === VIDEO) {
const impressionRequest = params.data.impressions.find(({id}) => id === impressionId)

formattedBid.vastXml = markupWithMacroReplaced

if (impressionRequest) {
formattedBid.renderer = buildXandrOutstreamRenderer(impressionId, impressionRequest.adUnitCode)
} else {
logWarn(`Could not find adUnitCode matching the impressionId ${impressionId} to setup the renderer`)
}
}

return formattedBid
})
},
getUserSyncs(syncOptions, serverResponses) {
Expand Down Expand Up @@ -188,3 +220,38 @@ function isValidResponse(response) {
isPlainObject(response.body) &&
isArray(response.body.bids)
}

function buildXandrOutstreamRenderer(bidId, adUnitCode) {
const renderer = Renderer.install({
id: bidId,
url: XANDR_OUTSTREAM_RENDERER_URL,
loaded: false,
adUnitCode,
targetId: adUnitCode
});

try {
renderer.setRender(xandrOutstreamRenderer);
} catch (err) {
logWarn('Prebid Error calling setRender on renderer', err);
}

return renderer;
}

function xandrOutstreamRenderer(bid) {
bid.renderer.push(() => {
window.ANOutstreamVideo.renderAd({
sizes: [bid.width, bid.height],
targetId: bid.adUnitCode,
rendererOptions: {
showBigPlayButton: false,
showProgressBar: 'bar',
showVolume: false,
allowFullscreen: true,
skippable: false,
content: bid.vastXml
}
});
});
}
21 changes: 19 additions & 2 deletions modules/mediaConsortiumBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

## Description

Module that connects to Media Consortium demand sources and supports the following media types: `banner`
Module that connects to Media Consortium demand sources and supports the following media types: `banner`, `video`

## Test Parameters
```
var adUnits = [
{
code: 'div-prebid',
code: 'div-prebid-banner',
mediaTypes:{
banner: {
sizes: [[300, 250]],
Expand All @@ -29,5 +29,22 @@ Module that connects to Media Consortium demand sources and supports the followi
}
]
},
{
code: 'div-prebid-video',
mediaTypes:{
video: {
playerSize: [
[300, 250]
],
context: 'outstream'
}
},
bids:[
{
bidder: 'mediaConsortium',
params: {}
}
]
}
];
```

0 comments on commit 23cfd86

Please sign in to comment.