Skip to content

Commit 4f59e48

Browse files
Enforce new required params + remove legacy mediaType support
1 parent bb83931 commit 4f59e48

File tree

2 files changed

+141
-147
lines changed

2 files changed

+141
-147
lines changed

modules/rubiconBidAdapter.js

+38-24
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ export const spec = {
102102
return false
103103
}
104104
}
105-
return !!bidType(bid, true);
105+
let bidFormat = bidType(bid, true);
106+
// bidType is undefined? Return false
107+
if (!bidFormat) {
108+
return false;
109+
} else if (bidFormat === 'video') { // bidType is video, make sure it has required params
110+
return hasValidVideoParams(bid);
111+
}
112+
// bidType is banner? return true
113+
return true;
106114
},
107115
/**
108116
* @param {BidRequest[]} bidRequests
@@ -718,9 +726,6 @@ function addVideoParameters(data, bidRequest) {
718726
if (typeof data.imp[0].video === 'object' && data.imp[0].video.pos === undefined) {
719727
data.imp[0].video.pos = bidRequest.params.position === 'atf' ? 1 : (bidRequest.params.position === 'btf' ? 3 : 0);
720728
}
721-
if (data.imp[0].bidfloor === undefined) {
722-
data.imp[0].bidfloor = parseFloat(bidRequest.params.floor) > 0.01 ? bidRequest.params.floor : 0.01;
723-
}
724729

725730
const size = parseSizes(bidRequest, 'video')
726731
data.imp[0].video.w = size[0]
@@ -753,7 +758,7 @@ export function hasVideoMediaType(bidRequest) {
753758
if (typeof utils.deepAccess(bidRequest, 'params.video') !== 'object') {
754759
return false;
755760
}
756-
return (bidRequest.mediaType === VIDEO || typeof utils.deepAccess(bidRequest, `mediaTypes.${VIDEO}`) !== 'undefined');
761+
return (typeof utils.deepAccess(bidRequest, `mediaTypes.${VIDEO}`) !== 'undefined');
757762
}
758763

759764
/**
@@ -765,27 +770,15 @@ export function hasVideoMediaType(bidRequest) {
765770
function bidType(bid, log = false) {
766771
// Is it considered video ad unit by rubicon
767772
if (hasVideoMediaType(bid)) {
768-
// legacy mediaType or the new mediaTypes
769-
// this is the preffered "new" way to define mediaTypes
770-
if (typeof utils.deepAccess(bid, `mediaTypes.${VIDEO}`) !== 'undefined') {
771-
// We require either context as instream or outstream
772-
if (['outstream', 'instream'].indexOf(utils.deepAccess(bid, `mediaTypes.${VIDEO}.context`)) === -1) {
773-
if (log) {
774-
utils.logError('Rubicon bid adapter requires mediaTypes.video.context to be one of outstream or instream');
775-
}
776-
return;
777-
}
778-
} else { // Otherwise its the legacy way where mediaType == 'video'
773+
// Removed legacy mediaType support. new way using mediaTypes.video object is now required
774+
// We require either context as instream or outstream
775+
if (['outstream', 'instream'].indexOf(utils.deepAccess(bid, `mediaTypes.${VIDEO}.context`)) === -1) {
779776
if (log) {
780-
utils.logWarn('Rubicon video bid requested using legacy `adUnit.mediaType = `video``\nThis is deprecated\nPlease move towards the PBJS standard using mediaTypes object!');
781-
}
782-
if (isNaN(parseInt(utils.deepAccess(bid, 'params.video.size_id')))) {
783-
if (log) {
784-
utils.logError('Rubicon bid adapter needs params.video.size_id to be declared and an integer in order to process a legacy video request using mediaType == video');
785-
}
786-
return;
777+
utils.logError('Rubicon bid adapter requires mediaTypes.video.context to be one of outstream or instream');
787778
}
779+
return;
788780
}
781+
789782
// we require playerWidth and playerHeight to come from one of params.playerWidth/playerHeight or mediaTypes.video.playerSize or adUnit.sizes
790783
if (parseSizes(bid, 'video').length < 2) {
791784
if (log) {
@@ -873,10 +866,31 @@ export function getPriceGranularity(config) {
873866
}
874867
}
875868

869+
// Function to validate the required video params
870+
export function hasValidVideoParams(bid) {
871+
let isValid = true;
872+
// required params and their associated object type
873+
var requiredParams = {
874+
mimes: '[object Array]',
875+
protocols: '[object Array]',
876+
maxduration: '[object Number]',
877+
linearity: '[object Number]',
878+
api: '[object Array]'
879+
}
880+
// loop through each param and verify it has the correct
881+
Object.keys(requiredParams).forEach(function(param) {
882+
if (Object.prototype.toString.call(utils.deepAccess(bid, 'mediaTypes.video.' + param)) !== requiredParams[param]) {
883+
isValid = false;
884+
utils.logError('Rubicon Bid Adapter: mediaTypes.video.' + param + ' is required and must be of type:' + requiredParams[param].substring(requiredParams[param].indexOf(' '), requiredParams[param].indexOf(']')));
885+
}
886+
})
887+
return isValid;
888+
}
889+
876890
var hasSynced = false;
877891

878892
export function resetUserSync() {
879893
hasSynced = false;
880894
}
881895

882-
registerBidder(spec);
896+
registerBidder(spec);

0 commit comments

Comments
 (0)