// Version: 20250729 (function(f,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(f=typeof globalThis<"u"?globalThis:f||self,j(f.JBLWebSocket={}))})(this,function(f){"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",T=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},Ht=t=>{var e;return e=t.split(".m3u8")[0],e},ze=(t,e)=>{e.time=new Date().getTime();let n=JSON.stringify(e);localStorage.setItem(t,n)},Mt=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},We="wss://web.analysiscloud.info/m1uudG5uIU/?project=",jt="https://web.analysiscloud.info/ccu/m1uudG5uIU/config",Ft="https://web.analysiscloud.info/ccu/m1uudG5uIU/upsert",Bt="https://web.analysiscloud.info/ccu/m1uudG5uIU/get";var ce=null,fe={},ge=null;const Re=t=>{ce=t,Ge(window.location.hostname,"x",navigator.appVersion,"",""),Pe()},Jt=()=>fetch(jt).then(t=>t.json()).then(t=>{Re(t)}).catch(t=>console.error(t)),Pe=()=>{if(Ae(),ce.streamTest_enable!=1){console.log("streamTest is disabled");return}ge=setInterval(()=>{try{let t=fe;if(t.uid)fetch(Ft,{method:"POST",body:JSON.stringify(t)}).catch(e=>console.error(e));else return}catch{}},ce.streamTest_interval*6e4)},Ae=()=>{b(ge)&&(clearInterval(ge),ge=null)},Ge=(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(),fe=r},E={ccu_config:ce,getInfo:()=>fe,setConfig:Re,restart:Jt,start:Pe,stop:Ae,upsert:Ge,remove:()=>{let t={};t.updateTime=new Date().getTime(),fe=t}};var m={},h={},X=null;const Ut=t=>(qe(),h.enable=t.apiTest_enable,h.timeout=t.apiTest_timeout,!h.enable||h.enable!=1||!h.timeout?(console.log("apiTest is disabled"),!1):(X=setInterval(()=>{Ke()},h.timeout),!0)),zt=()=>{h.enable=0,m={},qe()},qe=()=>{b(X)&&(clearInterval(X),X=null)},Wt=(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]=Ze(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]=Ze(n));let o=m[n];o.server="cache",o.cacheCount++},Pt=(t,e,n)=>{if(h.enable&&h.enable!=1||L.getHealthCallbakfun()!=null)return;let o=t.split("?")[0];m[o]||(m[o]=Xe(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++},At=(t,e,n)=>{if(h.enable&&h.enable!=1||L.getHealthCallbakfun()!=null)return;let o=t.split("?")[0];m[o]||(m[o]=Xe(o));let s=m[o];if(s.server=n,e!=null){let r="5xx@@@"+e.name+"@@@"+e.statusText;s.failMessage.add(r)}},Ke=()=>{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},Xe=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},Gt=(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 qt(){return m}const l={api_map:m,api_config:h,api_taskId:X,getApiTestInfo:qt,setJBLConfig:Ut,stop:zt,record:Wt,recordCache:Rt,recordfail:Pt,recordbest:At,sendData:Ke,sendWebSiteLog:Gt};var k={},V={},F=!0,Y=!0,w={},C=null,P=0,Q="",B="";const me=()=>{k.router="hlsTestInfo",k.data={},k.data.info=[]},Ve=()=>{V.router="hlsTsInfo",V.data={},V.data.info=[]},Kt=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(c){console.error(c)}}),r.on(Hls.Events.ERROR,(a,u)=>{s=!0}),new Promise(a=>{setTimeout(()=>{let u=Number(n/o).toFixed(2),c={url:t,error_status:s,ms:u};r.destroy(),a(c)},6e3)})},Zt=(t,e)=>{t==null||t==null||(C!=null&&clearInterval(C),w.timeout!=null&&(C=setInterval(()=>{F=!0,Y=!0},w.timeout)),Q!=e&&(Q=e,B=""),F=!0,Y=!0,t.on("hlsFragLoading",Qe),t.on("hlsLevelUpdated",et),t.on("hlsError",Ye),t.on("hlsFragBuffered",tt))},Ye=(t,e)=>{if(!F)return;F=!1;let n={};n.domain=B==""?T(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(),me(),k.data.info.push(n),pe(JSON.stringify(k))},Qe=(t,e)=>{let n=T(e.frag.url);n!=B&&B!=""&&nt(B),B=n},et=(t,e)=>{let n=e.details.fragments[e.details.fragments.length-1],o=n.baseurl,s=Ht(o),r=n.relurl.split("?")[0],a={m3u8url:s,relurl:r};Y&&(Y=!1,Ve(),V.data.info.push(a),ot(JSON.stringify(V)))},tt=(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=T(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,me(),k.data.info.push(a),pe(JSON.stringify(k))}catch(n){console.log(n)}},nt=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),me(),k.data.info.push(e),pe(JSON.stringify(k))},pe=t=>{if(!w.enable||w.enable!=1){console.log("hlsTest is disabled"),P=0;return}i.sendMsg(t)&&(P=0)},ot=t=>{if(!w.enable||w.enable!=1){console.log("hlsTs is disabled");return}i.sendMsg(t)},he={init:me,ts_init:Ve,createHls:Kt,testSpeedToHlsjs:Zt,listenError:Ye,listenUrl:Qe,listenM3U8:et,speedTest:tt,sendPunishment:nt,sendData:pe,sendTsData:ot,setJBLConfig:t=>{w.enable=t.hlsTest_enable,w.timeout=t.hlsTest_timeout,C!=null&&clearInterval(C),w.timeout!=null&&(C=setInterval(()=>{F=!0,Y=!0},w.timeout))},stop:()=>{w.enable=0,b(C)&&(clearInterval(C),C=null)}};var N={},D={},ee="",$={},ve=!1,J=null,be=0,Xt=0,te=0,ne=0,U=0,Le=0,A="";const Ee=()=>{N.router="flvTestInfo",N.data={},N.data.info=[],te=0,ne=0},Vt=(t,e)=>{t==null||t==null||(J!=null&&clearInterval(J),$.timeout!=null&&(J=setInterval(()=>{ve=!0},$.timeout)),ee!=e&&(ee=e,A=""),Ee(),U=0,D=t,D.on("statistics_info",rt))},st=t=>{let e=T(t.url);e!=A&&A!=""&&at(A),A=e},rt=t=>{st(t);let e=0;if(D.buffered.length>0){let o=0;D.buffered.end(0)>=be&&(o=D.buffered.end(0)-be),o!=0&&(te+=o,ne++),be=D.buffered.end(0)}let n=D._transmuxer._controller._ioctl._currentRange.to/1024;if(Le=n-U,te!=0&&ne!=0&&(e=te/ne),!$.enable||$.enable!=1){console.log("flvTest is disabled");return}if(ve&&!(t.speed==null||t.speed==0))try{let o=(t.speed/1024*8).toFixed(1),s={};s.domain=T(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(),ve=!1,Ee(),N.data.info.push(s),Ne(JSON.stringify(N))}catch(o){console.log(o)}},at=t=>{let e={};e.domain=t,e.channelName=ee,e.msTime=.1,e.speed=0,e.size=0,e.urlCount=1,e.totalSize=Le.toFixed(3),e.device=_(),e.browser=I(),Ee(),U=0,N.data.info.push(e),Ne(JSON.stringify(N))},Ne=t=>{i.sendMsg(t)},De={flvSpeedInfo:N,flvPlayer:D,channelName:ee,config:$,flag:ve,taskId:J,oldBuffer:be,oldDroppedFrames:Xt,totalDuration:te,count:ne,totalSize:U,change_size:Le,uUrl:A,testSpeedToFlvjs:Vt,listenUrl:st,speedTest:rt,sendPunishment:at,sendData:Ne,setJBLConfig:t=>{$.enable=t.hlsTest_enable,$.timeout=t.hlsTest_timeout},stop:()=>{$.enable=0,b(J)&&(clearInterval(J),J=null)}};var O={},d={},oe="",y={},Se=!1,z=null,we=0,x={url:"",channelName:"",buffered:0,oldBuffer:0,newBuffer:0},it=0,Yt=0,Te=0,$e=0,H=0;let ye=0;var _e=0,W="";const Ie=()=>{O.router="flvTestInfo",O.data={},O.data.info=[],Te=0,$e=0},Qt=(t,e)=>{t==null||t==null||(z!=null&&clearInterval(z),y.timeout!=null&&(z=setInterval(()=>{Se=!0},y.timeout)),oe!=e&&(oe=e,W=""),Ie(),x={url:"",channelName:e,buffered:0,oldBuffer:0,newBuffer:0},_e=H,H=0,ye=0,it=performance.now(),d=t,d.on("Exception",n=>{x.buffered=-1,ke(W)}),d.on("error",n=>{x.buffered=-1,ke(W)}),d.on("loading_complete",()=>{const o=performance.now()-it;let s=d._mediaDataSource?d._mediaDataSource:d._player_engine._media_data_source,r=T(s.url);r=Mt(r),l.sendWebSiteLog("s_"+r,o,0)}),d.on("metadata_arrived",n=>{performance.now()}),d.on("media_info",n=>{let o=d._transmuxer?d._transmuxer:d._player_engine._transmuxer;o!=null&&o.on("media_segment",(r,a)=>{const u=a.data.byteLength,c=u-ye;ye=u,c>0&&(H+=c)});let s=d._decompressor?d._decompressor:d._player_engine._decompressor;s!=null&&s.on("media_segment",(r,a)=>{let u=a.transfer.reduce((c,S)=>c+S.byteLength,0);H+=u})}),d.on("statistics_info",tn))},en=t=>{let e=T(t.url);x.url=e,e!=W&&W!=""&&ke(W),W=e},tn=t=>{if(en(t),d.buffered.length>0){let e=0;d.buffered.end(0)>=we&&(e=d.buffered.end(0)-we),Te+=e,$e++,x.buffered=d.buffered.end(0)-d.currentTime,x.newBuffer=e,x.oldBuffer=d.buffered.end(0),we=d.buffered.end(0)}if(!y.enable||y.enable!=1){Ie(),H=0,_e=0,console.log("mpegTest is disabled");return}if(Se&&!(t.speed==null||t.speed==0))try{let e=H/(y.timeout/1e3),n=Te/(y.timeout/1e3),o={};o.domain=T(t.url),o.speed=e,o.totalSize=(H/1024).toFixed(3),H=0,ye=0,o.msTime=n.toFixed(3),o.channelName=oe,o.device=_(),o.browser=I(),Se=!1,Ie(),O.data.info.push(o),Oe(JSON.stringify(O))}catch(e){console.log(e)}},nn=()=>x,ke=(t,e)=>{let n={};n.domain=T(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=(_e/1024).toFixed(3),n.loaderTime=0,Ie(),_e=0,O.data.info.push(n),Oe(JSON.stringify(O))},Oe=t=>{i.sendMsg(t)},se={mpegSpeedInfo:O,mpegPlayer:d,channelName:oe,config:y,flag:Se,taskId:z,oldBuffer:we,bufferInfo:x,oldDroppedFrames:Yt,totalDuration:Te,count:$e,testSpeedToMpegjs:Qt,getBuffer:nn,sendPunishment:ke,sendData:Oe,showLog:(t,e,n)=>{console.info("flag: ",n),console.info("Url: ",t.url),console.info("SeepData: ",e)},setJBLConfig:t=>{y.enable=t.hlsTest_enable,y.timeout=t.hlsTest_timeout},stop:()=>{y.enable=0,b(z)&&(clearInterval(z),z=null)}};var R=null,G=0,He={};const on=t=>{He=t,G=0};function sn(){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{}},He.heartbeat_timeout)}function rn(){b(R)&&(clearInterval(R),R=null)}function an(t){G=t}const Ce={config:He,setCount:an,setConfig:on,start:sn,close:rn};var lt="",re={};const ln=t=>{lt=t,ut()},un=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},ut=()=>{const t=new XMLHttpRequest;let e=lt+"?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(){let o={};if(t.readyState===4){t.getResponseHeader("Content-Type");const s=t.responseText;o.cacheControl=this.getResponseHeader("Cache-Control")||o;const r=re.monitor_check;if(r&&!s.includes(r)){let a={url:e,name:"Response mismatch",statusText:s};l.recordbest(e,a,"")}}},t.send()},dt={setConfig:un,receive:ln,run:ut};var q={result:{}},ae=[];const ct=(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(c=>c.type==t&&c.group==e).length==0&&ae.push(o)}))},K={groupResultObj:q,setGroupInfo:ct,resetGroupDataLine:async()=>{ae.forEach(async t=>{ct(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(Bt),c={};try{let S=800,Z=new AbortController,g=Z.signal;const v=setTimeout(()=>Z.abort(),S);Object.keys(s).forEach(Ot=>u.searchParams.append(Ot,s[Ot]));let ue=u.href,de=await fetch(ue,{signal:g});clearTimeout(v);let M=await de.json();c[M.name]=M.value,ze("group_best_line",q),q.result[e+"_"+n]=M.value==null?"":M.value}catch{q.result[e+"_"+n]=""}}};var p=null,Me="",je="",ft="",gt=!1,Fe={},Be={key:""};const dn=t=>{ft=t.socketUrl,t.webSocket},cn=()=>Be,fn=()=>p,gn=t=>{p=t},mn=()=>Me,pn=()=>je,hn=()=>Fe,mt=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=je,Je(JSON.stringify(s))},vn=async(t,e,n)=>{Me=t,je=e;let o=ft+Me;if(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"),mt(n),K.resetGroupDataLine(),null),p.onmessage=s=>{Ce.setCount(0);var r=JSON.parse(s.data);switch(r.router){case"heartbeat":Be={time:new Date().getTime(),key:r.data};break;case"getResourceUrl":Fe.result=r.data;break;case"getDomainSetting":dt.receive(r.data);break;case"getHealthStream":L.getHealthFun(r.data),l.stop();break;case"getGroupResult":K.groupResultObj.result[r.data.name]=r.data.value,ze("group_best_line",K.groupResultObj);break;case"getHlsConfigSetting":let a=r.data;l.setJBLConfig(a),E.setConfig(a),Ce.setConfig(a),Ce.start(),dt.setConfig(a),he.setJBLConfig(a),De.setJBLConfig(a),se.setJBLConfig(a);break}},p.onclose=()=>(l.stop(),he.stop(),De.stop(),se.stop(),console.log("jbl webSocket closed"),b(p)&&p.close(),Be=null,p=null,gt||E.restart(),null),window.onbeforeunload=()=>{try{gt=!0,E.stop(),Ce.close(),p.close()}catch{}},p},Je=t=>b(p)?(p.send(t),!0):(console.log("webSocket doesn't exist, do nothing"),!1),i={resourceUrlObj:Fe,getJblClientId:cn,getResourceUrlObj:hn,getWebSocket:fn,setWebSocket:gn,getProject:mn,getChannel:pn,getConfigData:mt,sendMsg:Je,createWebSocket:vn,setSocketConfig:dn};var ie={},xe=null;const bn=()=>{ie.router="userInfo",ie.data={}},Sn=t=>{let e={...t};const n=Intl.DateTimeFormat().resolvedOptions().timeZone,o=navigator.language||navigator.userLanguage;typeof t=="object"&&t!==null?e={...t}:e={},e.domain=window.location.hostname,e.zone=n,e.lang=o,bn();let s=i.getWebSocket();ie.data=e,s&&s.readyState===1?i.sendMsg(JSON.stringify(ie)):xe=JSON.stringify(ie),wn()},wn=()=>{let t=i.getWebSocket();t&&t.addEventListener("open",()=>{xe&&(i.sendMsg(xe),xe=null)})},Tn={sendData:Sn,stop};function yn(){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 _n(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("/"),c=u==null?void 0:u.pop();return s.signal&&c&&c.indexOf(".flv")!=-1?r:new Promise((S,Z)=>{r.then(g=>{if(g.ok){let v=g.clone(),ue=v.headers.get("Server")==null?"":v.headers.get("Server");v.arrayBuffer().then(de=>{let M=new Date().getTime()-n;g.status==200&&l.record(o,M,de.byteLength,ue)})}else{let v=g.headers.get("Server");l.recordfail(o,g,v)}return S(g)}).catch(g=>{if(g.response){let v={};g.response.headers.forEach((de,M)=>{v[M]=de});let ue={name:g.name,status:g.response.status,statusText:g.response.statusText};l.recordfail(o,ue,v.Server)}else{let v={name:g.name,status:"5xx",statusText:g.message||"Failed to fetch"};l.recordfail(o,v,"")}return Z(g)})})}}function In(){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 kn(){window.addEventListener("error",t=>{console.log("jbl window error:",t)})}function Cn(){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 xn(){window.addEventListener("beforeunload",()=>{l.sendData()})}function pt(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 ht(t){t.addEventListener("click",e=>{e.target.href!=null?l.record(e.target.href,0,0,""):l.record(e.currentTarget.href,0,0,"")})}function Ln(){document.addEventListener("DOMContentLoaded",function(){var t=document.getElementsByTagName("iframe");document.querySelectorAll("a").forEach(s=>{ht(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 le={load:In,error:kn,beforeunload:xn,open:Cn,contentLoaded:Ln,windowError:En},Nn={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(c=>c.text()).then(c=>{const S={};c.split(` `).forEach(Z=>{const[g,v]=Z.split("=");g&&v&&(S[g.trim()]=v.trim())}),n.ip=S.ip||"",n.loc=S.loc||"",S.loc&&S.loc.trim()==="GB"&&(e[2]=!0)}).catch(c=>{console.warn("GET IP Data Fail:",c)}),t.some(c=>e[c-1])&&(n.match="UK"),n}},Dn=XMLHttpRequest.prototype.open;if(typeof window<"u")try{yn(Dn),_n(window,window.fetch),le.load(),le.error(),le.open(),le.beforeunload(),le.contentLoaded()}catch(t){console.warn("modifyFetch patch failed:",t)}var Ue="";i.setSocketConfig({socketUrl:We,webSocket:null});const vt=(t,e,n)=>{let o=We+t;console.log("JBL Version:v20250729-1 "+o),Ue=t,i.createWebSocket(Ue,e,n)},bt=async(t,e)=>{L.setHealthFun(e),await i.createWebSocket(t,"",{}),L.sendHealthStream()},St=(t,e,n,o,s)=>{E.upsert(t,e,n,o,s)},wt=()=>{E.remove()},Tt=(t,e,n)=>{l.sendWebSiteLog(t,e,n)},yt=(t,e,n)=>{K.setGroupInfo(t,e,n)},_t=async(t,e)=>(await K.getGroupData(Ue,t,e),K.groupResultObj),It=(t,e)=>{he.testSpeedToHlsjs(t,e)},kt=t=>he.createHls(t),Ct=(t,e)=>{De.testSpeedToFlvjs(t,e)},xt=(t,e)=>{se.testSpeedToMpegjs(t,e)},Lt=(t,e)=>{se.sendPunishment(t,e)},Et=()=>se.getBuffer(),Nt=()=>i.resourceUrlObj,Dt=t=>T(t),$t=t=>Tn.sendData(t),$n={connect:vt,getHealthStream:bt,upsert:St,remove:wt,sendWebLog:Tt,testLine:yt,getGroupResult:_t,testHls:It,testSpeedHls:kt,testFlv:Ct,testMpeg:xt,sendMpegErrCode:Lt,getMpegBuffer:Et,getResourceUrl:Nt,extractHostname:Dt,sendUserInfo:$t,getLocating:Nn.getLocating};f.connect=vt,f.default=$n,f.extractHostname=Dt,f.getGroupResult=_t,f.getHealthStream=bt,f.getMpegBuffer=Et,f.getResourceUrl=Nt,f.remove=wt,f.sendMpegErrCode=Lt,f.sendUserInfo=$t,f.sendWebLog=Tt,f.testFlv=Ct,f.testHls=It,f.testLine=yt,f.testMpeg=xt,f.testSpeedHls=kt,f.upsert=St,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});