-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add support for video stream context #1483
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9bc0faa
Add support for video stream context
matthewlane 7b5d788
Define adapter as supporting video
matthewlane 2bff874
Use mediaTypes param to specify context
matthewlane ac8fea9
Use utils.deepAccess
matthewlane c581d4a
Check for outstream bids
matthewlane 81297c1
Add JSDoc and validation
matthewlane 3633165
Rename functions and add unit test
matthewlane 140675a
Update property name
matthewlane c9c366e
Update stubs to new sinon stub syntax
matthewlane 97cd71f
Only check context when mediaTypes.video was defined
matthewlane ccfc7ee
Retain video-outstream compatibility
matthewlane 0c8c9f1
Revert to Sinon 1 syntax
matthewlane 94bd7f2
Server and bid response ad type for any stream type is always 'video'
matthewlane 673dfef
Update to address code review
matthewlane 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
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,71 @@ | ||
import { isValidVideoBid } from 'src/video'; | ||
const utils = require('src/utils'); | ||
|
||
describe('video.js', () => { | ||
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); | ||
|
||
utils.getBidRequest.restore(); | ||
}); | ||
|
||
it('catches invalid instream bids', () => { | ||
sinon.stub(utils, 'getBidRequest', () => ({ | ||
bidder: 'appnexusAst', | ||
mediaTypes: { | ||
video: { context: 'instream' }, | ||
}, | ||
})); | ||
|
||
const valid = isValidVideoBid({}); | ||
|
||
expect(valid).to.be(false); | ||
|
||
utils.getBidRequest.restore(); | ||
}); | ||
|
||
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); | ||
|
||
utils.getBidRequest.restore(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these calls are better in a |
||
}); | ||
|
||
it('catches invalid outstream bids', () => { | ||
sinon.stub(utils, 'getBidRequest', () => ({ | ||
bidder: 'appnexusAst', | ||
mediaTypes: { | ||
video: { context: 'outstream' }, | ||
}, | ||
})); | ||
|
||
const valid = isValidVideoBid({}); | ||
|
||
expect(valid).to.be(false); | ||
|
||
utils.getBidRequest.restore(); | ||
}); | ||
}); |
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.
can you add the adUnit.code here so they know which adUnit failed validation?