Skip to content

Commit

Permalink
Merge pull request #2 from prebid/master
Browse files Browse the repository at this point in the history
updating fork from head
  • Loading branch information
vladgurgov authored Aug 10, 2019
2 parents d7e1e32 + bad3358 commit 8fd265c
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 129 deletions.
34 changes: 17 additions & 17 deletions modules/quantcastBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,7 @@ export const spec = {
* @return boolean `true` is this is a valid bid, and `false` otherwise
*/
isBidRequestValid(bid) {
if (!bid) {
return false;
}

const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video');
const context = utils.deepAccess(bid, 'mediaTypes.video.context');
if (videoMediaType && context == 'outstream') {
return false;
}

return true;
return !!bid.params.publisherId;
},

/**
Expand All @@ -112,12 +102,22 @@ export const spec = {
const page = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href');
const domain = getDomain(page);

const bidRequestsList = bids.map(bid => {
let bidRequestsList = [];

bids.forEach(bid => {
let imp;
const videoContext = utils.deepAccess(bid, 'mediaTypes.video.context');
if (videoContext === 'instream') {
imp = makeVideoImp(bid);
if (bid.mediaTypes) {
if (bid.mediaTypes.video && bid.mediaTypes.video.context === 'instream') {
imp = makeVideoImp(bid);
} else if (bid.mediaTypes.banner) {
imp = makeBannerImp(bid);
} else {
// Unsupported mediaType
utils.logInfo(`${BIDDER_CODE}: No supported mediaTypes found in ${JSON.stringify(bid.mediaTypes)}`);
return;
}
} else {
// Parse as banner by default
imp = makeBannerImp(bid);
}

Expand All @@ -143,11 +143,11 @@ export const spec = {
: QUANTCAST_DOMAIN;
const url = `${QUANTCAST_PROTOCOL}://${qcDomain}:${QUANTCAST_PORT}/qchb`;

return {
bidRequestsList.push({
data,
method: 'POST',
url
};
});
});

return bidRequestsList;
Expand Down
53 changes: 50 additions & 3 deletions modules/smilewantedBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as utils from '../src/utils';
import { Renderer } from '../src/Renderer';
import { config } from '../src/config';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';

export const spec = {
code: 'smilewanted',
aliases: ['smile', 'sw'],

supportedMediaTypes: [BANNER, VIDEO],
/**
* Determines whether or not the given bid request is valid.
*
Expand Down Expand Up @@ -65,6 +67,7 @@ export const spec = {
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];
var response = serverResponse.body;

try {
if (response) {
const bidResponse = {
Expand All @@ -77,10 +80,19 @@ export const spec = {
currency: response.currency,
netRevenue: response.isNetCpm,
ttl: response.ttl,
adUrl: response.adUrl,
ad: response.ad
ad: response.ad,
};

if (response.formatTypeSw == 'video_instream' || response.formatTypeSw == 'video_outstream') {
bidResponse['mediaType'] = 'video';
bidResponse['vastUrl'] = response.ad;
bidResponse['ad'] = null;
}

if (response.formatTypeSw == 'video_outstream') {
bidResponse['renderer'] = newRenderer(JSON.parse(bidRequest.data), response);
}

bidResponses.push(bidResponse);
}
} catch (error) {
Expand Down Expand Up @@ -110,4 +122,39 @@ export const spec = {
}
}

/**
* Create SmileWanted renderer
* @param requestId
* @returns {*}
*/
function newRenderer(bidRequest, bidResponse) {
const renderer = Renderer.install({
id: bidRequest.bidId,
url: bidResponse.OustreamTemplateUrl,
loaded: false
});

try {
renderer.setRender(outstreamRender);
} catch (err) {
utils.logWarn('Prebid Error calling setRender on newRenderer', err);
}
return renderer;
}

/**
* Initialise SmileWanted outstream
* @param bid
*/
function outstreamRender(bid) {
bid.renderer.push(() => {
window.SmileWantedOutStreamInit({
width: bid.width,
height: bid.height,
vastUrl: bid.vastUrl,
elId: bid.adUnitCode
});
});
}

registerBidder(spec);
40 changes: 40 additions & 0 deletions modules/smilewantedBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ To use us as a bidder you must have an account and an active "zoneId" on our Smi
# Test Parameters

## Web

### Display
```
var adUnits = [
{
Expand All @@ -28,4 +30,42 @@ To use us as a bidder you must have an account and an active "zoneId" on our Smi
]
}
];
```

### Video Instream
```
var videoAdUnit = {
code: 'video1',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'instream'
}
},
bids: [{
bidder: 'smilewanted',
params: {
zoneId: 2,
}
}]
};
```

### Video Outstream
```
var videoAdUnit = {
code: 'video1',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'outstream'
}
},
bids: [{
bidder: 'smilewanted',
params: {
zoneId: 3,
}
}]
};
```
5 changes: 2 additions & 3 deletions modules/spotxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ This adapter requires setup and approval from the SpotX team.
ad_unit: 'outstream',
outstream_options: {
slot: 'adSlot1',
content_width: 300,
content_height: 250,
custom_override: { // This option is not mandatory though used to override default renderer parameters using EASI player options in here: https://developer.spotxchange.com/content/local/docs/sdkDocs/EASI/README.md
content_width: 300,
content_height: 250,
collapse: '1',
hide_fullscreen: '1',
unmute_on_mouse: '1',
click_to_replay: '1',
continue_out_of_view: '1',
ad_volume: '100',
content_container_id: 'video1',
Expand Down
4 changes: 2 additions & 2 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ $$PREBID_GLOBAL$$.removeAdUnit = function (adUnitCode) {
}

adUnitCodes.forEach((adUnitCode) => {
for (let i = 0; i < $$PREBID_GLOBAL$$.adUnits.length; i++) {
for (let i = $$PREBID_GLOBAL$$.adUnits.length - 1; i >= 0; i--) {
if ($$PREBID_GLOBAL$$.adUnits[i].code === adUnitCode) {
$$PREBID_GLOBAL$$.adUnits.splice(i, 1);
}
}
})
});
};

/**
Expand Down
Loading

0 comments on commit 8fd265c

Please sign in to comment.