UNPKG

video-ad-sdk

Version:

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

39 lines (38 loc) 1.32 kB
import { renderIcon } from './renderIcon'; import { canBeShown } from './canBeShown'; export const renderIcons = async (icons, { onIconClick, videoAdContainer, logger = console }) => { const { element, videoElement } = videoAdContainer; const drawnIcons = []; const { iconsToShow, otherIcons } = icons.reduce((accumulator, icon) => { if (canBeShown(icon, videoElement)) { accumulator.iconsToShow.push(icon); } else { accumulator.otherIcons.push(icon); } return accumulator; }, { iconsToShow: [], otherIcons: [] }); otherIcons.forEach(({ element: iconElement }) => { var _a; (_a = iconElement === null || iconElement === void 0 ? void 0 : iconElement.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(iconElement); }); await iconsToShow.reduce(async (promise, icon) => { try { await promise; const renderedIcon = await renderIcon(icon, { document, drawnIcons, onIconClick, placeholder: element }); drawnIcons.push(renderedIcon); } catch (error) { logger.log(error); } }, Promise.resolve()); return drawnIcons; };