UNPKG

@flowplayer/player

Version:
1 lines 109 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).flowplayer=t.flowplayer||{},t.flowplayer.ads=e())}(this,function(){"use strict";var t;!function(t){t[t.ADS=2]="ADS",t[t.ANALYTICS=4]="ANALYTICS",t[t.NO_METERING=8]="NO_METERING",t[t.DEVELOPER_PLAN=16]="DEVELOPER_PLAN",t[t.WOWZA_VIDEO=32]="WOWZA_VIDEO"}(t||(t={}));const e=["localhost","127.0.0.1","0.0.0.0","s.codepen.io","cdpn.io","try.flowplayer.com"];function s(t,s){return!!~e.indexOf(t)||t.indexOf(s)===t.length-s.length}s.check_whitelist=function(t){return!!~e.indexOf(t)};function i(t){this.message=t}i.prototype=new Error,i.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new i("'atob' failed: The string to be decoded is not correctly encoded.");for(var s,r,a=0,n=0,o="";r=e.charAt(n++);~r&&(s=a%4?64*s+r:r,a++%4)?o+=String.fromCharCode(255&s>>(-2*a&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return o};var a=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(r(t).replace(/(.)/g,function(t,e){var s=e.charCodeAt(0).toString(16).toUpperCase();return s.length<2&&(s="0"+s),"%"+s}))}(e)}catch(t){return r(e)}};function n(t){this.message=t}n.prototype=new Error,n.prototype.name="InvalidTokenError";var o=function(t,e){if("string"!=typeof t)throw new n("Invalid token specified");var s=!0===(e=e||{}).header?0:1;try{return JSON.parse(a(t.split(".")[s]))}catch(t){throw new n("Invalid token specified: "+t.message)}};o.InvalidTokenError=n;const d="production";function l(t,e){const s={valid_jwt:!1,raw:"",data:{acl:0},exp:0};let i={c:"{}",exp:0};e=e||{};try{i=o(t),s.valid_jwt=!0}catch(t){}return s.raw=t,s.data=JSON.parse(i.c),s.exp=i.exp,e.require_valid_token&&l.validate(s),s}function c(t){return{grant:t,is_granted:e=>(t&e)===e}}function u(){const t="undefined"!=typeof document&&"undefined"!=typeof window,e=t?navigator.userAgent:"",s=/iP(hone|od)/i.test(e)&&!/iPad/.test(e)&&!/IEMobile/i.test(e),i=/Android/.test(e)&&!/Firefox/.test(e),r=/^((?!chrome|android).)*safari/i.test(e),a=/chrome|crios/i.test(e)&&!/opr|opera|chromium|edg|ucbrowser|googlebot/i.test(e),n=/firefox|fxios/i.test(e)&&!/seamonkey/i.test(e),o=/edg/i.test(e),d=/opr|opera/i.test(e),l=/SamsungBrowser/.test(e),c=l&&/SMART-TV/.test(e);return{controls:!s,video:function(e){return t&&document.createElement("video").canPlayType(e)},lang:t&&window.navigator.language,android:i,iphone:s,safari:r,edge:o,opera:d,chrome:a,firefox:n,ios:t&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,samsung:l,samsung_tv:l&&c,touch:"ontouchstart"in window,tizen:"tizen"in window,webOS:"webos"in window}}function h(t){return{width:t.clientWidth,height:t.clientHeight}}function p(t,e,s){return"number"==typeof s&&(s+="px"),t.style.setProperty(e,s),t}l.validate=function(t){if("string"==typeof t&&(t=l(t)),!t||!t.raw){if(s.check_whitelist(window.location.hostname)||"dev"===d.toString())return!0;throw new Error("No token provided in configuration")}if(!t.valid_jwt)throw new Error("Invalid token provided");const e=window.location.hostname,i=s.bind(null,e);if("dev"!==d.toString()&&t.data.domain&&t.data.domain.length&&!t.data.domain.some(i))throw new Error("Domain not allowed");if("dev"!==d.toString()&&1e3*t.exp-Date.now()<0)throw new Error("Expired token");return!0},l.id=function(t){if(t)return"string"==typeof t&&(t=l(t)),t.data.id},c.of=c,c.from_token=function(t){const e=l(t,{require_valid_token:!0});return c.of(e.data.acl)},c.permissions=t;const g="ad-initialized",m="ad-playback-error",_="ad-teardown",f="ad-videotag-attached",v="ad-request-error",y="ad-requested",A="ad-request-completed",b="ad-pause-content",w="ad-started",E="ad-completed",S="ad-paused",T="ad-resumed",L="ad-progress",O="ad-skipped",R="ad-muted",M="ad-volume-changed",P="ad-timeout",k="ad-break-completed",D="ad-postroll-finished",I="ad-preroll-finished",C="vpaid-init",N="ad-ima-adapter-init",U="ad-ima-before-ads-request",x="ad-ima-rendering-settings",F="ad-adapter-init-failed",B="ad-play-requested",j="reload-ad-requested",q="ad-error",H="request/ad/pause",V="request/ad/play",z="request/ad/muteunmute",G="ad/show-first-frame",W="ad/resize",Q="ad/set-ui-flags",$="ad/pbjs";var K=Object.freeze({__proto__:null,AD_INIT:g,AD_PLAYBACK_ERROR:m,AD_TEARDOWN:_,AD_VIDEOTAG_ATTACHED:f,AD_BLOCKED:"ad-blocked",AD_REQUEST_ERROR:v,AD_REQUESTED:y,AD_REQUEST_COMPLETED:A,AD_PAUSE_CONTENT:b,AD_STARTED:w,AD_COMPLETED:E,AD_PAUSED:S,AD_RESUMED:T,AD_WAITING:"ad-waiting",AD_PROGRESS:L,AD_SKIPPED:O,AD_MUTED:R,AD_VOLUME_CHANGED:M,AD_FULLSCREEN:"ad-fullscreen",AD_TIMEOUT:P,AD_BREAK_COMPLETED:k,AD_POSTROLL_FINISHED:D,AD_PREROLL_FINSIHED:I,AD_MIDROLL_FINISHED:"ad-midroll-finished",VPAID_INIT:C,IMA_ADAPTER_INIT:N,IMA_BEFORE_ADS_REQUEST:U,IMA_ADS_RENDERING_SETTINGS:x,ADAPTER_INIT_FAILED:F,AD_PLAY_REQUESTED:B,RELOAD_AD_REQUESTED:j,AD_ERROR:q,REQUEST_AD_PAUSE:H,REQUEST_AD_PLAY:V,REQUEST_AD_MUTE_UNMUTE:z,AD_SHOW_FIRST_FRAME:G,AD_RESIZE:W,AD_SET_UI_FLAGS:Q,PBJS_AVAILABLE:$});const Y="resize",Z="volumechange",J="playing",X="ended",tt="seeked",et="seeking",st="viewenter",it="beforeplay";const rt="is-playing",at="is-starting",nt="is-live",ot="is-waiting",dt="is-autoplay",lt="is-in-viewport";function ct(t,e,s){const i=function(t,e){const s=new CustomEvent(t,{detail:e,cancelable:!0});return e&&Object.defineProperty(s,"data",{get:()=>e}),s}(e,s);return t.dispatchEvent(i),t}var ut;!function(){let t=!1;try{const e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch(t){}}(),function(t){t[t.OFF=0]="OFF",t[t.ON=1]="ON",t[t.AUDIO_REQUIRED=2]="AUDIO_REQUIRED"}(ut||(ut={}));function ht(t){const e="number"==typeof t?t:parseInt(t,10);return(e>9?"":"0")+e}function pt(t){return function(t,e){const s=t.seekable;if("object"!=typeof t.opts||0==s.length)return{head:0,tail:0};const i=gt(t),r=e||t.live_state.dvr_window;return{head:i,tail:"number"!=typeof r||i-r<0?s.start(0):i-r}}(t).tail}function gt(t){var e;const s=t.seekable;return s.length?t.hasState("is-chromecast-playing")||!(null===(e=t.hls)||void 0===e?void 0:e.liveSyncPosition)?s.end(s.length-1):t.hls.liveSyncPosition:0}function mt(t){try{t.dvr_offset=0,t.currentTime=gt(t)}catch(t){console.warn("failed to seek to now: %j",t)}}const _t=1;function ft(t,e){if(!t.hasState(nt)||![void 0,0,-1].includes(e)||!t.seekable.length||t.hasState("has-casted"))return t.setState(at,!1);t.once(tt,()=>t.setState(at,!1)),0===e?function(t){t.currentTime=pt(t)}(t):mt(t)}const vt="is-popped-out";function yt(t,e){const s=function(){try{return localStorage.getItem("flowplayer/debug")}catch(t){return""}}(),i=(i,...r)=>{try{const a=(null==e?void 0:e.debug)||s;a&&t.match(a)&&console.log(`flowplayer/${t} -- ${i}`,...r)}catch(t){console.warn(t)}};return i.log=i,i}const At=(t,e)=>new(((t,e)=>{const s=t.get(e);if(!s)throw new Error(`no flowplayer component with the name ${e} exists`);const i=window.customElements.get(e);if(!i)throw new Error(`no default flowplayer component with the name ${e} exists`);const r=window.customElements.get(s);return"function"!=typeof r?i:r})(t._customElements,e))(t),bt=(t,e,s)=>{window.customElements.get(e)||window.customElements.define(e,s),t.customElements.get(e)||t.customElements.set(e,e)},wt="flowplayer-ad-ui",Et="flowplayer-ad-controls",St="flowplayer-ad-countdown",Tt="flowplayer-ad-indicator",Lt=new Blob([new Uint8Array([0,0,0,28,102,116,121,112,105,115,111,109,0,0,2,0,105,115,111,109,105,115,111,50,109,112,52,49,0,0,0,8,102,114,101,101,0,0,2,239,109,100,97,116,33,16,5,32,164,27,255,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,167,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,33,16,5,32,164,27,255,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,167,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,0,0,2,194,109,111,111,118,0,0,0,108,109,118,104,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,232,0,0,0,47,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,1,236,116,114,97,107,0,0,0,92,116,107,104,100,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,47,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,36,101,100,116,115,0,0,0,28,101,108,115,116,0,0,0,0,0,0,0,1,0,0,0,47,0,0,0,0,0,1,0,0,0,0,1,100,109,100,105,97,0,0,0,32,109,100,104,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,172,68,0,0,8,0,85,196,0,0,0,0,0,45,104,100,108,114,0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0,0,0,1,15,109,105,110,102,0,0,0,16,115,109,104,100,0,0,0,0,0,0,0,0,0,0,0,36,100,105,110,102,0,0,0,28,100,114,101,102,0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1,0,0,0,211,115,116,98,108,0,0,0,103,115,116,115,100,0,0,0,0,0,0,0,1,0,0,0,87,109,112,52,97,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,2,0,16,0,0,0,0,172,68,0,0,0,0,0,51,101,115,100,115,0,0,0,0,3,128,128,128,34,0,2,0,4,128,128,128,20,64,21,0,0,0,0,1,244,0,0,1,243,249,5,128,128,128,2,18,16,6,128,128,128,1,2,0,0,0,24,115,116,116,115,0,0,0,0,0,0,0,1,0,0,0,2,0,0,4,0,0,0,0,28,115,116,115,99,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0,28,115,116,115,122,0,0,0,0,0,0,0,0,0,0,0,2,0,0,1,115,0,0,1,116,0,0,0,20,115,116,99,111,0,0,0,0,0,0,0,1,0,0,0,44,0,0,0,98,117,100,116,97,0,0,0,90,109,101,116,97,0,0,0,0,0,0,0,33,104,100,108,114,0,0,0,0,0,0,0,0,109,100,105,114,97,112,112,108,0,0,0,0,0,0,0,0,0,0,0,0,45,105,108,115,116,0,0,0,37,169,116,111,111,0,0,0,29,100,97,116,97,0,0,0,1,0,0,0,0,76,97,118,102,53,54,46,52,48,46,49,48,49])],{type:"video/mp4"});let Ot=null;function Rt(t,e=2e3){return new Promise(s=>{const i=document.createElement("video"),r={autoplay_sound:!1,autoplay_muted:!1},a=()=>{i.pause(),i.currentTime=0,i.src="",i.remove(),s(r)},n=setTimeout(a,e);i.setAttribute("playsinline",""),i.setAttribute("webkit-playsinline",""),i.setAttribute("disablepictureinpicture",""),i.preload="auto",i.playsInline=!0,i.muted=!1,Object.assign(i.style,{position:"fixed",left:"-9999px",top:"0",width:"1px",height:"1px",opacity:"0",pointerEvents:"none"}),document.body.appendChild(i),i.src=(Ot||(Ot=URL.createObjectURL(Lt)),Ot);(async()=>{try{return await i.play(),clearTimeout(n),r.autoplay_sound=!0,r.autoplay_muted=!0,a()}catch(e){if(t)return clearTimeout(n),a()}try{i.muted=!0,i.setAttribute("muted",""),await i.play(),r.autoplay_muted=!0}catch(t){}clearTimeout(n),a()})()})}const Mt=yt("ads/lifecycle"),Pt=[m,_,k];async function kt({config:t,root:e,content:s,ads:i,ima:r}){var a;Mt("LifeCycle::initLifeCycle",t,e,s,i,r),s.autoplay=!1;const n=t.autoplay===ut.AUDIO_REQUIRED,o=function(t,e){return{muted:!(e||!t.muted),volume:t.volume}}(s,n);s.on(Z,()=>{o.volume=s.volume,o.muted=s.muted}),s.on(G,()=>{Mt("showFirstFrame"),e.classList.toggle("ad-hide-first-frame",!1)});const d=At(s,wt),l=d;s.emit(Q,{ui_flags:null===(a=t.ads)||void 0===a?void 0:a.ui}),s.renderPlugin(d);const c={listening:!1,preload:null==r?void 0:r.preload_ads};if(Mt("initial",o),i.setVideoTag(s),t.autoplay){Mt("Trying to autoplay"),e.classList.add("ad-hide-first-frame"),Mt("hideFirstFrame");const a=await async function(t,e){const[s,i]=[t.muted,t.volume];Mt("Lifecycle::peek_content(:muted => %s, :volume => %s)",s,i),await async function(t){return Mt("Lifecycle::wait_for_source"),new Promise((e,s)=>{const i=50,r=2e3;let a=0;const n=setInterval(()=>{if(++a>r/i)return clearInterval(n),s(new Error(`No source in ${r}ms, giving up`));(t.currentSrc||"dash"in t)&&(e(null),clearInterval(n))},i)})}(t),await function(t){return new Promise(e=>{if(t.hasState(lt))return e(null);t.once(st,()=>e(null))})}(t);const r=Date.now();!e&&t.opts.muted||(t.muted=!1);t.volume=t.volume?t.volume:1;const{autoplay_sound:a,autoplay_muted:n}=await Rt(e);return Mt("Lifecycle::peek_content:: ","audioRequired: "+e," autoplay_sound: "+a," autoplay_muted: "+n," peek_content_check_ms: "+(Date.now()-r)),t.opts.muted&&!e?n:!!a||!e&&(t.muted=!!n||s,n)}(s,n);a?(Mt("Can autoplay, start ad"),s.opts.autoplay=1,s.setState(dt,!0),Dt({ads:i,content:s,state:c,adContainer:l,ima:r,config:t})):(Mt("cannot autoplay(audioRequired: %s), fallback to poster state",n),t.autoplay=0,s.emit(G,{root:e}),s.setState("is-starting",!0))}!t.autoplay&&i.hasPreroll()&&function({content:t,ads:e,config:s,state:i,initial:r,adContainer:a,ima:n}){t.once(it,async function(o){(t.hasState(lt)||"touchend"!=o.type)&&e.shallPlayAd(0)&&(e.adapter.setAttemptingPrerollOnIOS(e.adapter.isCustomPlaybackEnabled()),e.adapter.isCustomPlaybackEnabled()||o.preventDefault(),Ut({ads:e,content:t,state:i}),Mt("user_gesture(:intercept) -> shallPlayAd(0: %s)",e.shallPlayAd(0)),s.muted=r.muted,await Dt({ads:e,content:t,state:i,adContainer:a,ima:n,config:s}),xt({ads:e,content:t}))})}({content:s,ads:i,config:t,state:c,initial:o,adContainer:l,ima:r}),!t.autoplay&&i.hasPreroll()&&c.preload&&Dt({ads:i,content:s,state:c,adContainer:l,ima:r,config:t}),Nt({config:t,root:e,content:s,ads:i,state:c,adContainer:l,ui:d,ima:r,initial:o});const u=async t=>{s.removeEventListener(it,u),i.resetScheduleCounter(),i.hasPreroll()&&(i.adapter.setAttemptingPrerollOnIOS(i.adapter.isCustomPlaybackEnabled()),t.preventDefault(),await i.setCurrentTime(0))};s.on("src",()=>{c.started&&(s.removeEventListener(it,u),s.addEventListener(it,u))}),s.on(it,t=>{(i.adBreak||i.adPlaying||i.adRequesting)&&(i.adBreak&&!i.adLinear||(Mt("prevented content from starting because ad break is active"),t.preventDefault()))})}async function Dt(t){t.state.started||(t.content.hasState(lt)?await It(t):t.content.once(st,async()=>{await It(t)}))}async function It({ads:t,content:e,adContainer:s,ima:i,state:r,config:a}){var n;r.started=!0;const o=function(t,e){var s={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(s[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(s[i[r]]=t[i[r]])}return s}(i,["ads"]),d=h(e.root),l=(null==a?void 0:a.muted)||e.muted,c=Object.assign(Object.assign(Object.assign({container:s,volume:l?0:e.volume,muted:l,autoplay:(null==a?void 0:a.autoplay)||!1,video_source:e.original_src,preload_ads:null===(n=null==a?void 0:a.ima)||void 0===n?void 0:n.preload_ads},o),d));Mt("start():",c,r),await t.initialize(!1,c,r.preload)}function Ct(t,e){var s,i;return{content_width:t.clientWidth||(null===(s=t.parentNode)||void 0===s?void 0:s.clientWidth)||e.clientWidth,content_height:t.clientHeight||(null===(i=t.parentNode)||void 0===i?void 0:i.clientHeight)||e.clientHeight}}function Nt({config:t,root:e,content:s,ads:i,initial:r,adContainer:a,state:n,ui:o,ima:d}){Mt("addUIListeners()");const l=async()=>{if(i){if(!(i.adapter.isAttemptingPrerollOnIOS()||i.adapter.isCustomPlaybackEnabled()&&s.currentSrc!==s.original_src)){if(s.off(J,l),Mt("addUIListeners() -> content started playing"),Ut({ads:i,content:s,state:n}),!i.shallPlayAd(0)||!i.adapter.isLinearAd())return Mt("addUIListeners() -> no more preroll ads -> resume content"),s.emit(G,{root:e}),await Dt({ads:i,content:s,state:n,adContainer:a,ima:d,config:t});s.togglePlay(!1),await Dt({ads:i,content:s,state:n,adContainer:a,ima:d,config:t}),i.shallPlayAd(0)&&i.adapter.isLinearAd()&&(o.classList.add("on","linear"),e.classList.add(ot),xt({ads:i,content:s}))}}else s.off(J,l)};s.on(J,l),s.on(["portrait","landscape"],function(){if(!i)return;const{content_width:t,content_height:r}=Ct(s,e);i.resize({height:r,width:t})}),s.on(Y,t=>{if(!i||!t.detail)return;const{width:e,height:s}=t.detail.contentRect;i.resize({width:e,height:s})}),s.on(X,t=>{var r;const a=()=>{t.preventDefault(),Object.assign(t,{prevented:!0})};if(e.classList.contains("ad-linear")&&e.classList.contains("ads-custom-playback-enabled"))return a();i&&(Mt("ui_listeners(:%s, event: %o)",t.type,t.detail),(null===(r=null==t?void 0:t.detail)||void 0===r?void 0:r.from)!==i&&(a(),i.finished(function(){s.emit(X,{from:i})})))}),i.on(y,()=>{e.classList.toggle(ot,!0)}),i.once(w,()=>{s.on([it,"beforepause"],t=>{var e;if(!i.adBreak||!i.adapter.isLinearAd())return;t.preventDefault();const s=(null===(e=t.detail)||void 0===e?void 0:e.forced)?t.type===it:!i.adPlaying;s&&i.paused&&i.resume(),s||i.paused||i.pause()})}),i.on(w,t=>{const a=t.detail,{linear:n,ad:o,ad_type:d}=a;let l;if(Mt(`Ad[linear: ${n}, currentTime: ${s.currentTime}] starting`,o),"preroll"==d&&!n&&s.paused&&s.togglePlay(!0),n&&(l=Ct(s,e)),i.resize({width:l?l.content_width:o.width,height:l?l.content_height:o.height,linear:n,resize_non_linear:!0}),s.emit(W,{opts:{linear:n,resizeContainerAlso:!0,width:n?void 0:o.width,height:n?void 0:o.height}}),e.classList.remove(ot),s.setState("ad-linear",n),s.setState("ad-non-linear",!n),!n){Mt("non-linear ad / restarting content");try{s.togglePlay(!0),s.volume=r.volume,s.muted=r.muted}catch(t){Mt(t)}}s.hasState(lt)||s.hasState(vt)||!n||i.pause()}),i.on(b,()=>{s.emit(W,{opts:{linear:!0,width:0,height:0}})}),s.on(Pt,t=>async function({root:t,content:e,ads:s,eventName:i,err:r={reason:""}}){Mt("teardown(event: %s)",i),s.adapter.isAttemptingPrerollOnIOS()&&(s.adapter.setAttemptingPrerollOnIOS(!1),!e.paused&&e.hasState(at)&&e.hasState(rt)&&ft(e,e.opts.start_time));t.classList.add("is-seamless"),t.classList.remove(ot),["ad-non-linear","ad-linear"].forEach(t=>e.setState(t,!1)),r.reason&&Mt("teardown(:err, reason: %s) %o",r.reason);const a=s.getLastAd();if(e.emit(G,{root:t}),!s.shouldRestartContent())return Mt("Lifecycle.teardown(:skip_restart, reason: %s)","Ad prevented restarting content"),Ft(t);if(e.currentTime>0&&e.currentTime>=e.duration||"postroll"==s.ad_type||!1===(null==a?void 0:a.restart))return Mt("Lifecycle.teardown(:skip_restart, reason: %s)","was a postroll ad"),Ft(t);""===e.currentSrc&&e.setSrc(e.original_src);e.paused&&s.shouldRestartContent()&&(Mt("Lifecycle.teardown(:toggle_play, %s)","attempting to restart content"),await e.togglePlay(!0));if(!e.paused)return Mt("Lifecycle.teardown(:ok)","restarted video content"),Ft(t)}({root:e,content:s,ads:i,ui:o,err:t.detail,eventName:t.type}));let c=!!t.autoplay;var u;s.on(st,()=>{c&&!1!==d.autopause&&i.resume()}),s.on("viewleave",(u=()=>{!1!==d.autopause&&(c=!i.paused,i.pause())},t=>{setTimeout(function(){if(!t.defaultPrevented&&!t.prevented)return u(t)},0)}))}function Ut({ads:t,content:e,state:s}){s.listening||(e.on(["timeupdate",tt,J,et],s=>{t.adapter.isCustomPlaybackEnabled()&&(t.adPlaying||t.paused)||(t.adPlaying&&t.adapter.isLinearAd()&&!e.paused&&e.pause(),xt({ads:t,content:e,seek:s.type===et}))}),s.listening=!0)}function xt({ads:t,content:e,seek:s=!1}){t&&t.setCurrentTime(e.currentTime,void 0,s)}function Ft(t){t.classList.remove("is-seamless")}const Bt=yt("ads/timers");class TimerRegistry{constructor(t={},e={}){this.intervals=t,this.timers=e}}let jt=-1;function qt(t,e,s){const i=setInterval(s,e);if(Bt(`TimerRegistry.createInterval() -> ${i}`,t.intervals),"object"==typeof i){const e=++jt;return t.intervals[e]=e,e}return t.intervals[i]=i,i}function Ht(t){if(t)return Bt("TimerRegistry.empty()",Object.keys(t.timers),Object.keys(t.intervals)),Object.keys(t.intervals).forEach(e=>function(t,e){return Bt(`TimerRegistry.removeInterval() -> ${e}`,t.intervals),clearInterval(t.intervals[e]),delete t.intervals[e],t}(t,e)),Object.keys(t.timers).forEach(e=>function(t,e){return Bt(`TimerRegistry.removeTimeout() -> ${e}`,t.timers),clearTimeout(t.timers[e]),delete t.timers[e],t}(t,e)),t}function Vt(t){try{return t.getAdPodInfo().getPodIndex()}catch(t){return}}class AdLoadingController{adRequestStart(t){"number"==typeof t&&"number"!=typeof this.requestStart&&(this.requestStart=performance.now())}adRequestEnd(){this.requestStart=void 0}getRemainingAdLoadTime(t,e){return"number"!=typeof e||"number"!=typeof this.requestStart?t:Math.max(0,e-(performance.now()-this.requestStart))}}function zt(t){return function(t){return!document.fullscreenEnabled&&"function"==typeof t.webkitEnterFullScreen&&"function"==typeof t.webkitExitFullScreen}(t)&&!t.root.classList.contains("no-fullscreen")}function Gt(t){const e=null==t?void 0:t.ads;return!!(e&&Array.isArray(e)&&e.length>0)}class IMA{constructor(t){this.eventHandler=t,this.log=yt("ads/adapter/ima"),this.google=window.google,this._adHandlers=[],this._timers=new TimerRegistry,this._started=!1,this._volumeLevel=0,this._adLoaded=!1,this.customPlaybackEnabled=!1,this._paused=!1,this._all_ads_completed=!1,this._currentDuration=0,this._currentRemaining=0,this._currentDisplayTs=0,this._isInitialized=!1,this._adBreakTime=0,this._prepared=!1,this.opts={},this.loadingController=new AdLoadingController}async init(t){this.log("init",this.videoTag,t),this.opts=t,this._dimensions={width:t.width,height:t.height,linear:t.linear},this._prepared=!0,!this._isInitialized&&this.videoTag&&await this.initAdapter()}async initAdapter(){this.log("initAdapter",this.opts);try{await this.initialize(this.opts),this._isInitialized=!0}catch(t){this.log("initAdapter failed:",t),this._prepared=!1,this.eventHandler.trigger(F)}}isReady(){return!!this._isInitialized}setVideoTag(t){this.videoTag=t,this.customPlaybackEnabled=zt(t),t.root.classList.toggle("ads-custom-playback-enabled",this.customPlaybackEnabled)}setAdBreakTime(t){this._adBreakTime=t}getAdBreakTime(){return this._adBreakTime}isCustomPlaybackEnabled(){return this.customPlaybackEnabled}isAttemptingPrerollOnIOS(){var t;return!!(null===(t=null==this?void 0:this.videoTag)||void 0===t?void 0:t.root.classList.contains("preroll-ios"))}setAttemptingPrerollOnIOS(t){var e;null===(e=null==this?void 0:this.videoTag)||void 0===e||e.root.classList.toggle("preroll-ios",t)}isLinearAd(){return!!this._adLinear}getVideoTag(){return this.videoTag}getDimensions(){return this._dimensions||{}}getOpts(){return this.opts}isPaused(){return this._paused}destroy(){const t=this;Ht(this._timers),this._adHandlers&&this._adHandlers.forEach(t=>t()),t._adHandlers=void 0,this._adDisplayContainer&&this._adDisplayContainer.destroy(),t._adDisplayContainer=void 0,this._adsLoader&&this._adsLoader.destroy(),t._adsLoader=void 0,this._adsManager&&this._adsManager.destroy(),t._adsManager=void 0}stop(){this._adsManager&&this._adsManager.stop()}initialize(t){const e=this.isAdPod(),s=this._adLoaded||e;if(this.cleanup(),!this.videoTag)return console.warn("videoTag not set during initialization");this.opts=t,this._volumeLevel=t.volume;const i=this.google.ima.settings;if(t.NumRedirects=t.NumRedirects||t.redirects,i.setVpaidMode(t.VpaidMode||this.google.ima.ImaSdkSettings.VpaidMode.INSECURE),i.setDisableCustomPlaybackForIOS10Plus(!this.customPlaybackEnabled),"NumRedirects"in t&&i.setNumRedirects(t.NumRedirects),"AutoPlayAdBreaks"in t&&i.setAutoPlayAdBreaks(t.AutoPlayAdBreaks),"Locale"in t&&i.setLocale(t.Locale),"Ppid"in t&&i.setPpid(t.Ppid),!document.body.contains(t.container))throw new Error("AdDisplayContainer was not found in the document.body");this._adDisplayContainer=new this.google.ima.AdDisplayContainer(t.container,u().tizen||u().webOS?void 0:this.videoTag),this._adDisplayContainer.initialize(),this._adsLoader=new this.google.ima.AdsLoader(this._adDisplayContainer),this.log("ima.initialise(:wait -> ADS_MANAGER_LOADED)",Object.assign(Object.assign({},t),{volume:this.videoTag.volume,muted:this.videoTag.muted})),this._adsLoader.addEventListener(this.google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,e=>{if(!this.videoTag)return;this.log("ima.initialise(:done -> ADS_MANAGER_LOADED)\n%o",Object.assign(Object.assign({},t),{volume:this.videoTag.volume,muted:this.videoTag.muted}));const s=new this.google.ima.AdsRenderingSettings;this.log("ima.rendering(preload: %s)",!!t.preload_ads),s.useStyledNonLinearAds=!0,s.enablePreloading=!!t.preload_ads,s.loadVideoTimeout=t.media_timeout||-1,s.restoreCustomPlaybackStateOnAdBreakComplete=this.customPlaybackEnabled,this.customPlaybackEnabled&&(s.playAdsAfterTime=this.videoTag.currentTime),this.eventHandler.trigger(x,s);const i=this._adsManager=e.getAdsManager(this.videoTag,s);this.eventHandler.trigger(N,i),i.addEventListener(this.google.ima.AdEvent.Type.LOADED,()=>{this.log("debug(ima.adsManager): google.ima.AdEvent.Type.LOADED")}),i.addEventListener(this.google.ima.AdErrorEvent.Type.AD_ERROR,()=>{this.log("debug(ima.adsManager): google.ima.AdErrorEvent.Type.AD_ERROR")}),i.addEventListener(this.google.ima.AdEvent.Type.STARTED,()=>{this.log("debug(ima.adsManager): google.ima.AdEvent.Type.STARTED")}),i.addEventListener(this.google.ima.AdEvent.Type.AD_PROGRESS,t=>{var e,s;const i=null===(e=t.getAdData())||void 0===e?void 0:e.duration,r=null===(s=t.getAdData())||void 0===s?void 0:s.currentTime;isNaN(i)||isNaN(r)||(this._currentRemaining=i-r,this.eventHandler.trigger(L,{remaining:this._currentRemaining,duration:i}))}),i.addEventListener(this.google.ima.AdEvent.Type.STARTED,t=>{this._currentRemaining=-1,this.debugEvent(t);const e=t.getAd();e&&(this._currentDuration=e.getDuration(),this._currentDisplayTs=Date.now(),this.emitWithAd(w,e),e.isLinear()&&IMA.pollRemaining({ima:this,adsManager:i}))}),i.addEventListener(this.google.ima.AdEvent.Type.COMPLETE,t=>{this.debugEvent(t);const e=t.getAd();e&&this.emitWithAd(E,e),Ht(this._timers)}),i.addEventListener(this.google.ima.AdEvent.Type.SKIPPED,t=>{this.debugEvent(t);const e=t.getAd();e&&this.emitWithAd(O,e)}),i.addEventListener(this.google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,t=>{if(this.isAdPod()&&this.videoTag){const t=Math.abs(this.videoTag.currentTime-this.videoTag.duration)<1?-1:this.videoTag.currentTime;this.setAdBreakTime(t)}this.debugEvent(t);const e=t.getAd();e&&this.emitWithAd(b,e)}),i.addEventListener(this.google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,t=>{this.debugEvent(t),this._started=!1,this._currentDisplayTs=0,this.eventHandler.trigger(k,{force:!0})}),i.addEventListener(this.google.ima.AdEvent.Type.VOLUME_CHANGED,t=>{this.log("IMA::volume(type: %s, event: %o)",t);const e=i.getVolume();this._volumeLevel=e,this.eventHandler.trigger(M,e)});const r=t=>{this._paused=t,this.eventHandler.trigger(t?S:T)};i.addEventListener(this.google.ima.AdEvent.Type.PAUSED,()=>r(!0)),i.addEventListener(this.google.ima.AdEvent.Type.RESUMED,()=>r(!1)),i.addEventListener(this.google.ima.AdEvent.Type.STARTED,()=>r(!1)),i.addEventListener(this.google.ima.AdEvent.Type.VOLUME_MUTED,t=>{this.log("IMA::volume(type: %s, event: %o)","mute",t),this.eventHandler.trigger(R)});const{width:a,height:n}=t;a&&n&&(i.init(a,n,this.google.ima.ViewMode.NORMAL),this.log("ima.initialise: done initializing"))}),s&&(this.log("Event(reload: %s)",j),this.eventHandler.trigger(j,e)),this.eventHandler.trigger(g,this)}destroyManager(t="unknown"){if(!this._adsManager)return this.log("ima::destroyManager(:skip, label: %s)",t);this.log("ima::destroyManager(:ok, label: %s)",t),this._adsManager.destroy()}reset(){this.destroyManager("reset"),Ht(this._timers),this.clearAdHandlers(),this._started=!1,this._adLoaded=!1}cleanup(){this.destroyManager("cleanup"),this._adsLoader&&this._adsLoader.destroy(),this._adDisplayContainer&&this._adDisplayContainer.destroy(),this._adLoaded=!1}waitForAdsManager(){return new Promise(t=>{this.log("ima.waitForAdsManager:",this._adsManager),this.once(this._adsLoader,this.google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,()=>{this.log("ima.waitForAdsManager(:ok)",this._adsManager),t(this._adsManager)})})}async initAd(t,e=5e3){var s;this.log(`ima.initAd(adTag: ${t}, timeout: ${e})`),this.customPlaybackEnabled||this.loadingController.adRequestStart(this.opts.total_loading_timeout);try{if(await this.requestAd(t,this.loadingController.getRemainingAdLoadTime(e,this.opts.total_loading_timeout)),this._adLoaded=!0,this.customPlaybackEnabled)return;null===(s=this._adsManager)||void 0===s||s.updateAdsRenderingSettings({loadVideoTimeout:this.loadingController.getRemainingAdLoadTime(this.opts.media_timeout||-1,this.opts.total_loading_timeout)})}catch(t){throw this.log("ima.initAd:",t),this._adLoaded=!1,t}finally{Ht(this._timers)}}async requestAd(t,e){if(this.destroyManager("requestAd"),!this.videoTag)return;this.setAdBreakTime(this.videoTag.currentTime);const{autoplay:s=!1}=this.opts,i=Date.now(),r=this.videoTag.muted;this._volumeLevel=this.videoTag.volume;const a=r||0==this._volumeLevel;this._all_ads_completed=!1,this.log("ima.requestAd(%o)",Object.assign(Object.assign({},this.opts),{autoplay:s,muted:r,timeout:e,adTag:t,_volumeLevel:this._volumeLevel,manager:this._adsManager})),this.clearAdHandlers();const n=new this.google.ima.AdsRequest;n.adTagUrl=t;const{height:o,width:d}=this.opts;return d&&(n.linearAdSlotWidth=d),o&&(n.linearAdSlotHeight=o),!this.opts.disable_non_linear_ads&&d&&(n.nonLinearAdSlotWidth=d),!this.opts.disable_non_linear_ads&&o&&(n.nonLinearAdSlotHeight=o-50),n.setAdWillAutoPlay(s),n.setAdWillPlayMuted(a),n.vastLoadTimeout=e,this.eventHandler.trigger(U,{request:n}),this._adsLoader?new Promise(async(t,s)=>{var i;const r=this.waitForAdsManager();null===(i=this._adsLoader)||void 0===i||i.requestAds(n),this.once(this._adsLoader,this.google.ima.AdErrorEvent.Type.AD_ERROR,t=>{s(()=>(this.emitError(v,t),Promise.reject(new Error("Ad load failed"))))}),setTimeout(()=>{s(()=>{r.then(t=>{t.destroy(),this._adsManager===t&&(this._adsManager=void 0)});const t=new Error("Ad internal timeout reached");return this.eventHandler.trigger(P,t),Promise.reject(t)})},e),t(await r)}).then(t=>new Promise((e,s)=>{this.volume(a?0:this._volumeLevel),this.eventHandler.trigger(M,this._volumeLevel);const r=this.cuepoints();if(r&&r.length&&0!==r[0])return e({ad:!1,adsManager:t});this.once(t,this.google.ima.AdErrorEvent.Type.AD_ERROR,t=>{s(()=>(this.emitError(v,t),Promise.reject(t)))}),this.once(t,this.google.ima.AdEvent.Type.ALL_ADS_COMPLETED,()=>{this._all_ads_completed=!0,e(null)}),this.once(t,this.google.ima.AdEvent.Type.LOADED,t=>{this.eventHandler.trigger(A,{request_load_time:Date.now()-i});const s=t.getAd();s&&(this.log("ima.requestAd: AD_REQUEST_COMPLETED",s.getContentType()),"application/javascript"==s.getContentType()&&this.eventHandler.trigger(C,s),e(null))}),this.once(t,this.google.ima.AdEvent.Type.CLICK,()=>{this.log("ima.requestAd: click event"),this.pause()})}),t=>t()):void 0}async playAd(){if(this.log("ima.playAd()",this),!this._adsManager||!this._adLoaded)return;const t=this.currentAd();if(t&&(!this.customPlaybackEnabled||t.isLinear()))try{await this.startAndWaitForAdCompletion(this._adsManager,t.isLinear())}catch(t){throw this.log("ima.playAd",t),t}finally{this._adLoaded=!1,Ht(this._timers)}}startAndWaitForAdCompletion(t,e){if(!this._started)return this.log("ima.startAndWaitForAdCompletion(manager: %o)",{volume:t.getVolume()}),new Promise((s,i)=>{let r=!1;this.once(t,this.google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,()=>{if(this.log("ima.startAndWaitForAdCompletion: CONTENT_RESUME_REQUESTED <<< happened"),this._started=!1,r)return this.log("ima.startAndWaitForAdCompletion: Content resume requested, but trying to recover from ad error");s()}),this.once(t,this.google.ima.AdErrorEvent.Type.AD_ERROR,async t=>{this.log("ima.startAndWaitForAdCompletion: beginning error recovery ->",t),r=!0;try{const{ok:e}=await IMA.pollForFatalError({err:t,ima:this});e&&(r=!1)}catch(e){this._started=!1,i(t)}});const a=this.getVideoTag();if(!a)return;const n=()=>{e&&(this._started=!0),t.start(),this.eventHandler.trigger(B)};if(!e||a.hasState(lt)||a.hasState(vt))return n();a.paused||a.pause(),a.once(st,()=>n())})}pause(){this.log("ima.pause()"),this._adsManager&&this._adsManager.pause()}resume(){this.log("ima.resume()"),this._adsManager&&this._adsManager.resume()}volume(t){if(this._adsManager)try{return arguments.length>0&&"number"==typeof t&&this._adsManager.setVolume(t),this._volumeLevel=this._adsManager.getVolume()}catch(t){this.log("ima.volume() failed (%o)",t)}}onResize({width:t,height:e,linear:s,silent:i,resize_non_linear:r}){this._adsManager&&(this._adLinear=void 0===s?this._adLinear:s,this.opts&&(t||e)&&(!1===s&&(t+=10,e+=10),this._dimensions={width:t,height:e,linear:s},s&&(this.opts.width=t,this.opts.height=e),(this._adLinear||r)&&(i||this.log("ima.onResize %s x %s",t,e),this._adsManager.resize(t,e,this.google.ima.ViewMode.NORMAL))))}onAdRequestEnd(){var t;this.customPlaybackEnabled||(this.loadingController.adRequestEnd(),null===(t=this._adsManager)||void 0===t||t.updateAdsRenderingSettings({loadVideoTimeout:this.opts.media_timeout||-1}))}getAdInfo(){const t=this.currentAd();if(t)return{duration:t.getDuration(),currentTime:this._currentRemaining}}currentAd(){const t=this._adsManager;if(t)return t.getCurrentAd()}isAdPod(){const t=this.cuepoints();return!!(t&&t.length>1)}cuepoints(){return this._adsManager&&this._adsManager.getCuePoints()}async contentComplete(){this.log("ima.contentComplete() -> ",this),this._adsLoader&&this._adsLoader.contentComplete();const t=this.cuepoints();t&&-1!==t.indexOf(-1)&&await new Promise(t=>{IMA.race(this.eventHandler,[k,q],t)})}isUiDisabled(){try{const t=this.currentAd();return t&&t.isUiDisabled()}catch(t){return null}}getAdPodInfo(){try{const t=this.currentAd();return t&&t.getAdPodInfo()}catch(t){return null}}canDismissNonLinear(){const t=this.currentAd();if(!t||t.isLinear()||!this._adsManager||!this._currentDisplayTs)return!0;const e=Date.now(),s=t.getMinSuggestedDuration();return e-this._currentDisplayTs>1e3*s}static unwrapError(t,e){if(!t)return"";if("function"==typeof t.getMessage){return t.getMessage()}return t.message?t.message:e||""}static pollForFatalError({err:t,ima:e}){let s;try{const e=t.getError(),i=e.getInnerError(),r=i?IMA.unwrapError(i,e.message):"";s={reason:r,type:e.getType(),code:e.getErrorCode()}}catch(t){}const i=e._currentRemaining;return new Promise((t,r)=>{const a=setTimeout(()=>{e.eventHandler&&e.eventHandler.trigger(m,s),r(new Error("Ad not progressing"))},2500);e.eventHandler.once(L,e=>{const s=e.detail.remaining;-1!==s&&s<i&&(clearTimeout(a),t({ok:1}))})})}static pollRemaining({ima:t,adsManager:e}){let s=-1;return qt(t._timers,250,function(){const i=e.getRemainingTime();-1!=t._currentRemaining&&t._currentRemaining<=i||(t._currentRemaining=e.getRemainingTime(),s!=t._currentRemaining&&(s=t._currentRemaining,t.eventHandler.trigger(L,{remaining:t._currentRemaining,duration:t._currentDuration})))})}once(t,e,s){this._adHandlers.push(function(t,e,s){const i=r=>{s(r),t.removeEventListener(e,i)};return t.addEventListener(e,i),()=>t.removeEventListener(e,i)}(t,e,s))}static race(t,e,s){e.forEach(i=>{const r=(...i)=>{e.forEach(e=>t.removeListener(e,r)),s(i)};t.on(i,r)})}clearAdHandlers(){this.log("ima.clearAdHandlers"),this._adHandlers.forEach(t=>t()),this._adHandlers=[]}emitWithAd(t,e){if(this.log("ima.emitWithAd",t,e),!this._adsManager)return;const s=function(t){try{return t.getAdPodInfo().getAdPosition()}catch(t){return}}(e),i=function(t){try{return t.getAdPodInfo().getTotalAds()}catch(t){return}}(e),r={ad:{duration:e.getDuration(),width:e.getWidth(),height:e.getHeight(),position:s,totals:i},volume:this._adsManager.getVolume(),vast_ad_id:e.getAdId(),linear:e.isLinear(),mime_type:e.getContentType(),ima_event:!0};this.log(`emitWithAd::event(name: ${t}, data: %o, ad: %o)`,r,e),this.eventHandler.trigger(t,r)}emitError(t,e){const s={vast_error_type:e.getError().getType(),reason:e.getError().getMessage(),vast_error:e.getError().getErrorCode()};this.log(`ima.error(${t})`,s),this.eventHandler.trigger(t,s)}debugEvent(t){try{const e=t.getAd();if(!e)return;this.log(`ima.event.${t.type} ->`,{event:t,data:t.getAdData(),position:Vt(e),ad:e})}catch(t){}}}var Wt=function(t){var e={exports:{}};return t(e,e.exports),e.exports}(function(t,e){var s=function(){for(var t=new Array(256),e=0;e<256;++e)t[e]="%"+((e<16?"0":"")+e.toString(16)).toUpperCase();return t}(),i=Object.prototype.hasOwnProperty;e.arrayToObject=function(t,e){for(var s=e.plainObjects?Object.create(null):{},i=0;i<t.length;++i)void 0!==t[i]&&(s[i]=t[i]);return s},e.merge=function(t,s,r){if(!s)return t;if("object"!=typeof s){if(Array.isArray(t))t.push(s);else{if("object"!=typeof t)return[t,s];(r.plainObjects||r.allowPrototypes||!i.call(Object.prototype,s))&&(t[s]=!0)}return t}if("object"!=typeof t)return[t].concat(s);var a=t;return Array.isArray(t)&&!Array.isArray(s)&&(a=e.arrayToObject(t,r)),Object.keys(s).reduce(function(t,a){var n=s[a];return i.call(t,a)?t[a]=e.merge(t[a],n,r):t[a]=n,t},a)},e.decode=function(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}},e.encode=function(t){if(0===t.length)return t;for(var e="string"==typeof t?t:String(t),i="",r=0;r<e.length;++r){var a=e.charCodeAt(r);45===a||46===a||95===a||126===a||a>=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122?i+=e.charAt(r):a<128?i+=s[a]:a<2048?i+=s[192|a>>6]+s[128|63&a]:a<55296||a>=57344?i+=s[224|a>>12]+s[128|a>>6&63]+s[128|63&a]:(r+=1,a=65536+((1023&a)<<10|1023&e.charCodeAt(r)),i+=s[240|a>>18]+s[128|a>>12&63]+s[128|a>>6&63]+s[128|63&a])}return i},e.compact=function(t,s){if("object"!=typeof t||null===t)return t;var i=s||[],r=i.indexOf(t);if(-1!==r)return i[r];if(i.push(t),Array.isArray(t)){for(var a=[],n=0;n<t.length;++n)t[n]&&"object"==typeof t[n]?a.push(e.compact(t[n],i)):void 0!==t[n]&&a.push(t[n]);return a}for(var o=Object.keys(t),d=0;d<o.length;++d){var l=o[d];t[l]=e.compact(t[l],i)}return t},e.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},e.isBuffer=function(t){return null!=t&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))}}),Qt={brackets:function(t){return t+"[]"},indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},$t={delimiter:"&",strictNullHandling:!1,skipNulls:!1,encode:!0,encoder:Wt.encode},Kt=function t(e,s,i,r,a,n,o,d,l){var c=e;if("function"==typeof o)c=o(s,c);else if(c instanceof Date)c=c.toISOString();else if(null===c){if(r)return n?n(s):s;c=""}if("string"==typeof c||"number"==typeof c||"boolean"==typeof c||Wt.isBuffer(c))return n?[n(s)+"="+n(c)]:[s+"="+String(c)];var u,h=[];if(void 0===c)return h;if(Array.isArray(o))u=o;else{var p=Object.keys(c);u=d?p.sort(d):p}for(var g=0;g<u.length;++g){var m=u[g];a&&null===c[m]||(h=Array.isArray(c)?h.concat(t(c[m],i(s,m),i,r,a,n,o,d,l)):h.concat(t(c[m],s+(l?"."+m:"["+m+"]"),i,r,a,n,o,d,l)))}return h},Yt=Object.prototype.hasOwnProperty,Zt={delimiter:"&",depth:5,arrayLimit:20,parameterLimit:1e3,strictNullHandling:!1,plainObjects:!1,allowPrototypes:!1,allowDots:!1,decoder:Wt.decode},Jt=function t(e,s,i){if(!e.length)return s;var r,a=e.shift();if("[]"===a)r=(r=[]).concat(t(e,s,i));else{r=i.plainObjects?Object.create(null):{};var n="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,o=parseInt(n,10);!isNaN(o)&&a!==n&&String(o)===n&&o>=0&&i.parseArrays&&o<=i.arrayLimit?(r=[])[o]=t(e,s,i):r[n]=t(e,s,i)}return r},Xt=function(t,e,s){if(t){var i=s.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,r=/(\[[^[\]]*])/g,a=/(\[[^[\]]*])/.exec(i),n=a?i.slice(0,a.index):i,o=[];if(n){if(!s.plainObjects&&Yt.call(Object.prototype,n)&&!s.allowPrototypes)return;o.push(n)}for(var d=0;null!==(a=r.exec(i))&&d<s.depth;){if(d+=1,!s.plainObjects&&Yt.call(Object.prototype,a[1].slice(1,-1))&&!s.allowPrototypes)return;o.push(a[1])}return a&&o.push("["+i.slice(a.index)+"]"),Jt(o,e,s)}},te=function(t,e){var s,i,r=t,a=e||{},n=void 0===a.delimiter?$t.delimiter:a.delimiter,o="boolean"==typeof a.strictNullHandling?a.strictNullHandling:$t.strictNullHandling,d="boolean"==typeof a.skipNulls?a.skipNulls:$t.skipNulls,l=("boolean"==typeof a.encode?a.encode:$t.encode)?"function"==typeof a.encoder?a.encoder:$t.encoder:null,c="function"==typeof a.sort?a.sort:null,u=void 0!==a.allowDots&&a.allowDots;if(null!==a.encoder&&void 0!==a.encoder&&"function"!=typeof a.encoder)throw new TypeError("Encoder has to be a function.");"function"==typeof a.filter?r=(i=a.filter)("",r):Array.isArray(a.filter)&&(s=i=a.filter);var h,p=[];if("object"!=typeof r||null===r)return"";h=a.arrayFormat in Qt?a.arrayFormat:"indices"in a?a.indices?"indices":"repeat":"indices";var g=Qt[h];s||(s=Object.keys(r)),c&&s.sort(c);for(var m=0;m<s.length;++m){var _=s[m];d&&null===r[_]||(p=p.concat(Kt(r[_],_,g,o,d,l,i,c,u)))}return p.join(n)},ee=function(t,e){var s=e||{};if(null!==s.decoder&&void 0!==s.decoder&&"function"!=typeof s.decoder)throw new TypeError("Decoder has to be a function.");if(s.delimiter="string"==typeof s.delimiter||Wt.isRegExp(s.delimiter)?s.delimiter:Zt.delimiter,s.depth="number"==typeof s.depth?s.depth:Zt.depth,s.arrayLimit="number"==typeof s.arrayLimit?s.arrayLimit:Zt.arrayLimit,s.parseArrays=!1!==s.parseArrays,s.decoder="function"==typeof s.decoder?s.decoder:Zt.decoder,s.allowDots="boolean"==typeof s.allowDots?s.allowDots:Zt.allowDots,s.plainObjects="boolean"==typeof s.plainObjects?s.plainObjects:Zt.plainObjects,s.allowPrototypes="boolean"==typeof s.allowPrototypes?s.allowPrototypes:Zt.allowPrototypes,s.parameterLimit="number"==typeof s.parameterLimit?s.parameterLimit:Zt.parameterLimit,s.strictNullHandling="boolean"==typeof s.strictNullHandling?s.strictNullHandling:Zt.strictNullHandling,""===t||null==t)return s.plainObjects?Object.create(null):{};for(var i="string"==typeof t?function(t,e){for(var s={},i=t.split(e.delimiter,e.parameterLimit===1/0?void 0:e.parameterLimit),r=0;r<i.length;++r){var a,n,o=i[r],d=-1===o.indexOf("]=")?o.indexOf("="):o.indexOf("]=")+1;-1===d?(a=e.decoder(o),n=e.strictNullHandling?null:""):(a=e.decoder(o.slice(0,d)),n=e.decoder(o.slice(d+1))),Yt.call(s,a)?s[a]=[].concat(s[a]).concat(n):s[a]=n}return s}(t,s):t,r=s.plainObjects?Object.create(null):{},a=Object.keys(i),n=0;n<a.length;++n){var o=a[n],d=Xt(o,i[o],s);r=Wt.merge(r,d,s)}return Wt.compact(r)};const se=yt("fpads:macros"),ie=/\[([\s\S]+?)\]/g;class Macros{static run(t){try{return t()}catch(t){return void console.error(t)}}static merge(...t){return t.reduce((t,e)=>Object.assign(t,e),{})}static cast(t){return void 0===t?"":"function"==typeof t?encodeURIComponent(Macros.run(t)||""):"string"==typeof t?encodeURIComponent(t):"number"==typeof t||"boolean"==typeof t?t.toString():""}static normalize(t){return t.trim()}static process_obj(t,e,s){return Object.keys(t).reduce((i,r)=>{const a=Macros.process_str(r,e,s,!0),n=t[r];return null===n?(i[a]=n,i):"object"==typeof n?(i[a]=Macros.process_obj(n,e,s),i):"string"==typeof n?(i[a]=Macros.process_str(n,e,s),i):(console.error(new Error(`${n} at ${r} not a handled Macro type`)),i)},{})}static process_str(t,e,s,i=!1){return t.replace(e.pattern,(t,e)=>{const r=Macros.normalize(e);if(!(r in s)||void 0===s[r])return t;const a=s[r],n=i?a:Macros.cast(a);return se("Macro.replace(raw: %s, macro: %s, value: %s)",i,e,n),n})}constructor(t={},e=ie){this.vars=t,this.pattern=e}fork(t={},e=this.pattern){const s=Macros.merge(this.vars,t);return new Macros(s,e)}compile(t,e={}){const s=Macros.merge(this.vars,e),[i,r]=t.split("?"),a=ee(r||"",{strictNullHandling:!0,decoder:t=>t}),n=te(Macros.process_obj(a,this,s),{encode:!1,strictNullHandling:!0});return Macros.process_str(i,this,s,!0)+"?"+n}}function re(t,e={width:0,height:0}){let s,i;try{const t=document.createElement("a");t.href=s=window.location!=window.parent.location?document.referrer:document.location.href,i=t.hostname}catch(t){console.error(t)}const{width:r,height:a}=e,{video_source:n}=t||{},o=function(){const t=window;return"object"==typeof t.__flowplayerAdParameters?t.__flowplayerAdParameters:{}}();return Object.assign({random:Date.now(),page_url:s,domain:i,player_width:r,player_height:a,video_url:n,videourl:n},o)}Macros.patterns={BRACKETS:ie,CURLY:/\{([\s\S]+?)\}/g,UNDERSCORE:/__([\s\S]+?)__/g};const ae=/^flowplayer:\/\/(.+)/;async function ne(t){if("string"==typeof t&&ae.test(t)){const e=ae.exec(t),s=e&&window[e[1]];if(s)return ne(s)}if("function"!=typeof t)return t;try{return await t()}catch(t){return""}}async function oe(t){if("function"==typeof t)return[await ne(t)];if("string"==typeof t)return[await ne(t)];if(Array.isArray(t)){const e=t;return await Promise.all(e.map(ne))}if("object"==typeof t&&t&&t.adTag)return await oe(t.adTag);throw new Error(`\n unhandled ads type ${typeof t}:\n ${JSON.stringify(t)}\n can be:\n | Array<string>\n | string\n | function\n | {adTag: Array<string>|string|function}\n `)}class Schedule{constructor(t,e={}){this._ads=t,this._opts=e,this._nextIndex=0,this._postroll=void 0,this._loadPending=!1,this._postrollActive=!1,this.reset(this._ads)}toJSON(){const t=(this._ads||[]).slice(this._nextIndex);return this._postroll&&t.push(this._postroll),t}reset(t){this.setAds(t),this._nextIndex=0,this._postrollActive=!1}resetCounter(){this._nextIndex=0,this._postrollActive=!1}setAds(t){this._ads=t||[],this.sort()}getAds(){return this._ads}getNextAd(t){return this._ads[this._nextIndex]||t}getCurrentAd(){return this._postrollActive?this._postroll:this._loadPending?0:this._ads[this._nextIndex-1]}getPostroll(){return this._postroll}isDrained(){return this._nextIndex+1>this._ads.length}setPostrollActive(){this._postrollActive=!0}updateContentDuration(t){this._opts.content_duration=t}increment(){++this._nextIndex}decrement(){this._nextIndex>0&&--this._nextIndex}getNextIndex(){return this._nextIndex}getCurrentType(){const t=this.getCurrentAd();if(t)return Schedule.kindOf(t.time)}sort(){this._postroll=this._ads.find(t=>-1===t.time),this._ads=this._ads.filter(t=>t!==this._postroll).sort((t,e)=>t.time===e.time?this._ads.indexOf(t)-this._ads.indexOf(e):t.time-e.time)}shallPlayAd(t){if(this._loadPending)return!1;const e=this.getCurrentAd()||this.getNextAd();return!!(e&&e.time<=t&&-1!==e.time)}shallPlayNext(){const t=this.getNextAd(),e=this.getCurrentAd();return!(!t||!e||t.time!==e.time)}waitForLoad(t,e,s){if(this._loadPending=!1,!e)return!1;const i=s?this._opts.preload_advance:0;return e.time>=0?this._loadPending=t<e.time-i:-1===e.time&&(this._loadPending=this._opts.content_duration>0&&-1!==t?t<this._opts.content_duration-i:-1!==t),this._loadPending}static hasPreroll(t){return!!t.find(t=>0===t.time)}static isOutstream(t){return Schedule.hasPreroll(t)&&!!t[0].outstream}static kindOf(t){switch(t){case 0:return"preroll";case-1:return"postroll";default:return"midroll"}}}const de=Object.prototype,le=Object.getPrototypeOf;const ce=yt("fpads:ads:state");var ue;!function(t){t[t.IDLE=0]="IDLE",t[t.INITIALIZING=1]="INITIALIZING",t[t.FETCHING_AD=2]="FETCHING_AD",t[t.AD_AVAILABLE=4]="AD_AVAILABLE",t[t.BREAK_ACTIVE=8]="BREAK_ACTIVE",t[t.PLAYING=16]="PLAYING",t[t.FATAL_ERROR=32]="FATAL_ERROR"}(ue||(ue={}));class AdsState{static of(){return new AdsState}constructor(t=0){this._state=t}reset(){this._state=0}toggleState(t,e){return void 0===t&&ce(new Error("AdState cannot toggleState for `undefined`")),void 0===e?this._state^=t:e?void(this._state|=t):this._state&=~t}hasAll(t){return this._state==(this._state|t)}hasAny(t){return!!(this._state&t)}get state(){return this._state}}const he={ok:yt("fpads:analytics:request-queue"),err:yt("fpads:analytics:request-queue:err"),warn:yt("fpads:analytics:request-queue:warn")};class RequestQueue{static of(){return new RequestQueue}static is_empty(t){return 0==t.pending.length}static is_high_water(t){return t.open.length==RequestQueue.MAX_OPEN_REQUESTS}static maybe_spawn_req(t){if(RequestQueue.is_empty(t))return he.ok("maybe_spawn_req called Queue that is EMPTY"),t;if(RequestQueue.is_high_water(t))return he.warn("maybe_spawn_req called on Queue that is HIGH_WATER"),t;try{const e=RequestQueue.lpop(t);e&&RequestQueue.request(t,e)}catch(t){he.err(t)}}static increment_failures(t){return t.stats.failures++,t.stats.failures>RequestQueue.MAX_FAILURE_COUNT&&(t.stats.ttl=Date.now()+RequestQueue.REQUEST_TTL_MS),t}static handle_error(t,e){RequestQueue.rm(t,e),RequestQueue.increment_failures(t)}static request(t,[e,s,i]){if(he.ok(`Request[${i.event_type}] request`,i,t.stats),Date.now()<t.stats.ttl)return he.warn(`Request[${i.event_type}] skipping because too many errors too quickly`,t.stats);const r=new XMLHttpRequest;t.open.push(r),r.timeout=RequestQueue.REQUEST_TIMEOUT_MS,r.ontimeout=function(){RequestQueue.handle_error(t,r),he.warn(`Request[${i.event_type}] timed out in ${r.timeout}ms`,t.stats)},r.onerror=function(e){RequestQueue.handle_error(t,r),e&&he.err(e),he.warn(`Request[${i.event_type}] encountered an Error`,r.responseText,t.stats)},r.onreadystatechange=function(){r.readyState==XMLHttpRequest.DONE&&RequestQueue.rm(t,r),Math.floor(r.status/100)},r.onload=function(){RequestQueue.rm(t,r),t.stats.failures&&t.stats.failures--,he.ok(`Request[${i.event_type}] :ok`,r.status)},r.open(s,e),r.setRequestHeader("Content-Type","text/plain;charset=UTF-8");try{r.send(