// Version: 20250627 (function(d,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(d=typeof globalThis<"u"?globalThis:d||self,j(d.JBLWebSocket={}))})(this,function(d){"use strict";var j=null;const L={sendHealthStream:()=>{let t={};t.router="getHealthStream";let e=i.getWebSocket();e.readyState===WebSocket.OPEN?i.sendMsg(JSON.stringify(t)):e.addEventListener("open",function(n){i.sendMsg(JSON.stringify(t))})},setHealthFun:t=>{j=t},getHealthFun:t=>{j(t)},getHealthCallbakfun:t=>j},b=t=>t!==null&&typeof t<"u",S=t=>{let e="";return t.indexOf("//")>-1?t.indexOf(".ourdvsss.com")>-1?e=t.split("/")[0]+"//"+t.split("/")[3]:e=t.split("/")[0]+"//"+t.split("/")[2]:e=t.split("/")[0],e=e.split("?")[0],e},Et=t=>{var e;return e=t.split(".m3u8")[0],e},Be=(t,e)=>{e.time=new Date().getTime();let n=JSON.stringify(e);localStorage.setItem(t,n)},Nt=t=>t.replace("https://","").replace("http://",""),_=()=>{const t=navigator.userAgent,e=[[/android/i,"Android Device"],[/(iPad|iPhone|iPod)/,"iOS Device"],[/Win/,"Windows Device"],[/Mac/,"MacOS Device"]];for(let[n,o]of e)if(n.test(t)&&!(o==="iOS Device"&&window.MSStream))return o;return"Unknown Device"},I=()=>{const t=navigator.userAgent,e=[[/Edg/i,"Edge"],[/Chrome/i,"Chrome"],[/Firefox/i,"Firefox"],[/Safari/i,"Safari"],[/MSIE/i,"IE"],[/FBAN/i,"Facebook"],[/instagram/i,"Instagram"],[/Zalo/i,"Zalo"],[/MicroMessenger/i,"WeChat"],[/WeChat/i,"WeChat"],[/StApp/i,"StApp"],[/KUAPP/i,"KUAPP"]];for(let[n,o]of e)if(n.test(t))return o;return t},Dt="wss://web.analysiscloud.info/m1uudG5uIU/?project=",$t="https://web.analysiscloud.info/ccu/m1uudG5uIU/config",Ht="https://web.analysiscloud.info/ccu/m1uudG5uIU/upsert",Ot="https://web.analysiscloud.info/ccu/m1uudG5uIU/get";var de=null,ce={},fe=null;const Je=t=>{de=t,We(window.location.hostname,"x",navigator.appVersion,"",""),Ue()},Mt=()=>fetch($t).then(t=>t.json()).then(t=>{Je(t)}).catch(t=>console.error(t)),Ue=()=>{if(ze(),de.streamTest_enable!=1){console.log("streamTest is disabled");return}fe=setInterval(()=>{try{let t=ce;if(t.uid)fetch(Ht,{method:"POST",body:JSON.stringify(t)}).catch(e=>console.error(e));else return}catch{}},de.streamTest_interval*6e4)},ze=()=>{b(fe)&&(clearInterval(fe),fe=null)},We=(t,e,n,o,s)=>{let r={};r={},r.projectName=i.getProject(),r.serverId=t,r.uid=e,r.device=n,r.streamName=o,r.cdnName=s,r.updateTime=new Date().getTime(),ce=r},E={ccu_config:de,getInfo:()=>ce,setConfig:Je,restart:Mt,start:Ue,stop:ze,upsert:We,remove:()=>{let t={};t.updateTime=new Date().getTime(),ce=t}};var m={},h={},Z=null;const jt=t=>(Re(),h.enable=t.apiTest_enable,h.timeout=t.apiTest_timeout,!h.enable||h.enable!=1||!h.timeout?(console.log("apiTest is disabled"),!1):(Z=setInterval(()=>{Pe()},h.timeout),!0)),Ft=()=>{h.enable=0,m={},Re()},Re=()=>{b(Z)&&(clearInterval(Z),Z=null)},Bt=(t,e,n,o)=>{if(h.enable&&h.enable!=1||L.getHealthCallbakfun()!=null)return;let s=t==null?void 0:t.split("?")[0];m[s]||(m[s]=Ae(s));let r=m[s];e=Number(e),r.server=o,r.maxSpeed=r.maxSpeed>e?r.maxSpeed:e,r.minSpeed=r.minSpeed{if(h.enable&&h.enable!=1||L.getHealthCallbakfun()!=null)return;let n=t.split("?")[0];m[n]||(m[n]=Ae(n));let o=m[n];o.server="cache",o.cacheCount++},Ut=(t,e,n)=>{if(h.enable&&h.enable!=1||L.getHealthCallbakfun()!=null)return;let o=t.split("?")[0];m[o]||(m[o]=Ge(o));let s=m[o];if(s.server=n,e!=null){let r=(e==null?void 0:e.status)+"@@@"+((e==null?void 0:e.name)==null?"":e.name)+"@@@"+e.statusText;s.failMessage.add(r)}s.failCount++},zt=(t,e,n)=>{if(h.enable&&h.enable!=1||L.getHealthCallbakfun()!=null)return;let o=t.split("?")[0];m[o]||(m[o]=Ge(o));let s=m[o];if(s.server=n,e!=null){let r="5xx@@@"+e.name+"@@@"+e.statusText;s.failMessage.add(r)}},Pe=()=>{let t=m;if(m={},L.getHealthCallbakfun()!=null)return;let e={},n=Object.keys(t).map(s=>t[s]);n.forEach(s=>{s.failMessage!=null&&(s.failMessage=Array.from(s.failMessage))}),e.router="apiTestInfo",e.data={};for(var o=0;o{let e={},n=E.getInfo();return e.server=n.serverId?n.serverId:"",e.domain=window.location.hostname,e.apiUrl=t,e.xfIp="",e.urlCount=0,e.cacheCount=0,e.failCount=0,e.maxSpeed=0,e.minSpeed=1/0,e.avgSpeed=0,e.totalSize=0,e.failMessage=new Set,e.device=_(),e.browser=I(),e},Ge=t=>{let e={},n=E.getInfo();return e.server=n.serverId?n.serverId:"",e.domain=window.location.hostname,e.apiUrl=t,e.xfIp="",e.urlCount=0,e.cacheCount=0,e.failCount=0,e.maxSpeed=0,e.minSpeed=1/0,e.avgSpeed=0,e.totalSize=0,e.failMessage=new Set,e.device=_(),e.browser=I(),e},Wt=(t,e,n)=>{let o={};o.router="apiTestInfo",o.data={};let s={},r=E.getInfo();s.server=r.serverId?r.serverId:"",s.domain=window.location.hostname,s.apiUrl=window.location.hostname+"/"+t,s.xfIp=t,s.urlCount=1,s.cacheCount=0,s.failCount=0,s.maxSpeed=e,s.minSpeed=e,s.avgSpeed=e,s.totalSize=n||0,s.device=_(),s.browser=I(),o.data.info=[s],i.sendMsg(JSON.stringify(o))};function Rt(){return m}const l={api_map:m,api_config:h,api_taskId:Z,getApiTestInfo:Rt,setJBLConfig:jt,stop:Ft,record:Bt,recordCache:Jt,recordfail:Ut,recordbest:zt,sendData:Pe,sendWebSiteLog:Wt};var k={},V={},F=!0,Y=!0,w={},x=null,P=0,Q="",B="";const ge=()=>{k.router="hlsTestInfo",k.data={},k.data.info=[]},qe=()=>{V.router="hlsTsInfo",V.data={},V.data.info=[]},Pt=t=>{let e=document.createElement("video");if(e.muted=!0,!Hls.isSupported())return console.log("Your Browser does not support MediaSourceExtension / MP4 mediasource"),!1;let n=0,o=0,s=!1,r=new Hls;return r.loadSource(t),r.autoLevelCapping=0,r.attachMedia(e),r.on(Hls.Events.MEDIA_ATTACHED,(a,u)=>{e.play()}),r.on(Hls.Events.FRAG_BUFFERED,function(a,u){try{n+=u.stats.loading.end-u.stats.loading.start,o++}catch(g){console.error(g)}}),r.on(Hls.Events.ERROR,(a,u)=>{s=!0}),new Promise(a=>{setTimeout(()=>{let u=Number(n/o).toFixed(2),g={url:t,error_status:s,ms:u};r.destroy(),a(g)},6e3)})},At=(t,e)=>{t==null||t==null||(x!=null&&clearInterval(x),w.timeout!=null&&(x=setInterval(()=>{F=!0,Y=!0},w.timeout)),Q!=e&&(Q=e,B=""),F=!0,Y=!0,t.on("hlsFragLoading",Xe),t.on("hlsLevelUpdated",Ze),t.on("hlsError",Ke),t.on("hlsFragBuffered",Ve))},Ke=(t,e)=>{if(!F)return;F=!1;let n={};n.domain=B==""?S(e.context.url):B,n.channelName=Q,n.msTime=.1,n.speed=0,n.size=0,n.urlCount=1,n.totalSize=P.toFixed(3),n.device=_(),n.browser=I(),ge(),k.data.info.push(n),me(JSON.stringify(k))},Xe=(t,e)=>{let n=S(e.frag.url);n!=B&&B!=""&&Ye(B),B=n},Ze=(t,e)=>{let n=e.details.fragments[e.details.fragments.length-1],o=n.baseurl,s=Et(o),r=n.relurl.split("?")[0],a={m3u8url:s,relurl:r};Y&&(Y=!1,qe(),V.data.info.push(a),Qe(JSON.stringify(V)))},Ve=(t,e)=>{P+=e.stats.total/1024;try{let n;e.stats.tbuffered?n=e.stats.tbuffered-e.stats.trequest:n=e.stats.loading.end-e.stats.loading.start;let o=Math.round(8*e.stats.total/n),s=e.frag.duration*1e3/n,r=(o/1e3).toFixed(2),a={};if(a.domain=S(e.frag.url),a.channelName=Q,a.speed=r,a.size=(e.stats.total/1024).toFixed(3),a.totalSize=P.toFixed(3),a.msTime=s.toFixed(3),a.urlCount=0,a.device=_(),a.browser=I(),!F)return;F=!1,ge(),k.data.info.push(a),me(JSON.stringify(k))}catch(n){console.log(n)}},Ye=t=>{let e={};e.domain=t,e.channelName=Q,e.msTime=.1,e.speed=0,e.size=0,e.urlCount=1,e.totalSize=P.toFixed(3),ge(),k.data.info.push(e),me(JSON.stringify(k))},me=t=>{if(!w.enable||w.enable!=1){console.log("hlsTest is disabled"),P=0;return}i.sendMsg(t)&&(P=0)},Qe=t=>{if(!w.enable||w.enable!=1){console.log("hlsTs is disabled");return}i.sendMsg(t)},pe={init:ge,ts_init:qe,createHls:Pt,testSpeedToHlsjs:At,listenError:Ke,listenUrl:Xe,listenM3U8:Ze,speedTest:Ve,sendPunishment:Ye,sendData:me,sendTsData:Qe,setJBLConfig:t=>{w.enable=t.hlsTest_enable,w.timeout=t.hlsTest_timeout,x!=null&&clearInterval(x),w.timeout!=null&&(x=setInterval(()=>{F=!0,Y=!0},w.timeout))},stop:()=>{w.enable=0,b(x)&&(clearInterval(x),x=null)}};var N={},D={},ee="",$={},he=!1,J=null,ve=0,Gt=0,te=0,ne=0,U=0,ke=0,A="";const xe=()=>{N.router="flvTestInfo",N.data={},N.data.info=[],te=0,ne=0},qt=(t,e)=>{t==null||t==null||(J!=null&&clearInterval(J),$.timeout!=null&&(J=setInterval(()=>{he=!0},$.timeout)),ee!=e&&(ee=e,A=""),xe(),U=0,D=t,D.on("statistics_info",tt))},et=t=>{let e=S(t.url);e!=A&&A!=""&&nt(A),A=e},tt=t=>{et(t);let e=0;if(D.buffered.length>0){let o=0;D.buffered.end(0)>=ve&&(o=D.buffered.end(0)-ve),o!=0&&(te+=o,ne++),ve=D.buffered.end(0)}let n=D._transmuxer._controller._ioctl._currentRange.to/1024;if(ke=n-U,te!=0&&ne!=0&&(e=te/ne),!$.enable||$.enable!=1){console.log("flvTest is disabled");return}if(he&&!(t.speed==null||t.speed==0))try{let o=(t.speed/1024*8).toFixed(1),s={};s.domain=S(t.url),s.speed=o,U==0?s.totalSize=n:s.totalSize=n-U,U=n,s.msTime=e.toFixed(3),s.channelName=ee,s.device=_(),s.browser=I(),he=!1,xe(),N.data.info.push(s),Ce(JSON.stringify(N))}catch(o){console.log(o)}},nt=t=>{let e={};e.domain=t,e.channelName=ee,e.msTime=.1,e.speed=0,e.size=0,e.urlCount=1,e.totalSize=ke.toFixed(3),e.device=_(),e.browser=I(),xe(),U=0,N.data.info.push(e),Ce(JSON.stringify(N))},Ce=t=>{i.sendMsg(t)},Le={flvSpeedInfo:N,flvPlayer:D,channelName:ee,config:$,flag:he,taskId:J,oldBuffer:ve,oldDroppedFrames:Gt,totalDuration:te,count:ne,totalSize:U,change_size:ke,uUrl:A,testSpeedToFlvjs:qt,listenUrl:et,speedTest:tt,sendPunishment:nt,sendData:Ce,setJBLConfig:t=>{$.enable=t.hlsTest_enable,$.timeout=t.hlsTest_timeout},stop:()=>{$.enable=0,b(J)&&(clearInterval(J),J=null)}};var H={},c={},oe="",T={},be=!1,z=null,we=0,C={url:"",channelName:"",buffered:0,oldBuffer:0,newBuffer:0},ot=0,Kt=0,Se=0,Ee=0,O=0,Te=0,W="";const ye=()=>{H.router="flvTestInfo",H.data={},H.data.info=[],Se=0,Ee=0},Xt=(t,e)=>{t==null||t==null||(z!=null&&clearInterval(z),T.timeout!=null&&(z=setInterval(()=>{be=!0},T.timeout)),oe!=e&&(oe=e,W=""),ye(),C={url:"",channelName:e,buffered:0,oldBuffer:0,newBuffer:0},Te=O,O=0,ot=performance.now(),c=t,c.on("Exception",n=>{C.buffered=-1,_e(W)}),c.on("error",n=>{C.buffered=-1,_e(W)}),c.on("loading_complete",()=>{const o=performance.now()-ot;let s=S(c._mediaDataSource.url);s=Nt(s),l.sendWebSiteLog("s_"+s,o,0)}),c.on("metadata_arrived",n=>{performance.now()}),c.on("media_info",n=>{c._transmuxer!=null&&c._transmuxer.on("media_segment",(o,s)=>{let r=s.data.byteLength;O+=r}),c._decompressor!=null&&c._decompressor.on("media_segment",(o,s)=>{let r=s.transfer.reduce((a,u)=>a+u.byteLength,0);O+=r})}),c.on("statistics_info",Vt))},Zt=t=>{let e=S(t.url);C.url=e,e!=W&&W!=""&&_e(W),W=e},Vt=t=>{if(Zt(t),c.buffered.length>0){let e=0;c.buffered.end(0)>=we&&(e=c.buffered.end(0)-we),Se+=e,Ee++,C.buffered=c.buffered.end(0)-c.currentTime,C.newBuffer=e,C.oldBuffer=c.buffered.end(0),we=c.buffered.end(0)}if(!T.enable||T.enable!=1){ye(),O=0,Te=0,console.log("mpegTest is disabled");return}if(be&&!(t.speed==null||t.speed==0))try{let e=O/(T.timeout/1e3),n=Se/(T.timeout/1e3),o={};o.domain=S(t.url),o.speed=e,o.totalSize=(O/1024).toFixed(3),O=0,o.msTime=n.toFixed(3),o.channelName=oe,o.device=_(),o.browser=I(),be=!1,ye(),H.data.info.push(o),Ne(JSON.stringify(H))}catch(e){console.log(e)}},Yt=()=>C,_e=(t,e)=>{let n={};n.domain=S(t),n.channelName=oe,n.msTime=.1,n.speed=0,n.size=0,n.urlCount=1,n.errCode=e||0,n.device=_(),n.browser=I(),n.totalSize=(Te/1024).toFixed(3),n.loaderTime=0,ye(),Te=0,H.data.info.push(n),Ne(JSON.stringify(H))},Ne=t=>{i.sendMsg(t)},se={mpegSpeedInfo:H,mpegPlayer:c,channelName:oe,config:T,flag:be,taskId:z,oldBuffer:we,bufferInfo:C,oldDroppedFrames:Kt,totalDuration:Se,count:Ee,testSpeedTompegjs:Xt,getBuffer:Yt,sendPunishment:_e,sendData:Ne,showLog:(t,e,n)=>{console.info("flag: ",n),console.info("Url: ",t.url),console.info("SeepData: ",e)},setJBLConfig:t=>{T.enable=t.hlsTest_enable,T.timeout=t.hlsTest_timeout},stop:()=>{T.enable=0,b(z)&&(clearInterval(z),z=null)}};var R=null,G=0,De={};const Qt=t=>{De=t,G=0};function en(){b(R)&&(clearInterval(R),R=null);let t={};t.router="heartbeat",t.data={key:i.getJblClientId().key};let e=JSON.stringify(t);i.getWebSocket().send(e),R=setInterval(()=>{try{if(G+=1,i.getWebSocket()===null){G=0,i.createWebSocket(i.getProject(),i.getChannel(),i.getSubproject());return}if(G>=3){G=0,b(i.getWebSocket())&&i.getWebSocket().close(),i.setWebSocket(null);return}b(i.getWebSocket())&&i.getWebSocket().readyState===WebSocket.OPEN&&(t.router="heartbeat",t.data={key:i.getJblClientId().key},e=JSON.stringify(t),i.getWebSocket().send(e))}catch{}},De.heartbeat_timeout)}function tn(){b(R)&&(clearInterval(R),R=null)}function nn(t){G=t}const Ie={config:De,setCount:nn,setConfig:Qt,start:en,close:tn};var st="",re={};const on=t=>{st=t,rt()},sn=t=>{t.monitor_check!=null&&t.monitor_check!==""&&(re.monitor_check=t.monitor_check),re.xhr_test_timeout=isNaN(Number(t.xhr_test_timeout))?1e3:t.xhr_test_timeout},rt=()=>{const t=new XMLHttpRequest;let e=st+"?t="+new Date().getTime();t.open("GET",e,!0),t.timeout=re.xhr_test_timeout,t.jbl_base_test=!1;const n={timeout:re.xhr_test_timeout};for(const o in n.headers)n.headers.hasOwnProperty(o)&&t.setRequestHeader(o,n.headers[o]);t.onreadystatechange=function(){if(t.readyState===4){t.getResponseHeader("Content-Type");const o=t.responseText,s=re.monitor_check;if(s&&!o.includes(s)){let r={url:e,name:"Response mismatch",statusText:o};l.recordbest(e,r,"")}}},t.send()},at={setConfig:sn,receive:on,run:rt};var q={result:{}},ae=[];const it=(t,e,n)=>{let o={};o.type=t,o.group=e,o.lines=n;let s={};s.router="getGroupResult",s.data=o;let r=i.getWebSocket();r!=null&&(r.readyState===WebSocket.OPEN?(i.sendMsg(JSON.stringify(s)),ae.filter(u=>u.type==t&&u.group==e).length==0&&ae.push(o)):r.addEventListener("open",function(a){i.sendMsg(JSON.stringify(s)),ae.filter(g=>g.type==t&&g.group==e).length==0&&ae.push(o)}))},K={groupResultObj:q,setGroupInfo:it,resetGroupDataLine:async()=>{ae.forEach(async t=>{it(t.type,t.group,t.lines)})},getGroupData:async(t,e,n)=>{let o=i.getProject(),s={};s.project=o,s.type=e,s.group=n;let r=localStorage.getItem("group_best_line"),a=JSON.parse(r);if(a!=null&&new Date().getTime()-a.time<6e4)return q.result=a.result,q;let u=new URL(Ot),g={};try{let y=800,X=new AbortController,f=X.signal;const v=setTimeout(()=>X.abort(),y);Object.keys(s).forEach(Lt=>u.searchParams.append(Lt,s[Lt]));let le=u.href,ue=await fetch(le,{signal:f});clearTimeout(v);let M=await ue.json();g[M.name]=M.value,Be("group_best_line",q),q.result[e+"_"+n]=M.value==null?"":M.value}catch{q.result[e+"_"+n]=""}}};var p=null,$e="",He="",lt="",ut=!1,Oe={},Me={key:""};const rn=t=>{lt=t.socketUrl,t.webSocket},an=()=>Me,ln=()=>p,un=t=>{p=t},dn=()=>$e,cn=()=>He,fn=()=>Oe,dt=t=>{let e={};e.router="getHlsConfigSetting",e.data={...t};const n=Intl.DateTimeFormat().resolvedOptions().timeZone,o=navigator.language||navigator.userLanguage;typeof t=="object"&&t!==null?e.data={...t}:e.data={},e.data.domain=window.location.hostname,e.data.zone=n,e.data.lang=o,je(JSON.stringify(e));let s={};s.router="getResourceUrl",s.data={},s.data.chname=He,je(JSON.stringify(s))},gn=async(t,e,n)=>{$e=t,He=e;let o=lt+$e;if(console.log("JBL Version:v20250627-1 "+o),b(p))return console.log("jbl connection exists, do nothing"),null;if("WebSocket"in window)p=new WebSocket(o);else return console.log("jbl webSocket is not supported"),null;return p.onerror=()=>(console.warn("jbl webSocket error"),b(p)&&p.close(),null),p.onopen=()=>(console.log("jbl webSocket connected"),dt(n),K.resetGroupDataLine(),null),p.onmessage=s=>{Ie.setCount(0);var r=JSON.parse(s.data);switch(r.router){case"heartbeat":Me={time:new Date().getTime(),key:r.data};break;case"getResourceUrl":Oe.result=r.data;break;case"getDomainSetting":at.receive(r.data);break;case"getHealthStream":L.getHealthFun(r.data),l.stop();break;case"getGroupResult":K.groupResultObj.result[r.data.name]=r.data.value,Be("group_best_line",K.groupResultObj);break;case"getHlsConfigSetting":let a=r.data;l.setJBLConfig(a),E.setConfig(a),Ie.setConfig(a),Ie.start(),at.setConfig(a),pe.setJBLConfig(a),Le.setJBLConfig(a),se.setJBLConfig(a);break}},p.onclose=()=>(l.stop(),pe.stop(),Le.stop(),se.stop(),console.log("jbl webSocket closed"),b(p)&&p.close(),Me=null,p=null,ut||E.restart(),null),window.onbeforeunload=()=>{try{ut=!0,E.stop(),Ie.close(),p.close()}catch{}},p},je=t=>b(p)?(p.send(t),!0):(console.log("webSocket doesn't exist, do nothing"),!1),i={resourceUrlObj:Oe,getJblClientId:an,getResourceUrlObj:fn,getWebSocket:ln,setWebSocket:un,getProject:dn,getChannel:cn,getConfigData:dt,sendMsg:je,createWebSocket:gn,setSocketConfig:rn};function mn(){var t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(){t.apply(this,arguments);let e=new Date().getTime(),n=arguments[1];this.addEventListener("progress",function(r){this.prvdownloaded=r.loaded}),this.addEventListener("load",function(){let r="";if(this.jbl_base_test&&(r=this.getResponseHeader("Server")),this.status>=200&&this.status<300){let a=new Date().getTime()-e;this.prvdownloaded==null?this.prvdownloaded=0:this.prvdownloaded,l.record(n,a,this.prvdownloaded,r)}else if(this.status>=400&&this.status<500){let a={status:this.status,statusText:this.statusText};l.recordfail(n,a,"")}else if(this.status>=500){let a={status:this.status,statusText:this.statusText};l.recordfail(n,a,"")}});const o=function(){let r={name:"Network Error",status:"5xx",statusText:"Network Error"};l.recordfail(n,r,"")},s=function(){let r={name:"Timeout",status:"0",statusText:"Timeout"};l.recordfail(n,r,"")};this.addEventListener("error",o),this.addEventListener("timeout",s)}}function pn(t,e){t.fetch=function(){let n=new Date().getTime(),o=arguments[0].url==null?arguments[0]:arguments[0].url,s=arguments[1]==null?{}:arguments[1],r=e.apply(this,arguments),a=o==null?void 0:o.split("?")[0],u=a==null?void 0:a.split("/"),g=u==null?void 0:u.pop();return s.signal&&g&&g.indexOf(".flv")!=-1?r:new Promise((y,X)=>{r.then(f=>{if(f.ok){let v=f.clone(),le=v.headers.get("Server")==null?"":v.headers.get("Server");v.arrayBuffer().then(ue=>{let M=new Date().getTime()-n;f.status==200&&l.record(o,M,ue.byteLength,le)})}else{let v=f.headers.get("Server");l.recordfail(o,f,v)}return y(f)}).catch(f=>{if(f.response){let v={};f.response.headers.forEach((ue,M)=>{v[M]=ue});let le={name:f.name,status:f.response.status,statusText:f.response.statusText};l.recordfail(o,le,v.Server)}else{let v={name:f.name,status:"5xx",statusText:f.message||"Failed to fetch"};l.recordfail(o,v,"")}return X(f)})})}}function hn(){window.addEventListener("load",()=>{var t=performance.getEntriesByType("resource");t.forEach(function(e){let n=e.responseStatus;if(n>=200&&n<=299)e.transferSize===0&&e.encodedBodySize===0&&e.decodedBodySize===0?l.recordCache(e.name,""):l.record(e.name,e.duration.toFixed(4),e.transferSize,"");else if(n>=400&&n<=599){let o={name:"window load Error",status:n,statusText:"window load Error"};l.recordfail(e.name,o)}else e.transferSize===0&&e.encodedBodySize===0&&e.decodedBodySize===0?l.recordCache(e.name,""):l.record(e.name,e.duration.toFixed(4),e.transferSize,"")})})}function vn(){window.addEventListener("error",t=>{console.log("jbl window error:",t)})}function bn(){const t=window.open;window.open=function(e,n,o){console.log("window.open called with URL:",e);const s=t.apply(this,arguments);let r=new Date().getTime();if(s)s.onload=function(){var u=new Date().getTime()-r;l.record(e,u.toFixed(4),0)},s.onerror=function(){console.error("Error loading new window:",e);let a={name:"New window Error",status:"5xx",statusText:"New window Error"};l.recordfail(e,a,"")};else{console.error("Failed to open new window:",e);let a={name:"New window Error",status:"5xx",statusText:"Failed to open new window"};l.recordfail(e,a,"")}return s}}function wn(){window.addEventListener("beforeunload",()=>{l.sendData()})}function ct(t){t.startTime=new Date().getTime(),t.count=0,t.onload=function(){var e=new Date().getTime(),n=e-t.startTime;t.count==0&&l.record(t.src,n,0,""),t.count++},t.onerror=function(){let e={name:"iframe Error",status:"5xx",statusText:"iframe Error"};l.recordfail(t.src,e,"")}}function ft(t){t.addEventListener("click",e=>{e.target.href!=null?l.record(e.target.href,0,0,""):l.record(e.currentTarget.href,0,0,"")})}function Sn(){document.addEventListener("DOMContentLoaded",function(){var t=document.getElementsByTagName("iframe");document.querySelectorAll("a").forEach(s=>{ft(s)});for(var n=0;n{console.error("Window error:",t);let e={name:"Window Error",status:"5xx",statusText:t.message||"Window Error"};l.recordfail("",e,"")}),window.addEventListener("unhandledrejection",t=>{console.error("Unhandled rejection:",t.reason);let e={name:"Unhandled Rejection",status:"5xx",statusText:t.reason.message||"Unhandled Rejection"};l.recordfail("",e,"")})}const ie={load:hn,error:vn,beforeunload:wn,open:bn,contentLoaded:Sn,windowError:Tn},yn={getLocating:async(t=[1])=>{Array.isArray(t)||(t=[t]);let e=[!1,!1,!1],n={match:"NOT UK",ip:"",loc:""};const o=Intl.DateTimeFormat().resolvedOptions().timeZone,s=navigator.language||navigator.userLanguage;["Europe/London","Europe/Belfast","Europe/Guernsey","Europe/Isle_of_Man","Europe/Jersey"].includes(o)&&(e[0]=!0),s.includes("GB")&&(e[1]=!0);const a="https://"+window.location.hostname+"/cdn-cgi/trace";return await fetch(a).then(g=>g.text()).then(g=>{const y={};g.split(` `).forEach(X=>{const[f,v]=X.split("=");f&&v&&(y[f.trim()]=v.trim())}),n.ip=y.ip||"",n.loc=y.loc||"",y.loc&&y.loc.trim()==="GB"&&(e[2]=!0)}).catch(g=>{console.warn("GET IP Data Fail:",g)}),t.every(g=>e[g-1])&&(n.match="UK"),n}},_n=XMLHttpRequest.prototype.open;if(typeof window<"u")try{mn(_n),pn(window,window.fetch),ie.load(),ie.error(),ie.open(),ie.beforeunload(),ie.contentLoaded()}catch(t){console.warn("modifyFetch patch failed:",t)}var Fe="";i.setSocketConfig({socketUrl:Dt,webSocket:null});const gt=(t,e,n)=>{Fe=t,i.createWebSocket(Fe,e,n)},mt=async(t,e)=>{L.setHealthFun(e),await i.createWebSocket(t,"",{}),L.sendHealthStream()},pt=(t,e,n,o,s)=>{E.upsert(t,e,n,o,s)},ht=()=>{E.remove()},vt=(t,e,n)=>{l.sendWebSiteLog(t,e,n)},bt=(t,e,n)=>{K.setGroupInfo(t,e,n)},wt=async(t,e)=>(await K.getGroupData(Fe,t,e),K.groupResultObj),St=(t,e)=>{pe.testSpeedToHlsjs(t,e)},Tt=t=>pe.createHls(t),yt=(t,e)=>{Le.testSpeedToFlvjs(t,e)},_t=(t,e)=>{se.testSpeedTompegjs(t,e)},It=(t,e)=>{se.sendPunishment(t,e)},kt=()=>se.getBuffer(),xt=()=>i.resourceUrlObj,Ct=t=>S(t),In={connect:gt,getHealthStream:mt,upsert:pt,remove:ht,sendWebLog:vt,testLine:bt,getGroupResult:wt,testHls:St,testSpeedHls:Tt,testFlv:yt,testMpeg:_t,sendMpegErrCode:It,getMpegBuffer:kt,getResourceUrl:xt,extractHostname:Ct,getLocating:yn.getLocating};d.connect=gt,d.default=In,d.extractHostname=Ct,d.getGroupResult=wt,d.getHealthStream=mt,d.getMpegBuffer=kt,d.getResourceUrl=xt,d.remove=ht,d.sendMpegErrCode=It,d.sendWebLog=vt,d.testFlv=yt,d.testHls=St,d.testLine=bt,d.testMpeg=_t,d.testSpeedHls=Tt,d.upsert=pt,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});