forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for video stream context (prebid#1483)
* Add support for video stream context * Define adapter as supporting video * Use mediaTypes param to specify context * Use utils.deepAccess * Check for outstream bids * Add JSDoc and validation * Rename functions and add unit test * Update property name * Update stubs to new sinon stub syntax * Only check context when mediaTypes.video was defined * Retain video-outstream compatibility * Revert to Sinon 1 syntax * Server and bid response ad type for any stream type is always 'video' * Update to address code review
- Loading branch information
1 parent
77b1ccc
commit be34e00
Showing
10 changed files
with
229 additions
and
14 deletions.
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
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
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 |
---|---|---|
@@ -1,8 +1,44 @@ | ||
import { videoAdapters } from './adaptermanager'; | ||
import { getBidRequest, deepAccess } from './utils'; | ||
|
||
const VIDEO_MEDIA_TYPE = 'video'; | ||
const OUTSTREAM = 'outstream'; | ||
|
||
/** | ||
* Helper functions for working with video-enabled adUnits | ||
*/ | ||
export const videoAdUnit = adUnit => adUnit.mediaType === 'video'; | ||
export const videoAdUnit = adUnit => adUnit.mediaType === VIDEO_MEDIA_TYPE; | ||
const nonVideoBidder = bid => !videoAdapters.includes(bid.bidder); | ||
export const hasNonVideoBidder = adUnit => adUnit.bids.filter(nonVideoBidder).length; | ||
export const hasNonVideoBidder = adUnit => | ||
adUnit.bids.filter(nonVideoBidder).length; | ||
|
||
/** | ||
* @typedef {object} VideoBid | ||
* @property {string} adId id of the bid | ||
*/ | ||
|
||
/** | ||
* Validate that the assets required for video context are present on the bid | ||
* @param {VideoBid} bid video bid to validate | ||
* @return {boolean} If object is valid | ||
*/ | ||
export function isValidVideoBid(bid) { | ||
const bidRequest = getBidRequest(bid.adId); | ||
|
||
const videoMediaType = | ||
bidRequest && deepAccess(bidRequest, 'mediaTypes.video'); | ||
const context = videoMediaType && deepAccess(videoMediaType, 'context'); | ||
|
||
// if context not defined assume default 'instream' for video bids | ||
// instream bids require a vast url or vast xml content | ||
if (!bidRequest || (videoMediaType && context !== OUTSTREAM)) { | ||
return !!(bid.vastUrl || bid.vastXml); | ||
} | ||
|
||
// outstream bids require a renderer on the bid or pub-defined on adunit | ||
if (context === OUTSTREAM) { | ||
return !!(bid.renderer || bidRequest.renderer); | ||
} | ||
|
||
return true; | ||
} |
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,67 @@ | ||
import { isValidVideoBid } from 'src/video'; | ||
const utils = require('src/utils'); | ||
|
||
describe('video.js', () => { | ||
afterEach(() => { | ||
utils.getBidRequest.restore(); | ||
}); | ||
|
||
it('validates valid instream bids', () => { | ||
sinon.stub(utils, 'getBidRequest', () => ({ | ||
bidder: 'appnexusAst', | ||
mediaTypes: { | ||
video: { context: 'instream' }, | ||
}, | ||
})); | ||
|
||
const valid = isValidVideoBid({ | ||
vastUrl: 'http://www.example.com/vastUrl' | ||
}); | ||
|
||
expect(valid).to.be(true); | ||
}); | ||
|
||
it('catches invalid instream bids', () => { | ||
sinon.stub(utils, 'getBidRequest', () => ({ | ||
bidder: 'appnexusAst', | ||
mediaTypes: { | ||
video: { context: 'instream' }, | ||
}, | ||
})); | ||
|
||
const valid = isValidVideoBid({}); | ||
|
||
expect(valid).to.be(false); | ||
}); | ||
|
||
it('validates valid outstream bids', () => { | ||
sinon.stub(utils, 'getBidRequest', () => ({ | ||
bidder: 'appnexusAst', | ||
mediaTypes: { | ||
video: { context: 'outstream' }, | ||
}, | ||
})); | ||
|
||
const valid = isValidVideoBid({ | ||
renderer: { | ||
url: 'render.url', | ||
render: () => true, | ||
} | ||
}); | ||
|
||
expect(valid).to.be(true); | ||
}); | ||
|
||
it('catches invalid outstream bids', () => { | ||
sinon.stub(utils, 'getBidRequest', () => ({ | ||
bidder: 'appnexusAst', | ||
mediaTypes: { | ||
video: { context: 'outstream' }, | ||
}, | ||
})); | ||
|
||
const valid = isValidVideoBid({}); | ||
|
||
expect(valid).to.be(false); | ||
}); | ||
}); |