Skip to content

Commit

Permalink
Smartx Bid Adapter: updated out-stream render to support smartPlay 5.2 (
Browse files Browse the repository at this point in the history
#6370)

* Add smartclipBidAdapter

* smartxBidAdapter.js - removed unused variables, removed debug, added window before the outstream related functions

* - made outstream player configurable

* remove wrong named files

* camelcase

* fix

* Out-Stream render update to SmartPlay 5.2

* ESlint fix

* ESlint fix

* ESlint fix

* adjust tests, fixes

* ESlint

Co-authored-by: smartclip AdTechnology <adtech@smartclip.com>
Co-authored-by: Gino Cirlini <adtech@smartclip.tv>
  • Loading branch information
3 people authored Mar 5, 2021
1 parent f51ce4e commit dc15ae5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 51 deletions.
64 changes: 20 additions & 44 deletions modules/smartxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const spec = {
return false;
}
if (!utils.getBidIdParameter('outstream_function', bid.params)) {
utils.logMessage(BIDDER_CODE + ': outstream_function parameter is not defined. The default outstream renderer will be injected in the header. You can override the default SmartX outstream rendering by defining your own Outstream function using field outstream_function.');
utils.logMessage(BIDDER_CODE + ': outstream_function parameter is not defined. The default outstream renderer will be injected in the header.');
return true;
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ export const spec = {
return utils.logMessage('SmartX outstream video loaded event');
},
ended: function ended() {
utils.logMessage('SmartX outstream renderer video event');
return utils.logMessage('SmartX outstream renderer video event');
}
});
} catch (err) {
Expand All @@ -328,50 +328,25 @@ export const spec = {
}

function createOutstreamScript(bid) {
// for SmartPlay 4.12
function scPrebidClose(ele, completeCollapsed) {
if (completeCollapsed) {
document.getElementById(ele.id).style.display = 'none';
}
}

const confMinAdWidth = utils.getBidIdParameter('minAdWidth', bid.renderer.config.outstream_options) || 290;
const confMaxAdWidth = utils.getBidIdParameter('maxAdWidth', bid.renderer.config.outstream_options) || 900;
const confStartOpen = utils.getBidIdParameter('startOpen', bid.renderer.config.outstream_options) || 'false';
const confEndingScreen = utils.getBidIdParameter('endingScreen', bid.renderer.config.outstream_options) || 'true';
const confHeaderText = utils.getBidIdParameter('headerText', bid.renderer.config.outstream_options) || '';
const confSkipOffset = utils.getBidIdParameter('skipOffset', bid.renderer.config.outstream_options) || 0;
const confDesiredBitrate = utils.getBidIdParameter('desiredBitrate', bid.renderer.config.outstream_options) || 1600;
const confStartOpen = utils.getBidIdParameter('startOpen', bid.renderer.config.outstream_options);
const confEndingScreen = utils.getBidIdParameter('endingScreen', bid.renderer.config.outstream_options);
const confTitle = utils.getBidIdParameter('title', bid.renderer.config.outstream_options);
const confSkipOffset = utils.getBidIdParameter('skipOffset', bid.renderer.config.outstream_options);
const confDesiredBitrate = utils.getBidIdParameter('desiredBitrate', bid.renderer.config.outstream_options);
const elementId = utils.getBidIdParameter('slot', bid.renderer.config.outstream_options) || bid.adUnitCode;

// for SmartPlay 4.12
let initCollapsed = true;
let completeCollapsed = true;
if (confStartOpen === 'true') {
initCollapsed = false;
}
if (confEndingScreen === 'true') {
completeCollapsed = false;
}

utils.logMessage('[SMARTX][renderer] Handle SmartX outstream renderer');

let smartPlayObj = {
var smartPlayObj = {
minAdWidth: confMinAdWidth,
maxAdWidth: confMaxAdWidth,
headerText: confHeaderText,
title: confTitle,
skipOffset: confSkipOffset,
behaviourMatrix: {
init: {
'collapsed': initCollapsed
},
complete: {
'collapsed': completeCollapsed
}
},
environmentVars: {
desiredBitrate: confDesiredBitrate,
},
startOpen: confStartOpen,
endingScreen: confEndingScreen,
desiredBitrate: confDesiredBitrate,
onStartCallback: function (m, n) {
try {
window.sc_smartIntxtStart(n);
Expand All @@ -384,23 +359,24 @@ function createOutstreamScript(bid) {
},
onEndCallback: function (m, n) {
try {
scPrebidClose(n, completeCollapsed); // for SmartPlay 4.12
window.sc_smartIntxtEnd(n);
} catch (f) {}
},
};

smartPlayObj.adResponse = bid.vastContent;
const script = window.document.createElement('script');

const divID = '#' + elementId;
var script = document.createElement('script');
script.src = 'https://dco.smartclip.net/?plc=7777778';
script.type = 'text/javascript';
script.async = 'true';
script.src = 'https://dco.smartclip.net/?plc=7777777';
script.onload = script.onreadystatechange = function () {
var rs = this.readyState;
if (rs && rs != 'complete' && rs != 'loaded') return;
try {
window.SmartPlay(elementId, smartPlayObj);
// eslint-disable-next-line
let _outstreamPlayer = new OutstreamPlayer(divID, smartPlayObj);
} catch (e) {
utils.logError('error caught : ' + e);
utils.logError('[SmartPlay][renderer] Error caught: ' + e);
}
};
return script;
Expand Down
12 changes: 6 additions & 6 deletions modules/smartxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ This adapter requires setup and approval from the smartclip team.
slot: 'video1',
minAdWidth: 290,
maxAdWidth: 900,
headerText: '',
title: '',
skipOffset: 0,
startOpen: 'true',
endingScreen: 'true',
startOpen: true,
endingScreen: true,
desiredBitrate: 1600,
},
}
Expand Down Expand Up @@ -71,10 +71,10 @@ This adapter requires setup and approval from the smartclip team.
slot: 'video1',
minAdWidth: 290,
maxAdWidth: 900,
headerText: '',
title: '',
skipOffset: 0,
startOpen: 'true',
endingScreen: 'true',
startOpen: true,
endingScreen: true,
desiredBitrate: 1600,
},
user: {
Expand Down
4 changes: 3 additions & 1 deletion test/spec/modules/smartxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ describe('The smartx adapter', function () {
it('should return an array of bid responses', function () {
var responses = spec.interpretResponse(serverResponse, bidderRequestObj);
expect(responses).to.be.an('array').with.length(2);
expect(bidderRequestObj).to.be.an('Object');
expect(bidderRequestObj.bidRequest.bids).to.be.an('array').with.length(2);
expect(responses[0].requestId).to.equal(123);
expect(responses[0].currency).to.equal('USD');
expect(responses[0].cpm).to.equal(12);
Expand Down Expand Up @@ -505,7 +507,7 @@ describe('The smartx adapter', function () {
responses[0].renderer.render(responses[0]);

expect(scriptTag.getAttribute('type')).to.equal('text/javascript');
expect(scriptTag.getAttribute('src')).to.equal('https://dco.smartclip.net/?plc=7777777');
expect(scriptTag.getAttribute('src')).to.equal('https://dco.smartclip.net/?plc=7777778');

window.document.getElementById.restore();
});
Expand Down

0 comments on commit dc15ae5

Please sign in to comment.