Skip to content

Commit

Permalink
DMX Fix video bug (#5910)
Browse files Browse the repository at this point in the history
* adding DMX

test @97%, two files added one updated

* Update districtm_spec.js

* Update districtmDMX.js

* adding all districtm needed file

* remove legacy file

* remove typo || 0 in the test method

* force default to return a valid width and height

* update unit test code for failing test

* changed class for an object

* remove package-lock.json

* change file name for dmx adapter

* renamed files

* restaure package-lock.json

* update to last package-lock state

* update gdpr user consent

* fix sizes issue

* Documentation updates

Adding the readme.md info

* update file name and update unit testing import file location

* current machine state

* lint correction

* remove variable assigment duplicate

* adding CCPA support for DMX

* adding test for ccpa and gdpr

* districtm dmx adding deal id field

* idsync support ccpa & gdpr

* fix error on vast response that failed

Co-authored-by: Steve Alliance <[email protected]>
Co-authored-by: Luis <[email protected]>
Co-authored-by: Steve Alliance <[email protected]>
Co-authored-by: Steve Alliance <[email protected]>
Co-authored-by: steve-a-districtm <[email protected]>
  • Loading branch information
6 people authored Nov 2, 2020
1 parent 348a4f5 commit e3a9c60
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 47 deletions.
72 changes: 28 additions & 44 deletions modules/districtmDMXBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const spec = {
nBid.requestId = nBid.impid;
nBid.width = nBid.w || width;
nBid.height = nBid.h || height;
nBid.mediaType = bid.mediaTypes && bid.mediaTypes.video ? 'video' : null;
nBid.mediaType = bid.mediaTypes && bid.mediaTypes.video ? 'video' : 'banner';
if (nBid.mediaType) {
nBid.vastXml = cleanVast(nBid.adm);
nBid.vastXml = cleanVast(nBid.adm, nBid.nurl);
}
if (nBid.dealid) {
nBid.dealId = nBid.dealid;
Expand Down Expand Up @@ -154,19 +154,16 @@ export const spec = {
if (dmx.mediaTypes && dmx.mediaTypes.video) {
obj.video = {
topframe: 1,
skip: dmx.mediaTypes.video.skippable || 0,
skip: dmx.mediaTypes.video.skip || 0,
linearity: dmx.mediaTypes.video.linearity || 1,
minduration: dmx.mediaTypes.video.minduration || 5,
maxduration: dmx.mediaTypes.video.maxduration || 60,
playbackmethod: getPlaybackmethod(dmx.mediaTypes.video.playback_method),
playbackmethod: dmx.mediaTypes.video.playbackmethod || [2],
api: getApi(dmx.mediaTypes.video),
mimes: dmx.mediaTypes.video.mimes || ['video/mp4'],
protocols: getProtocols(dmx.mediaTypes.video),
w: dmx.mediaTypes.video.playerSize[0][0],
h: dmx.mediaTypes.video.playerSize[0][1],
format: dmx.mediaTypes.video.playerSize.map(s => {
return {w: s[0], h: s[1]};
}).filter(obj => typeof obj.w === 'number' && typeof obj.h === 'number')
w: dmx.mediaTypes.video.playerSize[0][0]
};
} else {
obj.banner = {
Expand Down Expand Up @@ -380,20 +377,10 @@ export function bindUserId(eids, value, source, atype) {
}
}

export function getApi({protocols}) {
export function getApi({api}) {
let defaultValue = [2];
let listProtocols = [
{key: 'VPAID_1_0', value: 1},
{key: 'VPAID_2_0', value: 2},
{key: 'MRAID_1', value: 3},
{key: 'ORMMA', value: 4},
{key: 'MRAID_2', value: 5},
{key: 'MRAID_3', value: 6},
];
if (protocols) {
return listProtocols.filter(p => {
return protocols.indexOf(p.key) !== -1;
}).map(p => p.value)
if (api && Array.isArray(api) && api.length > 0) {
return api
} else {
return defaultValue;
}
Expand All @@ -409,35 +396,32 @@ export function getPlaybackmethod(playback) {

export function getProtocols({protocols}) {
let defaultValue = [2, 3, 5, 6, 7, 8];
let listProtocols = [
{key: 'VAST_1_0', value: 1},
{key: 'VAST_2_0', value: 2},
{key: 'VAST_3_0', value: 3},
{key: 'VAST_1_0_WRAPPER', value: 4},
{key: 'VAST_2_0_WRAPPER', value: 5},
{key: 'VAST_3_0_WRAPPER', value: 6},
{key: 'VAST_4_0', value: 7},
{key: 'VAST_4_0_WRAPPER', value: 8}
];
if (protocols) {
return listProtocols.filter(p => {
return protocols.indexOf(p.key) !== -1
}).map(p => p.value);
if (protocols && Array.isArray(protocols) && protocols.length > 0) {
return protocols;
} else {
return defaultValue;
}
}

export function cleanVast(str) {
const toberemove = /<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/
const [img, url] = str.match(toberemove)
str = str.replace(toberemove, '')
if (img) {
if (url) {
const insrt = `<Impression><![CDATA[${url}]]></Impression>`
str = str.replace('</Impression>', `</Impression>${insrt}`)
export function cleanVast(str, nurl) {
try {
const toberemove = /<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/
const [img, url] = str.match(toberemove)
str = str.replace(toberemove, '')
if (img) {
if (url) {
const insrt = `<Impression><![CDATA[${url}]]></Impression>`
str = str.replace('</Impression>', `</Impression>${insrt}`)
}
}
return str;
} catch (e) {
if(!nurl) {
return str
}
const insrt = `<Impression><![CDATA[${nurl}]]></Impression>`
str = str.replace('</Impression>', `</Impression>${insrt}`)
return str
}
return str;
}
registerBidder(spec);
7 changes: 4 additions & 3 deletions test/spec/modules/districtmDmxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const bidRequestVideo = [{
}
},
'mediaTypes': { video: {context: 'instream', // or 'outstream'
playerSize: [[640, 480]]} },
playerSize: [[640, 480]]} },
'adUnitCode': 'div-gpt-ad-12345678-1',
'transactionId': 'f6d13fa6-ebc1-41ac-9afa-d8171d22d2c2',
'sizes': [
Expand Down Expand Up @@ -616,7 +616,7 @@ describe('DistrictM Adaptor', function () {
})
describe('Test getApi function', function() {
const data = {
protocols: ['VPAID_1_0']
api: [1]
}
it('Will return 1 for vpaid version 1', function() {
expect(getApi(data)[0]).to.be.equal(1)
Expand Down Expand Up @@ -646,7 +646,7 @@ describe('DistrictM Adaptor', function () {

describe('Test getProtocols function', function() {
it('getProtocols will return 3', function() {
expect(getProtocols({protocols: ['VAST_3_0']})[0]).to.be.equal(3)
expect(getProtocols({protocols: [3]})[0]).to.be.equal(3)
})
it('getProtocols will return 6', function() {
expect(_.isEqual(getProtocols({}), [2, 3, 5, 6, 7, 8])).to.be.equal(true)
Expand Down Expand Up @@ -811,3 +811,4 @@ describe('DistrictM Adaptor', function () {
});
});
});

0 comments on commit e3a9c60

Please sign in to comment.