/
video.js
62 lines (53 loc) · 2.23 KB
/
video.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {deepAccess, logError} from './utils.js';
import {config} from '../src/config.js';
import {hook} from './hook.js';
import {auctionManager} from './auctionManager.js';
export const OUTSTREAM = 'outstream';
export const INSTREAM = 'instream';
export function fillVideoDefaults(adUnit) {
const video = adUnit?.mediaTypes?.video;
if (video != null && video.plcmt == null) {
if (video.context === OUTSTREAM || [2, 3, 4].includes(video.placement)) {
video.plcmt = 4;
} else if (video.context !== OUTSTREAM && [2, 6].includes(video.playbackmethod)) {
video.plcmt = 2;
}
}
}
/**
* @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
* @param index
* @return {Boolean} If object is valid
*/
export function isValidVideoBid(bid, {index = auctionManager.index} = {}) {
const videoMediaType = deepAccess(index.getMediaTypes(bid), 'video');
const context = videoMediaType && deepAccess(videoMediaType, 'context');
const useCacheKey = videoMediaType && deepAccess(videoMediaType, 'useCacheKey');
const adUnit = index.getAdUnit(bid);
// if context not defined assume default 'instream' for video bids
// instream bids require a vast url or vast xml content
return checkVideoBidSetup(bid, adUnit, videoMediaType, context, useCacheKey);
}
export const checkVideoBidSetup = hook('sync', function(bid, adUnit, videoMediaType, context, useCacheKey) {
if (videoMediaType && (useCacheKey || context !== OUTSTREAM)) {
// xml-only video bids require a prebid cache url
if (!config.getConfig('cache.url') && bid.vastXml && !bid.vastUrl) {
logError(`
This bid contains only vastXml and will not work when a prebid cache url is not specified.
Try enabling prebid cache with $$PREBID_GLOBAL$$.setConfig({ cache: {url: "..."} });
`);
return false;
}
return !!(bid.vastUrl || bid.vastXml);
}
// outstream bids require a renderer on the bid or pub-defined on adunit
if (context === OUTSTREAM && !useCacheKey) {
return !!(bid.renderer || (adUnit && adUnit.renderer) || videoMediaType.renderer);
}
return true;
}, 'checkVideoBidSetup');