diff --git a/dist/player.js b/dist/player.js index d7139b8..afe6b15 100644 --- a/dist/player.js +++ b/dist/player.js @@ -1561,7 +1561,7 @@ html body { div:focus { outline: none; } -`;var z8=({options:e})=>{var R;let{ref:t,isOpen:r,playerOptions:n,playerSize:o,isMaskActive:a,isError:s,trackInfo:u,setPlayerOptions:f,updateTime:d,onLoadAudio:h,setIsPlay:v,isAddPlayed:S,setIsAddPlayed:x,setIsShowAdNow:g}=Ie(),k=O8(a,500),{color:b,width:w,type:y}=n,[C,P]=It.default.useState(!1),O=/(iPad|iPhone|iPod)/g.test(navigator.userAgent);(0,It.useEffect)(()=>{f(e)},[e]),(0,It.useEffect)(()=>{C||u.duration&&(t!=null&&t.current)&&(t==null?void 0:t.current.currentTime)*1e3>=5e3&&!S&&O&&(P(!0),(()=>{let q=document.getElementById("hiddenAdTrigger");q&&q.click()})())},[u.duration,(R=t==null?void 0:t.current)==null?void 0:R.currentTime,S,C,O]);let D=()=>{var q,z,Q;let L="https://statics.dmcdn.net/h/html/vast/simple-inline.xml";(q=n.imaManager)==null||q.requestAds(L),g(!0),v(!1),(z=t==null?void 0:t.current)==null||z.pause(),(Q=n.imaManager)==null||Q.addAdListener(window.google.ima.AdEvent.Type.COMPLETE,()=>{var re;x(!0),(re=t==null?void 0:t.current)==null||re.play(),g(!1),v(!0)})};return It.default.createElement(It.default.Fragment,null,It.default.createElement(Ms,null,It.default.createElement("style",null,"@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');")),s&&It.default.createElement(jd,{playerData:n,errorText:Xa}),y==="static"&&!s&&It.default.createElement(R8,{width:w||600,color:b||"grey",isMaskActive:k,className:`ty-player-container-${o}`},It.default.createElement(V6,null),It.default.createElement(It.default.Fragment,null,It.default.createElement("audio",{ref:t,onTimeUpdate:d,onLoadedMetadata:h,id:"videoElement"}),It.default.createElement("div",{id:"adContainer",style:{display:"none"}}),O&&It.default.createElement("button",{id:"hiddenAdTrigger",onClick:D},"Start Ad"))),y==="dynamic"&&!s&&It.default.createElement(F8,{className:r?"open":"closed"},!r&&It.default.createElement(_6,null),r&&It.default.createElement(A8,null),It.default.createElement("audio",{ref:t,onTimeUpdate:d,onLoadedMetadata:h})))};var $d=H(Z());var Hd=class extends $d.Component{constructor(r){super(r);Sa(this,"error");Sa(this,"playerOptions");Sa(this,"state",{error:!1});this.playerOptions=r.playerOptions}componentDidCatch(r,n){console.log(r,n),this.setState({error:!0})}render(){return this.state.error?$d.default.createElement(jd,{playerData:this.playerOptions,errorText:Y2}):this.props.children}};var zE=e=>new Promise((t,r)=>{let n=document.createElement("script");n.async=!0,n.src=e,n.onload=t,n.onerror=r,document.body.appendChild(n)}),xh=zE;var YE="https://imasdk.googleapis.com/js/sdkloader/ima3.js",Ds=null,Y8=()=>{Ds=null},BE=()=>{let e=window;return e.google&&e.google.ima?Promise.resolve(e.google.ima):Ds||(Ds=xh(YE).then(()=>e.google.ima),Ds.then(Y8).catch(Y8),Ds)},Th=BE;async function B8(e){await Th().catch(r=>console.error("IMA SDK could not be loaded. Check your ad blocker."))&&(console.info("IMA SDK successfully loaded."),e())}var Wd=class{constructor(t,r){this.videoElement=t,this.adContainer=r,this.adsLoader=null,this.adsManager=null,this.listeners={},this.timeRemaining=0,this.countdownTimer=null,this.onAdsManagerLoaded=this.onAdsManagerLoaded.bind(this),this.onAdError=this.onAdError.bind(this),this.onAdsStarted=this.onAdsStarted.bind(this),this.onContentResumeRequested=this.onContentResumeRequested.bind(this)}onAdsManagerLoaded(t){console.info("Ads manager loaded");let r=window.google.ima,n=new r.AdsRenderingSettings;n.loadVideoTimeout=9e3,this.adsManager=t.getAdsManager(this.videoElement,n),[window.google.ima.AdEvent.Type.STARTED,window.google.ima.AdEvent.Type.PAUSED,window.google.ima.AdEvent.Type.RESUMED,window.google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED,window.google.ima.AdEvent.Type.SKIPPED,window.google.ima.AdEvent.Type.CLICK,window.google.ima.AdEvent.Type.VOLUME_CHANGED,window.google.ima.AdEvent.Type.COMPLETE,window.google.ima.AdEvent.Type.ALL_ADS_COMPLETED,window.google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,window.google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED].forEach(a=>{this.adsManager&&this.adsManager.addEventListener(a,this.listeners[a]?this.listeners[a]:()=>{})}),this.adsManager&&(this.adsManager.addEventListener(r.AdEvent.Type.LOADED,()=>this.adsManager.start()),this.adsManager.addEventListener(r.AdErrorEvent.Type.AD_ERROR,this.onAdError),this.adsManager.init(this.videoElement.clientWidth,this.videoElement.clientHeight,r.ViewMode.NORMAL),this.adsManager.addEventListener(r.AdEvent.Type.STARTED,this.onAdsStarted),this.adsManager.addEventListener(r.AdEvent.Type.CONTENT_RESUME_REQUESTED,this.onContentResumeRequested))}onAdsStarted(t){this.countdownTimer=setInterval(()=>{this.adsManager&&(this.timeRemaining=this.adsManager.getRemainingTime())},1e3)}onContentResumeRequested(t){this.countdownTimer&&(clearInterval(this.countdownTimer),this.countdownTimer=null)}onAdError(t){console.error(t.getError().getErrorCode(),t.getError().getMessage()),console.dir(t.getError())}resume(){this.adsManager&&this.adsManager.resume()}pause(){this.adsManager&&this.adsManager.pause()}skip(){this.adsManager&&this.adsManager.getAdSkippableState()&&this.adsManager.skip()}addAdListener(t,r){this.listeners[t]=r}init(){if(this.adsLoader)return;let t=window.google.ima,r=new t.AdDisplayContainer(this.adContainer,this.videoElement);r.initialize(),this.adsLoader=new t.AdsLoader(r),this.adsLoader.addEventListener(t.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.onAdsManagerLoaded),this.adsLoader.addEventListener(t.AdErrorEvent.Type.AD_ERROR,this.onAdError)}requestAds(t){if(!this.adsLoader)return;this.adsManager&&this.adsManager.destroy();let r=new window.google.ima.AdsRequest;r.adTagUrl=t,this.adsLoader.requestAds(r)}getTimeRemaining(){return parseInt(this.timeRemaining)}};var Ud=class{constructor(){Sa(this,"options",{})}async fetchOptions(t){try{let n=await(await ho.getPlayerOptions(t)).data;this.options=n;let o=document.createElement("link");o.type="text/css",o.rel="stylesheet",document.head.appendChild(o),o.href=`${"https://ty.mailstone.net/api/"==null?void 0:"https://ty.mailstone.net/api/".slice(0,29-4)}widget/player.css`}catch(r){console.log(r)}}createAdService(){setTimeout(()=>{let t=document.getElementById("videoElement"),r=document.getElementById("adContainer");if(t===null||r===null)throw Error("VideoElement or AdContainer not included in DOM");let n=new Wd(t,r);n.init(),this.options.imaManager=n,console.log("createAdService",this.options.imaManager)},2e3)}createWidgetContainer(){let t=document.createElement("div");return t.id="ty-project-widget",t.className="ty-project-widget",t}render(t){(0,j8.createRoot)(t).render(Vd.default.createElement(Hd,{playerOptions:this.options},Vd.default.createElement(E4,null,Vd.default.createElement(z8,{options:this.options}))))}async init(t){await this.fetchOptions(t);let r=this.createWidgetContainer();if(this.options.status==="active"){if(this.options.type==="static"){Yl(r,Mm);let n=setInterval(()=>{let o=document.getElementById(this.options.id);if(o){let a=o.parentNode;a&&(a.insertBefore(r,o),clearInterval(n))}},1500)}else Yl(r,Dm),document.body.appendChild(r);this.render(r),B8(this.createAdService.bind(this))}}async initInBlock(t){await this.fetchOptions(t);let r=this.createWidgetContainer();if(this.options.status==="active"){if(this.options.type==="static"){Yl(r,Mm);let n=setInterval(()=>{let o=document.getElementById(`ty-project-player-${t}`);o&&(o.hasChildNodes()||o.appendChild(r),clearInterval(n))},1500)}if(this.options.type==="dynamic"){let n=setInterval(()=>{let o=document.getElementById(`ty-project-player-${t}`);o&&(Yl(o,[...Dm,{key:"minWidth",value:"100%"}]),o.appendChild(r),clearInterval(n))},1500)}this.render(r)}}};window.TYLR_Widget=new Ud;window.Widget=window.TYLR_Widget;})(); +`;var z8=({options:e})=>{var R;let{ref:t,isOpen:r,playerOptions:n,playerSize:o,isMaskActive:a,isError:s,trackInfo:u,setPlayerOptions:f,updateTime:d,onLoadAudio:h,setIsPlay:v,isAddPlayed:S,setIsAddPlayed:x,setIsShowAdNow:g}=Ie(),k=O8(a,500),{color:b,width:w,type:y}=n,[C,P]=It.default.useState(!1),O=/(iPad|iPhone|iPod)/g.test(navigator.userAgent);(0,It.useEffect)(()=>{f(e)},[e]),(0,It.useEffect)(()=>{C||u.duration&&(t!=null&&t.current)&&(t==null?void 0:t.current.currentTime)*1e3>=5e3&&!S&&O&&(P(!0),(()=>{let q=document.getElementById("hiddenAdTrigger");q&&q.click()})())},[u.duration,(R=t==null?void 0:t.current)==null?void 0:R.currentTime,S,C,O]);let D=()=>{var q,z,Q;let L="https://statics.dmcdn.net/h/html/vast/simple-inline.xml";(q=n.imaManager)==null||q.requestAds(L),g(!0),v(!1),(z=t==null?void 0:t.current)==null||z.pause(),(Q=n.imaManager)==null||Q.addAdListener(window.google.ima.AdEvent.Type.COMPLETE,()=>{var re;x(!0),(re=t==null?void 0:t.current)==null||re.play(),g(!1),v(!0)})};return It.default.createElement(It.default.Fragment,null,It.default.createElement(Ms,null,It.default.createElement("style",null,"@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');")),s&&It.default.createElement(jd,{playerData:n,errorText:Xa}),y==="static"&&!s&&It.default.createElement(R8,{width:w||600,color:b||"grey",isMaskActive:k,className:`ty-player-container-${o}`},It.default.createElement(V6,null),It.default.createElement(It.default.Fragment,null,It.default.createElement("audio",{ref:t,onTimeUpdate:d,onLoadedMetadata:h,id:"videoElement"}),It.default.createElement("div",{id:"adContainer",style:{display:"none"}}),O&&It.default.createElement("button",{id:"hiddenAdTrigger",style:{display:"none"},onClick:D},"Start Ad"))),y==="dynamic"&&!s&&It.default.createElement(F8,{className:r?"open":"closed"},!r&&It.default.createElement(_6,null),r&&It.default.createElement(A8,null),It.default.createElement("audio",{ref:t,onTimeUpdate:d,onLoadedMetadata:h})))};var $d=H(Z());var Hd=class extends $d.Component{constructor(r){super(r);Sa(this,"error");Sa(this,"playerOptions");Sa(this,"state",{error:!1});this.playerOptions=r.playerOptions}componentDidCatch(r,n){console.log(r,n),this.setState({error:!0})}render(){return this.state.error?$d.default.createElement(jd,{playerData:this.playerOptions,errorText:Y2}):this.props.children}};var zE=e=>new Promise((t,r)=>{let n=document.createElement("script");n.async=!0,n.src=e,n.onload=t,n.onerror=r,document.body.appendChild(n)}),xh=zE;var YE="https://imasdk.googleapis.com/js/sdkloader/ima3.js",Ds=null,Y8=()=>{Ds=null},BE=()=>{let e=window;return e.google&&e.google.ima?Promise.resolve(e.google.ima):Ds||(Ds=xh(YE).then(()=>e.google.ima),Ds.then(Y8).catch(Y8),Ds)},Th=BE;async function B8(e){await Th().catch(r=>console.error("IMA SDK could not be loaded. Check your ad blocker."))&&(console.info("IMA SDK successfully loaded."),e())}var Wd=class{constructor(t,r){this.videoElement=t,this.adContainer=r,this.adsLoader=null,this.adsManager=null,this.listeners={},this.timeRemaining=0,this.countdownTimer=null,this.onAdsManagerLoaded=this.onAdsManagerLoaded.bind(this),this.onAdError=this.onAdError.bind(this),this.onAdsStarted=this.onAdsStarted.bind(this),this.onContentResumeRequested=this.onContentResumeRequested.bind(this)}onAdsManagerLoaded(t){console.info("Ads manager loaded");let r=window.google.ima,n=new r.AdsRenderingSettings;n.loadVideoTimeout=9e3,this.adsManager=t.getAdsManager(this.videoElement,n),[window.google.ima.AdEvent.Type.STARTED,window.google.ima.AdEvent.Type.PAUSED,window.google.ima.AdEvent.Type.RESUMED,window.google.ima.AdEvent.Type.SKIPPABLE_STATE_CHANGED,window.google.ima.AdEvent.Type.SKIPPED,window.google.ima.AdEvent.Type.CLICK,window.google.ima.AdEvent.Type.VOLUME_CHANGED,window.google.ima.AdEvent.Type.COMPLETE,window.google.ima.AdEvent.Type.ALL_ADS_COMPLETED,window.google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,window.google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED].forEach(a=>{this.adsManager&&this.adsManager.addEventListener(a,this.listeners[a]?this.listeners[a]:()=>{})}),this.adsManager&&(this.adsManager.addEventListener(r.AdEvent.Type.LOADED,()=>this.adsManager.start()),this.adsManager.addEventListener(r.AdErrorEvent.Type.AD_ERROR,this.onAdError),this.adsManager.init(this.videoElement.clientWidth,this.videoElement.clientHeight,r.ViewMode.NORMAL),this.adsManager.addEventListener(r.AdEvent.Type.STARTED,this.onAdsStarted),this.adsManager.addEventListener(r.AdEvent.Type.CONTENT_RESUME_REQUESTED,this.onContentResumeRequested))}onAdsStarted(t){this.countdownTimer=setInterval(()=>{this.adsManager&&(this.timeRemaining=this.adsManager.getRemainingTime())},1e3)}onContentResumeRequested(t){this.countdownTimer&&(clearInterval(this.countdownTimer),this.countdownTimer=null)}onAdError(t){console.error(t.getError().getErrorCode(),t.getError().getMessage()),console.dir(t.getError())}resume(){this.adsManager&&this.adsManager.resume()}pause(){this.adsManager&&this.adsManager.pause()}skip(){this.adsManager&&this.adsManager.getAdSkippableState()&&this.adsManager.skip()}addAdListener(t,r){this.listeners[t]=r}init(){if(this.adsLoader)return;let t=window.google.ima,r=new t.AdDisplayContainer(this.adContainer,this.videoElement);r.initialize(),this.adsLoader=new t.AdsLoader(r),this.adsLoader.addEventListener(t.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.onAdsManagerLoaded),this.adsLoader.addEventListener(t.AdErrorEvent.Type.AD_ERROR,this.onAdError)}requestAds(t){if(!this.adsLoader)return;this.adsManager&&this.adsManager.destroy();let r=new window.google.ima.AdsRequest;r.adTagUrl=t,this.adsLoader.requestAds(r)}getTimeRemaining(){return parseInt(this.timeRemaining)}};var Ud=class{constructor(){Sa(this,"options",{})}async fetchOptions(t){try{let n=await(await ho.getPlayerOptions(t)).data;this.options=n;let o=document.createElement("link");o.type="text/css",o.rel="stylesheet",document.head.appendChild(o),o.href=`${"https://ty.mailstone.net/api/"==null?void 0:"https://ty.mailstone.net/api/".slice(0,29-4)}widget/player.css`}catch(r){console.log(r)}}createAdService(){setTimeout(()=>{let t=document.getElementById("videoElement"),r=document.getElementById("adContainer");if(t===null||r===null)throw Error("VideoElement or AdContainer not included in DOM");let n=new Wd(t,r);n.init(),this.options.imaManager=n,console.log("createAdService",this.options.imaManager)},2e3)}createWidgetContainer(){let t=document.createElement("div");return t.id="ty-project-widget",t.className="ty-project-widget",t}render(t){(0,j8.createRoot)(t).render(Vd.default.createElement(Hd,{playerOptions:this.options},Vd.default.createElement(E4,null,Vd.default.createElement(z8,{options:this.options}))))}async init(t){await this.fetchOptions(t);let r=this.createWidgetContainer();if(this.options.status==="active"){if(this.options.type==="static"){Yl(r,Mm);let n=setInterval(()=>{let o=document.getElementById(this.options.id);if(o){let a=o.parentNode;a&&(a.insertBefore(r,o),clearInterval(n))}},1500)}else Yl(r,Dm),document.body.appendChild(r);this.render(r),B8(this.createAdService.bind(this))}}async initInBlock(t){await this.fetchOptions(t);let r=this.createWidgetContainer();if(this.options.status==="active"){if(this.options.type==="static"){Yl(r,Mm);let n=setInterval(()=>{let o=document.getElementById(`ty-project-player-${t}`);o&&(o.hasChildNodes()||o.appendChild(r),clearInterval(n))},1500)}if(this.options.type==="dynamic"){let n=setInterval(()=>{let o=document.getElementById(`ty-project-player-${t}`);o&&(Yl(o,[...Dm,{key:"minWidth",value:"100%"}]),o.appendChild(r),clearInterval(n))},1500)}this.render(r)}}};window.TYLR_Widget=new Ud;window.Widget=window.TYLR_Widget;})(); /*! Bundled license information: react/cjs/react.production.min.js: