forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect coreVideo to Prebid #6
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6f4b9e3
prevents registering a same provider twice
karimMourra 42cba91
adds pb video
karimMourra 61b586b
adds video module to submodules list
karimMourra 944f9c3
adds integration example
karimMourra ee2882e
implements ad unit enrichment
karimMourra e56a4b2
moves submodule to parent dir
karimMourra 7664f81
removes comment
karimMourra 6db04d7
implements event listener
karimMourra c76b581
adds unit tests
karimMourra 06c01c6
tests updating video config
karimMourra cc33458
tests events surfacing
karimMourra 2dcc542
nests the event trigger tests
karimMourra 396158c
restores factory
karimMourra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<!-- | ||
|
||
--> | ||
|
||
<html> | ||
|
||
<head> | ||
<script async src="../../build/dev/prebid.js"></script> | ||
<script> | ||
var adUnits = [{ | ||
code: 'div-gpt-ad-51545-0', | ||
sizes: [[600, 500]], | ||
mediaTypes: { | ||
video: { | ||
sizes: [[600, 500]] | ||
} | ||
}, | ||
video: { | ||
divId: 'vid-div-1', | ||
adServer: { | ||
vendorCode: "gam", | ||
params: { | ||
iu: '/19968336/prebid_cache_video_adunit', | ||
cust_params: { | ||
section: 'blog', | ||
anotherKey: 'anotherValue' | ||
}, | ||
output: 'vast' | ||
} | ||
}, | ||
}, | ||
|
||
// Replace this object to test a new Adapter! | ||
bids: [{ | ||
bidder: 'ix', | ||
params: { | ||
siteId: '300', | ||
size: [600, 500] | ||
} | ||
}] | ||
}]; | ||
|
||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
</script> | ||
<script> | ||
pbjs.que.push(function () { | ||
pbjs.onEvent('adImpression', event => { | ||
console.log('adImpression: ', event); | ||
}); | ||
pbjs.addAdUnits(adUnits); | ||
pbjs.setConfig({ | ||
video: { | ||
providers: [{ | ||
divId: 'vid-div-1', | ||
vendorCode: 1, | ||
playerConfig: { | ||
licenseKey: "INSERT LICENSE KEY HERE", | ||
params: { | ||
vendorConfig: { | ||
"file": "http://content.bitsontherun.com/videos/3XnJSIm4-52qL9xLP.mp4", | ||
mediaid: 'd9J2zcaA', | ||
"advertising": { | ||
"adscheduleid": "00000000", | ||
client: 'vast', | ||
"offset": "10", | ||
"tag": [ | ||
"http://playertest.longtailvideo.com/pre-bad.xml", | ||
"http://playertest.longtailvideo.com/mid.xml" | ||
], | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
divId: 'vid-div-2', | ||
vendorCode: 1, | ||
playerConfig: { | ||
licenseKey: "INSERT LICENSE KEY HERE", | ||
params: { | ||
vendorConfig: { | ||
"file": "http://content.bitsontherun.com/videos/3XnJSIm4-52qL9xLP.mp4", | ||
mediaid: 'd9J2zcaA', | ||
"advertising": { | ||
"adscheduleid": "00000000", | ||
client: 'vast', | ||
"offset": "10", | ||
"tag": [ | ||
"http://playertest.longtailvideo.com/pre-bad.xml", | ||
"http://playertest.longtailvideo.com/mid.xml" | ||
], | ||
} | ||
} | ||
} | ||
} | ||
}] | ||
} | ||
}); | ||
pbjs.requestBids(); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h2>Prebid.js Test</h2> | ||
<h5>Div-1</h5> | ||
<div id='vid-div-1'></div> | ||
<h5>Div-2</h5> | ||
<div id='vid-div-2'></div> | ||
</body> | ||
|
||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...odule/submodules/jwplayerVideoProvider.js → modules/jwplayerVideoProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {config} from '../../src/config.js'; | ||
import events from '../../src/events.js'; | ||
import { allVideoEvents } from './constants/events.js'; | ||
import CONSTANTS from '../../src/constants.json'; | ||
import { videoCoreFactory } from './coreVideo.js'; | ||
|
||
events.addEvents(allVideoEvents); | ||
|
||
export function PbVideo(videoCore_, getConfig_, pbGlobal_, pbEvents_, videoEvents_) { | ||
const videoCore = videoCore_; | ||
const getConfig = getConfig_; | ||
const pbGlobal = pbGlobal_; | ||
const requestBids = pbGlobal.requestBids; | ||
const pbEvents = pbEvents_; | ||
const videoEvents = videoEvents_; | ||
|
||
function init() { | ||
getConfig('video', ({ video }) => { | ||
video.providers.forEach(provider => { | ||
try { | ||
videoCore.registerProvider(provider); | ||
videoCore.onEvents(videoEvents, (type, payload) => { | ||
pbEvents.emit(type, payload); | ||
}, provider.divId); | ||
} catch (e) {} | ||
}); | ||
}); | ||
|
||
requestBids.before(enrichAdUnits, 40); | ||
|
||
pbEvents.on(CONSTANTS.EVENTS.AUCTION_END, function(auctionResult) { | ||
// TODO: requires AdServer Module. | ||
// get ad tag from adServer - auctionResult.winningBids | ||
// coreVideo.setAdTagUrl(adTag, divId); | ||
}); | ||
} | ||
|
||
function enrichAdUnits(nextFn, bidRequest) { | ||
const adUnits = bidRequest.adUnits || pbGlobal.adUnits || []; | ||
adUnits.forEach(adUnit => { | ||
const oRtbParams = videoCore.getOrtbParams(adUnit.video.divId); | ||
adUnit.mediaTypes.video = Object.assign({}, adUnit.mediaTypes.video, oRtbParams); | ||
}); | ||
return nextFn.call(this, bidRequest); | ||
} | ||
|
||
return { init }; | ||
} | ||
|
||
function pbVideoFactory() { | ||
const videoCore = videoCoreFactory(); | ||
const pbVideo = PbVideo(videoCore, config.getConfig, $$PREBID_GLOBAL$$, events, allVideoEvents); | ||
pbVideo.init(); | ||
return pbVideo; | ||
} | ||
|
||
pbVideoFactory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { expect } from 'chai'; | ||
import { PbVideo } from 'modules/videoModule/index.js'; | ||
|
||
let ortbParamsMock; | ||
let videoCoreMock; | ||
let getConfigMock; | ||
let requestBidsMock; | ||
let pbGlobalMock; | ||
let pbEventsMock; | ||
let videoEventsMock; | ||
|
||
function resetTestVars() { | ||
ortbParamsMock = { | ||
'video': {}, | ||
'content': {} | ||
} | ||
videoCoreMock = { | ||
registerProvider: sinon.spy(), | ||
onEvents: sinon.spy(), | ||
getOrtbParams: () => ortbParamsMock | ||
}; | ||
getConfigMock = () => {}; | ||
requestBidsMock = { | ||
before: sinon.spy() | ||
}; | ||
pbGlobalMock = { | ||
requestBids: requestBidsMock | ||
}; | ||
pbEventsMock = { | ||
emit: sinon.spy(), | ||
on: sinon.spy() | ||
}; | ||
videoEventsMock = []; | ||
} | ||
|
||
let pbVideoFactory = (videoCore, getConfig, pbGlobal, pbEvents, videoEvents) => { | ||
const pbVideo = PbVideo( | ||
videoCore || videoCoreMock, | ||
getConfig || getConfigMock, | ||
pbGlobal || pbGlobalMock, | ||
pbEvents || pbEventsMock, | ||
videoEvents || videoEventsMock | ||
); | ||
pbVideo.init(); | ||
return pbVideo; | ||
} | ||
|
||
describe('Prebid Video', function () { | ||
beforeEach(() => resetTestVars()); | ||
|
||
describe('Setting video to config', function () { | ||
let providers = [{ divId: 'div1' }, { divId: 'div2' }]; | ||
let getConfigCallback; | ||
let getConfig = (video, callback) => { | ||
getConfigCallback = callback; | ||
}; | ||
|
||
beforeEach(() => { | ||
pbVideoFactory(null, getConfig); | ||
getConfigCallback({ video: { providers } }); | ||
}); | ||
|
||
it('Should register providers', function () { | ||
expect(videoCoreMock.registerProvider.calledTwice).to.be.true; | ||
}); | ||
|
||
it('Should register events', function () { | ||
expect(videoCoreMock.onEvents.calledTwice).to.be.true; | ||
const onEventsSpy = videoCoreMock.onEvents; | ||
expect(onEventsSpy.getCall(0).args[2]).to.be.equal('div1'); | ||
expect(onEventsSpy.getCall(1).args[2]).to.be.equal('div2'); | ||
}); | ||
|
||
describe('Event triggering', function () { | ||
it('Should emit events off of Prebid\'s Events', function () { | ||
let eventHandler; | ||
const videoCore = Object.assign({}, videoCoreMock, { | ||
onEvents: (events, eventHandler_) => eventHandler = eventHandler_ | ||
}); | ||
pbVideoFactory(videoCore, getConfig); | ||
getConfigCallback({ video: { providers } }); | ||
const expectedType = 'test_event'; | ||
const expectedPayload = {'test': 'data'}; | ||
eventHandler(expectedType, expectedPayload); | ||
expect(pbEventsMock.emit.calledOnce).to.be.true; | ||
expect(pbEventsMock.emit.getCall(0).args[0]).to.be.equal(expectedType); | ||
expect(pbEventsMock.emit.getCall(0).args[1]).to.be.equal(expectedPayload); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Ad unit Enrichment', function () { | ||
it('registers before:bidRequest hook', function () { | ||
const pbVideo = pbVideoFactory(); | ||
expect(requestBidsMock.before.calledOnce).to.be.true; | ||
}); | ||
|
||
it('requests oRtb params and writes them to ad unit', function() { | ||
const getOrtbParamsSpy = sinon.spy(videoCoreMock, 'getOrtbParams'); | ||
let beforeBidRequestCallback; | ||
const requestBids = { | ||
before: callback_ => beforeBidRequestCallback = callback_ | ||
}; | ||
|
||
const pbVideo = pbVideoFactory(null, null, { requestBids }); | ||
expect(beforeBidRequestCallback).to.not.be.undefined; | ||
const nextFn = sinon.spy(); | ||
const adUnits = [{ | ||
code: 'ad1', | ||
mediaTypes: { | ||
video: {} | ||
}, | ||
video: { divId: 'divId' } | ||
}]; | ||
beforeBidRequestCallback(nextFn, { adUnits }); | ||
expect(getOrtbParamsSpy.calledOnce).to.be.true; | ||
const adUnit = adUnits[0]; | ||
expect(adUnit.mediaTypes.video).to.have.property('video'); | ||
expect(adUnit.mediaTypes.video).to.have.property('content'); | ||
expect(nextFn.calledOnce).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('Ad tag injection', function () { | ||
// TODO: requires adServer to be implemented | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsnellbaker how do you feel about
events.addEvents
?