!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["whepvideo.component"]=t():e["whepvideo.component"]=t()}(self,(()=>(()=>{var e={248:function(e,t){!function(e){"use strict";function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function n(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(e,t)}function d(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function h(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=l(e);if(t){var i=l(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return d(this,n)}}function p(e){return function(e){if(Array.isArray(e))return f(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function v(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{id:e.id||null,adId:e.adId||null,sequence:e.sequence||null,apiFramework:e.apiFramework||null,universalAdIds:[],creativeExtensions:[]}}var m=["ADCATEGORIES","ADCOUNT","ADPLAYHEAD","ADSERVINGID","ADTYPE","APIFRAMEWORKS","APPBUNDLE","ASSETURI","BLOCKEDADCATEGORIES","BREAKMAXADLENGTH","BREAKMAXADS","BREAKMAXDURATION","BREAKMINADLENGTH","BREAKMINDURATION","BREAKPOSITION","CLICKPOS","CLICKTYPE","CLIENTUA","CONTENTID","CONTENTPLAYHEAD","CONTENTURI","DEVICEIP","DEVICEUA","DOMAIN","EXTENSIONS","GDPRCONSENT","IFA","IFATYPE","INVENTORYSTATE","LATLONG","LIMITADTRACKING","MEDIAMIME","MEDIAPLAYHEAD","OMIDPARTNER","PAGEURL","PLACEMENTTYPE","PLAYERCAPABILITIES","PLAYERSIZE","PLAYERSTATE","PODSEQUENCE","REGULATIONS","SERVERSIDE","SERVERUA","TRANSACTIONID","UNIVERSALADID","VASTVERSIONS","VERIFICATIONVENDORS"];function g(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=[],i=A(e);for(var a in!t.ERRORCODE||n.isCustomCode||/^[0-9]{3}$/.test(t.ERRORCODE)||(t.ERRORCODE=900),t.CACHEBUSTING=R(Math.round(1e8*Math.random())),t.TIMESTAMP=(new Date).toISOString(),t.RANDOM=t.random=t.CACHEBUSTING,t)t[a]=E(t[a]);for(var o in i){var s=i[o];"string"==typeof s&&r.push(y(s,t))}return r}function y(e,t){var n=(e=T(e,t)).match(/[^[\]]+(?=])/g);if(!n)return e;var r=n.filter((function(e){return m.indexOf(e)>-1}));return 0===r.length?e:T(e,r=r.reduce((function(e,t){return e[t]=-1,e}),{}))}function T(e,t){var n=e;for(var r in t){var i=t[r];n=n.replace(new RegExp("(?:\\[|%%)(".concat(r,")(?:\\]|%%)"),"g"),i)}return n}function A(e){return Array.isArray(e)?e.map((function(e){return e&&e.hasOwnProperty("url")?e.url:e})):e}function b(e,t){for(var n=0;n<t.length;n++)if(k(t[n],e))return!0;return!1}function k(e,t){if(e&&t){var n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertyNames(t);return n.length===r.length&&e.id===t.id&&e.url===t.url}return!1}function E(e){return encodeURIComponent(e).replace(/[!'()*]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16))}))}function R(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8;return e.toString().padStart(t,"0")}var w={track:function(e,t,n){g(e,t,n).forEach((function(e){"undefined"!=typeof window&&null!==window&&((new Image).src=e)}))},resolveURLTemplates:g,extractURLsFromTemplates:A,containsTemplateObject:b,isTemplateObjectEqual:k,encodeURIComponentRFC3986:E,replaceUrlMacros:y,isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},flatten:function e(t){return t.reduce((function(t,n){return t.concat(Array.isArray(n)?e(n):n)}),[])},joinArrayOfUniqueTemplateObjs:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=Array.isArray(e)?e:[],r=Array.isArray(t)?t:[];return n.concat(r).reduce((function(e,t){return b(t,e)||e.push(t),e}),[])},isValidTimeValue:function(e){return Number.isFinite(e)&&e>=-2},addLeadingZeros:R};function L(e){return-1!==["true","TRUE","True","1"].indexOf(e)}var C={childByName:function(e,t){var n=e.childNodes;for(var r in n){var i=n[r];if(i.nodeName===t)return i}},childrenByName:function(e,t){var n=[],r=e.childNodes;for(var i in r){var a=r[i];a.nodeName===t&&n.push(a)}return n},resolveVastAdTagURI:function(e,t){if(!t)return e;if(0===e.indexOf("//")){var n=location.protocol;return"".concat(n).concat(e)}if(-1===e.indexOf("://")){var r=t.slice(0,t.lastIndexOf("/"));return"".concat(r,"/").concat(e)}return e},parseBoolean:L,parseNodeText:function(e){return e&&(e.textContent||e.text||"").trim()},copyNodeAttribute:function(e,t,n){var r=t.getAttribute(e);r&&n.setAttribute(e,r)},parseAttributes:function(e){for(var t=e.attributes,n={},r=0;r<t.length;r++)n[t[r].nodeName]=t[r].nodeValue;return n},parseDuration:function(e){if(null==e)return-1;if(w.isNumeric(e))return parseInt(e);var t=e.split(":");if(3!==t.length)return-1;var n=t[2].split("."),r=parseInt(n[0]);2===n.length&&(r+=parseFloat("0.".concat(n[1])));var i=parseInt(60*t[1]),a=parseInt(60*t[0]*60);return isNaN(a)||isNaN(i)||isNaN(r)||i>3600||r>60?-1:a+i+r},splitVAST:function(e){var t=[],n=null;return e.forEach((function(r,i){if(r.sequence&&(r.sequence=parseInt(r.sequence,10)),r.sequence>1){var a=e[i-1];if(a&&a.sequence===r.sequence-1)return void(n&&n.push(r));delete r.sequence}n=[r],t.push(n)})),t},assignAttributes:function(e,t){if(e)for(var n in e){var r=e[n];if(r.nodeName&&r.nodeValue&&t.hasOwnProperty(r.nodeName)){var i=r.nodeValue;"boolean"==typeof t[r.nodeName]&&(i=L(i)),t[r.nodeName]=i}}},mergeWrapperAdData:function(e,t){e.errorURLTemplates=t.errorURLTemplates.concat(e.errorURLTemplates),e.impressionURLTemplates=t.impressionURLTemplates.concat(e.impressionURLTemplates),e.extensions=t.extensions.concat(e.extensions),t.viewableImpression.length>0&&(e.viewableImpression=[].concat(p(e.viewableImpression),p(t.viewableImpression))),e.followAdditionalWrappers=t.followAdditionalWrappers,e.allowMultipleAds=t.allowMultipleAds,e.fallbackOnNoAd=t.fallbackOnNoAd;var n=(t.creatives||[]).filter((function(e){return e&&"companion"===e.type})),r=n.reduce((function(e,t){return(t.variations||[]).forEach((function(t){(t.companionClickTrackingURLTemplates||[]).forEach((function(t){w.containsTemplateObject(t,e)||e.push(t)}))})),e}),[]);e.creatives=n.concat(e.creatives);var i=t.videoClickTrackingURLTemplates&&t.videoClickTrackingURLTemplates.length,a=t.videoCustomClickURLTemplates&&t.videoCustomClickURLTemplates.length;e.creatives.forEach((function(e){if(t.trackingEvents&&t.trackingEvents[e.type])for(var n in t.trackingEvents[e.type]){var o=t.trackingEvents[e.type][n];Array.isArray(e.trackingEvents[n])||(e.trackingEvents[n]=[]),e.trackingEvents[n]=e.trackingEvents[n].concat(o)}"linear"===e.type&&(i&&(e.videoClickTrackingURLTemplates=e.videoClickTrackingURLTemplates.concat(t.videoClickTrackingURLTemplates)),a&&(e.videoCustomClickURLTemplates=e.videoCustomClickURLTemplates.concat(t.videoCustomClickURLTemplates)),!t.videoClickThroughURLTemplate||null!==e.videoClickThroughURLTemplate&&void 0!==e.videoClickThroughURLTemplate||(e.videoClickThroughURLTemplate=t.videoClickThroughURLTemplate)),"companion"===e.type&&r.length&&(e.variations||[]).forEach((function(e){e.companionClickTrackingURLTemplates=w.joinArrayOfUniqueTemplateObjs(e.companionClickTrackingURLTemplates,r)}))})),t.adVerifications&&(e.adVerifications=e.adVerifications.concat(t.adVerifications)),t.blockedAdCategories&&(e.blockedAdCategories=e.blockedAdCategories.concat(t.blockedAdCategories))}};function S(e,t){var n=function(){var e=v(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return{id:e.id,adId:e.adId,sequence:e.sequence,apiFramework:e.apiFramework,type:"companion",required:null,variations:[]}}(t);return n.required=e.getAttribute("required")||null,n.variations=C.childrenByName(e,"Companion").map((function(e){var t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{id:e.id||null,adType:"companionAd",width:e.width||0,height:e.height||0,assetWidth:e.assetWidth||null,assetHeight:e.assetHeight||null,expandedWidth:e.expandedWidth||null,expandedHeight:e.expandedHeight||null,apiFramework:e.apiFramework||null,adSlotID:e.adSlotID||null,pxratio:e.pxratio||"1",renderingMode:e.renderingMode||"default",staticResources:[],htmlResources:[],iframeResources:[],adParameters:null,xmlEncoded:null,altText:null,companionClickThroughURLTemplate:null,companionClickTrackingURLTemplates:[],trackingEvents:{}}}(C.parseAttributes(e));t.htmlResources=C.childrenByName(e,"HTMLResource").reduce((function(e,t){var n=C.parseNodeText(t);return n?e.concat(n):e}),[]),t.iframeResources=C.childrenByName(e,"IFrameResource").reduce((function(e,t){var n=C.parseNodeText(t);return n?e.concat(n):e}),[]),t.staticResources=C.childrenByName(e,"StaticResource").reduce((function(e,t){var n=C.parseNodeText(t);return n?e.concat({url:n,creativeType:t.getAttribute("creativeType")||null}):e}),[]),t.altText=C.parseNodeText(C.childByName(e,"AltText"))||null;var n=C.childByName(e,"TrackingEvents");n&&C.childrenByName(n,"Tracking").forEach((function(e){var n=e.getAttribute("event"),r=C.parseNodeText(e);n&&r&&(Array.isArray(t.trackingEvents[n])||(t.trackingEvents[n]=[]),t.trackingEvents[n].push(r))})),t.companionClickTrackingURLTemplates=C.childrenByName(e,"CompanionClickTracking").map((function(e){return{id:e.getAttribute("id")||null,url:C.parseNodeText(e)}})),t.companionClickThroughURLTemplate=C.parseNodeText(C.childByName(e,"CompanionClickThrough"))||null;var r=C.childByName(e,"AdParameters");return r&&(t.adParameters=C.parseNodeText(r),t.xmlEncoded=r.getAttribute("xmlEncoded")||null),t})),n}function N(e){return"linear"===e.type}function P(e,t){var n,r=function(){var e=v(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return{id:e.id,adId:e.adId,sequence:e.sequence,apiFramework:e.apiFramework,type:"linear",duration:0,skipDelay:null,mediaFiles:[],mezzanine:null,interactiveCreativeFile:null,closedCaptionFiles:[],videoClickThroughURLTemplate:null,videoClickTrackingURLTemplates:[],videoCustomClickURLTemplates:[],adParameters:null,icons:[],trackingEvents:{}}}(t);r.duration=C.parseDuration(C.parseNodeText(C.childByName(e,"Duration")));var i=e.getAttribute("skipoffset");if(null==i)r.skipDelay=null;else if("%"===i.charAt(i.length-1)&&-1!==r.duration){var a=parseInt(i,10);r.skipDelay=r.duration*(a/100)}else r.skipDelay=C.parseDuration(i);var o=C.childByName(e,"VideoClicks");if(o){var s=C.childByName(o,"ClickThrough");r.videoClickThroughURLTemplate=s?{id:s.getAttribute("id")||null,url:C.parseNodeText(s)}:null,C.childrenByName(o,"ClickTracking").forEach((function(e){r.videoClickTrackingURLTemplates.push({id:e.getAttribute("id")||null,url:C.parseNodeText(e)})})),C.childrenByName(o,"CustomClick").forEach((function(e){r.videoCustomClickURLTemplates.push({id:e.getAttribute("id")||null,url:C.parseNodeText(e)})}))}var c=C.childByName(e,"AdParameters");c&&(r.adParameters=C.parseNodeText(c)),C.childrenByName(e,"TrackingEvents").forEach((function(e){C.childrenByName(e,"Tracking").forEach((function(e){var t=e.getAttribute("event"),i=C.parseNodeText(e);if(t&&i){if("progress"===t){if(!(n=e.getAttribute("offset")))return;t="%"===n.charAt(n.length-1)?"progress-".concat(n):"progress-".concat(Math.round(C.parseDuration(n)))}Array.isArray(r.trackingEvents[t])||(r.trackingEvents[t]=[]),r.trackingEvents[t].push(i)}}))})),C.childrenByName(e,"MediaFiles").forEach((function(e){C.childrenByName(e,"MediaFile").forEach((function(e){r.mediaFiles.push(function(e){var t={id:null,fileURL:null,fileSize:0,deliveryType:"progressive",mimeType:null,mediaType:null,codec:null,bitrate:0,minBitrate:0,maxBitrate:0,width:0,height:0,apiFramework:null,scalable:null,maintainAspectRatio:null};t.id=e.getAttribute("id"),t.fileURL=C.parseNodeText(e),t.deliveryType=e.getAttribute("delivery"),t.codec=e.getAttribute("codec"),t.mimeType=e.getAttribute("type"),t.mediaType=e.getAttribute("mediaType")||"2D",t.apiFramework=e.getAttribute("apiFramework"),t.fileSize=parseInt(e.getAttribute("fileSize")||0),t.bitrate=parseInt(e.getAttribute("bitrate")||0),t.minBitrate=parseInt(e.getAttribute("minBitrate")||0),t.maxBitrate=parseInt(e.getAttribute("maxBitrate")||0),t.width=parseInt(e.getAttribute("width")||0),t.height=parseInt(e.getAttribute("height")||0);var n=e.getAttribute("scalable");n&&"string"==typeof n&&(t.scalable=C.parseBoolean(n));var r=e.getAttribute("maintainAspectRatio");return r&&"string"==typeof r&&(t.maintainAspectRatio=C.parseBoolean(r)),t}(e))}));var t=C.childByName(e,"InteractiveCreativeFile");t&&(r.interactiveCreativeFile=function(e){var t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{type:e.type||null,apiFramework:e.apiFramework||null,variableDuration:C.parseBoolean(e.variableDuration),fileURL:null}}(C.parseAttributes(e));return t.fileURL=C.parseNodeText(e),t}(t));var n=C.childByName(e,"ClosedCaptionFiles");n&&C.childrenByName(n,"ClosedCaptionFile").forEach((function(e){var t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{type:e.type||null,language:e.language||null,fileURL:null}}(C.parseAttributes(e));t.fileURL=C.parseNodeText(e),r.closedCaptionFiles.push(t)}));var i,a,o,s=C.childByName(e,"Mezzanine"),c=(i=s,a={},o=!1,["delivery","type","width","height"].forEach((function(e){i&&i.getAttribute(e)?a[e]=i.getAttribute(e):o=!0})),o?null:a);if(c){var l={id:null,fileURL:null,delivery:null,codec:null,type:null,width:0,height:0,fileSize:0,mediaType:"2D"};l.id=s.getAttribute("id"),l.fileURL=C.parseNodeText(s),l.delivery=c.delivery,l.codec=s.getAttribute("codec"),l.type=c.type,l.width=parseInt(c.width,10),l.height=parseInt(c.height,10),l.fileSize=parseInt(s.getAttribute("fileSize"),10),l.mediaType=s.getAttribute("mediaType")||"2D",r.mezzanine=l}}));var l=C.childByName(e,"Icons");return l&&C.childrenByName(l,"Icon").forEach((function(e){r.icons.push(function(e){var t={program:null,height:0,width:0,xPosition:0,yPosition:0,apiFramework:null,offset:null,duration:0,type:null,staticResource:null,htmlResource:null,iframeResource:null,pxratio:"1",iconClickThroughURLTemplate:null,iconClickTrackingURLTemplates:[],iconViewTrackingURLTemplate:null};t.program=e.getAttribute("program"),t.height=parseInt(e.getAttribute("height")||0),t.width=parseInt(e.getAttribute("width")||0),t.xPosition=function(e){return-1!==["left","right"].indexOf(e)?e:parseInt(e||0)}(e.getAttribute("xPosition")),t.yPosition=function(e){return-1!==["top","bottom"].indexOf(e)?e:parseInt(e||0)}(e.getAttribute("yPosition")),t.apiFramework=e.getAttribute("apiFramework"),t.pxratio=e.getAttribute("pxratio")||"1",t.offset=C.parseDuration(e.getAttribute("offset")),t.duration=C.parseDuration(e.getAttribute("duration")),C.childrenByName(e,"HTMLResource").forEach((function(e){t.type=e.getAttribute("creativeType")||"text/html",t.htmlResource=C.parseNodeText(e)})),C.childrenByName(e,"IFrameResource").forEach((function(e){t.type=e.getAttribute("creativeType")||0,t.iframeResource=C.parseNodeText(e)})),C.childrenByName(e,"StaticResource").forEach((function(e){t.type=e.getAttribute("creativeType")||0,t.staticResource=C.parseNodeText(e)}));var n=C.childByName(e,"IconClicks");return n&&(t.iconClickThroughURLTemplate=C.parseNodeText(C.childByName(n,"IconClickThrough")),C.childrenByName(n,"IconClickTracking").forEach((function(e){t.iconClickTrackingURLTemplates.push({id:e.getAttribute("id")||null,url:C.parseNodeText(e)})}))),t.iconViewTrackingURLTemplate=C.parseNodeText(C.childByName(e,"IconViewTracking")),t}(e))})),r}function I(e,t){var n=function(){var e=v(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return{id:e.id,adId:e.adId,sequence:e.sequence,apiFramework:e.apiFramework,type:"nonlinear",variations:[],trackingEvents:{}}}(t);return C.childrenByName(e,"TrackingEvents").forEach((function(e){var t,r;C.childrenByName(e,"Tracking").forEach((function(e){t=e.getAttribute("event"),r=C.parseNodeText(e),t&&r&&(Array.isArray(n.trackingEvents[t])||(n.trackingEvents[t]=[]),n.trackingEvents[t].push(r))}))})),C.childrenByName(e,"NonLinear").forEach((function(e){var t={id:null,width:0,height:0,expandedWidth:0,expandedHeight:0,scalable:!0,maintainAspectRatio:!0,minSuggestedDuration:0,apiFramework:"static",adType:"nonLinearAd",type:null,staticResource:null,htmlResource:null,iframeResource:null,nonlinearClickThroughURLTemplate:null,nonlinearClickTrackingURLTemplates:[],adParameters:null};t.id=e.getAttribute("id")||null,t.width=e.getAttribute("width"),t.height=e.getAttribute("height"),t.expandedWidth=e.getAttribute("expandedWidth"),t.expandedHeight=e.getAttribute("expandedHeight"),t.scalable=C.parseBoolean(e.getAttribute("scalable")),t.maintainAspectRatio=C.parseBoolean(e.getAttribute("maintainAspectRatio")),t.minSuggestedDuration=C.parseDuration(e.getAttribute("minSuggestedDuration")),t.apiFramework=e.getAttribute("apiFramework"),C.childrenByName(e,"HTMLResource").forEach((function(e){t.type=e.getAttribute("creativeType")||"text/html",t.htmlResource=C.parseNodeText(e)})),C.childrenByName(e,"IFrameResource").forEach((function(e){t.type=e.getAttribute("creativeType")||0,t.iframeResource=C.parseNodeText(e)})),C.childrenByName(e,"StaticResource").forEach((function(e){t.type=e.getAttribute("creativeType")||0,t.staticResource=C.parseNodeText(e)}));var r=C.childByName(e,"AdParameters");r&&(t.adParameters=C.parseNodeText(r)),t.nonlinearClickThroughURLTemplate=C.parseNodeText(C.childByName(e,"NonLinearClickThrough")),C.childrenByName(e,"NonLinearClickTracking").forEach((function(e){t.nonlinearClickTrackingURLTemplates.push({id:e.getAttribute("id")||null,url:C.parseNodeText(e)})})),n.variations.push(t)})),n}function U(e){var t=[];return e.forEach((function(e){var n=O(e);n&&t.push(n)})),t}function O(e){if("#comment"===e.nodeName)return null;var t,n={name:null,value:null,attributes:{},children:[]},r=e.attributes,i=e.childNodes;if(n.name=e.nodeName,e.attributes)for(var a in r)if(r.hasOwnProperty(a)){var o=r[a];o.nodeName&&o.nodeValue&&(n.attributes[o.nodeName]=o.nodeValue)}for(var s in i)if(i.hasOwnProperty(s)){var c=O(i[s]);c&&n.children.push(c)}if(0===n.children.length||1===n.children.length&&["#cdata-section","#text"].indexOf(n.children[0].name)>=0){var l=C.parseNodeText(e);""!==l&&(n.value=l),n.children=[]}return null===(t=n).value&&0===Object.keys(t.attributes).length&&0===t.children.length?null:n}function x(e){var t=[];return e.forEach((function(e){var n,r={id:e.getAttribute("id")||null,adId:V(e),sequence:e.getAttribute("sequence")||null,apiFramework:e.getAttribute("apiFramework")||null},i=[];C.childrenByName(e,"UniversalAdId").forEach((function(e){var t={idRegistry:e.getAttribute("idRegistry")||"unknown",value:C.parseNodeText(e)};i.push(t)}));var a=C.childByName(e,"CreativeExtensions");for(var o in a&&(n=U(C.childrenByName(a,"CreativeExtension"))),e.childNodes){var s=e.childNodes[o],c=void 0;switch(s.nodeName){case"Linear":c=P(s,r);break;case"NonLinearAds":c=I(s,r);break;case"CompanionAds":c=S(s,r)}c&&(i&&(c.universalAdIds=i),n&&(c.creativeExtensions=n),t.push(c))}})),t}function V(e){return e.getAttribute("AdID")||e.getAttribute("adID")||e.getAttribute("adId")||null}var D={Wrapper:{subElements:["VASTAdTagURI","Impression"]},BlockedAdCategories:{attributes:["authority"]},InLine:{subElements:["AdSystem","AdTitle","Impression","AdServingId","Creatives"]},Category:{attributes:["authority"]},Pricing:{attributes:["model","currency"]},Verification:{oneOfinLineResources:["JavaScriptResource","ExecutableResource"],attributes:["vendor"]},UniversalAdId:{attributes:["idRegistry"]},JavaScriptResource:{attributes:["apiFramework","browserOptional"]},ExecutableResource:{attributes:["apiFramework","type"]},Tracking:{attributes:["event"]},Creatives:{subElements:["Creative"]},Creative:{subElements:["UniversalAdId"]},Linear:{subElements:["MediaFiles","Duration"]},MediaFiles:{subElements:["MediaFile"]},MediaFile:{attributes:["delivery","type","width","height"]},Mezzanine:{attributes:["delivery","type","width","height"]},NonLinear:{oneOfinLineResources:["StaticResource","IFrameResource","HTMLResource"],attributes:["width","height"]},Companion:{oneOfinLineResources:["StaticResource","IFrameResource","HTMLResource"],attributes:["width","height"]},StaticResource:{attributes:["creativeType"]},Icons:{subElements:["Icon"]},Icon:{oneOfinLineResources:["StaticResource","IFrameResource","HTMLResource"]}};function M(e,t){if(D[e.nodeName]&&D[e.nodeName].attributes){var n=D[e.nodeName].attributes.filter((function(t){return!e.getAttribute(t)}));n.length>0&&j({name:e.nodeName,parentName:e.parentNode.nodeName,attributes:n},t)}}function B(e,t,n){var r=D[e.nodeName],i=!n&&"Wrapper"!==e.nodeName;if(r&&!i){if(r.subElements){var a=r.subElements.filter((function(t){return!C.childByName(e,t)}));a.length>0&&j({name:e.nodeName,parentName:e.parentNode.nodeName,subElements:a},t)}n&&r.oneOfinLineResources&&(r.oneOfinLineResources.some((function(t){return C.childByName(e,t)}))||j({name:e.nodeName,parentName:e.parentNode.nodeName,oneOfResources:r.oneOfinLineResources},t))}}function F(e){return e.children&&0!==e.children.length}function j(e,t){var n=e.name,r=e.parentName,i=e.attributes,a=e.subElements,o=e.oneOfResources,s="Element '".concat(n,"'");t("VAST-warning",{message:s+=i?" missing required attribute(s) '".concat(i.join(", "),"' "):a?" missing required sub element(s) '".concat(a.join(", "),"' "):o?" must provide one of the following '".concat(o.join(", "),"' "):" is empty",parentElement:r,specVersion:4.1})}var _=function e(t,n,r){if(t&&t.nodeName)if("InLine"===t.nodeName&&(r=!0),M(t,n),F(t)){B(t,n,r);for(var i=0;i<t.children.length;i++)e(t.children[i],n,r)}else 0===C.parseNodeText(t).length&&j({name:t.nodeName,parentName:t.parentNode.nodeName},n)};function W(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.allowMultipleAds,i=n.followAdditionalWrappers,a=e.childNodes;for(var o in a){var s=a[o];if(-1!==["Wrapper","InLine"].indexOf(s.nodeName)&&("Wrapper"!==s.nodeName||!1!==i)){if(C.copyNodeAttribute("id",e,s),C.copyNodeAttribute("sequence",e,s),C.copyNodeAttribute("adType",e,s),"Wrapper"===s.nodeName)return{ad:q(s,t),type:"WRAPPER"};if("InLine"===s.nodeName)return{ad:H(s,t,{allowMultipleAds:r}),type:"INLINE"}}}}function H(e,t){return!1===(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).allowMultipleAds&&e.getAttribute("sequence")?null:G(e,t)}function G(e,t){var n=[];t&&_(e,t);var r=e.childNodes,i=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{id:e.id||null,sequence:e.sequence||null,adType:e.adType||null,adServingId:null,categories:[],expires:null,viewableImpression:[],system:null,title:null,description:null,advertiser:null,pricing:null,survey:null,errorURLTemplates:[],impressionURLTemplates:[],creatives:[],extensions:[],adVerifications:[],blockedAdCategories:[],followAdditionalWrappers:!0,allowMultipleAds:!1,fallbackOnNoAd:null}}(C.parseAttributes(e));for(var a in r){var o=r[a];switch(o.nodeName){case"Error":i.errorURLTemplates.push(C.parseNodeText(o));break;case"Impression":i.impressionURLTemplates.push({id:o.getAttribute("id")||null,url:C.parseNodeText(o)});break;case"Creatives":i.creatives=x(C.childrenByName(o,"Creative"));break;case"Extensions":var s=C.childrenByName(o,"Extension");i.extensions=U(s),i.adVerifications.length||(n=Y(s));break;case"AdVerifications":i.adVerifications=K(C.childrenByName(o,"Verification"));break;case"AdSystem":i.system={value:C.parseNodeText(o),version:o.getAttribute("version")||null};break;case"AdTitle":i.title=C.parseNodeText(o);break;case"AdServingId":i.adServingId=C.parseNodeText(o);break;case"Category":i.categories.push({authority:o.getAttribute("authority")||null,value:C.parseNodeText(o)});break;case"Expires":i.expires=parseInt(C.parseNodeText(o),10);break;case"ViewableImpression":i.viewableImpression.push(Q(o));break;case"Description":i.description=C.parseNodeText(o);break;case"Advertiser":i.advertiser={id:o.getAttribute("id")||null,value:C.parseNodeText(o)};break;case"Pricing":i.pricing={value:C.parseNodeText(o),model:o.getAttribute("model")||null,currency:o.getAttribute("currency")||null};break;case"Survey":i.survey=C.parseNodeText(o);break;case"BlockedAdCategories":i.blockedAdCategories.push({authority:o.getAttribute("authority")||null,value:C.parseNodeText(o)})}}return n.length&&(i.adVerifications=i.adVerifications.concat(n)),i}function q(e,t){var n=G(e,t),r=e.getAttribute("followAdditionalWrappers"),i=e.getAttribute("allowMultipleAds"),a=e.getAttribute("fallbackOnNoAd");n.followAdditionalWrappers=!r||C.parseBoolean(r),n.allowMultipleAds=!!i&&C.parseBoolean(i),n.fallbackOnNoAd=a?C.parseBoolean(a):null;var o=C.childByName(e,"VASTAdTagURI");if(o?n.nextWrapperURL=C.parseNodeText(o):(o=C.childByName(e,"VASTAdTagURL"))&&(n.nextWrapperURL=C.parseNodeText(C.childByName(o,"URL"))),n.creatives.forEach((function(e){if(-1!==["linear","nonlinear"].indexOf(e.type)){if(e.trackingEvents){n.trackingEvents||(n.trackingEvents={}),n.trackingEvents[e.type]||(n.trackingEvents[e.type]={});var t=function(t){var r=e.trackingEvents[t];Array.isArray(n.trackingEvents[e.type][t])||(n.trackingEvents[e.type][t]=[]),r.forEach((function(r){n.trackingEvents[e.type][t].push(r)}))};for(var r in e.trackingEvents)t(r)}e.videoClickTrackingURLTemplates&&(Array.isArray(n.videoClickTrackingURLTemplates)||(n.videoClickTrackingURLTemplates=[]),e.videoClickTrackingURLTemplates.forEach((function(e){n.videoClickTrackingURLTemplates.push(e)}))),e.videoClickThroughURLTemplate&&(n.videoClickThroughURLTemplate=e.videoClickThroughURLTemplate),e.videoCustomClickURLTemplates&&(Array.isArray(n.videoCustomClickURLTemplates)||(n.videoCustomClickURLTemplates=[]),e.videoCustomClickURLTemplates.forEach((function(e){n.videoCustomClickURLTemplates.push(e)})))}})),n.nextWrapperURL)return n}function K(e){var t=[];return e.forEach((function(e){var n={resource:null,vendor:null,browserOptional:!1,apiFramework:null,type:null,parameters:null,trackingEvents:{}},r=e.childNodes;for(var i in C.assignAttributes(e.attributes,n),r){var a=r[i];switch(a.nodeName){case"JavaScriptResource":case"ExecutableResource":n.resource=C.parseNodeText(a),C.assignAttributes(a.attributes,n);break;case"VerificationParameters":n.parameters=C.parseNodeText(a)}}var o=C.childByName(e,"TrackingEvents");o&&C.childrenByName(o,"Tracking").forEach((function(e){var t=e.getAttribute("event"),r=C.parseNodeText(e);t&&r&&(Array.isArray(n.trackingEvents[t])||(n.trackingEvents[t]=[]),n.trackingEvents[t].push(r))})),t.push(n)})),t}function Y(e){var t=null,n=[];return e.some((function(e){return t=C.childByName(e,"AdVerifications")})),t&&(n=K(C.childrenByName(t,"Verification"))),n}function Q(e){var t={};t.id=e.getAttribute("id")||null;var n=e.childNodes;for(var r in n){var i=n[r],a=i.nodeName,o=C.parseNodeText(i);if(("Viewable"===a||"NotViewable"===a||"ViewUndetermined"===a)&&o){var s=a.toLowerCase();Array.isArray(t[s])||(t[s]=[]),t[s].push(o)}}return t}var z=function(){function e(){i(this,e),this._handlers=[]}return o(e,[{key:"on",value:function(e,t){if("function"!=typeof t)throw new TypeError("The handler argument must be of type Function. Received type ".concat(r(t)));if(!e)throw new TypeError("The event argument must be of type String. Received type ".concat(r(e)));return this._handlers.push({event:e,handler:t}),this}},{key:"once",value:function(e,t){return this.on(e,function(e,t,n){var r={fired:!1,wrapFn:void 0};function i(){r.fired||(e.off(t,r.wrapFn),r.fired=!0,n.bind(e).apply(void 0,arguments))}return r.wrapFn=i,i}(this,e,t))}},{key:"off",value:function(e,t){return this._handlers=this._handlers.filter((function(n){return n.event!==e||n.handler!==t})),this}},{key:"emit",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var i=!1;return this._handlers.forEach((function(t){"*"===t.event&&(i=!0,t.handler.apply(t,[e].concat(n))),t.event===e&&(i=!0,t.handler.apply(t,n))})),i}},{key:"removeAllListeners",value:function(e){return e?(this._handlers=this._handlers.filter((function(t){return t.event!==e})),this):(this._handlers=[],this)}},{key:"listenerCount",value:function(e){return this._handlers.filter((function(t){return t.event===e})).length}},{key:"listeners",value:function(e){return this._handlers.reduce((function(t,n){return n.event===e&&t.push(n.handler),t}),[])}},{key:"eventNames",value:function(){return this._handlers.map((function(e){return e.event}))}}]),e}(),X=function(e,t,n){n(new Error("Please bundle the library for node to use the node urlHandler"))},$=12e4;function J(){try{var e=new window.XMLHttpRequest;return"withCredentials"in e?e:null}catch(e){return null}}function Z(e,t,n){var r=n?408:e.status,i=n?"XHRURLHandler: Request timed out after ".concat(e.timeout," ms (").concat(r,")"):"XHRURLHandler: ".concat(e.statusText," (").concat(r,")");t(new Error(i),null,{statusCode:r})}var ee=function(e,t,n){if("https:"===window.location.protocol&&0===e.indexOf("http://"))return n(new Error("XHRURLHandler: Cannot go from HTTPS to HTTP."));try{var r=J();r.open("GET",e),r.timeout=t.timeout||$,r.withCredentials=t.withCredentials||!1,r.overrideMimeType&&r.overrideMimeType("text/xml"),r.onload=function(){return function(e,t){200===e.status?t(null,e.responseXML,{byteLength:e.response.length,statusCode:e.status}):Z(e,t,!1)}(r,n)},r.onerror=function(){return Z(r,n,!1)},r.onabort=function(){return Z(r,n,!1)},r.ontimeout=function(){return Z(r,n,!0)},r.send()}catch(e){n(new Error("XHRURLHandler: Unexpected error"))}},te=function(){return!!J()},ne={get:function(e,t,n){return n||("function"==typeof t&&(n=t),t={}),"undefined"==typeof window||null===window?X(e,t,n):te()?ee(e,t,n):n(new Error("Current context is not supported by any of the default URLHandlers. Please provide a custom URLHandler"))}},re=0,ie=0,ae=function(e,t){!e||!t||e<=0||t<=0||(ie=(ie*re+8*e/t)/++re)},oe={ERRORCODE:900,extensions:[]},se=function(e){c(n,e);var t=h(n);function n(){var e;return i(this,n),(e=t.call(this)).remainingAds=[],e.parentURLs=[],e.errorURLTemplates=[],e.rootErrorURLTemplates=[],e.maxWrapperDepth=null,e.URLTemplateFilters=[],e.fetchingOptions={},e.parsingOptions={},e}return o(n,[{key:"addURLTemplateFilter",value:function(e){"function"==typeof e&&this.URLTemplateFilters.push(e)}},{key:"removeURLTemplateFilter",value:function(){this.URLTemplateFilters.pop()}},{key:"countURLTemplateFilters",value:function(){return this.URLTemplateFilters.length}},{key:"clearURLTemplateFilters",value:function(){this.URLTemplateFilters=[]}},{key:"trackVastError",value:function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];this.emit("VAST-error",Object.assign.apply(Object,[{},oe,t].concat(r))),w.track(e,t)}},{key:"getErrorURLTemplates",value:function(){return this.rootErrorURLTemplates.concat(this.errorURLTemplates)}},{key:"getEstimatedBitrate",value:function(){return ie}},{key:"fetchVAST",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return new Promise((function(a,o){t.URLTemplateFilters.forEach((function(t){e=t(e)})),t.parentURLs.push(e);var s=Date.now();t.emit("VAST-resolving",{url:e,previousUrl:r,wrapperDepth:n,maxWrapperDepth:t.maxWrapperDepth,timeout:t.fetchingOptions.timeout,wrapperAd:i}),t.urlHandler.get(e,t.fetchingOptions,(function(i,c){var l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=Math.round(Date.now()-s),d=Object.assign({url:e,previousUrl:r,wrapperDepth:n,error:i,duration:u},l);t.emit("VAST-resolved",d),ae(l.byteLength,u),i?o(i):a(c)}))}))}},{key:"initParsingStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.errorURLTemplates=[],this.fetchingOptions={timeout:e.timeout||$,withCredentials:e.withCredentials},this.maxWrapperDepth=e.wrapperLimit||10,this.parentURLs=[],this.parsingOptions={allowMultipleAds:e.allowMultipleAds},this.remainingAds=[],this.rootErrorURLTemplates=[],this.rootURL="",this.urlHandler=e.urlHandler||e.urlhandler||ne,this.vastVersion=null,ae(e.byteLength,e.requestDuration)}},{key:"getRemainingAds",value:function(e){var t=this;if(0===this.remainingAds.length)return Promise.reject(new Error("No more ads are available for the given VAST"));var n=e?w.flatten(this.remainingAds):this.remainingAds.shift();return this.errorURLTemplates=[],this.parentURLs=[],this.resolveAds(n,{wrapperDepth:0,url:this.rootURL}).then((function(e){return t.buildVASTResponse(e)}))}},{key:"getAndParseVAST",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.initParsingStatus(n),this.URLTemplateFilters.forEach((function(t){e=t(e)})),this.rootURL=e,this.fetchVAST(e).then((function(r){return n.previousUrl=e,n.isRootVAST=!0,n.url=e,t.parse(r,n).then((function(e){return t.buildVASTResponse(e)}))}))}},{key:"parseVAST",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.initParsingStatus(n),n.isRootVAST=!0,this.parse(e,n).then((function(e){return t.buildVASTResponse(e)}))}},{key:"buildVASTResponse",value:function(e){var t,n={ads:(t={ads:e,errorURLTemplates:this.getErrorURLTemplates(),version:this.vastVersion}).ads||[],errorURLTemplates:t.errorURLTemplates||[],version:t.version||null};return this.completeWrapperResolving(n),n}},{key:"parseVastXml",value:function(e,t){var n=t.isRootVAST,r=void 0!==n&&n,i=t.url,a=void 0===i?null:i,o=t.wrapperDepth,s=void 0===o?0:o,c=t.allowMultipleAds,l=t.followAdditionalWrappers;if(!e||!e.documentElement||"VAST"!==e.documentElement.nodeName)throw this.emit("VAST-ad-parsed",{type:"ERROR",url:a,wrapperDepth:s}),new Error("Invalid VAST XMLDocument");var u=[],d=e.documentElement.childNodes,h=e.documentElement.getAttribute("version");for(var p in r&&h&&(this.vastVersion=h),d){var f=d[p];if("Error"===f.nodeName){var v=C.parseNodeText(f);r?this.rootErrorURLTemplates.push(v):this.errorURLTemplates.push(v)}else if("Ad"===f.nodeName){if(this.vastVersion&&parseFloat(this.vastVersion)<3)c=!0;else if(!1===c&&u.length>1)break;var m=W(f,this.emit.bind(this),{allowMultipleAds:c,followAdditionalWrappers:l});m.ad?(u.push(m.ad),this.emit("VAST-ad-parsed",{type:m.type,url:a,wrapperDepth:s,adIndex:u.length-1,vastVersion:h})):this.trackVastError(this.getErrorURLTemplates(),{ERRORCODE:101})}}return u}},{key:"parse",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.url,r=void 0===n?null:n,i=t.resolveAll,a=void 0===i||i,o=t.wrapperSequence,s=void 0===o?null:o,c=t.previousUrl,l=void 0===c?null:c,u=t.wrapperDepth,d=void 0===u?0:u,h=t.isRootVAST,p=void 0!==h&&h,f=t.followAdditionalWrappers,v=t.allowMultipleAds,m=[];this.vastVersion&&parseFloat(this.vastVersion)<3&&p&&(v=!0);try{m=this.parseVastXml(e,{isRootVAST:p,url:r,wrapperDepth:d,allowMultipleAds:v,followAdditionalWrappers:f})}catch(e){return Promise.reject(e)}return 1===m.length&&null!=s&&(m[0].sequence=s),!1===a&&(this.remainingAds=C.splitVAST(m),m=this.remainingAds.shift()),this.resolveAds(m,{wrapperDepth:d,previousUrl:l,url:r})}},{key:"resolveAds",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0,r=n.wrapperDepth,i=n.previousUrl,a=n.url,o=[];return i=a,t.forEach((function(t){var n=e.resolveWrappers(t,r,i);o.push(n)})),Promise.all(o).then((function(t){var n=w.flatten(t);if(!n&&e.remainingAds.length>0){var o=e.remainingAds.shift();return e.resolveAds(o,{wrapperDepth:r,previousUrl:i,url:a})}return n}))}},{key:"resolveWrappers",value:function(e,t,n){var r=this;return new Promise((function(i){var a;if(t++,!e.nextWrapperURL)return delete e.nextWrapperURL,i(e);if(t>=r.maxWrapperDepth||-1!==r.parentURLs.indexOf(e.nextWrapperURL))return e.errorCode=302,delete e.nextWrapperURL,i(e);e.nextWrapperURL=C.resolveVastAdTagURI(e.nextWrapperURL,n),r.URLTemplateFilters.forEach((function(t){e.nextWrapperURL=t(e.nextWrapperURL)}));var o=null!==(a=r.parsingOptions.allowMultipleAds)&&void 0!==a?a:e.allowMultipleAds,s=e.sequence;r.fetchVAST(e.nextWrapperURL,t,n,e).then((function(a){return r.parse(a,{url:e.nextWrapperURL,previousUrl:n,wrapperSequence:s,wrapperDepth:t,followAdditionalWrappers:e.followAdditionalWrappers,allowMultipleAds:o}).then((function(t){if(delete e.nextWrapperURL,0===t.length)return e.creatives=[],i(e);t.forEach((function(t){t&&C.mergeWrapperAdData(t,e)})),i(t)}))})).catch((function(t){e.errorCode=301,e.errorMessage=t.message,i(e)}))}))}},{key:"completeWrapperResolving",value:function(e){if(0===e.ads.length)this.trackVastError(e.errorURLTemplates,{ERRORCODE:303});else for(var t=e.ads.length-1;t>=0;t--){var n=e.ads[t];(n.errorCode||0===n.creatives.length)&&(this.trackVastError(n.errorURLTemplates.concat(e.errorURLTemplates),{ERRORCODE:n.errorCode||303},{ERRORMESSAGE:n.errorMessage||""},{extensions:n.extensions},{system:n.system}),e.ads.splice(t,1))}}}]),n}(z),ce=null,le={data:{},length:0,getItem:function(e){return this.data[e]},setItem:function(e,t){this.data[e]=t,this.length=Object.keys(this.data).length},removeItem:function(e){delete this.data[e],this.length=Object.keys(this.data).length},clear:function(){this.data={},this.length=0}},ue=function(){function e(){i(this,e),this.storage=this.initStorage()}return o(e,[{key:"initStorage",value:function(){if(ce)return ce;try{ce="undefined"!=typeof window&&null!==window?window.localStorage||window.sessionStorage:null}catch(e){ce=null}return ce&&!this.isStorageDisabled(ce)||(ce=le).clear(),ce}},{key:"isStorageDisabled",value:function(e){var t="__VASTStorage__";try{if(e.setItem(t,t),e.getItem(t)!==t)return e.removeItem(t),!0}catch(e){return!0}return e.removeItem(t),!1}},{key:"getItem",value:function(e){return this.storage.getItem(e)}},{key:"setItem",value:function(e,t){return this.storage.setItem(e,t)}},{key:"removeItem",value:function(e){return this.storage.removeItem(e)}},{key:"clear",value:function(){return this.storage.clear()}}]),e}(),de=function(){function e(t,n,r){i(this,e),this.cappingFreeLunch=t||0,this.cappingMinimumTimeInterval=n||0,this.defaultOptions={withCredentials:!1,timeout:0},this.vastParser=new se,this.storage=r||new ue,void 0===this.lastSuccessfulAd&&(this.lastSuccessfulAd=0),void 0===this.totalCalls&&(this.totalCalls=0),void 0===this.totalCallsTimeout&&(this.totalCallsTimeout=0)}return o(e,[{key:"getParser",value:function(){return this.vastParser}},{key:"lastSuccessfulAd",get:function(){return this.storage.getItem("vast-client-last-successful-ad")},set:function(e){this.storage.setItem("vast-client-last-successful-ad",e)}},{key:"totalCalls",get:function(){return this.storage.getItem("vast-client-total-calls")},set:function(e){this.storage.setItem("vast-client-total-calls",e)}},{key:"totalCallsTimeout",get:function(){return this.storage.getItem("vast-client-total-calls-timeout")},set:function(e){this.storage.setItem("vast-client-total-calls-timeout",e)}},{key:"hasRemainingAds",value:function(){return this.vastParser.remainingAds.length>0}},{key:"getNextAds",value:function(e){return this.vastParser.getRemainingAds(e)}},{key:"get",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Date.now();return(n=Object.assign({},this.defaultOptions,n)).hasOwnProperty("resolveAll")||(n.resolveAll=!1),this.totalCallsTimeout<r?(this.totalCalls=1,this.totalCallsTimeout=r+36e5):this.totalCalls++,new Promise((function(i,a){if(t.cappingFreeLunch>=t.totalCalls)return a(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(t.totalCalls,"/").concat(t.cappingFreeLunch)));var o=r-t.lastSuccessfulAd;if(o<0)t.lastSuccessfulAd=0;else if(o<t.cappingMinimumTimeInterval)return a(new Error("VAST call canceled – (".concat(t.cappingMinimumTimeInterval,")ms minimum interval reached")));t.vastParser.getAndParseVAST(e,n).then((function(e){return i(e)})).catch((function(e){return a(e)}))}))}}]),e}(),he=function(e){c(a,e);var t=h(a);function a(e,n,r){var o,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;for(var c in i(this,a),(o=t.call(this)).ad=n,o.creative=r,o.variation=s,o.muted=!1,o.impressed=!1,o.skippable=!1,o.trackingEvents={},o.lastPercentage=0,o._alreadyTriggeredQuartiles={},o.emitAlwaysEvents=["creativeView","start","firstQuartile","midpoint","thirdQuartile","complete","resume","pause","rewind","skip","closeLinear","close"],o.creative.trackingEvents){var l=o.creative.trackingEvents[c];o.trackingEvents[c]=l.slice(0)}return N(o.creative)?o._initLinearTracking():o._initVariationTracking(),e&&o.on("start",(function(){e.lastSuccessfulAd=Date.now()})),o}return o(a,[{key:"_initLinearTracking",value:function(){this.linear=!0,this.skipDelay=this.creative.skipDelay,this.setDuration(this.creative.duration),this.clickThroughURLTemplate=this.creative.videoClickThroughURLTemplate,this.clickTrackingURLTemplates=this.creative.videoClickTrackingURLTemplates}},{key:"_initVariationTracking",value:function(){if(this.linear=!1,this.skipDelay=-1,this.variation){for(var e in this.variation.trackingEvents){var t=this.variation.trackingEvents[e];this.trackingEvents[e]?this.trackingEvents[e]=this.trackingEvents[e].concat(t.slice(0)):this.trackingEvents[e]=t.slice(0)}"nonLinearAd"===this.variation.adType?(this.clickThroughURLTemplate=this.variation.nonlinearClickThroughURLTemplate,this.clickTrackingURLTemplates=this.variation.nonlinearClickTrackingURLTemplates,this.setDuration(this.variation.minSuggestedDuration)):function(e){return"companionAd"===e.adType}(this.variation)&&(this.clickThroughURLTemplate=this.variation.companionClickThroughURLTemplate,this.clickTrackingURLTemplates=this.variation.companionClickTrackingURLTemplates)}}},{key:"setDuration",value:function(e){w.isValidTimeValue(e)&&(this.assetDuration=e,this.quartiles={firstQuartile:Math.round(25*this.assetDuration)/100,midpoint:Math.round(50*this.assetDuration)/100,thirdQuartile:Math.round(75*this.assetDuration)/100})}},{key:"setProgress",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(w.isValidTimeValue(e)&&"object"===r(n)){var i=this.skipDelay||-1;if(-1===i||this.skippable||(i>e?this.emit("skip-countdown",i-e):(this.skippable=!0,this.emit("skip-countdown",0))),this.assetDuration>0){var a=Math.round(e/this.assetDuration*100),o=[];if(e>0){o.push("start");for(var s=this.lastPercentage;s<a;s++)o.push("progress-".concat(s+1,"%"));for(var c in o.push("progress-".concat(Math.round(e))),this.quartiles)this.isQuartileReached(c,this.quartiles[c],e)&&(o.push(c),this._alreadyTriggeredQuartiles[c]=!0);this.lastPercentage=a}o.forEach((function(e){t.track(e,{macros:n,once:!0})})),e<this.progress&&this.track("rewind",{macros:n})}this.progress=e}}},{key:"isQuartileReached",value:function(e,t,n){var r=!1;return t<=n&&!this._alreadyTriggeredQuartiles[e]&&(r=!0),r}},{key:"setMuted",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"boolean"==typeof e&&"object"===r(t)&&(this.muted!==e&&this.track(e?"mute":"unmute",{macros:t}),this.muted=e)}},{key:"setPaused",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"boolean"==typeof e&&"object"===r(t)&&(this.paused!==e&&this.track(e?"pause":"resume",{macros:t}),this.paused=e)}},{key:"setFullscreen",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"boolean"==typeof e&&"object"===r(t)&&(this.fullscreen!==e&&this.track(e?"fullscreen":"exitFullscreen",{macros:t}),this.fullscreen=e)}},{key:"setExpand",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"boolean"==typeof e&&"object"===r(t)&&(this.expanded!==e&&(this.track(e?"expand":"collapse",{macros:t}),this.track(e?"playerExpand":"playerCollapse",{macros:t})),this.expanded=e)}},{key:"setSkipDelay",value:function(e){w.isValidTimeValue(e)&&(this.skipDelay=e)}},{key:"trackImpression",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&(this.impressed||(this.impressed=!0,this.trackURLs(this.ad.impressionURLTemplates,e),this.track("creativeView",{macros:e})))}},{key:"error",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];"object"===r(e)&&"boolean"==typeof t&&this.trackURLs(this.ad.errorURLTemplates,e,{isCustomCode:t})}},{key:"errorWithCode",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];"string"==typeof e&&"boolean"==typeof t&&(this.error({ERRORCODE:e},t),console.log("The method errorWithCode is deprecated, please use vast tracker error method instead"))}},{key:"complete",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("complete",{macros:e})}},{key:"notUsed",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&(this.track("notUsed",{macros:e}),this.trackingEvents=[])}},{key:"otherAdInteraction",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("otherAdInteraction",{macros:e})}},{key:"acceptInvitation",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("acceptInvitation",{macros:e})}},{key:"adExpand",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("adExpand",{macros:e})}},{key:"adCollapse",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("adCollapse",{macros:e})}},{key:"minimize",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("minimize",{macros:e})}},{key:"verificationNotExecuted",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("string"==typeof e&&"object"===r(t)){if(!this.ad||!this.ad.adVerifications||!this.ad.adVerifications.length)throw new Error("No adVerifications provided");if(!e)throw new Error("No vendor provided, unable to find associated verificationNotExecuted");var n=this.ad.adVerifications.find((function(t){return t.vendor===e}));if(!n)throw new Error("No associated verification element found for vendor: ".concat(e));var i=n.trackingEvents;if(i&&i.verificationNotExecuted){var a=i.verificationNotExecuted;this.trackURLs(a,t),this.emit("verificationNotExecuted",{trackingURLTemplates:a})}}}},{key:"overlayViewDuration",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"string"==typeof e&&"object"===r(t)&&(t.ADPLAYHEAD=e,this.track("overlayViewDuration",{macros:t}))}},{key:"close",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track(this.linear?"closeLinear":"close",{macros:e})}},{key:"skip",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("skip",{macros:e})}},{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"object"===r(e)&&this.track("loaded",{macros:e})}},{key:"click",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if((null===e||"string"==typeof e)&&"object"===r(t)){this.clickTrackingURLTemplates&&this.clickTrackingURLTemplates.length&&this.trackURLs(this.clickTrackingURLTemplates,t);var i=this.clickThroughURLTemplate||e,a=n({},t);if(i){this.progress&&(a.ADPLAYHEAD=this.progressFormatted());var o=w.resolveURLTemplates([i],a)[0];this.emit("clickthrough",o)}}}},{key:"track",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.macros,i=void 0===n?{}:n,a=t.once,o=void 0!==a&&a;if("object"===r(i)){"closeLinear"===e&&!this.trackingEvents[e]&&this.trackingEvents.close&&(e="close");var s=this.trackingEvents[e],c=this.emitAlwaysEvents.indexOf(e)>-1;s?(this.emit(e,{trackingURLTemplates:s}),this.trackURLs(s,i)):c&&this.emit(e,null),o&&(delete this.trackingEvents[e],c&&this.emitAlwaysEvents.splice(this.emitAlwaysEvents.indexOf(e),1))}}},{key:"trackURLs",value:function(e){var t,r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n({},arguments.length>1&&void 0!==arguments[1]?arguments[1]:{});this.linear&&(this.creative&&this.creative.mediaFiles&&this.creative.mediaFiles[0]&&this.creative.mediaFiles[0].fileURL&&(a.ASSETURI=this.creative.mediaFiles[0].fileURL),this.progress&&(a.ADPLAYHEAD=this.progressFormatted())),null!==(t=this.creative)&&void 0!==t&&null!==(r=t.universalAdIds)&&void 0!==r&&r.length&&(a.UNIVERSALADID=this.creative.universalAdIds.map((function(e){return e.idRegistry.concat(" ",e.value)})).join(",")),this.ad&&(this.ad.sequence&&(a.PODSEQUENCE=this.ad.sequence),this.ad.adType&&(a.ADTYPE=this.ad.adType),this.ad.adServingId&&(a.ADSERVINGID=this.ad.adServingId),this.ad.categories&&this.ad.categories.length&&(a.ADCATEGORIES=this.ad.categories.map((function(e){return e.value})).join(",")),this.ad.blockedAdCategories&&this.ad.blockedAdCategories.length&&(a.BLOCKEDADCATEGORIES=this.ad.blockedAdCategories)),w.track(e,a,i)}},{key:"convertToTimecode",value:function(e){if(!w.isValidTimeValue(e))return"";var t=1e3*e,n=Math.floor(t/36e5),r=Math.floor(t/6e4%60),i=Math.floor(t/1e3%60),a=Math.floor(t%1e3);return"".concat(w.addLeadingZeros(n,2),":").concat(w.addLeadingZeros(r,2),":").concat(w.addLeadingZeros(i,2),".").concat(w.addLeadingZeros(a,3))}},{key:"progressFormatted",value:function(){return this.convertToTimecode(this.progress)}}]),a}(z);e.VASTClient=de,e.VASTParser=se,e.VASTTracker=he,Object.defineProperty(e,"__esModule",{value:!0})}(t)},228:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>s});const r=class{constructor(e){this.id=e.getAttribute("id"),this.allowMultipleAds=e.getAttribute("allowMultipleAds"),this.followRedirects=e.getAttribute("followRedirects"),this.vastAdData=null,this.adTagURI=null,this.customData=null;for(const t in e.childNodes){const n=e.childNodes[t];switch(n.localName){case"AdTagURI":this.adTagURI={templateType:n.getAttribute("templateType"),uri:(n.textContent||n.text||"").trim()};break;case"VASTAdData":for(this.vastAdData=n.firstChild;this.vastAdData&&1!==this.vastAdData.nodeType;)this.vastAdData=this.vastAdData.nextSibling;break;case"CustomAdData":this.customData=n}}}};function i(e,t){const n=[];for(const r in e.childNodes){const i=e.childNodes[r];i.nodeName!==t&&t!==`vmap:${i.nodeName}`&&i.nodeName!==`vmap:${t}`||n.push(i)}return n}function a(e){const t={attributes:{},children:{},value:{}};t.value=function(e){if(!e||!e.childNodes)return{};const t=e.childNodes,n=[];for(const e in t){const r=t[e];"#cdata-section"===r.nodeName&&n.push(r)}if(n&&n.length>0)try{return JSON.parse(n[0].data)}catch(e){}let r="";for(const e in t){const n=t[e];switch(n.nodeName){case"#text":r+=n.textContent.trim();break;case"#cdata-section":r+=n.data}}return r}(e);const n=e.attributes;if(n)for(const e in n){const r=n[e];r.nodeName&&void 0!==r.nodeValue&&null!==r.nodeValue&&(t.attributes[r.nodeName]=r.nodeValue)}const r=e.childNodes;if(r)for(const e in r){const n=r[e];n.nodeName&&"#"!==n.nodeName.substring(0,1)&&(t.children[n.nodeName]=a(n))}return t}const o=class{constructor(e){this.timeOffset=e.getAttribute("timeOffset"),this.breakType=e.getAttribute("breakType"),this.breakId=e.getAttribute("breakId"),this.repeatAfter=e.getAttribute("repeatAfter"),this.adSource=null,this.trackingEvents=[],this.extensions=[];for(const t in e.childNodes){const n=e.childNodes[t];switch(n.localName){case"AdSource":this.adSource=new r(n);break;case"TrackingEvents":for(const e in n.childNodes){const t=n.childNodes[e];"Tracking"===t.localName&&this.trackingEvents.push({event:t.getAttribute("event"),uri:(t.textContent||t.text||"").trim()})}break;case"Extensions":this.extensions=i(n,"Extension").map((e=>a(e)))}}}track(e,t){for(const n in this.trackingEvents){const r=this.trackingEvents[n];if(r.event===e){let{uri:e}=r;"error"===r.event&&(e=e.replace("[ERRORCODE]",t)),this.tracker(e)}}}tracker(e){"undefined"!=typeof window&&null!==window&&((new Image).src=e)}},s=class{constructor(e){if(!e||!e.documentElement||"VMAP"!==e.documentElement.localName)throw new Error("Not a VMAP document");this.version=e.documentElement.getAttribute("version"),this.adBreaks=[],this.extensions=[];for(const t in e.documentElement.childNodes){const n=e.documentElement.childNodes[t];switch(n.localName){case"AdBreak":this.adBreaks.push(new o(n));break;case"Extensions":this.extensions=i(n,"Extension").map((e=>a(e)))}}}}},270:(e,t,n)=>{var r=n(155),i=n(248),a=n(228),o=n(855);function s(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}function c(e){return e&&e.__esModule?e.default:e}s(e.exports,"AdBreakTrackingEvent",(()=>d)),s(e.exports,"AdTrackingEvent",(()=>u));var l={};s(l,"CSAIManager",(()=>N),(e=>N=e));var u,d,h,p,f,v={};function m(e){for(var t=e.split(":"),n=0,r=1;t.length>0;)n+=r*parseInt(t.pop(),10),r*=60;return n}s(v,"AdServerService",(()=>R),(e=>R=e)),function(e){e.START="start",e.IMPRESSION="impression",e.EXPAND="expand",e.MUTE="mute",e.UNMUTE="unmute",e.PAUSE="pause",e.RESUME="resume",e.REWIND="rewind",e.CLOSE="close",e.COMPLETE="complete",e.FIRST_QUARTILE="firstQuartile",e.MIDPOINT="midpoint",e.THIRD_QUARTILE="thirdQuartile",e.CLICK_THROUGH="clickThrough",e.ERROR="error"}(u||(u={})),function(e){e.BREAK_START="breakStart",e.BREAK_END="breakEnd"}(d||(d={})),function(e){e.ClientSide="csai",e.ServerSide="ssai"}(h||(h={})),function(e){e.Preroll="preroll",e.Midroll="midroll",e.Postroll="postroll"}(p||(p={})),function(e){e.NORMAL="NORMAL",e.SPONSOR="BUMPER",e.VIGNETTE="VIGNETTE",e.TRAILER="TRAILER"}(f||(f={}));var g,y,T,A=function(){return A=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},A.apply(this,arguments)},b=function(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}c((r=r.apply(e,t||[])).next())}))},k=function(e,t){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}},E=function(e,t,n){if(n||2===arguments.length)for(var r,i=0,a=t.length;i<a;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))},R=function(){function e(e){void 0===e&&(e=!1),this.debug=!1,this.estimatedBandwidth=500,this.debug=!!e,this.vastParser=new i.VASTParser}return e.prototype.getVMAP=function(e){return b(this,void 0,Promise,(function(){var t,n;return k(this,(function(r){switch(r.label){case 0:return this.debug&&console.debug("[CSAIManager] getVMAP",e),[4,this.fetchAdsVMAP(e)];case 1:return t=r.sent(),[4,this.resolveAds(t)];case 2:return n=r.sent(),this.debug&&console.debug("[CSAIManager] resolved VMAP to ad breaks",n),[2,n]}}))}))},e.prototype.getVASTs=function(e){return b(this,void 0,Promise,(function(){var t,n,r,i,a,o;return k(this,(function(s){switch(s.label){case 0:this.debug&&console.debug("[CSAIManager] getVASTs",e),t=[],n=0,r=e,s.label=1;case 1:return n<r.length?(i=r[n],[4,this.vastParser.getAndParseVAST(i.vastUrl)]):[3,4];case 2:if(!(a=s.sent()))return[2];o=a.ads,t.push(this.mapAdBreakObject({timeOffset:i.timeOffset.toString()},o)),s.label=3;case 3:return n++,[3,1];case 4:return this.debug&&console.debug("[CSAIManager] resolved VAST to ad break",t),[2,t]}}))}))},e.prototype.getVast=function(e){return b(this,void 0,Promise,(function(){var t,n,r;return k(this,(function(i){switch(i.label){case 0:return this.debug&&console.debug("[CSAIManager] get vast",e),[4,this.vastParser.getAndParseVAST(e)];case 1:return(t=i.sent())?(n=t.ads,r=this.mapAdBreakObject({timeOffset:"100"},n),this.debug&&console.debug("[CSAIManager] resolved vast to ad break",r),[2,r]):[2]}}))}))},e.prototype.fetchAdsVMAP=function(e){return b(this,void 0,Promise,(function(){var t,n,r;return k(this,(function(i){switch(i.label){case 0:return[4,fetch(e)];case 1:return[4,i.sent().text()];case 2:return t=i.sent(),n=new DOMParser,r=n.parseFromString(t,"text/xml"),[2,new(c(a))(r)]}}))}))},e.prototype.resolveAds=function(e){var t;return b(this,void 0,Promise,(function(){var n,r,i,a,o,s,c;return k(this,(function(l){switch(l.label){case 0:n=[],r=0,i=e.adBreaks,l.label=1;case 1:return r<i.length?"linear"!==(a=i[r]).breakType?[2,n]:(o=null===(t=a.adSource)||void 0===t?void 0:t.vastAdData,s=[],o?(c={isRootVAST:!0,timeout:1e4,withCredentials:!0,wrapperLimit:10,followAdditionalWrappers:!0},this.vastParser.initParsingStatus(c),[4,this.vastParser.parseVAST({documentElement:o},c)]):[3,3]):[3,5];case 2:s=l.sent().ads,this.estimatedBandwidth=this.vastParser.getEstimatedBitrate(),l.label=3;case 3:n.push(this.mapAdBreakObject(a,s)),l.label=4;case 4:return r++,[3,1];case 5:return[2,n]}}))}))},e.prototype.mapAdBreakObject=function(e,t){var n,r,i,a,o=this;return{insertionType:h.ClientSide,breakType:"start"===e.timeOffset||"0"===e.timeOffset?p.Preroll:p.Midroll,timeOffset:"start"===e.timeOffset||"0"===e.timeOffset?0:m(e.timeOffset),ads:null==t?void 0:t.map((function(e){return o.mapAdsObject(e)})).filter((function(e){return null!==e})),trackingEvents:{breakStart:(null===(r=null===(n=e.trackingEvents)||void 0===n?void 0:n.filter((function(e){return e.event===d.BREAK_START})))||void 0===r?void 0:r.map((function(e){return e.uri})))||[],breakEnd:(null===(a=null===(i=e.trackingEvents)||void 0===i?void 0:i.filter((function(e){return e.event===d.BREAK_END})))||void 0===a?void 0:a.map((function(e){return e.uri})))||[]}}},e.prototype.mapAdsObject=function(e){var t,n,r,i,a,o=this,s=e.extensions.find((function(e){return"AdServer"===e.attributes.type})),c=(null===(n=null===(t=null==s?void 0:s.children.find((function(e){return"AdInfo"===e.name})))||void 0===t?void 0:t.attributes)||void 0===n?void 0:n.customaid)||void 0,l=(null===(i=null===(r=null==s?void 0:s.children.find((function(e){return"AdInfo"===e.name})))||void 0===r?void 0:r.attributes)||void 0===i?void 0:i.variant)||f.NORMAL,u=this.findCreative(e.creatives.map((function(e){return o.mapCreativeObject(e)})));return u?{id:e.id,customAdId:c,programmatic:"PROGRAMMATIC"===c,system:null===(a=e.system)||void 0===a?void 0:a.value,sequence:e.sequence,title:e.title,variant:l,creative:u,errorUrlTemplates:e.errorURLTemplates,impressionUrlTemplates:e.impressionURLTemplates.map((function(e){return e.url}))}:null},e.prototype.findCreative=function(e){return e.find((function(e){return"linear"===e.type&&e.mediafiles.length>0}))},e.prototype.mapCreativeObject=function(e){var t,n=this;return{id:e.id,adId:e.adId,type:e.type,duration:e.duration,mediafiles:this.filterMediaFiles(e.mediaFiles.map((function(e){return n.mapMediaFileObject(e)}))),trackingEvents:A((t={},t[u.CLICK_THROUGH]=E([],e.videoClickTrackingURLTemplates,!0),t),e.trackingEvents),clickThroughUrlTemplate:e.videoClickThroughURLTemplate}},e.prototype.filterMediaFiles=function(e){var t=this,n=e.filter((function(e){return"video/mp4"===e.mimeType})),r=n.filter((function(e){return"video/mp4"===e.mimeType&&e.fileUrl.length>0&&(!e.bitrate||e.bitrate<t.estimatedBandwidth)}));return 0===r.length&&(r=n),r.sort((function(e,t){return e.bitrate&&t.bitrate?e.bitrate-t.bitrate:0}))},e.prototype.mapMediaFileObject=function(e){return{id:e.id,mimeType:e.mimeType,fileUrl:e.fileURL,bitrate:e.bitrate,height:e.height,width:e.width}},e}(),w=function(){function e(){this.emitter=c(o)()}return e.prototype.on=function(e,t){this.emitter.on.apply(this,[e,t])},e.prototype.off=function(e,t){this.emitter&&this.emitter.off.apply(this,[e,t])},e.prototype.clear=function(){this.emitter.all.clear()},e.prototype.emit=function(e,t){this.emitter&&this.emitter.emit.apply(this,[e,t])},e}(),L=(g=function(e,t){return(g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}g(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),C=function(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}c((r=r.apply(e,t||[])).next())}))},S=function(e,t){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}},N=function(e){function t(t){var n=e.call(this)||this;return n.debug=!1,n.autoManagePlayback=!0,n.adBreaks=[],n.adMarkers=[],n.currentAdBreakVideos=[],n.validCurrentTime=0,n.trackedAdBreaks={},n.trackedAds={},n.debug=!!t.debug,n.initOptions=t,n.state="idle",n.adServerService=new v.AdServerService(n.debug),t=function(e){var t;return e.container||e.adVideoElement||(console.warn("[CSAIManager] container or adVideoElement is expected, choosing the parent of contentVideoElement as container"),e.container=e.contentVideoElement.parentElement),e.container&&e.adVideoElement&&(console.warn("[CSAIManager] either container or adVideoElement is expected, not both, choosing the adVideoElement"),delete e.container),e.isLive||e.vmapUrl||e.adBreakVASTList||console.error("[CSAIManager] vmapUrl or adBreakVASTList is required"),e.vmapUrl&&e.adBreakVASTList&&(console.warn("[CSAIManager] either vmapUrl or adBreakVASTList is expected, not both, choosing the adBreakVASTList"),delete e.vmapUrl),e.isLive&&(e.vmapUrl||(null===(t=e.adBreakVASTList)||void 0===t?void 0:t.length)>1)&&console.warn("[CSAIManager] isLive is true, vmapUrl and adBreakVASTList are not expected, ignoring them"),e}(t),n.autoManagePlayback&&t.contentVideoElement.pause(),n.contentVideoElement=t.contentVideoElement,n.adVideoElement=n.setupAdVideoElement(t),n.videoEventFilter=new r.VideoEventFilter(n.adVideoElement),n.autoManagePlayback=!t.autoManagePlayback||t.autoManagePlayback,n.fetchAds(t),n}return L(t,e),t.prototype.setupAdVideoElement=function(e){if(e.adVideoElement)return e.adVideoElement;if(e.container){var t=function(e){var t=document.createElement("video");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t.style.backgroundColor="black",t.style.display="none",e&&(t.playsInline=e.playsInline,t.muted=e.muted,t.volume=e.volume),t}(this.contentVideoElement);return e.container.appendChild(t),t}},t.prototype.fetchAds=function(e){var t;return C(this,void 0,Promise,(function(){var n,r;return S(this,(function(i){switch(i.label){case 0:return e.isLive&&(null===(t=e.adBreakVASTList)||void 0===t?void 0:t.length)>1?[2]:e.vmapUrl?(n=this,[4,this.adServerService.getVMAP(e.vmapUrl)]):[3,2];case 1:n.adBreaks=i.sent(),i.label=2;case 2:return e.adBreakVASTList?(r=this,[4,this.adServerService.getVASTs(e.adBreakVASTList)]):[3,4];case 3:r.adBreaks=i.sent(),i.label=4;case 4:return this.adBreaks=this.adBreaks.sort((function(e,t){return e.timeOffset-t.timeOffset})),this.adMarkers=this.adBreaks.map((function(e){return e.timeOffset})),this.start(),[2]}}))}))},t.prototype.play=function(){"idle"===this.state&&(this.state="playing",this.playNextVideo())},t.prototype.fetchAdBreak=function(e){return C(this,void 0,Promise,(function(){var t;return S(this,(function(n){switch(n.label){case 0:return[4,this.adServerService.getVast(e)];case 1:return(t=n.sent())&&this.adBreaks.push(t),[2]}}))}))},t.prototype.triggerAdBreak=function(){return C(this,void 0,Promise,(function(){return S(this,(function(e){return this.adBreaks&&0!==this.adBreaks.length?(this.playAdBreak(this.adBreaks.shift()),[2]):[2]}))}))},t.prototype.start=function(){var e=this;if(0===this.adMarkers[0])this.adMarkers.shift(),this.playAdBreak(this.adBreaks.shift());else{if(!this.adMarkers.find((function(t){return t>e.contentVideoElement.currentTime})))return;this.contentVideoElement.addEventListener("timeupdate",this.onContentTimeUpdateRef=this.onContentTimeUpdate.bind(this))}},t.prototype.playAdBreak=function(e){this.autoManagePlayback&&this.contentVideoElement.pause(),this.currentAdBreak=e,this.trackAdBreakEvent(this.currentAdBreak,d.BREAK_START);for(var t=0,n=e.ads;t<n.length;t++){var r=n[t];this.currentAdBreakVideos.push(r)}this.playNextVideo()},t.prototype.playNextVideo=function(){this.videoEventFilter.clear(),this.adVideoElement.removeEventListener("seeking",this.onAdSeekingRef);var e=this.currentAdBreakVideos.shift();e?this.playAd(e):this.playContent()},t.prototype.playAd=function(e){var t=this,n=e.creative.mediafiles[0].fileUrl;if(this.debug&&console.debug("[CSAIManager] play ad",e),!n)return this.playNextVideo();this.currentAd=e,this.adVideoElement.style.display="block",this.adVideoElement.src=n,("idle"!==this.state||this.initOptions.autoplay)&&this.adVideoElement.play(),this.adVideoElement.addEventListener("playing",(function(){t.trackEvent(u.START,t.currentAd),t.trackEvent(u.IMPRESSION,t.currentAd),t.state="playing"}),{once:!0}),this.adVideoElement.addEventListener("ended",(function(){t.trackEvent(u.COMPLETE,t.currentAd),t.state="ended",t.validCurrentTime=0,t.playNextVideo()}),{once:!0}),this.videoEventFilter.addEventListener(r.PlayerEvents.TimeUpdate,(function(){t.adVideoElement.seeking||(t.validCurrentTime=t.adVideoElement.currentTime),t.monitorProgress()})),this.videoEventFilter.addEventListener(r.PlayerEvents.Pause,(function(){t.trackEvent(u.PAUSE,t.currentAd)})),this.videoEventFilter.addEventListener(r.PlayerEvents.Resume,(function(){t.trackEvent(u.RESUME,t.currentAd)})),this.videoEventFilter.addEventListener(r.PlayerEvents.Error,(function(){t.trackEvent(u.ERROR,t.currentAd)})),this.adVideoElement.addEventListener("seeking",this.onAdSeekingRef=function(){var e=t.adVideoElement.currentTime-t.validCurrentTime;Math.abs(e)>.01&&(t.adVideoElement.currentTime=t.validCurrentTime)})},t.prototype.playContent=function(){var e=this;this.debug&&console.debug("[CSAIManager] play content"),this.adVideoElement.style.display="none",this.adVideoElement.src="",this.currentAdBreak&&(this.trackAdBreakEvent(this.currentAdBreak,d.BREAK_END),this.currentAdBreak=null),this.autoManagePlayback&&this.contentVideoElement.play();var t=this.adMarkers.find((function(t){return t>e.contentVideoElement.currentTime}));t&&(this.debug&&console.debug("[CSAIManager] waiting for next break",t),this.contentVideoElement.addEventListener("timeupdate",this.onContentTimeUpdateRef=this.onContentTimeUpdate.bind(this)))},t.prototype.onContentTimeUpdate=function(){this.contentVideoElement.currentTime>this.adMarkers[0]&&(this.contentVideoElement.removeEventListener("timeupdate",this.onContentTimeUpdateRef),this.adMarkers.shift(),this.playAdBreak(this.adBreaks.shift()))},t.prototype.monitorProgress=function(){var e=this,t=this.adVideoElement.currentTime,n=this.adVideoElement.duration;if(this.currentAd){var r=n-t,i=Math.round(100-100*r/n),a={25:u.FIRST_QUARTILE,50:u.MIDPOINT,75:u.THIRD_QUARTILE};Object.keys(a).map((function(t){var n=a[t];i>parseInt(t,10)&&e.currentAd&&e.trackEvent(n,e.currentAd)}))}},t.prototype.trackAdBreakEvent=function(e,t){var n=this;e&&e.trackingEvents&&t&&(!this.trackedAdBreaks[e.timeOffset]||!0!==this.trackedAdBreaks[e.timeOffset][t])&&(this.trackedAdBreaks[e.timeOffset]||(this.trackedAdBreaks[e.timeOffset]={}),this.emit(t,e),(e.trackingEvents[t]||[]).forEach((function(e){return C(n,void 0,void 0,(function(){return S(this,(function(n){return this.debug&&console.debug("[CSAIManager] ad break tracking event -> ".concat(t),e),(new Image).src=e,[2]}))}))})),this.trackedAdBreaks[e.timeOffset][t]=!0)},t.prototype.trackEvent=function(e,t){var n=this;if(t&&e&&(!this.trackedAds[t.id]||!0!==this.trackedAds[t.id][e])){this.trackedAds[t.id]||(this.trackedAds[t.id]={});var r=[];switch(e){case u.IMPRESSION:r=t.impressionUrlTemplates||[];break;case u.ERROR:r=t.errorUrlTemplates||[];break;default:r=t.creative.trackingEvents[e]||[]}this.emit(e,t),null==r||r.forEach((function(t){return C(n,void 0,void 0,(function(){return S(this,(function(n){return this.debug&&console.debug("[CSAIManager] ad tracking event -> ".concat(e),t),(new Image).src=t,[2]}))}))})),this.trackedAds[t.id][e]=!0}},t.prototype.destroy=function(){this.adBreaks=[],this.adMarkers=[],this.currentAd=null,this.currentAdBreak=null,this.currentAdBreakVideos=[],this.onContentTimeUpdateRef=null,this.onAdSeekingRef=null,this.trackedAdBreaks={},this.trackedAds={},this.videoEventFilter.clear(),this.videoEventFilter.destroy(),this.initOptions.adVideoElement||this.adVideoElement.remove()},t}(w);y=e.exports,T=l,Object.keys(T).forEach((function(e){"default"===e||"__esModule"===e||y.hasOwnProperty(e)||Object.defineProperty(y,e,{enumerable:!0,get:function(){return T[e]}})}))},155:(e,t,n)=>{var r=n(734);function i(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}i(e.exports,"VideoEventFilter",(()=>a.VideoEventFilter)),i(e.exports,"PlayerEvents",(()=>a.PlayerEvents)),i(e.exports,"PlayerState",(()=>a.PlayerState));var a={};i(a,"PlayerState",(()=>s),(e=>s=e)),i(a,"PlayerEvents",(()=>c),(e=>c=e)),i(a,"VideoEventFilter",(()=>v),(e=>v=e));var o,s,c,l,u,d,h,p=function(){function e(){var e;this.emitter=((e=r)&&e.__esModule?e.default:e)()}return e.prototype.addEventListener=function(e,t){this.emitter.on.apply(this,[e,t])},e.prototype.removeEventListener=function(e,t){this.emitter&&this.emitter.off.apply(this,[e,t])},e.prototype.clear=function(){this.emitter.all.clear()},e.prototype.emit=function(e,t){this.emitter&&this.emitter.emit.apply(this,[e,t])},e.prototype.destroy=function(){this.emitter.all.clear(),this.emitter=null},e}(),f=(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});!function(e){e.Idle="idle",e.Loading="loading",e.Playing="playing",e.Paused="paused",e.Buffering="buffering",e.Seeking="seeking",e.Ended="ended"}(s||(s={})),function(e){e.Loading="loading",e.Loaded="loaded",e.Play="play",e.Resume="resume",e.Pause="pause",e.Seeking="seeking",e.Seeked="seeked",e.Buffering="buffering",e.Buffered="buffered",e.TimeUpdate="timeupdate",e.Ended="ended",e.Error="error"}(c||(c={})),(u=l||(l={}))[u.NETWORK_EMPTY=0]="NETWORK_EMPTY",u[u.NETWORK_IDLE=1]="NETWORK_IDLE",u[u.NETWORK_LOADING=2]="NETWORK_LOADING",u[u.NETWORK_NO_SOURCE=3]="NETWORK_NO_SOURCE",(h=d||(d={}))[h.HAVE_NOTHING=0]="HAVE_NOTHING",h[h.HAVE_METADATA=1]="HAVE_METADATA",h[h.HAVE_CURRENT_DATA=2]="HAVE_CURRENT_DATA",h[h.HAVE_FUTURE_DATA=3]="HAVE_FUTURE_DATA",h[h.HAVE_ENOUGH_DATA=4]="HAVE_ENOUGH_DATA";var v=function(e){function t(t){var n=e.call(this)||this;return n.listeners=[],n.videoElement=t,"string"==typeof t&&(n.videoElement=document.querySelector(t)),n.state=function(e){return e.readyState===d.HAVE_NOTHING&&e.networkState===l.NETWORK_EMPTY?s.Idle:e.networkState===l.NETWORK_LOADING?s.Loading:e.ended?s.Ended:e.paused?s.Paused:s.Playing}(t),n.setupEventListeners(),n}return f(t,e),t.prototype.setupEventListeners=function(){this.addListener("loadstart",this.onLoading),this.addListener("loadeddata",this.onLoaded),this.addListener("playing",this.onPlaying),this.addListener("pause",this.onPause),this.addListener("seeking",this.onSeeking),this.addListener("seeked",this.onSeeked),this.addListener("waiting",this.onBuffering),this.addListener("timeupdate",this.onTimeUpdate),this.addListener("error",this.onError),this.addListener("ended",this.onEnded)},t.prototype.addListener=function(e,t){var n=t.bind(this);this.videoElement.addEventListener(e,n),this.listeners.push({type:e,handler:n})},t.prototype.onLoading=function(){this.state!==s.Loading&&(this.setState(s.Loading),this.emit(c.Loading))},t.prototype.onLoaded=function(){this.state===s.Loading&&this.emit(c.Loaded)},t.prototype.onPlaying=function(){this.state===s.Ended&&this.setState(s.Loading),[s.Loading,s.Paused].includes(this.state)&&(this.state===s.Loading&&this.emit(c.Play),this.state===s.Paused&&(this.lastState=s.Paused,this.emit(c.Resume)),this.setState(s.Playing,!0)),this.state===s.Buffering&&this.onBuffered()},t.prototype.onPause=function(){var e=this;this.state===s.Playing&&(clearTimeout(this.pauseDebounce),this.pauseDebounce=window.setTimeout((function(){e.emit(c.Pause),e.setState(s.Paused,!0)}),200))},t.prototype.onSeeking=function(){[s.Loading,s.Seeking,s.Ended].includes(this.state)||(clearTimeout(this.pauseDebounce),this.setState(s.Seeking,!0),this.emit(c.Seeking))},t.prototype.onSeeked=function(){this.state===s.Seeking&&(this.setState(this.lastState,!0),this.emit(c.Seeked))},t.prototype.onBuffering=function(){[s.Loading,s.Buffering,s.Seeking,s.Ended].includes(this.state)||(this.setState(s.Buffering,!0),this.emit(c.Buffering))},t.prototype.onBuffered=function(){this.state===s.Buffering&&(this.setState(this.lastState,!0),this.emit(c.Buffered))},t.prototype.onTimeUpdate=function(){this.videoElement.seeking||[s.Loading,s.Paused,s.Seeking,s.Buffering,s.Ended].includes(this.state)||this.emit(c.TimeUpdate)},t.prototype.onEnded=function(){clearTimeout(this.pauseDebounce),this.state!==s.Ended&&(this.setState(s.Ended),this.emit(c.Ended))},t.prototype.onError=function(){this.state!==s.Ended&&(this.emit(c.Error,this.videoElement.error),this.onEnded())},t.prototype.getState=function(){return this.state},t.prototype.setState=function(e,t){t&&this.updateLastState(this.state),this.state=e},t.prototype.updateLastState=function(e){this.lastState=e||this.state},t.prototype.destroy=function(){var t=this;this.listeners.forEach((function(e){var n=e.type,r=e.handler;t.videoElement.removeEventListener(n,r)})),e.prototype.destroy.call(this)},t}(p)},734:(e,t,n)=>{"use strict";function r(e){return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r&&r.push(n)||e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&r.splice(r.indexOf(n)>>>0,1)},emit:function(t,n){(e.get(t)||[]).slice().map((function(e){e(n)})),(e.get("*")||[]).slice().map((function(e){e(t,n)}))}}}n.r(t),n.d(t,{default:()=>r})},357:(e,t,n)=>{var r=n(187),i=n(270),a=n(291);function o(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}o(e.exports,"WebRTCPlayer",(()=>p)),o(e.exports,"ListAvailableAdapters",(()=>h));class s{constructor(e,t,n){this.channelUrl=t,this.resetPeer(e)}enableDebug(){this.debug=!0}resetPeer(e){this.localPeer=e}getPeer(){return this.localPeer}async connect(e){this.client=new a.WHPPClient(this.localPeer,this.channelUrl,{debug:this.debug}),await this.client.connect()}log(...e){this.debug&&console.log("WebRTC-player",...e)}error(...e){console.error("WebRTC-player",...e)}}class c{waitingForCandidates=!1;resourceUrl=void 0;constructor(e,t,n){this.channelUrl=t,this.debug=!0,this.resetPeer(e)}enableDebug(){this.debug=!0}resetPeer(e){this.localPeer=e,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}getPeer(){return this.localPeer}async connect(e){this.localPeer.addTransceiver("video",{direction:"recvonly"}),this.localPeer.addTransceiver("audio",{direction:"recvonly"});const t=await this.localPeer.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0});this.localPeer.setLocalDescription(t),this.waitingForCandidates=!0,this.iceGatheringTimeout=setTimeout(this.onIceGatheringTimeout.bind(this),e&&e.timeout||2e3)}log(...e){this.debug&&console.log("WebRTC-player",...e)}error(...e){console.error("WebRTC-player",...e)}onIceGatheringStateChange(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()}onIceConnectionStateChange(e){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()}async onIceCandidate(e){if("icecandidate"!==e.type)return;const t=e.candidate;t&&this.log("IceCandidate",t.candidate)}onIceCandidateError(e){this.log("IceCandidateError",e)}onIceGatheringTimeout(){this.log("IceGatheringTimeout"),this.waitingForCandidates&&this.onDoneWaitingForCandidates()}async onDoneWaitingForCandidates(){this.waitingForCandidates=!1,clearTimeout(this.iceGatheringTimeout);const e=await fetch(this.channelUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sdp:this.localPeer.localDescription.sdp})});if(e.ok){const{sdp:t}=await e.json();this.localPeer.setRemoteDescription({type:"answer",sdp:t})}}}let l;!function(e){e[e.Client=0]="Client",e[e.Server=1]="Server"}(l||(l={}));class u{constructor(e,t,n){this.channelUrl=t,this.whepType=l.Client,this.onErrorHandler=n,this.resetPeer(e)}enableDebug(){this.debug=!0}resetPeer(e){this.localPeer=e,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}getPeer(){return this.localPeer}async connect(e){await this.initSdpExchange()}async initSdpExchange(){if(clearTimeout(this.iceGatheringTimeout),this.whepType===l.Client){this.localPeer.addTransceiver("video",{direction:"recvonly"}),this.localPeer.addTransceiver("audio",{direction:"recvonly"});const e=await this.localPeer.createOffer();await this.localPeer.setLocalDescription(e),this.waitingForCandidates=!0,this.iceGatheringTimeout=setTimeout(this.onIceGatheringTimeout.bind(this),2e3)}else{const e=await this.requestOffer();await this.localPeer.setRemoteDescription({type:"offer",sdp:e});const t=await this.localPeer.createAnswer();await this.localPeer.setLocalDescription(t),this.waitingForCandidates=!0,this.iceGatheringTimeout=setTimeout(this.onIceGatheringTimeout.bind(this),2e3)}}async onIceCandidate(e){if("icecandidate"!==e.type)return;const t=e.candidate;t&&this.log(t.candidate)}onIceGatheringStateChange(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()}onIceGatheringTimeout(){this.log("IceGatheringTimeout"),this.waitingForCandidates&&this.onDoneWaitingForCandidates()}async onDoneWaitingForCandidates(){this.waitingForCandidates=!1,clearTimeout(this.iceGatheringTimeout),this.whepType===l.Client?await this.sendOffer():await this.sendAnswer()}async requestOffer(){if(this.whepType===l.Server){const e=await fetch(this.channelUrl.href,{method:"POST",headers:{"Content-Type":"application/sdp"},body:""});if(e.ok)return this.resource=e.headers.get("Location"),this.log("WHEP Resource",this.resource),await e.text()}}async sendAnswer(){if(this.whepType===l.Server){const e=this.localPeer.localDescription,t=await fetch(this.resource,{method:"PATCH",headers:{"Content-Type":"application/sdp"},body:e.sdp});t.ok||this.error(`sendAnswer response: ${t.status}`)}}async sendOffer(){const e=this.localPeer.localDescription;if(this.whepType===l.Client){const t=await fetch(this.channelUrl.href,{method:"POST",headers:{"Content-Type":"application/sdp"},body:e.sdp});if(t.ok){this.resource=t.headers.get("Location"),this.log("WHEP Resource",this.resource);const e=await t.text();await this.localPeer.setRemoteDescription({type:"answer",sdp:e})}else 400===t.status?(this.log("server does not support client-offer, need to reconnect"),this.whepType=l.Server,this.onErrorHandler("reconnectneeded")):this.error(`sendAnswer response: ${t.status}`)}}log(...e){this.debug&&console.log("WebRTC-player",...e)}error(...e){console.error("WebRTC-player",...e)}}const d={"se.eyevinn.whpp":(e,t,n)=>new s(e,t,n),"se.eyevinn.webrtc":(e,t,n)=>new c(e,t,n),whep:(e,t,n)=>new u(e,t,n)};function h(){return Object.keys(d)}class p extends r.EventEmitter{reconnectAttemptsLeft=2;constructor(e){super(),this.videoElement=e.video,this.adapterType=e.type,this.adapterFactory=e.adapterFactory,this.statsTypeFilter=e.statsTypeFilter,this.iceServers=[{urls:"stun:stun.l.google.com:19302"}],e.iceServers&&(this.iceServers=e.iceServers),this.debug=!!e.debug,e.vmapUrl&&(this.csaiManager=new i.CSAIManager({contentVideoElement:this.videoElement,vmapUrl:e.vmapUrl,isLive:!0,autoplay:!0}),this.videoElement.addEventListener("ended",(()=>{this.csaiManager.destroy()})))}async load(e){this.channelUrl=e,this.connect()}log(...e){this.debug&&console.log("WebRTC-player",...e)}error(...e){console.error("WebRTC-player",...e)}onConnectionStateChange(e){if("failed"===this.peer.connectionState){if(this.peer&&this.peer.close(),this.reconnectAttemptsLeft<=0)return void this.error("Connection failed, reconnecting failed");this.log(`Connection failed, recreating peer connection, attempts left ${this.reconnectAttemptsLeft}`),this.connect(),this.reconnectAttemptsLeft--}else"connected"===this.peer.connectionState&&(this.log("Connected"),this.reconnectAttemptsLeft=2,this.videoElement.srcObject||(this.log("Updating video element srcobject"),this.videoElement.srcObject=this.stream))}onErrorHandler(e){this.log(`onError=${e}`),"reconnectneeded"===e&&(this.peer&&this.peer.close(),this.videoElement.srcObject=void 0,this.setupPeer(),this.adapter.resetPeer(this.peer),this.adapter.connect())}async onConnectionStats(){this.peer&&this.statsTypeFilter&&(await this.peer.getStats(null)).forEach((e=>{e.type.match(this.statsTypeFilter)&&this.emit(`stats:${e.type}`,e)}))}setupPeer(){this.stream=new MediaStream,this.peer=new RTCPeerConnection({iceServers:this.iceServers}),this.peer.onconnectionstatechange=this.onConnectionStateChange.bind(this),this.peer.ontrack=this.onTrack.bind(this)}onTrack(e){const t=e.track;switch(t.kind){case"video":if("feedbackvideolabel"!==t.label){const e=t.clone();this.log("Adding video track",e),this.stream.addTrack(e)}break;case"audio":const e=t.clone();this.log("Adding audio track",e),this.stream.addTrack(e);break;default:this.log("unknown track",t)}}async connect(){var e,t,n,r;if(this.setupPeer(),"custom"!==this.adapterType?this.adapter=(e=this.adapterType,t=this.peer,n=this.channelUrl,r=this.onErrorHandler.bind(this),d[e](t,n,r)):this.adapterFactory&&(this.adapter=this.adapterFactory(this.peer,this.channelUrl,this.onErrorHandler.bind(this))),!this.adapter)throw new Error(`Failed to create adapter (${this.adapterType})`);this.debug&&this.adapter.enableDebug(),this.statsInterval=setInterval(this.onConnectionStats.bind(this),5e3),await this.adapter.connect()}mute(){this.videoElement.muted=!0}unmute(){this.videoElement.muted=!1}stop(){clearInterval(this.statsInterval),this.peer.close(),this.videoElement.src=null,this.videoElement.load()}destroy(){this.stop(),this.removeAllListeners()}}},291:(e,t,n)=>{"use strict";n.r(t),n.d(t,{WHPPClient:()=>r});var r=function(){function e(e,t,n){this.localPeer=void 0,this.whppUrl=void 0,this.iceGatheringTimeout=void 0,this.waitingForCandidates=!1,this.resourceUrl=void 0,this.opts=void 0,this.localPeer=e,this.whppUrl=t,this.opts=n,this.localPeer.onicegatheringstatechange=this.onIceGatheringStateChange.bind(this),this.localPeer.oniceconnectionstatechange=this.onIceConnectionStateChange.bind(this),this.localPeer.onicecandidateerror=this.onIceCandidateError.bind(this),this.localPeer.onicecandidate=this.onIceCandidate.bind(this)}var t=e.prototype;return t.getPeer=function(){return this.localPeer},t.connect=function(){try{var e,t=this;return Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:"{}"})).then((function(e){var n;function r(r){return n?r:Promise.resolve(e.json()).then((function(n){var r=e.headers.get("location");return t.resourceUrl=new URL(r),t.log(n.offer),Promise.resolve(function(e){try{return Promise.resolve(fetch(e.href,{method:"OPTIONS"})).then((function(e){return!(!e.ok||!e.headers.get("Allow")||!e.headers.get("Allow").split(",").find((function(e){return"PATCH"===e.trimStart()})))}))}catch(e){return Promise.reject(e)}}(t.resourceUrl)).then((function(e){return t.log("ICE trickle supported by endpoint: "+e),t.opts||(t.opts={}),t.opts.noIceTrickle=!e,t.supportsTrickleIce()||(t.waitingForCandidates=!0),Promise.resolve(t.localPeer.setRemoteDescription({type:"offer",sdp:n.offer})).then((function(){return Promise.resolve(t.localPeer.createAnswer()).then((function(e){return Promise.resolve(t.localPeer.setLocalDescription(e)).then((function(){var e=function(){if(t.supportsTrickleIce())return t.log("ICE trickle supported, sending answer"),Promise.resolve(t.sendAnswer()).then((function(){}));var e;t.iceGatheringTimeout=setTimeout(t.onIceGatheringTimeout.bind(t),(null==(e=t.opts)?void 0:e.timeout)||2e3)}();if(e&&e.then)return e.then((function(){}))}))}))}))}))}))}var i=function(){if(!e.ok)return function(){if(415===e.status)return t.opts.useLegacyContentType=!0,Promise.resolve(fetch(t.whppUrl.href,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})).then((function(t){e=t}));n=1}()}();return i&&i.then?i.then(r):r(i)}))}catch(e){return Promise.reject(e)}},t.log=function(){var e,t;null!=(e=this.opts)&&e.debug&&(t=console).log.apply(t,["whpp-client"].concat([].slice.call(arguments)))},t.error=function(){var e;(e=console).error.apply(e,["whpp-client"].concat([].slice.call(arguments)))},t.onIceGatheringStateChange=function(e){this.log("IceGatheringState",this.localPeer.iceGatheringState),"complete"===this.localPeer.iceGatheringState&&!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.onIceConnectionStateChange=function(e){this.log("IceConnectionState",this.localPeer.iceConnectionState),"failed"===this.localPeer.iceConnectionState&&this.localPeer.close()},t.onIceCandidate=function(e){try{var t=this;if("icecandidate"!==e.type)return Promise.resolve();var n=e.candidate;return n?(t.log("IceCandidate",n.candidate),t.supportsTrickleIce()?(t.sendCandidate(n),Promise.resolve()):Promise.resolve()):Promise.resolve()}catch(e){return Promise.reject(e)}},t.onIceCandidateError=function(e){this.log("IceCandidateError",e)},t.onIceGatheringTimeout=function(){this.log("IceGatheringTimeout"),!this.supportsTrickleIce()&&this.waitingForCandidates&&this.onDoneWaitingForCandidates()},t.supportsTrickleIce=function(){return this.opts&&!this.opts.noIceTrickle},t.onDoneWaitingForCandidates=function(){try{var e=this;return e.waitingForCandidates=!1,clearTimeout(e.iceGatheringTimeout),Promise.resolve(e.sendAnswer()).then((function(){}))}catch(e){return Promise.reject(e)}},t.sendCandidate=function(e){try{var t,n=this;return Promise.resolve(fetch(n.resourceUrl.href,{method:"PATCH",headers:{"Content-Type":null!=(t=n.opts)&&t.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify({candidate:e.candidate})})).then((function(e){e.ok||(n.error("sendCandidate response: "+e.status),405===e.status&&n.log("ICE trickle not supported by endpoint"))}))}catch(e){return Promise.reject(e)}},t.sendAnswer=function(){try{var e,t=this,n={answer:t.localPeer.localDescription.sdp};return t.log(n.answer),Promise.resolve(fetch(t.resourceUrl.href,{method:"PUT",headers:{"Content-Type":null!=(e=t.opts)&&e.useLegacyContentType?"application/json":"application/whpp+json"},body:JSON.stringify(n)})).then((function(e){e.ok||t.error("sendAnswer response: "+e.status)}))}catch(e){return Promise.reject(e)}},e}()},187:e=>{"use strict";var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function a(){a.init.call(this)}e.exports=a,e.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}v(e,t,a,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&v(e,"error",t,{once:!0})}(e,i)}))},a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var o=10;function s(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?a.defaultMaxListeners:e._maxListeners}function l(e,t,n,r){var i,a,o,l;if(s(n),void 0===(a=e._events)?(a=e._events=Object.create(null),e._eventsCount=0):(void 0!==a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),o=a[t]),void 0===o)o=a[t]=n,++e._eventsCount;else if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=c(e))>0&&o.length>i&&!o.warned){o.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=o.length,l=u,console&&console.warn&&console.warn(l)}return e}function u(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=u.bind(r);return i.listener=n,r.wrapFn=i,i}function h(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):f(i,i.length)}function p(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function f(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function v(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(a){r.once&&e.removeEventListener(t,i),n(a)}))}}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),a.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},a.prototype.getMaxListeners=function(){return c(this)},a.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,a=this._events;if(void 0!==a)i=i&&void 0===a.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var c=a[e];if(void 0===c)return!1;if("function"==typeof c)r(c,this,t);else{var l=c.length,u=f(c,l);for(n=0;n<l;++n)r(u[n],this,t)}return!0},a.prototype.addListener=function(e,t){return l(this,e,t,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(e,t){return l(this,e,t,!0)},a.prototype.once=function(e,t){return s(t),this.on(e,d(this,e,t)),this},a.prototype.prependOnceListener=function(e,t){return s(t),this.prependListener(e,d(this,e,t)),this},a.prototype.removeListener=function(e,t){var n,r,i,a,o;if(s(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,a=Object.keys(n);for(r=0;r<a.length;++r)"removeListener"!==(i=a[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},a.prototype.listeners=function(e){return h(this,e,!0)},a.prototype.rawListeners=function(e){return h(this,e,!1)},a.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},a.prototype.listenerCount=p,a.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},855:e=>{e.exports=function(e){return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map((function(e){e(n)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,n)}))}}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var a=t[r]={exports:{}};return e[r].call(a.exports,a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.d(r,{default:()=>a});var e=n(357);const t={SOURCE:"src",AUTOPLAY:"autoplay",MUTED:"muted"},i=e=>""===e||!!e;class a extends HTMLElement{static get observedAttributes(){return Object.values(t)}constructor(){super();const e=this.setupDOM();this.setupPlayer(e)}setupDOM(){this.attachShadow({mode:"open"});const{shadowRoot:e}=this;let t=document.createElement("style");t.innerHTML="video { width: inherit; } div { width: inherit }",e.appendChild(t);const n=document.createElement("div");return e.appendChild(n),this.video=document.createElement("video"),n.appendChild(this.video),n}setupPlayer(t){this.player=new e.WebRTCPlayer({video:this.video,type:"whep",debug:!0})}async attributeChangedCallback(e){const n=this.getAttribute(t.SOURCE),r=this.getAttribute(t.AUTOPLAY),a=this.getAttribute(t.MUTED);e===t.SOURCE&&(i(n)?(await this.player.load(new URL(n)),i(r)&&(this.video.muted=i(a),this.video.autoplay=!0)):console.error("Missing src attribute in <whep-video> element")),e===t.MUTED&&(this.video.muted=i(a))}disconnectedCallback(){this.player.destroy()}}customElements.define("whep-video",a)})(),r.default})()));
|