UNPKG

video-ad-sdk

Version:

VAST/VPAID SDK that allows video ads to be played on top of any player

25 lines (24 loc) 961 B
import { hasAdPod, getAds, getPodAdSequence, isPodAd } from '../../vastSelectors'; import { hasAdBeenRequested } from './adUtils'; const getNextPod = (currentPod, ads) => { const nextPodSequence = (getPodAdSequence(currentPod) || 0) + 1; return ads.find((ad) => getPodAdSequence(ad) === nextPodSequence); }; export const getNextAd = ({ ad, parsedXML }, { fallbackOnNoAd = true, useAdBuffet = false }) => { const ads = getAds(parsedXML); const availableAds = ads.filter((adDefinition) => !hasAdBeenRequested(adDefinition)); let nextAd; if (hasAdPod(parsedXML)) { if (useAdBuffet) { nextAd = availableAds.find((adDefinition) => !isPodAd(adDefinition)); } if (ad && !nextAd) { nextAd = getNextPod(ad, availableAds); } } else if (availableAds.length > 0 && fallbackOnNoAd) { const [availableAd] = availableAds; nextAd = availableAd; } return nextAd; };