@voicenter-team/events-sdk 0.0.90 → 0.0.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,5 +15,5 @@
15
15
  `+x+lt.join(`,
16
16
  `+x)+`
17
17
  `+Pt+"}":"{"+lt.join(",")+"}":"{}";return U.pop(),jt}};p.stringify=function(w,O,C){var D,S,x,U;if(typeof O=="function"||typeof O=="object"&&O){if((U=d.call(O))==i)S=O;else if(U==y){x={};for(var N,q=0,J=O.length;J>q;N=O[q++],U=d.call(N),(U==g||U==f)&&(x[N]=1));}}if(C)if((U=d.call(C))==f){if((C-=C%1)>0)for(D="",C>10&&(C=10);D.length<C;D+=" ");}else U==g&&(D=C.length<=10?C:C.slice(0,10));return R("",(N={},N[""]=w,N),S,x,D,"",[])}}if(!r("json-parse")){var k,W,G=String.fromCharCode,H={92:"\\",34:'"',47:"/",98:"\b",116:" ",110:`
18
- `,102:"\f",114:"\r"},M=function(){throw k=W=null,SyntaxError()},Y=function(){for(var w,O,C,D,S,x=W,U=x.length;U>k;)switch(S=x.charCodeAt(k)){case 9:case 10:case 13:case 32:k++;break;case 123:case 125:case 91:case 93:case 58:case 44:return w=j?x.charAt(k):x[k],k++,w;case 34:for(w="@",k++;U>k;)if(S=x.charCodeAt(k),32>S)M();else if(S==92)switch(S=x.charCodeAt(++k)){case 92:case 34:case 47:case 98:case 116:case 110:case 102:case 114:w+=H[S],k++;break;case 117:for(O=++k,C=k+4;C>k;k++)S=x.charCodeAt(k),S>=48&&57>=S||S>=97&&102>=S||S>=65&&70>=S||M();w+=G("0x"+x.slice(O,k));break;default:M()}else{if(S==34)break;for(S=x.charCodeAt(k),O=k;S>=32&&S!=92&&S!=34;)S=x.charCodeAt(++k);w+=x.slice(O,k)}if(x.charCodeAt(k)==34)return k++,w;M();default:if(O=k,S==45&&(D=!0,S=x.charCodeAt(++k)),S>=48&&57>=S){for(S==48&&(S=x.charCodeAt(k+1),S>=48&&57>=S)&&M(),D=!1;U>k&&(S=x.charCodeAt(k),S>=48&&57>=S);k++);if(x.charCodeAt(k)==46){for(C=++k;U>C&&(S=x.charCodeAt(C),S>=48&&57>=S);C++);C==k&&M(),k=C}if(S=x.charCodeAt(k),S==101||S==69){for(S=x.charCodeAt(++k),(S==43||S==45)&&k++,C=k;U>C&&(S=x.charCodeAt(C),S>=48&&57>=S);C++);C==k&&M(),k=C}return+x.slice(O,k)}if(D&&M(),x.slice(k,k+4)=="true")return k+=4,!0;if(x.slice(k,k+5)=="false")return k+=5,!1;if(x.slice(k,k+4)=="null")return k+=4,null;M()}return"$"},gt=function(w){var O,C;if(w=="$"&&M(),typeof w=="string"){if((j?w.charAt(0):w[0])=="@")return w.slice(1);if(w=="["){for(O=[];w=Y(),w!="]";C||(C=!0))C&&(w==","?(w=Y(),w=="]"&&M()):M()),w==","&&M(),O.push(gt(w));return O}if(w=="{"){for(O={};w=Y(),w!="}";C||(C=!0))C&&(w==","?(w=Y(),w=="}"&&M()):M()),(w==","||typeof w!="string"||(j?w.charAt(0):w[0])!="@"||Y()!=":")&&M(),O[w.slice(1)]=gt(Y());return O}M()}return w},oe=function(w,O,C){var D=ie(w,O,C);D===h?delete w[O]:w[O]=D},ie=function(w,O,C){var D,S=w[O];if(typeof S=="object"&&S)if(d.call(S)==y)for(D=S.length;D--;)oe(S,D,C);else u(S,function(x){oe(S,x,C)});return C.call(w,O,S)};p.parse=function(w,O){var C,D;return k=0,W=""+w,C=gt(Y()),Y()!="$"&&M(),k=W=null,O&&d.call(O)==i?ie((D={},D[""]=C,D),"",O):C}}}})(this)},{}],48:[function(s,e){function t(n,r){var o=[];r=r||0;for(var u=r||0;u<n.length;u++)o[u-r]=n[u];return o}e.exports=t},{}]},{},[1])(1)}const rn=Object.freeze(Object.defineProperty({__proto__:null,default:sn},Symbol.toStringTag,{value:"Module"})),on=Object.assign({"./v1_3_7.js":rn}),an=/v\d+_\d+_\d+/;function cn(s){return typeof s=="function"}const Wt=Object.entries(on).reduce((s,e)=>{var r;const t=e[1].default,n=(r=e[0].match(an))==null?void 0:r[0];return cn(t)&&n&&(s[n]=t()),s},{}),Ee=s=>{if(s in Wt)return Wt[s];throw new Error(`Socket version ${s} not found`)},hn=(s,...e)=>Ee(s)(...e),ln={...Wt,getSocketVersion:Ee,makeSocketVersion:hn};var Te=(s=>(s.RINGING="Ringing",s.TALKING="Talking",s.DIALING="Dialing",s.HOLD="Hold",s))(Te||{}),Ae=(s=>(s.INCOMING="Incoming",s.OUTGOING="Outgoing",s))(Ae||{}),pt=(s=>(s.CONNECTED="connected",s.DISCONNECTED="disconnected",s.TRYING_TO_CONNECT="tryingToConnect",s))(pt||{}),Ne=(s=>(s.AUTOMATIC="Automatic",s.IVR="IVR",s))(Ne||{}),_e=(s=>(s.INCOMINC="Incoming",s.OUTGOING="Outgoing",s.SPY="Spy",s.CLICK2CALL="Click2Call",s))(_e||{}),Oe=(s=>(s.RESPONSE_FROM_API_VALID="RESPONSE_FROM_API_VALID",s.RESPONSE_FROM_API_INVALID="RESPONSE_FROM_API_INVALID",s))(Oe||{}),P=(s=>(s.ALL_DIALER_STATUS="AllDialersStatus",s.ALL_EXTENSION_STATUS="AllExtensionsStatus",s.ALL_USERS_STATUS="AllUsersStatus",s.CONNECT="connect",s.DISCONNECT="disconnect",s.CONNECT_ERROR_EVENT="connect_error",s.EXTENSION_EVENT="ExtensionEvent",s.KEEP_ALIVE="keepalive",s.KEEP_ALIVE_RESPONSE="keepaliveResponse",s.LOGIN_STATUS="loginStatus",s.LOGIN_SUCCESS="loginSuccess",s.QUEUE_EVENT="QueueEvent",s.ONLINE_STATUS_EVENT="onlineStatusEvent",s.DIALER_EVENT="DialerEvent",s.EXTENSIONS_UPDATED="ExtensionsUpdated",s))(P||{}),Yt=(s=>(s.NEWCALL="NEWCALL",s.ANSWER="ANSWER",s.HOLD="HOLD",s.UNHOLD="UNHOLD",s.HANGUP="HANGUP",s.USER_STATUS_UPDATE="userStatusUpdate",s))(Yt||{}),Le=(s=>(s.NORMAL_HANGUP="Normal hangup",s.USER_BUSY="User busy",s.CALL_REJECTED="Call Rejected",s.UNALLOCATED_NUMBER="Unallocated (unassigned) number",s.UNKNOWN="Unknown",s.NO_USER_RESPONDING="No user responding",s.USER_ALERTING="User alerting, no answer",s.ANSWERED_ELSEWHERE="Answered elsewhere",s))(Le||{}),Re=(s=>(s.ANSWER="ANSWER",s.ABANDONED="ABANDONED",s.EXIT="EXIT",s.JOIN="JOIN",s))(Re||{});class wt{static mapExtensionEvent(e){var u,h;const t=e.reason;let n,r;e.data.currentCall&&(r=this.mapExtensionCall(e,e.data.currentCall));const o=this.mapExtensionData(e,e.data);return t===Yt.HANGUP?n={...e,reason:t,data:{...o,currentCall:r?{...r,duration:r.callAnswered_UTC_CLIENT?Date.now()-r.callAnswered_UTC_CLIENT:0}:void 0,calls:(u=e.data.calls)==null?void 0:u.map(d=>{const c=this.mapExtensionCall(e,d);return{...c,duration:c.callAnswered_UTC_CLIENT?Date.now()-c.callAnswered_UTC_CLIENT:0}})}}:n={...e,data:{...o,currentCall:r,calls:(h=e.data.calls)==null?void 0:h.map(d=>this.mapExtensionCall(e,d))},reason:t},n}static mapAllExtensionStatus(e){return{...e,extensions:e.extensions.map(t=>{var n;return{...this.mapExtensionData(e,t),currentCall:t.currentCall?this.mapExtensionCall(e,t.currentCall):void 0,calls:(n=t.calls)==null?void 0:n.map(r=>this.mapExtensionCall(e,r))}})}}static mapExtensionData(e,t){return this.configureUTCForObject(t,[{key:"lastAnsweredCallEventEpoch",format:"sec"},{key:"lastCallEventEpoch",format:"sec"},{key:"lastHangupCallEpoch",format:"sec"},{key:"representativeUpdated",format:"ms"}],e.servertime,e.servertimeoffset)}static mapExtensionCall(e,t){return this.configureUTCForObject(t,[{key:"callAnswered",format:"sec"},{key:"callStarted",format:"sec"}],e.servertime,e.servertimeoffset)}static mapQueueCall(e,t){return this.configureUTCForObject(t,[{key:"JoinTimeStamp",format:"sec"},{key:"VHJoinTimeStamp",format:"sec"}],e.servertime,e.servertimeoffset)}static mapLoginStatusEvent(e){return{...e,queues:e.queues.map(t=>({...t,Calls:t.Calls.map(n=>this.mapQueueCall(e,n))}))}}static mapQueueEvent(e){return{...e,data:{...e.data,Calls:e.data.Calls.map(t=>this.mapQueueCall(e,t))}}}static assignProperty(e,t,n){e[t]=n}static configureUTCForObject(e,t,n,r){const o=(n-r*60)*1e3,u=Date.now()-o,h={};return t.forEach(d=>{const c=e[d.key],p=d.key;if(c!==0&&typeof c=="number"&&!isNaN(c)){let l=c;d.format==="ms"&&(l=Math.floor(l/1e3));const i=(l-r*60)*1e3;this.assignProperty(h,`${p}_UTC`,i),this.assignProperty(h,`${p}_UTC_CLIENT`,i+u)}else this.assignProperty(h,`${p}_UTC`,0),this.assignProperty(h,`${p}_UTC_CLIENT`,0)}),{...e,...h}}}var Qt=(s=>(s.UPDATE_MONITORED_EXTENSIONS="updateMonitoredExtensions",s.KEEP_ALIVE="keepalive",s))(Qt||{});class un{constructor(e){K(this,"io");K(this,"ioFunction");K(this,"lastEventTimestamp",new Date().getTime());K(this,"doReconnect",!0);K(this,"keepAliveInterval");K(this,"keepReconnectInterval");K(this,"keepReconnectTimeout");K(this,"connected",!1);K(this,"reconnectionTime",20);this.eventsSdkClass=e,this.eventsSdkClass=e,typeof window<"u"&&(window.addEventListener("offline",()=>{this.closeAllConnections()}),window.addEventListener("online",()=>{setTimeout(()=>{this.keepReconnectTimeout&&clearTimeout(this.keepReconnectTimeout),this.eventsSdkClass.connect(at.NEXT)},5e3)})),typeof self<"u"&&typeof window>"u"&&typeof global>"u"&&(self.addEventListener("offline",()=>{this.closeAllConnections()}),self.addEventListener("online",()=>{setTimeout(()=>{this.keepReconnectTimeout&&clearTimeout(this.keepReconnectTimeout),this.eventsSdkClass.connect(at.NEXT)},5e3)}))}getSocketIoFunction(e){const t=e.split("v="),n="v".concat(t[t.length-1]).replaceAll(".","_");this.ioFunction=ln.getSocketVersion(n)}initSocketConnection(){const e=this.eventsSdkClass.authClass.token,t=this.eventsSdkClass.options.protocol,n=this.eventsSdkClass.server;try{const r=n?n.Domain:this.eventsSdkClass.URL,o=n?`${t}://${r}`:this.eventsSdkClass.URL,u={reconnection:!1,upgrade:!1,transports:["websocket"],forceNew:!0,query:{token:e},timeout:this.eventsSdkClass.options.timeout};if(this.ioFunction&&o)this.io=this.ioFunction(o,u),this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{attemptToConnect:o,connectionStatus:pt.TRYING_TO_CONNECT}),this.eventsSdkClass.loggerClass.sdkAttemptToConnect(r);else throw new Error("Socket server url no defined")}catch(r){this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(r)}}clearKeepAliveInterval(){this.keepAliveInterval&&clearInterval(this.keepAliveInterval)}initKeepAlive(){this.keepAliveInterval&&clearInterval(this.keepAliveInterval),this.keepAliveInterval=setInterval(async()=>{if(new Date().getTime()>this.lastEventTimestamp+this.eventsSdkClass.options.keepAliveTimeout&&this.io&&this.eventsSdkClass.authClass.token){this.eventsSdkClass.emit(Qt.KEEP_ALIVE,this.eventsSdkClass.authClass.token),this.eventsSdkClass.loggerClass.keepAliveEmit();return}},this.eventsSdkClass.options.keepAliveTimeout)}closeAllConnections(){var e;this.io&&(this.io.close(),(e=this.io)==null||e.disconnect(),this.io=void 0),this.eventsSdkClass.loggerClass.stop(),kt.clearSessionStorage()}initSocketEvents(){this.io&&this.io.on(P.LOGIN_SUCCESS,e=>this.onLoginSuccessEvent(e,P.LOGIN_SUCCESS)).on(P.QUEUE_EVENT,e=>this.onQueueEvent(e,P.QUEUE_EVENT)).on(P.EXTENSION_EVENT,e=>this.onExtensionEvent(e,P.EXTENSION_EVENT)).on(P.DIALER_EVENT,e=>this.onDialerEvent(e,P.DIALER_EVENT)).on(P.LOGIN_STATUS,e=>this.onLoginStatusEvent(e,P.LOGIN_STATUS)).on(P.ALL_EXTENSION_STATUS,e=>this.onAllExtensionStatus(e,P.ALL_EXTENSION_STATUS)).on(P.ALL_DIALER_STATUS,e=>this.onAllDialerStatus(e,P.ALL_DIALER_STATUS)).on(P.KEEP_ALIVE_RESPONSE,e=>this.onKeepAliveResponse(e)).on(P.EXTENSIONS_UPDATED,e=>this.onExtensionsUpdatedEvent(e,P.EXTENSIONS_UPDATED)).on(P.CONNECT,()=>this.onConnect()).on(P.DISCONNECT,e=>this.onDisconnect(e)).on(P.CONNECT_ERROR_EVENT,e=>this.onConnectError(e))}onLoginSuccessEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onQueueEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,wt.mapQueueEvent(e))}onExtensionEvent(e,t){const n=wt.mapExtensionEvent(e);n&&(this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,n))}onDialerEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onLoginStatusEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,wt.mapLoginStatusEvent(e))}onAllExtensionStatus(e,t){const n=wt.mapAllExtensionStatus(e);this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,n)}onAllDialerStatus(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onKeepAliveResponse(e){if(this.eventsSdkClass.loggerClass.keepAliveResponse(e),e.errorCode){this.initSocketConnection();return}this.connected?this.lastEventTimestamp=new Date().getTime():this.initSocketConnection()}onExtensionsUpdatedEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onConnect(){this.connected=!0,this.keepReconnectInterval&&clearInterval(this.keepReconnectInterval),this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:pt.CONNECTED}),this.eventsSdkClass.loggerClass.start().then(()=>{this.eventsSdkClass.loggerClass.sdkConnectionSuccess()})}onDisconnect(e){this.connected=!1,this.doReconnect&&(this.closeAllConnections(),this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:this.doReconnect?pt.TRYING_TO_CONNECT:pt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkDisconnect([e]),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>120&&(this.reconnectionTime=20),this.eventsSdkClass.connect(at.NEXT)},this.reconnectionTime*1e3))}onConnectError(e){this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:this.doReconnect?pt.TRYING_TO_CONNECT:pt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(e),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>60&&(this.reconnectionTime=20),this.eventsSdkClass.connect(at.NEXT)},this.reconnectionTime*1e3)}}var pn=Object.defineProperty,fn=(s,e,t)=>e in s?pn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,X=(s,e,t)=>(fn(s,typeof e!="symbol"?e+"":e,t),t);const ht=Object.create(null);ht.open="0";ht.close="1";ht.ping="2";ht.pong="3";ht.message="4";ht.upgrade="5";ht.noop="6";const _t=Object.create(null);Object.keys(ht).forEach(s=>{_t[ht[s]]=s});const Gt={type:"error",data:"parser error"},Ie=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",xe=typeof ArrayBuffer=="function",Be=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,Zt=({type:s,data:e},t,n)=>Ie&&e instanceof Blob?t?n(e):he(e,n):xe&&(e instanceof ArrayBuffer||Be(e))?t?n(e):he(new Blob([e]),n):n(ht[s]+(e||"")),he=(s,e)=>{const t=new FileReader;return t.onload=function(){const n=t.result.split(",")[1];e("b"+(n||""))},t.readAsDataURL(s)};function le(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}let Ft;function dn(s,e){if(Ie&&s.data instanceof Blob)return s.data.arrayBuffer().then(le).then(e);if(xe&&(s.data instanceof ArrayBuffer||Be(s.data)))return e(le(s.data));Zt(s,!1,t=>{Ft||(Ft=new TextEncoder),e(Ft.encode(t))})}const ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",St=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<ue.length;s++)St[ue.charCodeAt(s)]=s;const gn=s=>{let e=s.length*.75,t=s.length,n,r=0,o,u,h,d;s[s.length-1]==="="&&(e--,s[s.length-2]==="="&&e--);const c=new ArrayBuffer(e),p=new Uint8Array(c);for(n=0;n<t;n+=4)o=St[s.charCodeAt(n)],u=St[s.charCodeAt(n+1)],h=St[s.charCodeAt(n+2)],d=St[s.charCodeAt(n+3)],p[r++]=o<<2|u>>4,p[r++]=(u&15)<<4|h>>2,p[r++]=(h&3)<<6|d&63;return c},yn=typeof ArrayBuffer=="function",te=(s,e)=>{if(typeof s!="string")return{type:"message",data:Ue(s,e)};const t=s.charAt(0);return t==="b"?{type:"message",data:mn(s.substring(1),e)}:_t[t]?s.length>1?{type:_t[t],data:s.substring(1)}:{type:_t[t]}:Gt},mn=(s,e)=>{if(yn){const t=gn(s);return Ue(t,e)}else return{base64:!0,data:s}},Ue=(s,e)=>{switch(e){case"blob":return s instanceof Blob?s:new Blob([s]);case"arraybuffer":default:return s instanceof ArrayBuffer?s:s.buffer}},De="",vn=(s,e)=>{const t=s.length,n=new Array(t);let r=0;s.forEach((o,u)=>{Zt(o,!1,h=>{n[u]=h,++r===t&&e(n.join(De))})})},kn=(s,e)=>{const t=s.split(De),n=[];for(let r=0;r<t.length;r++){const o=te(t[r],e);if(n.push(o),o.type==="error")break}return n};function Sn(){return new TransformStream({transform(s,e){dn(s,t=>{const n=t.length;let r;if(n<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,n);else if(n<65536){r=new Uint8Array(3);const o=new DataView(r.buffer);o.setUint8(0,126),o.setUint16(1,n)}else{r=new Uint8Array(9);const o=new DataView(r.buffer);o.setUint8(0,127),o.setBigUint64(1,BigInt(n))}s.data&&typeof s.data!="string"&&(r[0]|=128),e.enqueue(r),e.enqueue(t)})}})}let Mt;function Ct(s){return s.reduce((e,t)=>e+t.length,0)}function Et(s,e){if(s[0].length===e)return s.shift();const t=new Uint8Array(e);let n=0;for(let r=0;r<e;r++)t[r]=s[0][n++],n===s[0].length&&(s.shift(),n=0);return s.length&&n<s[0].length&&(s[0]=s[0].slice(n)),t}function bn(s,e){Mt||(Mt=new TextDecoder);const t=[];let n=0,r=-1,o=!1;return new TransformStream({transform(u,h){for(t.push(u);;){if(n===0){if(Ct(t)<1)break;const d=Et(t,1);o=(d[0]&128)===128,r=d[0]&127,r<126?n=3:r===126?n=1:n=2}else if(n===1){if(Ct(t)<2)break;const d=Et(t,2);r=new DataView(d.buffer,d.byteOffset,d.length).getUint16(0),n=3}else if(n===2){if(Ct(t)<8)break;const d=Et(t,8),c=new DataView(d.buffer,d.byteOffset,d.length),p=c.getUint32(0);if(p>Math.pow(2,21)-1){h.enqueue(Gt);break}r=p*Math.pow(2,32)+c.getUint32(4),n=3}else{if(Ct(t)<r)break;const d=Et(t,r);h.enqueue(te(o?d:Mt.decode(d),e)),n=0}if(r===0||r>s){h.enqueue(Gt);break}}}})}const Pe=4;function $(s){if(s)return wn(s)}function wn(s){for(var e in $.prototype)s[e]=$.prototype[e];return s}$.prototype.on=$.prototype.addEventListener=function(s,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(e),this};$.prototype.once=function(s,e){function t(){this.off(s,t),e.apply(this,arguments)}return t.fn=e,this.on(s,t),this};$.prototype.off=$.prototype.removeListener=$.prototype.removeAllListeners=$.prototype.removeEventListener=function(s,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+s];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+s],this;for(var n,r=0;r<t.length;r++)if(n=t[r],n===e||n.fn===e){t.splice(r,1);break}return t.length===0&&delete this._callbacks["$"+s],this};$.prototype.emit=function(s){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),t=this._callbacks["$"+s],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(t){t=t.slice(0);for(var n=0,r=t.length;n<r;++n)t[n].apply(this,e)}return this};$.prototype.emitReserved=$.prototype.emit;$.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]};$.prototype.hasListeners=function(s){return!!this.listeners(s).length};const nt=typeof self<"u"?self:typeof window<"u"?window:Function("return this")();function je(s,...e){return e.reduce((t,n)=>(s.hasOwnProperty(n)&&(t[n]=s[n]),t),{})}const Cn=nt.setTimeout,En=nt.clearTimeout;function Rt(s,e){e.useNativeTimers?(s.setTimeoutFn=Cn.bind(nt),s.clearTimeoutFn=En.bind(nt)):(s.setTimeoutFn=nt.setTimeout.bind(nt),s.clearTimeoutFn=nt.clearTimeout.bind(nt))}const Tn=1.33;function An(s){return typeof s=="string"?Nn(s):Math.ceil((s.byteLength||s.size)*Tn)}function Nn(s){let e=0,t=0;for(let n=0,r=s.length;n<r;n++)e=s.charCodeAt(n),e<128?t+=1:e<2048?t+=2:e<55296||e>=57344?t+=3:(n++,t+=4);return t}function _n(s){let e="";for(let t in s)s.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(s[t]));return e}function On(s){let e={},t=s.split("&");for(let n=0,r=t.length;n<r;n++){let o=t[n].split("=");e[decodeURIComponent(o[0])]=decodeURIComponent(o[1])}return e}class Ln extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}class ee extends ${constructor(e){super(),this.writable=!1,Rt(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,n){return super.emitReserved("error",new Ln(e,t,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=te(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){const e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){const t=_n(e);return t.length?"?"+t:""}}const qe="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),Jt=64,Rn={};let pe=0,Tt=0,fe;function de(s){let e="";do e=qe[s%Jt]+e,s=Math.floor(s/Jt);while(s>0);return e}function Fe(){const s=de(+new Date);return s!==fe?(pe=0,fe=s):s+"."+de(pe++)}for(;Tt<Jt;Tt++)Rn[qe[Tt]]=Tt;let Me=!1;try{Me=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const In=Me;function Ve(s){const e=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||In))return new XMLHttpRequest}catch{}if(!e)try{return new nt[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function xn(){}const Bn=function(){return new Ve({xdomain:!1}).responseType!=null}();class Un extends ee{constructor(e){if(super(e),this.polling=!1,typeof location<"u"){const n=location.protocol==="https:";let r=location.port;r||(r=n?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||r!==e.port}const t=e&&e.forceBase64;this.supportsBinary=Bn&&!t,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(e){this.readyState="pausing";const t=()=>{this.readyState="paused",e()};if(this.polling||!this.writable){let n=0;this.polling&&(n++,this.once("pollComplete",function(){--n||t()})),this.writable||(n++,this.once("drain",function(){--n||t()}))}else t()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){const t=n=>{if(this.readyState==="opening"&&n.type==="open"&&this.onOpen(),n.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(n)};kn(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,vn(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(t[this.opts.timestampParam]=Fe()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}request(e={}){return Object.assign(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new ct(this.uri(),e)}doWrite(e,t){const n=this.request({method:"POST",data:e});n.on("success",t),n.on("error",(r,o)=>{this.onError("xhr post error",r,o)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,n)=>{this.onError("xhr poll error",t,n)}),this.pollXhr=e}}class ct extends ${constructor(e,t){super(),Rt(this,t),this.opts=t,this.method=t.method||"GET",this.uri=e,this.data=t.data!==void 0?t.data:null,this.create()}create(){var e;const t=je(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd;const n=this.xhr=new Ve(t);try{n.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let r in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(r)&&n.setRequestHeader(r,this.opts.extraHeaders[r])}}catch{}if(this.method==="POST")try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{n.setRequestHeader("Accept","*/*")}catch{}(e=this.opts.cookieJar)===null||e===void 0||e.addCookies(n),"withCredentials"in n&&(n.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(n.timeout=this.opts.requestTimeout),n.onreadystatechange=()=>{var r;n.readyState===3&&((r=this.opts.cookieJar)===null||r===void 0||r.parseCookies(n)),n.readyState===4&&(n.status===200||n.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof n.status=="number"?n.status:0)},0))},n.send(this.data)}catch(r){this.setTimeoutFn(()=>{this.onError(r)},0);return}typeof document<"u"&&(this.index=ct.requestsCount++,ct.requests[this.index]=this)}onError(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}cleanup(e){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=xn,e)try{this.xhr.abort()}catch{}typeof document<"u"&&delete ct.requests[this.index],this.xhr=null}}onLoad(){const e=this.xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}ct.requestsCount=0;ct.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",ge);else if(typeof addEventListener=="function"){const s="onpagehide"in nt?"pagehide":"unload";addEventListener(s,ge,!1)}}function ge(){for(let s in ct.requests)ct.requests.hasOwnProperty(s)&&ct.requests[s].abort()}const ne=typeof Promise=="function"&&typeof Promise.resolve=="function"?s=>Promise.resolve().then(s):(s,e)=>e(s,0),At=nt.WebSocket||nt.MozWebSocket,ye=!0,Dn="arraybuffer",me=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Pn extends ee{constructor(e){super(e),this.supportsBinary=!e.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const e=this.uri(),t=this.opts.protocols,n=me?{}:je(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=ye&&!me?t?new At(e,t):new At(e):new At(e,t,n)}catch(r){return this.emitReserved("error",r)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t===e.length-1;Zt(n,this.supportsBinary,o=>{try{ye&&this.ws.send(o)}catch{}r&&ne(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=Fe()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}check(){return!!At}}class jn extends ee{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(e=>{const t=bn(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=Sn();r.readable.pipeTo(e.writable),this.writer=r.writable.getWriter();const o=()=>{n.read().then(({done:h,value:d})=>{h||(this.onPacket(d),o())}).catch(h=>{})};o();const u={type:"open"};this.query.sid&&(u.data=`{"sid":"${this.query.sid}"}`),this.writer.write(u).then(()=>this.onOpen())})}))}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t===e.length-1;this.writer.write(n).then(()=>{r&&ne(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this.transport)===null||e===void 0||e.close()}}const qn={websocket:Pn,webtransport:jn,polling:Un},Fn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Mn=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Xt(s){if(s.length>2e3)throw"URI too long";const e=s,t=s.indexOf("["),n=s.indexOf("]");t!=-1&&n!=-1&&(s=s.substring(0,t)+s.substring(t,n).replace(/:/g,";")+s.substring(n,s.length));let r=Fn.exec(s||""),o={},u=14;for(;u--;)o[Mn[u]]=r[u]||"";return t!=-1&&n!=-1&&(o.source=e,o.host=o.host.substring(1,o.host.length-1).replace(/;/g,":"),o.authority=o.authority.replace("[","").replace("]","").replace(/;/g,":"),o.ipv6uri=!0),o.pathNames=Vn(o,o.path),o.queryKey=Kn(o,o.query),o}function Vn(s,e){const t=/\/{2,9}/g,n=e.replace(t,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&n.splice(0,1),e.slice(-1)=="/"&&n.splice(n.length-1,1),n}function Kn(s,e){const t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(n,r,o){r&&(t[r]=o)}),t}let Ke=class ft extends ${constructor(e,t={}){super(),this.binaryType=Dn,this.writeBuffer=[],e&&typeof e=="object"&&(t=e,e=null),e?(e=Xt(e),t.hostname=e.host,t.secure=e.protocol==="https"||e.protocol==="wss",t.port=e.port,e.query&&(t.query=e.query)):t.host&&(t.hostname=Xt(t.host).host),Rt(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=t.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=On(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=Pe,t.transport=e,this.id&&(t.sid=this.id);const n=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new qn[e](n)}open(){let e;if(this.opts.rememberUpgrade&&ft.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)e="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else e=this.transports[0];this.readyState="opening";try{e=this.createTransport(e)}catch{this.transports.shift(),this.open();return}e.open(),this.setTransport(e)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",t=>this.onClose("transport close",t))}probe(e){let t=this.createTransport(e),n=!1;ft.priorWebsocketSuccess=!1;const r=()=>{n||(t.send([{type:"ping",data:"probe"}]),t.once("packet",l=>{if(!n)if(l.type==="pong"&&l.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;ft.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{n||this.readyState!=="closed"&&(p(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{const i=new Error("probe error");i.transport=t.name,this.emitReserved("upgradeError",i)}}))};function o(){n||(n=!0,p(),t.close(),t=null)}const u=l=>{const i=new Error("probe error: "+l);i.transport=t.name,o(),this.emitReserved("upgradeError",i)};function h(){u("transport closed")}function d(){u("socket closed")}function c(l){t&&l.name!==t.name&&o()}const p=()=>{t.removeListener("open",r),t.removeListener("error",u),t.removeListener("close",h),this.off("close",d),this.off("upgrading",c)};t.once("open",r),t.once("error",u),t.once("close",h),this.once("close",d),this.once("upgrading",c),this.upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onOpen(){if(this.readyState="open",ft.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let e=0;const t=this.upgrades.length;for(;e<t;e++)this.probe(this.upgrades[e])}}onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let e=1;for(let t=0;t<this.writeBuffer.length;t++){const n=this.writeBuffer[t].data;if(n&&(e+=An(n)),t>0&&e>this.maxPayload)return this.writeBuffer.slice(0,t);e+=2}return this.writeBuffer}write(e,t,n){return this.sendPacket("message",e,t,n),this}send(e,t,n){return this.sendPacket("message",e,t,n),this}sendPacket(e,t,n,r){if(typeof t=="function"&&(r=t,t=void 0),typeof n=="function"&&(r=n,n=null),this.readyState==="closing"||this.readyState==="closed")return;n=n||{},n.compress=n.compress!==!1;const o={type:e,data:t,options:n};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),r&&this.once("flush",r),this.flush()}close(){const e=()=>{this.onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},n=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():e()}):this.upgrading?n():e()),this}onError(e){ft.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,t){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const t=[];let n=0;const r=e.length;for(;n<r;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}};Ke.protocol=Pe;function Wn(s,e="",t){let n=s;t=t||typeof location<"u"&&location,s==null&&(s=t.protocol+"//"+t.host),typeof s=="string"&&(s.charAt(0)==="/"&&(s.charAt(1)==="/"?s=t.protocol+s:s=t.host+s),/^(https?|wss?):\/\//.test(s)||(typeof t<"u"?s=t.protocol+"//"+s:s="https://"+s),n=Xt(s)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";const r=n.host.indexOf(":")!==-1?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+r+":"+n.port+e,n.href=n.protocol+"://"+r+(t&&t.port===n.port?"":":"+n.port),n}const Gn=typeof ArrayBuffer=="function",Jn=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s.buffer instanceof ArrayBuffer,We=Object.prototype.toString,Xn=typeof Blob=="function"||typeof Blob<"u"&&We.call(Blob)==="[object BlobConstructor]",$n=typeof File=="function"||typeof File<"u"&&We.call(File)==="[object FileConstructor]";function se(s){return Gn&&(s instanceof ArrayBuffer||Jn(s))||Xn&&s instanceof Blob||$n&&s instanceof File}function Ot(s,e){if(!s||typeof s!="object")return!1;if(Array.isArray(s)){for(let t=0,n=s.length;t<n;t++)if(Ot(s[t]))return!0;return!1}if(se(s))return!0;if(s.toJSON&&typeof s.toJSON=="function"&&arguments.length===1)return Ot(s.toJSON(),!0);for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)&&Ot(s[t]))return!0;return!1}function zn(s){const e=[],t=s.data,n=s;return n.data=$t(t,e),n.attachments=e.length,{packet:n,buffers:e}}function $t(s,e){if(!s)return s;if(se(s)){const t={_placeholder:!0,num:e.length};return e.push(s),t}else if(Array.isArray(s)){const t=new Array(s.length);for(let n=0;n<s.length;n++)t[n]=$t(s[n],e);return t}else if(typeof s=="object"&&!(s instanceof Date)){const t={};for(const n in s)Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=$t(s[n],e));return t}return s}function Hn(s,e){return s.data=zt(s.data,e),delete s.attachments,s}function zt(s,e){if(!s)return s;if(s&&s._placeholder===!0){if(typeof s.num=="number"&&s.num>=0&&s.num<e.length)return e[s.num];throw new Error("illegal attachments")}else if(Array.isArray(s))for(let t=0;t<s.length;t++)s[t]=zt(s[t],e);else if(typeof s=="object")for(const t in s)Object.prototype.hasOwnProperty.call(s,t)&&(s[t]=zt(s[t],e));return s}const Yn=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Qn=5;var V;(function(s){s[s.CONNECT=0]="CONNECT",s[s.DISCONNECT=1]="DISCONNECT",s[s.EVENT=2]="EVENT",s[s.ACK=3]="ACK",s[s.CONNECT_ERROR=4]="CONNECT_ERROR",s[s.BINARY_EVENT=5]="BINARY_EVENT",s[s.BINARY_ACK=6]="BINARY_ACK"})(V||(V={}));class Zn{constructor(e){this.replacer=e}encode(e){return(e.type===V.EVENT||e.type===V.ACK)&&Ot(e)?this.encodeAsBinary({type:e.type===V.EVENT?V.BINARY_EVENT:V.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return(e.type===V.BINARY_EVENT||e.type===V.BINARY_ACK)&&(t+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(t+=e.nsp+","),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){const t=zn(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}}function ve(s){return Object.prototype.toString.call(s)==="[object Object]"}class re extends ${constructor(e){super(),this.reviver=e}add(e){let t;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);const n=t.type===V.BINARY_EVENT;n||t.type===V.BINARY_ACK?(t.type=n?V.EVENT:V.ACK,this.reconstructor=new ts(t),t.attachments===0&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else if(se(e)||e.base64)if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let t=0;const n={type:Number(e.charAt(0))};if(V[n.type]===void 0)throw new Error("unknown packet type "+n.type);if(n.type===V.BINARY_EVENT||n.type===V.BINARY_ACK){const o=t+1;for(;e.charAt(++t)!=="-"&&t!=e.length;);const u=e.substring(o,t);if(u!=Number(u)||e.charAt(t)!=="-")throw new Error("Illegal attachments");n.attachments=Number(u)}if(e.charAt(t+1)==="/"){const o=t+1;for(;++t&&!(e.charAt(t)===","||t===e.length););n.nsp=e.substring(o,t)}else n.nsp="/";const r=e.charAt(t+1);if(r!==""&&Number(r)==r){const o=t+1;for(;++t;){const u=e.charAt(t);if(u==null||Number(u)!=u){--t;break}if(t===e.length)break}n.id=Number(e.substring(o,t+1))}if(e.charAt(++t)){const o=this.tryParse(e.substr(t));if(re.isPayloadValid(n.type,o))n.data=o;else throw new Error("invalid payload")}return n}tryParse(e){try{return JSON.parse(e,this.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case V.CONNECT:return ve(t);case V.DISCONNECT:return t===void 0;case V.CONNECT_ERROR:return typeof t=="string"||ve(t);case V.EVENT:case V.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&Yn.indexOf(t[0])===-1);case V.ACK:case V.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class ts{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const t=Hn(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const es=Object.freeze(Object.defineProperty({__proto__:null,Decoder:re,Encoder:Zn,get PacketType(){return V},protocol:Qn},Symbol.toStringTag,{value:"Module"}));function rt(s,e,t){return s.on(e,t),function(){s.off(e,t)}}const ns=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Ge extends ${constructor(e,t,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[rt(e,"open",this.onopen.bind(this)),rt(e,"packet",this.onpacket.bind(this)),rt(e,"error",this.onerror.bind(this)),rt(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){if(ns.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const n={type:V.EVENT,data:t};if(n.options={},n.options.compress=this.flags.compress!==!1,typeof t[t.length-1]=="function"){const o=this.ids++,u=t.pop();this._registerAckCallback(o,u),n.id=o}const r=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!r||!this.connected)||(this.connected?(this.notifyOutgoingListeners(n),this.packet(n)):this.sendBuffer.push(n)),this.flags={},this}_registerAckCallback(e,t){var n;const r=(n=this.flags.timeout)!==null&&n!==void 0?n:this._opts.ackTimeout;if(r===void 0){this.acks[e]=t;return}const o=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let u=0;u<this.sendBuffer.length;u++)this.sendBuffer[u].id===e&&this.sendBuffer.splice(u,1);t.call(this,new Error("operation has timed out"))},r);this.acks[e]=(...u)=>{this.io.clearTimeoutFn(o),t.apply(this,[null,...u])}}emitWithAck(e,...t){const n=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((r,o)=>{t.push((u,h)=>n?u?o(u):r(h):r(u)),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]=="function"&&(t=e.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((r,...o)=>n!==this._queue[0]?void 0:(r!==null?n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(r)):(this._queue.shift(),t&&t(null,...o)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;const t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:V.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t)}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case V.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case V.EVENT:case V.BINARY_EVENT:this.onevent(e);break;case V.ACK:case V.BINARY_ACK:this.onack(e);break;case V.DISCONNECT:this.ondisconnect();break;case V.CONNECT_ERROR:this.destroy();const t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t);break}}onevent(e){const t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const n of t)n.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let n=!1;return function(...r){n||(n=!0,t.packet({type:V.ACK,id:e,data:r}))}}onack(e){const t=this.acks[e.id];typeof t=="function"&&(t.apply(this,e.data),delete this.acks[e.id])}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:V.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const t=this._anyOutgoingListeners.slice();for(const n of t)n.apply(this,e.data)}}}function dt(s){s=s||{},this.ms=s.min||100,this.max=s.max||1e4,this.factor=s.factor||2,this.jitter=s.jitter>0&&s.jitter<=1?s.jitter:0,this.attempts=0}dt.prototype.duration=function(){var s=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*s);s=Math.floor(e*10)&1?s+t:s-t}return Math.min(s,this.max)|0};dt.prototype.reset=function(){this.attempts=0};dt.prototype.setMin=function(s){this.ms=s};dt.prototype.setMax=function(s){this.max=s};dt.prototype.setJitter=function(s){this.jitter=s};class Ht extends ${constructor(e,t){var n;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,Rt(this,t),this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((n=t.randomizationFactor)!==null&&n!==void 0?n:.5),this.backoff=new dt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;const r=t.parser||es;this.encoder=new r.Encoder,this.decoder=new r.Decoder,this._autoConnect=t.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new Ke(this.uri,this.opts);const t=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const r=rt(t,"open",function(){n.onopen(),e&&e()}),o=h=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",h),e?e(h):this.maybeReconnectOnOpen()},u=rt(t,"error",o);if(this._timeout!==!1){const h=this._timeout,d=this.setTimeoutFn(()=>{r(),o(new Error("timeout")),t.close()},h);this.opts.autoUnref&&d.unref(),this.subs.push(()=>{this.clearTimeoutFn(d)})}return this.subs.push(r),this.subs.push(u),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(rt(e,"ping",this.onping.bind(this)),rt(e,"data",this.ondata.bind(this)),rt(e,"error",this.onerror.bind(this)),rt(e,"close",this.onclose.bind(this)),rt(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(t){this.onclose("parse error",t)}}ondecoded(e){ne(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new Ge(this,e,t),this.nsps[e]=n),n}_destroy(e){const t=Object.keys(this.nsps);for(const n of t)if(this.nsps[n].active)return;this._close()}_packet(e){const t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(e,t){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(r=>{r?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",r)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const vt={};function Lt(s,e){typeof s=="object"&&(e=s,s=void 0),e=e||{};const t=Wn(s,e.path||"/socket.io"),n=t.source,r=t.id,o=t.path,u=vt[r]&&o in vt[r].nsps,h=e.forceNew||e["force new connection"]||e.multiplex===!1||u;let d;return h?d=new Ht(n,e):(vt[r]||(vt[r]=new Ht(n,e)),d=vt[r]),t.query&&!e.query&&(e.query=t.queryKey),d.socket(t.path,e)}Object.assign(Lt,{Manager:Ht,Socket:Ge,io:Lt,connect:Lt});let Nt;const ss=new Uint8Array(16);function rs(){if(!Nt&&(Nt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Nt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Nt(ss)}const z=[];for(let s=0;s<256;++s)z.push((s+256).toString(16).slice(1));function os(s,e=0){return z[s[e+0]]+z[s[e+1]]+z[s[e+2]]+z[s[e+3]]+"-"+z[s[e+4]]+z[s[e+5]]+"-"+z[s[e+6]]+z[s[e+7]]+"-"+z[s[e+8]]+z[s[e+9]]+"-"+z[s[e+10]]+z[s[e+11]]+z[s[e+12]]+z[s[e+13]]+z[s[e+14]]+z[s[e+15]]}const is=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ke={randomUUID:is};function as(s,e,t){if(ke.randomUUID&&!e&&!s)return ke.randomUUID();s=s||{};const n=s.random||(s.rng||rs)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){t=t||0;for(let r=0;r<16;++r)e[t+r]=n[r];return e}return os(n)}function cs(s,e){const t=e.map(r=>JSON.stringify(r)).join(" "),n=new Date().toISOString();return JSON.stringify({level:s,time:n,message:t})}function hs(s,e){const t=JSON.parse(s);return e.forEach(n=>delete t[n]),t}function ls(s){if(typeof s=="object"&&s!==null)return s;try{return JSON.parse(s)}catch{return{extraData:s}}}function us(s){const e=/\(([^)]+)\)/,t=s.match(e);if(t&&t[1]){const n=t[1].split(";");for(let r of n)if(r=r.trim(),r.startsWith("Windows")||r.startsWith("Macintosh")||r.startsWith("Linux"))return r}return"Unknown"}function Se(s){return(...e)=>new Promise((t,n)=>{try{const r=s(...e);t(r)}catch(r){n(r)}})}const ps={reconnection:!0,reconnectionDelay:5e3,reconnectionAttempts:10,upgrade:!1,transports:["websocket"],debug:!1},Vt={logToConsole:!0,overloadGlobalConsole:!1,socketEmitInterval:6e4},ot={CREATE:"Create",READ:"Read",UPDATE:"Update",DELETE:"Delete",CONVERT:"Convert",DOWNLOAD:"Download",UPLOAD:"Upload",ENCRYPT:"Encrypt",DECRYPT:"Decrypt",FILTER:"Filter",INPUT:"Input",OUTPUT:"Output",PLUGIN:"Plugin",LOGIN:"Login",LOGOUT:"Logout",REFRESH:"Refresh",CHECK:"Check",WEBHOOK:"Webhook",WSCONNECT:"WSConnect"},fs={Create:1,Read:2,Update:3,Delete:4,Convert:5,Download:6,Upload:7,Encrypt:8,Decrypt:9,Filter:10,Input:11,Output:12,Plugin:13,Login:14,Logout:15,Refresh:16,Check:17,Webhook:18,WSConnect:19},it={INFO:"info",WARNING:"warning",MODIFY:"modify",ERROR:"error",VIEW:"view"},Q={INFO:"info",WARNING:"warning",ERROR:"error",DEBUG:"debug"};let Z=console;class ds{constructor(e){X(this,"logToConsole"),X(this,"overloadGlobalConsole"),X(this,"system"),X(this,"socketEmitInterval"),X(this,"storageId"),X(this,"emitInProgress"),X(this,"queue"),X(this,"processing"),X(this,"storageInitialized"),X(this,"interval"),X(this,"logIndex"),X(this,"socket"),X(this,"requestUrl"),X(this,"staticObject",{}),X(this,"localObject",{}),X(this,"isGetItemAsync"),X(this,"isSetItemAsync"),X(this,"getItem"),X(this,"setItem"),X(this,"parseLog"),X(this,"_logMethod"),X(this,"_warnMethod"),X(this,"_errorMethod"),X(this,"_debugMethod");const{loggerOptions:t}=e;if(!t.system)throw new Error("Config property 'system' should be provided!");this.isGetItemAsync=t.isGetItemAsync||!1,this.isSetItemAsync=t.isSetItemAsync||!1,this.setupStorageFunctions(t.getItem,t.setItem,t.parseLog),this.system=t.system,this.socketEmitInterval=t.socketEmitInterval||Vt.socketEmitInterval,this.logToConsole=t.logToConsole!==void 0?t.logToConsole:Vt.logToConsole,this.overloadGlobalConsole=t.overloadGlobalConsole!==void 0?t.overloadGlobalConsole:Vt.overloadGlobalConsole,this.storageId=this.getStorageName(),this.queue=[],this.processing=!1,this.storageInitialized=!1,this.emitInProgress=!1,this.logIndex=0,this.init(e)}setupStorageFunctions(e,t,n){this.getItem=e&&typeof e=="function"?this.isGetItemAsync?e:Se(e):this.defaultGetItemFunction,this.setItem=t&&typeof t=="function"?this.isSetItemAsync?t:Se(t):this.defaultSetItemFunction,this.parseLog=n&&typeof n=="function"?n:cs}sendHttpRequest(e){if(!this.requestUrl)throw new Error("requestUrl is not provided");const t={Data:e};return fetch(this.requestUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}init(e){const{socket:t,url:n,requestUrl:r,socketOptions:o={}}=e;this._logMethod=Z.log.bind(Z),this._warnMethod=Z.warn.bind(Z),this._errorMethod=Z.error.bind(Z),this._debugMethod=Z.debug.bind(Z),this.initStorage().then(()=>{if(t)this.socket=t;else if(n)this.socket=this.createConnection(n,o);else if(r)this.requestUrl=r;else throw new Error("Must provide either a 'socket', 'requestUrl' or a 'url' for logger requests");this.interval=setInterval(async()=>{await this.emitLogs()},this.socketEmitInterval),this.overloadGlobalConsole&&this._overloadConsole()})}createConnection(e,t={}){const n={...ps,...t};return Lt(e,n)}async emitLogs(){if(!this.emitInProgress)try{const e=await this.getItem(this.storageId),t=JSON.parse(e||"{}"),n={...this.localObject,...t};if(!Object.keys(n).length)return;const r=[];this.emitInProgress=!0;const o=Object.keys(n);if(!o.length)return;if((!this.socket||!this.socket.connected)&&!this.requestUrl)throw new Error("Log request can't be sent. Socket is disconnected or requestUrl is not provided");const u=[];for(const c of o){const p=ls(n[c]),l={...this.staticObject,...p},i=this.populateSendingLog(l);i.Body&&typeof i.Body=="string"&&(i.Body=JSON.parse(i.Body)),this.socket?await this.socket.emit("Log",i):this.requestUrl&&u.push(i),r.push(c)}u.length&&await this.sendHttpRequest(u);const h=await this.getItem(this.storageId);if(!h)return;const d=hs(h,r);this.localObject={},await this.setItem(this.storageId,JSON.stringify(d))}catch(e){this._errorMethod(e)}finally{this.emitInProgress=!1}}populateSendingLog(e){const t={...e},n=t.ActionName;return n&&(t.ActionID=fs[n]),t}setupStaticFields(e){this.staticObject={...e}}populateMetaData(){const e=new Date;let t;typeof window<"u"&&typeof window.document<"u"?t=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(t=self.navigator.userAgent);let n;return t&&(n=us(t)),{System:this.system,DateTime:e,UserAgent:t,OSVersion:n}}async stop(){!this.socket||!this.socket.connected||(clearInterval(this.interval),await this.emitLogs(),this.socket.disconnect())}async start(){this.socket&&this.socket.connected||(this.socket.connect(),this.interval=setInterval(async()=>{await this.emitLogs()},this.socketEmitInterval))}_overloadConsole(){Z=Object.assign(Z,{log:e=>{this.log(e)},warn:e=>{this.warn(e)},error:e=>{this.error(e)},debug:e=>{this.debug(e)}})}async initStorage(){const e=await this.getItem(this.storageId);(!e||typeof e!="string")&&(await this.setItem(this.storageId,JSON.stringify({})),this.storageInitialized=!0)}async resetStorage(){await this.setItem(this.storageId,JSON.stringify({}))}getStorageName(){const e=as();return this.system.toString().toUpperCase()+e+Date.now()}async processLog(...e){try{if(e.length<2)return;const t=e[0],n=e[1],r=this.formItemKey(t);if(!this.storageInitialized){this.localObject={...this.localObject,[r]:n};return}const o=await this.getItem(this.storageId);if(!o)return;const u=JSON.parse(o);u[r]=JSON.stringify(n),await this.setItem(this.storageId,JSON.stringify(u))}catch(t){this._errorMethod(t)}}async processQueue(){if(this.processing||this.queue.length===0)return;const e=this.queue.shift();e&&(this.processing=!0,await this.processLog(...e).finally(()=>{this.processing=!1,this.processQueue()}))}log(e){const t={...this.populateMetaData(),...e},n=["INFO",t];this.queue.push(n),this.logToConsole&&this._logMethod.apply(Z,[t]),this.processQueue()}warn(e){const t=["WARN",e];this.queue.push(t),this.logToConsole&&this._warnMethod.apply(Z,[e]),this.processQueue()}error(e){const t=["ERROR",e];this.queue.push(t),this.logToConsole&&this._errorMethod.apply(Z,[e]),this.processQueue()}debug(e){const t=["DEBUG",e];this.queue.push(t),this.logToConsole&&this._debugMethod.apply(Z,[e]),this.processQueue()}async defaultGetItemFunction(e){return localStorage.getItem(e)}async defaultSetItemFunction(e,t){try{localStorage.setItem(e,t)}catch(n){this._errorMethod(n)}}formItemKey(e){const t=new Date().toISOString();return this.logIndex++,`${e}-${this.system}-${t}-${this.logIndex}`}}class gs{constructor(e){K(this,"storageLogger");this.eventsSdkClass=e,this.eventsSdkClass=e}init(){if(!this.eventsSdkClass.options.useLogger)return;if(this.eventsSdkClass.options.storageLoggerInstance){this.storageLogger=this.eventsSdkClass.options.storageLoggerInstance;return}let e;this.eventsSdkClass.options.loggerSocketConnection&&(e=this.eventsSdkClass.options.loggerSocketConnection),this.eventsSdkClass.socketIoClass.ioFunction&&!e&&(e=this.eventsSdkClass.socketIoClass.ioFunction(this.eventsSdkClass.options.loggerServer,this.eventsSdkClass.options.loggerConnectOptions)),e&&(this.storageLogger=new ds({socket:e,loggerOptions:this.eventsSdkClass.options.loggerConfig}))}async start(){this.storageLogger&&await this.storageLogger.start()}stop(){this.storageLogger&&this.storageLogger.stop()}log(e){this.eventsSdkClass.options.useLogger&&(this.storageLogger?e.Level===Q.INFO?this.storageLogger.log(e):e.Level===Q.ERROR&&this.storageLogger.error(e):e.Level===Q.INFO?console.log(e):e.Level===Q.ERROR&&console.error(e))}sdkConnectionSuccess(){const e={...this.eventsSdkClass.options,token:"CENSORED",password:"CENSORED"};this.log({Message:`Sdk connected to the socket server ${this.eventsSdkClass.server&&this.eventsSdkClass.server.Domain?this.eventsSdkClass.server.Domain:this.eventsSdkClass.URL}`,Body:JSON.stringify(e,this.eventsSdkClass.getCircularReplacer()),ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Connection established",StatusCode:200,Level:Q.INFO,LogType:it.INFO})}sdkDisconnect(e){this.log({Message:`Sdk disconnected from the socket server ${this.eventsSdkClass.server&&this.eventsSdkClass.server.Domain?this.eventsSdkClass.server.Domain:this.eventsSdkClass.URL} (${e})`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Connection closed",StatusCode:200,Level:Q.INFO,LogType:it.INFO})}sdkAttemptToConnect(e){this.log({Message:`${this.eventsSdkClass.options.loggerConfig.system} is trying to connect to WS server ${e}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Switching Protocols",StatusCode:101,Level:Q.INFO,LogType:it.INFO})}sdkAttemptToConnectError(e){this.log({Message:`${e}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Connection error",StatusCode:500,Level:Q.ERROR,LogType:it.ERROR})}loginError(e,t,n,r){this.log({Message:`External login request error with the login type ${e} ${e===st.TOKEN?n:r}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"External login error",StatusCode:t||400,Level:Q.ERROR,LogType:it.ERROR})}getSettingsError(e,t){this.log({Message:`Get settings error with token ${e}, error: ${t}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:it.ERROR})}refreshTokenError(e,t,n){this.log({Message:`Refresh token error with old refresh token ${e}, url: ${t}, error: ${n}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:it.ERROR})}keepAliveEmit(){this.log({Message:`Keep alive event emitted with this token: ${this.eventsSdkClass.authClass.token}`,ActionName:ot.WSCONNECT,isShowClient:!1,Level:Q.INFO,LogType:it.INFO})}keepAliveResponse(e){this.log({Message:`Keep alive response: ${JSON.stringify(e)}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Successful",StatusCode:200,Level:Q.INFO,LogType:it.INFO})}eventLog(e,t){const n={[ut.FULL]:[],[ut.BOOTSTRAP]:[P.LOGIN_STATUS,P.LOGIN_SUCCESS,P.ALL_EXTENSION_STATUS,P.ALL_DIALER_STATUS],[ut.DEBUG_EXTENSIONS]:[P.ALL_EXTENSION_STATUS,P.EXTENSION_EVENT,P.EXTENSIONS_UPDATED],[ut.DEBUG_DIALER]:[P.ALL_DIALER_STATUS,P.DIALER_EVENT],[ut.DEBUG_QUEUE]:[P.QUEUE_EVENT]};this.eventsSdkClass.options.debugOption&&(n[this.eventsSdkClass.options.debugOption].includes(e)||this.eventsSdkClass.options.debugOption===ut.FULL)&&this.log({Message:`Event name: ${e}`,Body:t,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Successful",Level:Q.INFO,LogType:it.INFO})}}class ys{constructor(e){K(this,"listeners",{[P.ALL_EXTENSION_STATUS]:[],[P.ALL_DIALER_STATUS]:[],[P.ALL_USERS_STATUS]:[],[P.QUEUE_EVENT]:[],[P.EXTENSION_EVENT]:[],[P.DIALER_EVENT]:[],[P.LOGIN_SUCCESS]:[],[P.LOGIN_STATUS]:[],[P.KEEP_ALIVE_RESPONSE]:[],[P.ONLINE_STATUS_EVENT]:[],[P.EXTENSIONS_UPDATED]:[]});K(this,"allListeners",[]);this.eventsSdkClass=e,this.eventsSdkClass=e}on(e,t){e==="*"?this.allListeners.push(t):this.listeners[e].push(t)}off(e,t){if(e==="*")this.allListeners=this.allListeners.filter(n=>n!==t);else{const r=this.listeners[e].filter(o=>o!==t);this.listeners={...this.listeners,[e]:r}}}emit(e,t){this.eventsSdkClass.socketIoClass.lastEventTimestamp=new Date().getTime(),this.listeners[e].forEach(r=>r({name:e,data:t}));const n={name:e,data:t};this.allListeners.forEach(r=>r(n))}}class ms{constructor(e){K(this,"options");K(this,"servers",[]);K(this,"URLList",[]);K(this,"server");K(this,"URL");K(this,"socket");K(this,"mainServer");K(this,"alreadyAttemptedOtherServers",[]);K(this,"authClass",new en(this));K(this,"socketIoClass",new un(this));K(this,"loggerClass",new gs(this));K(this,"eventEmitterClass",new ys(this));K(this,"getCircularReplacer",()=>{const e=new WeakSet;return(t,n)=>{if(!(t==="socket"||t==="io"||t==="nsps")){if(typeof n=="object"&&n!==null){if(e.has(n))return;e.add(n)}return n}}});this.options={...nn,...e}}on(e,t){this.eventEmitterClass.on(e,t)}emit(e,...t){this.socketIoClass.io&&this.socketIoClass.io.emit(e,...t)}connect(e){e===at.MAIN&&this.findMainServer(),e===at.NEXT&&this.findNextServer(),this.socketIoClass.doReconnect=!0;try{this.loggerClass.init()}catch(t){console.error(t)}this.socketIoClass.initSocketConnection(),this.socketIoClass.initSocketEvents(),this.socketIoClass.initKeepAlive()}disconnect(){this.socketIoClass.doReconnect=!1,this.socketIoClass.closeAllConnections(),this.loggerClass.stop()}clearKeepAliveInterval(){this.socketIoClass.clearKeepAliveInterval()}findMainServer(){this.servers.length?(this.mainServer=this.servers.reduce((e,t)=>t.Priority>e.Priority?t:e),this.server=this.mainServer):this.URLList.length&&(this.URL=this.URLList[0])}findNextServer(){if(this.servers.length&&this.server)if(this.server.Priority===this.mainServer.Priority){let e=this.servers.filter(t=>t.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(t.Priority)+1===0);e.length||(this.alreadyAttemptedOtherServers=[],e=this.servers.filter(t=>t.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(t.Priority)+1===0)),e.length&&(this.server=e.reduce((t,n)=>n.Priority>t.Priority?n:t),this.alreadyAttemptedOtherServers.push(this.server.Priority))}else this.server=this.mainServer;else if(this.URLList.length)if(this.URL===this.URLList[0]){let e=this.URLList.filter(t=>t!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(t)+1===0);e.length||(this.alreadyAttemptedOtherServers=[],e=this.URLList.filter(t=>t!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(t)+1===0)),e.length&&(this.URL=e[0],this.alreadyAttemptedOtherServers.push(this.URL))}else this.URL=this.URLList[0]}async init(){const e=await this.authClass.login();return e&&this.authClass.onLoginResponse(e),!0}getCurrentMonitorServer(){return this.server}}exports.CallStatusEnum=Te;exports.CallTypeEnum=Ae;exports.ConnectionStatusEnum=pt;exports.DebugOption=ut;exports.DialerTypeEnum=Ne;exports.DirectionEnum=_e;exports.DoNotCallMeStatusCodeEnum=Oe;exports.EventsEnum=P;exports.ExtensionEventReasonEnum=Yt;exports.ExtensionHangupCauseEnum=Le;exports.LoginType=st;exports.QueueEventReasonEnum=Re;exports.ServerListenerEventsEnum=Qt;exports.ServerParameter=at;exports.default=ms;
18
+ `,102:"\f",114:"\r"},M=function(){throw k=W=null,SyntaxError()},Y=function(){for(var w,O,C,D,S,x=W,U=x.length;U>k;)switch(S=x.charCodeAt(k)){case 9:case 10:case 13:case 32:k++;break;case 123:case 125:case 91:case 93:case 58:case 44:return w=j?x.charAt(k):x[k],k++,w;case 34:for(w="@",k++;U>k;)if(S=x.charCodeAt(k),32>S)M();else if(S==92)switch(S=x.charCodeAt(++k)){case 92:case 34:case 47:case 98:case 116:case 110:case 102:case 114:w+=H[S],k++;break;case 117:for(O=++k,C=k+4;C>k;k++)S=x.charCodeAt(k),S>=48&&57>=S||S>=97&&102>=S||S>=65&&70>=S||M();w+=G("0x"+x.slice(O,k));break;default:M()}else{if(S==34)break;for(S=x.charCodeAt(k),O=k;S>=32&&S!=92&&S!=34;)S=x.charCodeAt(++k);w+=x.slice(O,k)}if(x.charCodeAt(k)==34)return k++,w;M();default:if(O=k,S==45&&(D=!0,S=x.charCodeAt(++k)),S>=48&&57>=S){for(S==48&&(S=x.charCodeAt(k+1),S>=48&&57>=S)&&M(),D=!1;U>k&&(S=x.charCodeAt(k),S>=48&&57>=S);k++);if(x.charCodeAt(k)==46){for(C=++k;U>C&&(S=x.charCodeAt(C),S>=48&&57>=S);C++);C==k&&M(),k=C}if(S=x.charCodeAt(k),S==101||S==69){for(S=x.charCodeAt(++k),(S==43||S==45)&&k++,C=k;U>C&&(S=x.charCodeAt(C),S>=48&&57>=S);C++);C==k&&M(),k=C}return+x.slice(O,k)}if(D&&M(),x.slice(k,k+4)=="true")return k+=4,!0;if(x.slice(k,k+5)=="false")return k+=5,!1;if(x.slice(k,k+4)=="null")return k+=4,null;M()}return"$"},gt=function(w){var O,C;if(w=="$"&&M(),typeof w=="string"){if((j?w.charAt(0):w[0])=="@")return w.slice(1);if(w=="["){for(O=[];w=Y(),w!="]";C||(C=!0))C&&(w==","?(w=Y(),w=="]"&&M()):M()),w==","&&M(),O.push(gt(w));return O}if(w=="{"){for(O={};w=Y(),w!="}";C||(C=!0))C&&(w==","?(w=Y(),w=="}"&&M()):M()),(w==","||typeof w!="string"||(j?w.charAt(0):w[0])!="@"||Y()!=":")&&M(),O[w.slice(1)]=gt(Y());return O}M()}return w},oe=function(w,O,C){var D=ie(w,O,C);D===h?delete w[O]:w[O]=D},ie=function(w,O,C){var D,S=w[O];if(typeof S=="object"&&S)if(d.call(S)==y)for(D=S.length;D--;)oe(S,D,C);else u(S,function(x){oe(S,x,C)});return C.call(w,O,S)};p.parse=function(w,O){var C,D;return k=0,W=""+w,C=gt(Y()),Y()!="$"&&M(),k=W=null,O&&d.call(O)==i?ie((D={},D[""]=C,D),"",O):C}}}})(this)},{}],48:[function(s,e){function t(n,r){var o=[];r=r||0;for(var u=r||0;u<n.length;u++)o[u-r]=n[u];return o}e.exports=t},{}]},{},[1])(1)}const rn=Object.freeze(Object.defineProperty({__proto__:null,default:sn},Symbol.toStringTag,{value:"Module"})),on=Object.assign({"./v1_3_7.js":rn}),an=/v\d+_\d+_\d+/;function cn(s){return typeof s=="function"}const Wt=Object.entries(on).reduce((s,e)=>{var r;const t=e[1].default,n=(r=e[0].match(an))==null?void 0:r[0];return cn(t)&&n&&(s[n]=t()),s},{}),Ee=s=>{if(s in Wt)return Wt[s];throw new Error(`Socket version ${s} not found`)},hn=(s,...e)=>Ee(s)(...e),ln={...Wt,getSocketVersion:Ee,makeSocketVersion:hn};var Te=(s=>(s.RINGING="Ringing",s.TALKING="Talking",s.DIALING="Dialing",s.HOLD="Hold",s))(Te||{}),Ae=(s=>(s.INCOMING="Incoming",s.OUTGOING="Outgoing",s))(Ae||{}),pt=(s=>(s.CONNECTED="connected",s.DISCONNECTED="disconnected",s.TRYING_TO_CONNECT="tryingToConnect",s))(pt||{}),Ne=(s=>(s.AUTOMATIC="Automatic",s.IVR="IVR",s))(Ne||{}),_e=(s=>(s.INCOMINC="Incoming",s.OUTGOING="Outgoing",s.SPY="Spy",s.CLICK2CALL="Click2Call",s))(_e||{}),Oe=(s=>(s.RESPONSE_FROM_API_VALID="RESPONSE_FROM_API_VALID",s.RESPONSE_FROM_API_INVALID="RESPONSE_FROM_API_INVALID",s))(Oe||{}),P=(s=>(s.ALL_DIALER_STATUS="AllDialersStatus",s.ALL_EXTENSION_STATUS="AllExtensionsStatus",s.ALL_USERS_STATUS="AllUsersStatus",s.CONNECT="connect",s.DISCONNECT="disconnect",s.CONNECT_ERROR_EVENT="connect_error",s.EXTENSION_EVENT="ExtensionEvent",s.KEEP_ALIVE="keepalive",s.KEEP_ALIVE_RESPONSE="keepaliveResponse",s.LOGIN_STATUS="loginStatus",s.LOGIN_SUCCESS="loginSuccess",s.QUEUE_EVENT="QueueEvent",s.ONLINE_STATUS_EVENT="onlineStatusEvent",s.DIALER_EVENT="DialerEvent",s.EXTENSIONS_UPDATED="ExtensionsUpdated",s))(P||{}),Yt=(s=>(s.NEWCALL="NEWCALL",s.ANSWER="ANSWER",s.HOLD="HOLD",s.UNHOLD="UNHOLD",s.HANGUP="HANGUP",s.USER_STATUS_UPDATE="userStatusUpdate",s))(Yt||{}),Le=(s=>(s.NORMAL_HANGUP="Normal hangup",s.USER_BUSY="User busy",s.CALL_REJECTED="Call Rejected",s.UNALLOCATED_NUMBER="Unallocated (unassigned) number",s.UNKNOWN="Unknown",s.NO_USER_RESPONDING="No user responding",s.USER_ALERTING="User alerting, no answer",s.ANSWERED_ELSEWHERE="Answered elsewhere",s))(Le||{}),Re=(s=>(s.ANSWER="ANSWER",s.ABANDONED="ABANDONED",s.EXIT="EXIT",s.JOIN="JOIN",s))(Re||{});class wt{static mapExtensionEvent(e){var u,h;const t=e.reason;let n,r;e.data.currentCall&&(r=this.mapExtensionCall(e,e.data.currentCall));const o=this.mapExtensionData(e,e.data);return t===Yt.HANGUP?n={...e,reason:t,data:{...o,currentCall:r?{...r,duration:r.callAnswered_UTC_CLIENT?Date.now()-r.callAnswered_UTC_CLIENT:0}:void 0,calls:(u=e.data.calls)==null?void 0:u.map(d=>{const c=this.mapExtensionCall(e,d);return{...c,duration:c.callAnswered_UTC_CLIENT?Date.now()-c.callAnswered_UTC_CLIENT:0}})}}:n={...e,data:{...o,currentCall:r,calls:(h=e.data.calls)==null?void 0:h.map(d=>this.mapExtensionCall(e,d))},reason:t},n}static mapAllExtensionStatus(e){return{...e,extensions:e.extensions.map(t=>{var n;return{...this.mapExtensionData(e,t),currentCall:t.currentCall?this.mapExtensionCall(e,t.currentCall):void 0,calls:(n=t.calls)==null?void 0:n.map(r=>this.mapExtensionCall(e,r))}})}}static mapExtensionData(e,t){return this.configureUTCForObject(t,[{key:"lastAnsweredCallEventEpoch",format:"sec"},{key:"lastCallEventEpoch",format:"sec"},{key:"lastHangupCallEpoch",format:"sec"},{key:"representativeUpdated",format:"ms"}],e.servertime,e.servertimeoffset)}static mapExtensionCall(e,t){return this.configureUTCForObject(t,[{key:"callAnswered",format:"sec"},{key:"callStarted",format:"sec"}],e.servertime,e.servertimeoffset)}static mapQueueCall(e,t){return this.configureUTCForObject(t,[{key:"JoinTimeStamp",format:"sec"},{key:"VHJoinTimeStamp",format:"sec"}],e.servertime,e.servertimeoffset)}static mapLoginStatusEvent(e){return{...e,queues:e.queues.map(t=>({...t,Calls:t.Calls.map(n=>this.mapQueueCall(e,n))}))}}static mapQueueEvent(e){return{...e,data:{...e.data,Calls:e.data.Calls.map(t=>this.mapQueueCall(e,t))}}}static assignProperty(e,t,n){e[t]=n}static configureUTCForObject(e,t,n,r){const o=(n-r*60)*1e3,u=Date.now()-o,h={};return t.forEach(d=>{const c=e[d.key],p=d.key;if(c!==0&&typeof c=="number"&&!isNaN(c)){let l=c;d.format==="ms"&&(l=Math.floor(l/1e3));const i=(l-r*60)*1e3;this.assignProperty(h,`${p}_UTC`,i),this.assignProperty(h,`${p}_UTC_CLIENT`,i+u)}else this.assignProperty(h,`${p}_UTC`,0),this.assignProperty(h,`${p}_UTC_CLIENT`,0)}),{...e,...h}}}var Qt=(s=>(s.UPDATE_MONITORED_EXTENSIONS="updateMonitoredExtensions",s.KEEP_ALIVE="keepalive",s))(Qt||{});class un{constructor(e){K(this,"io");K(this,"ioFunction");K(this,"lastEventTimestamp",new Date().getTime());K(this,"doReconnect",!0);K(this,"keepAliveInterval");K(this,"keepReconnectInterval");K(this,"keepReconnectTimeout");K(this,"connected",!1);K(this,"reconnectionTime",20);this.eventsSdkClass=e,this.eventsSdkClass=e,typeof window<"u"&&(window.addEventListener("offline",()=>{this.closeAllConnections()}),window.addEventListener("online",()=>{setTimeout(()=>{this.keepReconnectTimeout&&clearTimeout(this.keepReconnectTimeout),this.eventsSdkClass.connect(at.NEXT)},5e3)})),typeof self<"u"&&typeof window>"u"&&typeof global>"u"&&(self.addEventListener("offline",()=>{this.closeAllConnections()}),self.addEventListener("online",()=>{setTimeout(()=>{this.keepReconnectTimeout&&clearTimeout(this.keepReconnectTimeout),this.eventsSdkClass.connect(at.NEXT)},5e3)}))}getSocketIoFunction(e){const t=e.split("v="),n="v".concat(t[t.length-1]).replaceAll(".","_");this.ioFunction=ln.getSocketVersion(n)}initSocketConnection(){const e=this.eventsSdkClass.authClass.token,t=this.eventsSdkClass.options.protocol,n=this.eventsSdkClass.server;try{const r=n?n.Domain:this.eventsSdkClass.URL,o=n?`${t}://${r}`:this.eventsSdkClass.URL,u={reconnection:!1,upgrade:!1,transports:["websocket"],forceNew:!0,query:{token:e},timeout:this.eventsSdkClass.options.timeout};if(this.ioFunction&&o)this.io=this.ioFunction(o,u),this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{attemptToConnect:o,connectionStatus:pt.TRYING_TO_CONNECT}),this.eventsSdkClass.loggerClass.sdkAttemptToConnect(r);else throw new Error("Socket server url no defined")}catch(r){this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(r)}}clearKeepAliveInterval(){this.keepAliveInterval&&clearInterval(this.keepAliveInterval)}initKeepAlive(){this.keepAliveInterval&&clearInterval(this.keepAliveInterval),this.keepAliveInterval=setInterval(async()=>{if(new Date().getTime()>this.lastEventTimestamp+this.eventsSdkClass.options.keepAliveTimeout&&this.io&&this.eventsSdkClass.authClass.token){this.eventsSdkClass.emit(Qt.KEEP_ALIVE,this.eventsSdkClass.authClass.token),this.eventsSdkClass.loggerClass.keepAliveEmit();return}},this.eventsSdkClass.options.keepAliveTimeout)}closeAllConnections(){var e;this.io&&(this.io.close(),(e=this.io)==null||e.disconnect(),this.io=void 0),this.eventsSdkClass.loggerClass.stop(),kt.clearSessionStorage()}initSocketEvents(){this.io&&this.io.on(P.LOGIN_SUCCESS,e=>this.onLoginSuccessEvent(e,P.LOGIN_SUCCESS)).on(P.QUEUE_EVENT,e=>this.onQueueEvent(e,P.QUEUE_EVENT)).on(P.EXTENSION_EVENT,e=>this.onExtensionEvent(e,P.EXTENSION_EVENT)).on(P.DIALER_EVENT,e=>this.onDialerEvent(e,P.DIALER_EVENT)).on(P.LOGIN_STATUS,e=>this.onLoginStatusEvent(e,P.LOGIN_STATUS)).on(P.ALL_EXTENSION_STATUS,e=>this.onAllExtensionStatus(e,P.ALL_EXTENSION_STATUS)).on(P.ALL_DIALER_STATUS,e=>this.onAllDialerStatus(e,P.ALL_DIALER_STATUS)).on(P.KEEP_ALIVE_RESPONSE,e=>this.onKeepAliveResponse(e)).on(P.EXTENSIONS_UPDATED,e=>this.onExtensionsUpdatedEvent(e,P.EXTENSIONS_UPDATED)).on(P.CONNECT,()=>this.onConnect()).on(P.DISCONNECT,e=>this.onDisconnect(e)).on(P.CONNECT_ERROR_EVENT,e=>this.onConnectError(e))}onLoginSuccessEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onQueueEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,wt.mapQueueEvent(e))}onExtensionEvent(e,t){const n=wt.mapExtensionEvent(e);n&&(this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,n))}onDialerEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onLoginStatusEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,wt.mapLoginStatusEvent(e))}onAllExtensionStatus(e,t){const n=wt.mapAllExtensionStatus(e);this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,n)}onAllDialerStatus(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onKeepAliveResponse(e){if(this.eventsSdkClass.loggerClass.keepAliveResponse(e),e.errorCode){this.initSocketConnection();return}this.connected?this.lastEventTimestamp=new Date().getTime():this.initSocketConnection()}onExtensionsUpdatedEvent(e,t){this.eventsSdkClass.loggerClass.eventLog(t,e),this.eventsSdkClass.eventEmitterClass.emit(t,e)}onConnect(){this.connected=!0,this.keepReconnectInterval&&clearInterval(this.keepReconnectInterval),this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:pt.CONNECTED}),this.eventsSdkClass.loggerClass.start().then(()=>{this.eventsSdkClass.loggerClass.sdkConnectionSuccess()})}onDisconnect(e){this.connected=!1,this.doReconnect&&(this.closeAllConnections(),this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:this.doReconnect?pt.TRYING_TO_CONNECT:pt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkDisconnect([e]),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>120&&(this.reconnectionTime=20),this.eventsSdkClass.connect(at.NEXT)},this.reconnectionTime*1e3))}onConnectError(e){this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:this.doReconnect?pt.TRYING_TO_CONNECT:pt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(e),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>60&&(this.reconnectionTime=20),this.eventsSdkClass.connect(at.NEXT)},this.reconnectionTime*1e3)}}var pn=Object.defineProperty,fn=(s,e,t)=>e in s?pn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,X=(s,e,t)=>(fn(s,typeof e!="symbol"?e+"":e,t),t);const ht=Object.create(null);ht.open="0";ht.close="1";ht.ping="2";ht.pong="3";ht.message="4";ht.upgrade="5";ht.noop="6";const _t=Object.create(null);Object.keys(ht).forEach(s=>{_t[ht[s]]=s});const Gt={type:"error",data:"parser error"},Ie=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",xe=typeof ArrayBuffer=="function",Be=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,Zt=({type:s,data:e},t,n)=>Ie&&e instanceof Blob?t?n(e):he(e,n):xe&&(e instanceof ArrayBuffer||Be(e))?t?n(e):he(new Blob([e]),n):n(ht[s]+(e||"")),he=(s,e)=>{const t=new FileReader;return t.onload=function(){const n=t.result.split(",")[1];e("b"+(n||""))},t.readAsDataURL(s)};function le(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}let Ft;function dn(s,e){if(Ie&&s.data instanceof Blob)return s.data.arrayBuffer().then(le).then(e);if(xe&&(s.data instanceof ArrayBuffer||Be(s.data)))return e(le(s.data));Zt(s,!1,t=>{Ft||(Ft=new TextEncoder),e(Ft.encode(t))})}const ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",St=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<ue.length;s++)St[ue.charCodeAt(s)]=s;const gn=s=>{let e=s.length*.75,t=s.length,n,r=0,o,u,h,d;s[s.length-1]==="="&&(e--,s[s.length-2]==="="&&e--);const c=new ArrayBuffer(e),p=new Uint8Array(c);for(n=0;n<t;n+=4)o=St[s.charCodeAt(n)],u=St[s.charCodeAt(n+1)],h=St[s.charCodeAt(n+2)],d=St[s.charCodeAt(n+3)],p[r++]=o<<2|u>>4,p[r++]=(u&15)<<4|h>>2,p[r++]=(h&3)<<6|d&63;return c},yn=typeof ArrayBuffer=="function",te=(s,e)=>{if(typeof s!="string")return{type:"message",data:Ue(s,e)};const t=s.charAt(0);return t==="b"?{type:"message",data:mn(s.substring(1),e)}:_t[t]?s.length>1?{type:_t[t],data:s.substring(1)}:{type:_t[t]}:Gt},mn=(s,e)=>{if(yn){const t=gn(s);return Ue(t,e)}else return{base64:!0,data:s}},Ue=(s,e)=>{switch(e){case"blob":return s instanceof Blob?s:new Blob([s]);case"arraybuffer":default:return s instanceof ArrayBuffer?s:s.buffer}},De="",vn=(s,e)=>{const t=s.length,n=new Array(t);let r=0;s.forEach((o,u)=>{Zt(o,!1,h=>{n[u]=h,++r===t&&e(n.join(De))})})},kn=(s,e)=>{const t=s.split(De),n=[];for(let r=0;r<t.length;r++){const o=te(t[r],e);if(n.push(o),o.type==="error")break}return n};function Sn(){return new TransformStream({transform(s,e){dn(s,t=>{const n=t.length;let r;if(n<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,n);else if(n<65536){r=new Uint8Array(3);const o=new DataView(r.buffer);o.setUint8(0,126),o.setUint16(1,n)}else{r=new Uint8Array(9);const o=new DataView(r.buffer);o.setUint8(0,127),o.setBigUint64(1,BigInt(n))}s.data&&typeof s.data!="string"&&(r[0]|=128),e.enqueue(r),e.enqueue(t)})}})}let Mt;function Ct(s){return s.reduce((e,t)=>e+t.length,0)}function Et(s,e){if(s[0].length===e)return s.shift();const t=new Uint8Array(e);let n=0;for(let r=0;r<e;r++)t[r]=s[0][n++],n===s[0].length&&(s.shift(),n=0);return s.length&&n<s[0].length&&(s[0]=s[0].slice(n)),t}function bn(s,e){Mt||(Mt=new TextDecoder);const t=[];let n=0,r=-1,o=!1;return new TransformStream({transform(u,h){for(t.push(u);;){if(n===0){if(Ct(t)<1)break;const d=Et(t,1);o=(d[0]&128)===128,r=d[0]&127,r<126?n=3:r===126?n=1:n=2}else if(n===1){if(Ct(t)<2)break;const d=Et(t,2);r=new DataView(d.buffer,d.byteOffset,d.length).getUint16(0),n=3}else if(n===2){if(Ct(t)<8)break;const d=Et(t,8),c=new DataView(d.buffer,d.byteOffset,d.length),p=c.getUint32(0);if(p>Math.pow(2,21)-1){h.enqueue(Gt);break}r=p*Math.pow(2,32)+c.getUint32(4),n=3}else{if(Ct(t)<r)break;const d=Et(t,r);h.enqueue(te(o?d:Mt.decode(d),e)),n=0}if(r===0||r>s){h.enqueue(Gt);break}}}})}const Pe=4;function $(s){if(s)return wn(s)}function wn(s){for(var e in $.prototype)s[e]=$.prototype[e];return s}$.prototype.on=$.prototype.addEventListener=function(s,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(e),this};$.prototype.once=function(s,e){function t(){this.off(s,t),e.apply(this,arguments)}return t.fn=e,this.on(s,t),this};$.prototype.off=$.prototype.removeListener=$.prototype.removeAllListeners=$.prototype.removeEventListener=function(s,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+s];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+s],this;for(var n,r=0;r<t.length;r++)if(n=t[r],n===e||n.fn===e){t.splice(r,1);break}return t.length===0&&delete this._callbacks["$"+s],this};$.prototype.emit=function(s){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),t=this._callbacks["$"+s],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(t){t=t.slice(0);for(var n=0,r=t.length;n<r;++n)t[n].apply(this,e)}return this};$.prototype.emitReserved=$.prototype.emit;$.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]};$.prototype.hasListeners=function(s){return!!this.listeners(s).length};const nt=typeof self<"u"?self:typeof window<"u"?window:Function("return this")();function je(s,...e){return e.reduce((t,n)=>(s.hasOwnProperty(n)&&(t[n]=s[n]),t),{})}const Cn=nt.setTimeout,En=nt.clearTimeout;function Rt(s,e){e.useNativeTimers?(s.setTimeoutFn=Cn.bind(nt),s.clearTimeoutFn=En.bind(nt)):(s.setTimeoutFn=nt.setTimeout.bind(nt),s.clearTimeoutFn=nt.clearTimeout.bind(nt))}const Tn=1.33;function An(s){return typeof s=="string"?Nn(s):Math.ceil((s.byteLength||s.size)*Tn)}function Nn(s){let e=0,t=0;for(let n=0,r=s.length;n<r;n++)e=s.charCodeAt(n),e<128?t+=1:e<2048?t+=2:e<55296||e>=57344?t+=3:(n++,t+=4);return t}function _n(s){let e="";for(let t in s)s.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(s[t]));return e}function On(s){let e={},t=s.split("&");for(let n=0,r=t.length;n<r;n++){let o=t[n].split("=");e[decodeURIComponent(o[0])]=decodeURIComponent(o[1])}return e}class Ln extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}class ee extends ${constructor(e){super(),this.writable=!1,Rt(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,n){return super.emitReserved("error",new Ln(e,t,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=te(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){const e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){const t=_n(e);return t.length?"?"+t:""}}const qe="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),Jt=64,Rn={};let pe=0,Tt=0,fe;function de(s){let e="";do e=qe[s%Jt]+e,s=Math.floor(s/Jt);while(s>0);return e}function Fe(){const s=de(+new Date);return s!==fe?(pe=0,fe=s):s+"."+de(pe++)}for(;Tt<Jt;Tt++)Rn[qe[Tt]]=Tt;let Me=!1;try{Me=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const In=Me;function Ve(s){const e=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||In))return new XMLHttpRequest}catch{}if(!e)try{return new nt[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function xn(){}const Bn=function(){return new Ve({xdomain:!1}).responseType!=null}();class Un extends ee{constructor(e){if(super(e),this.polling=!1,typeof location<"u"){const n=location.protocol==="https:";let r=location.port;r||(r=n?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||r!==e.port}const t=e&&e.forceBase64;this.supportsBinary=Bn&&!t,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(e){this.readyState="pausing";const t=()=>{this.readyState="paused",e()};if(this.polling||!this.writable){let n=0;this.polling&&(n++,this.once("pollComplete",function(){--n||t()})),this.writable||(n++,this.once("drain",function(){--n||t()}))}else t()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){const t=n=>{if(this.readyState==="opening"&&n.type==="open"&&this.onOpen(),n.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(n)};kn(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,vn(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(t[this.opts.timestampParam]=Fe()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}request(e={}){return Object.assign(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new ct(this.uri(),e)}doWrite(e,t){const n=this.request({method:"POST",data:e});n.on("success",t),n.on("error",(r,o)=>{this.onError("xhr post error",r,o)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,n)=>{this.onError("xhr poll error",t,n)}),this.pollXhr=e}}class ct extends ${constructor(e,t){super(),Rt(this,t),this.opts=t,this.method=t.method||"GET",this.uri=e,this.data=t.data!==void 0?t.data:null,this.create()}create(){var e;const t=je(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd;const n=this.xhr=new Ve(t);try{n.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let r in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(r)&&n.setRequestHeader(r,this.opts.extraHeaders[r])}}catch{}if(this.method==="POST")try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{n.setRequestHeader("Accept","*/*")}catch{}(e=this.opts.cookieJar)===null||e===void 0||e.addCookies(n),"withCredentials"in n&&(n.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(n.timeout=this.opts.requestTimeout),n.onreadystatechange=()=>{var r;n.readyState===3&&((r=this.opts.cookieJar)===null||r===void 0||r.parseCookies(n)),n.readyState===4&&(n.status===200||n.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof n.status=="number"?n.status:0)},0))},n.send(this.data)}catch(r){this.setTimeoutFn(()=>{this.onError(r)},0);return}typeof document<"u"&&(this.index=ct.requestsCount++,ct.requests[this.index]=this)}onError(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}cleanup(e){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=xn,e)try{this.xhr.abort()}catch{}typeof document<"u"&&delete ct.requests[this.index],this.xhr=null}}onLoad(){const e=this.xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}ct.requestsCount=0;ct.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",ge);else if(typeof addEventListener=="function"){const s="onpagehide"in nt?"pagehide":"unload";addEventListener(s,ge,!1)}}function ge(){for(let s in ct.requests)ct.requests.hasOwnProperty(s)&&ct.requests[s].abort()}const ne=typeof Promise=="function"&&typeof Promise.resolve=="function"?s=>Promise.resolve().then(s):(s,e)=>e(s,0),At=nt.WebSocket||nt.MozWebSocket,ye=!0,Dn="arraybuffer",me=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Pn extends ee{constructor(e){super(e),this.supportsBinary=!e.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const e=this.uri(),t=this.opts.protocols,n=me?{}:je(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=ye&&!me?t?new At(e,t):new At(e):new At(e,t,n)}catch(r){return this.emitReserved("error",r)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t===e.length-1;Zt(n,this.supportsBinary,o=>{try{ye&&this.ws.send(o)}catch{}r&&ne(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=Fe()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}check(){return!!At}}class jn extends ee{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(e=>{const t=bn(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=Sn();r.readable.pipeTo(e.writable),this.writer=r.writable.getWriter();const o=()=>{n.read().then(({done:h,value:d})=>{h||(this.onPacket(d),o())}).catch(h=>{})};o();const u={type:"open"};this.query.sid&&(u.data=`{"sid":"${this.query.sid}"}`),this.writer.write(u).then(()=>this.onOpen())})}))}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t===e.length-1;this.writer.write(n).then(()=>{r&&ne(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this.transport)===null||e===void 0||e.close()}}const qn={websocket:Pn,webtransport:jn,polling:Un},Fn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Mn=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Xt(s){if(s.length>2e3)throw"URI too long";const e=s,t=s.indexOf("["),n=s.indexOf("]");t!=-1&&n!=-1&&(s=s.substring(0,t)+s.substring(t,n).replace(/:/g,";")+s.substring(n,s.length));let r=Fn.exec(s||""),o={},u=14;for(;u--;)o[Mn[u]]=r[u]||"";return t!=-1&&n!=-1&&(o.source=e,o.host=o.host.substring(1,o.host.length-1).replace(/;/g,":"),o.authority=o.authority.replace("[","").replace("]","").replace(/;/g,":"),o.ipv6uri=!0),o.pathNames=Vn(o,o.path),o.queryKey=Kn(o,o.query),o}function Vn(s,e){const t=/\/{2,9}/g,n=e.replace(t,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&n.splice(0,1),e.slice(-1)=="/"&&n.splice(n.length-1,1),n}function Kn(s,e){const t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(n,r,o){r&&(t[r]=o)}),t}let Ke=class ft extends ${constructor(e,t={}){super(),this.binaryType=Dn,this.writeBuffer=[],e&&typeof e=="object"&&(t=e,e=null),e?(e=Xt(e),t.hostname=e.host,t.secure=e.protocol==="https"||e.protocol==="wss",t.port=e.port,e.query&&(t.query=e.query)):t.host&&(t.hostname=Xt(t.host).host),Rt(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=t.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=On(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=Pe,t.transport=e,this.id&&(t.sid=this.id);const n=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new qn[e](n)}open(){let e;if(this.opts.rememberUpgrade&&ft.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)e="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else e=this.transports[0];this.readyState="opening";try{e=this.createTransport(e)}catch{this.transports.shift(),this.open();return}e.open(),this.setTransport(e)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",t=>this.onClose("transport close",t))}probe(e){let t=this.createTransport(e),n=!1;ft.priorWebsocketSuccess=!1;const r=()=>{n||(t.send([{type:"ping",data:"probe"}]),t.once("packet",l=>{if(!n)if(l.type==="pong"&&l.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;ft.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{n||this.readyState!=="closed"&&(p(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{const i=new Error("probe error");i.transport=t.name,this.emitReserved("upgradeError",i)}}))};function o(){n||(n=!0,p(),t.close(),t=null)}const u=l=>{const i=new Error("probe error: "+l);i.transport=t.name,o(),this.emitReserved("upgradeError",i)};function h(){u("transport closed")}function d(){u("socket closed")}function c(l){t&&l.name!==t.name&&o()}const p=()=>{t.removeListener("open",r),t.removeListener("error",u),t.removeListener("close",h),this.off("close",d),this.off("upgrading",c)};t.once("open",r),t.once("error",u),t.once("close",h),this.once("close",d),this.once("upgrading",c),this.upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onOpen(){if(this.readyState="open",ft.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let e=0;const t=this.upgrades.length;for(;e<t;e++)this.probe(this.upgrades[e])}}onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let e=1;for(let t=0;t<this.writeBuffer.length;t++){const n=this.writeBuffer[t].data;if(n&&(e+=An(n)),t>0&&e>this.maxPayload)return this.writeBuffer.slice(0,t);e+=2}return this.writeBuffer}write(e,t,n){return this.sendPacket("message",e,t,n),this}send(e,t,n){return this.sendPacket("message",e,t,n),this}sendPacket(e,t,n,r){if(typeof t=="function"&&(r=t,t=void 0),typeof n=="function"&&(r=n,n=null),this.readyState==="closing"||this.readyState==="closed")return;n=n||{},n.compress=n.compress!==!1;const o={type:e,data:t,options:n};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),r&&this.once("flush",r),this.flush()}close(){const e=()=>{this.onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},n=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():e()}):this.upgrading?n():e()),this}onError(e){ft.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,t){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const t=[];let n=0;const r=e.length;for(;n<r;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}};Ke.protocol=Pe;function Wn(s,e="",t){let n=s;t=t||typeof location<"u"&&location,s==null&&(s=t.protocol+"//"+t.host),typeof s=="string"&&(s.charAt(0)==="/"&&(s.charAt(1)==="/"?s=t.protocol+s:s=t.host+s),/^(https?|wss?):\/\//.test(s)||(typeof t<"u"?s=t.protocol+"//"+s:s="https://"+s),n=Xt(s)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";const r=n.host.indexOf(":")!==-1?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+r+":"+n.port+e,n.href=n.protocol+"://"+r+(t&&t.port===n.port?"":":"+n.port),n}const Gn=typeof ArrayBuffer=="function",Jn=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s.buffer instanceof ArrayBuffer,We=Object.prototype.toString,Xn=typeof Blob=="function"||typeof Blob<"u"&&We.call(Blob)==="[object BlobConstructor]",$n=typeof File=="function"||typeof File<"u"&&We.call(File)==="[object FileConstructor]";function se(s){return Gn&&(s instanceof ArrayBuffer||Jn(s))||Xn&&s instanceof Blob||$n&&s instanceof File}function Ot(s,e){if(!s||typeof s!="object")return!1;if(Array.isArray(s)){for(let t=0,n=s.length;t<n;t++)if(Ot(s[t]))return!0;return!1}if(se(s))return!0;if(s.toJSON&&typeof s.toJSON=="function"&&arguments.length===1)return Ot(s.toJSON(),!0);for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)&&Ot(s[t]))return!0;return!1}function zn(s){const e=[],t=s.data,n=s;return n.data=$t(t,e),n.attachments=e.length,{packet:n,buffers:e}}function $t(s,e){if(!s)return s;if(se(s)){const t={_placeholder:!0,num:e.length};return e.push(s),t}else if(Array.isArray(s)){const t=new Array(s.length);for(let n=0;n<s.length;n++)t[n]=$t(s[n],e);return t}else if(typeof s=="object"&&!(s instanceof Date)){const t={};for(const n in s)Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=$t(s[n],e));return t}return s}function Hn(s,e){return s.data=zt(s.data,e),delete s.attachments,s}function zt(s,e){if(!s)return s;if(s&&s._placeholder===!0){if(typeof s.num=="number"&&s.num>=0&&s.num<e.length)return e[s.num];throw new Error("illegal attachments")}else if(Array.isArray(s))for(let t=0;t<s.length;t++)s[t]=zt(s[t],e);else if(typeof s=="object")for(const t in s)Object.prototype.hasOwnProperty.call(s,t)&&(s[t]=zt(s[t],e));return s}const Yn=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Qn=5;var V;(function(s){s[s.CONNECT=0]="CONNECT",s[s.DISCONNECT=1]="DISCONNECT",s[s.EVENT=2]="EVENT",s[s.ACK=3]="ACK",s[s.CONNECT_ERROR=4]="CONNECT_ERROR",s[s.BINARY_EVENT=5]="BINARY_EVENT",s[s.BINARY_ACK=6]="BINARY_ACK"})(V||(V={}));class Zn{constructor(e){this.replacer=e}encode(e){return(e.type===V.EVENT||e.type===V.ACK)&&Ot(e)?this.encodeAsBinary({type:e.type===V.EVENT?V.BINARY_EVENT:V.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return(e.type===V.BINARY_EVENT||e.type===V.BINARY_ACK)&&(t+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(t+=e.nsp+","),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){const t=zn(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}}function ve(s){return Object.prototype.toString.call(s)==="[object Object]"}class re extends ${constructor(e){super(),this.reviver=e}add(e){let t;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);const n=t.type===V.BINARY_EVENT;n||t.type===V.BINARY_ACK?(t.type=n?V.EVENT:V.ACK,this.reconstructor=new ts(t),t.attachments===0&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else if(se(e)||e.base64)if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let t=0;const n={type:Number(e.charAt(0))};if(V[n.type]===void 0)throw new Error("unknown packet type "+n.type);if(n.type===V.BINARY_EVENT||n.type===V.BINARY_ACK){const o=t+1;for(;e.charAt(++t)!=="-"&&t!=e.length;);const u=e.substring(o,t);if(u!=Number(u)||e.charAt(t)!=="-")throw new Error("Illegal attachments");n.attachments=Number(u)}if(e.charAt(t+1)==="/"){const o=t+1;for(;++t&&!(e.charAt(t)===","||t===e.length););n.nsp=e.substring(o,t)}else n.nsp="/";const r=e.charAt(t+1);if(r!==""&&Number(r)==r){const o=t+1;for(;++t;){const u=e.charAt(t);if(u==null||Number(u)!=u){--t;break}if(t===e.length)break}n.id=Number(e.substring(o,t+1))}if(e.charAt(++t)){const o=this.tryParse(e.substr(t));if(re.isPayloadValid(n.type,o))n.data=o;else throw new Error("invalid payload")}return n}tryParse(e){try{return JSON.parse(e,this.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case V.CONNECT:return ve(t);case V.DISCONNECT:return t===void 0;case V.CONNECT_ERROR:return typeof t=="string"||ve(t);case V.EVENT:case V.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&Yn.indexOf(t[0])===-1);case V.ACK:case V.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class ts{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const t=Hn(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const es=Object.freeze(Object.defineProperty({__proto__:null,Decoder:re,Encoder:Zn,get PacketType(){return V},protocol:Qn},Symbol.toStringTag,{value:"Module"}));function rt(s,e,t){return s.on(e,t),function(){s.off(e,t)}}const ns=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Ge extends ${constructor(e,t,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[rt(e,"open",this.onopen.bind(this)),rt(e,"packet",this.onpacket.bind(this)),rt(e,"error",this.onerror.bind(this)),rt(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){if(ns.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const n={type:V.EVENT,data:t};if(n.options={},n.options.compress=this.flags.compress!==!1,typeof t[t.length-1]=="function"){const o=this.ids++,u=t.pop();this._registerAckCallback(o,u),n.id=o}const r=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!r||!this.connected)||(this.connected?(this.notifyOutgoingListeners(n),this.packet(n)):this.sendBuffer.push(n)),this.flags={},this}_registerAckCallback(e,t){var n;const r=(n=this.flags.timeout)!==null&&n!==void 0?n:this._opts.ackTimeout;if(r===void 0){this.acks[e]=t;return}const o=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let u=0;u<this.sendBuffer.length;u++)this.sendBuffer[u].id===e&&this.sendBuffer.splice(u,1);t.call(this,new Error("operation has timed out"))},r);this.acks[e]=(...u)=>{this.io.clearTimeoutFn(o),t.apply(this,[null,...u])}}emitWithAck(e,...t){const n=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((r,o)=>{t.push((u,h)=>n?u?o(u):r(h):r(u)),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]=="function"&&(t=e.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((r,...o)=>n!==this._queue[0]?void 0:(r!==null?n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(r)):(this._queue.shift(),t&&t(null,...o)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;const t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:V.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t)}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case V.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case V.EVENT:case V.BINARY_EVENT:this.onevent(e);break;case V.ACK:case V.BINARY_ACK:this.onack(e);break;case V.DISCONNECT:this.ondisconnect();break;case V.CONNECT_ERROR:this.destroy();const t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t);break}}onevent(e){const t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const n of t)n.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let n=!1;return function(...r){n||(n=!0,t.packet({type:V.ACK,id:e,data:r}))}}onack(e){const t=this.acks[e.id];typeof t=="function"&&(t.apply(this,e.data),delete this.acks[e.id])}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:V.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const t=this._anyOutgoingListeners.slice();for(const n of t)n.apply(this,e.data)}}}function dt(s){s=s||{},this.ms=s.min||100,this.max=s.max||1e4,this.factor=s.factor||2,this.jitter=s.jitter>0&&s.jitter<=1?s.jitter:0,this.attempts=0}dt.prototype.duration=function(){var s=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*s);s=Math.floor(e*10)&1?s+t:s-t}return Math.min(s,this.max)|0};dt.prototype.reset=function(){this.attempts=0};dt.prototype.setMin=function(s){this.ms=s};dt.prototype.setMax=function(s){this.max=s};dt.prototype.setJitter=function(s){this.jitter=s};class Ht extends ${constructor(e,t){var n;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,Rt(this,t),this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((n=t.randomizationFactor)!==null&&n!==void 0?n:.5),this.backoff=new dt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;const r=t.parser||es;this.encoder=new r.Encoder,this.decoder=new r.Decoder,this._autoConnect=t.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new Ke(this.uri,this.opts);const t=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const r=rt(t,"open",function(){n.onopen(),e&&e()}),o=h=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",h),e?e(h):this.maybeReconnectOnOpen()},u=rt(t,"error",o);if(this._timeout!==!1){const h=this._timeout,d=this.setTimeoutFn(()=>{r(),o(new Error("timeout")),t.close()},h);this.opts.autoUnref&&d.unref(),this.subs.push(()=>{this.clearTimeoutFn(d)})}return this.subs.push(r),this.subs.push(u),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(rt(e,"ping",this.onping.bind(this)),rt(e,"data",this.ondata.bind(this)),rt(e,"error",this.onerror.bind(this)),rt(e,"close",this.onclose.bind(this)),rt(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(t){this.onclose("parse error",t)}}ondecoded(e){ne(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new Ge(this,e,t),this.nsps[e]=n),n}_destroy(e){const t=Object.keys(this.nsps);for(const n of t)if(this.nsps[n].active)return;this._close()}_packet(e){const t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(e,t){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(r=>{r?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",r)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const vt={};function Lt(s,e){typeof s=="object"&&(e=s,s=void 0),e=e||{};const t=Wn(s,e.path||"/socket.io"),n=t.source,r=t.id,o=t.path,u=vt[r]&&o in vt[r].nsps,h=e.forceNew||e["force new connection"]||e.multiplex===!1||u;let d;return h?d=new Ht(n,e):(vt[r]||(vt[r]=new Ht(n,e)),d=vt[r]),t.query&&!e.query&&(e.query=t.queryKey),d.socket(t.path,e)}Object.assign(Lt,{Manager:Ht,Socket:Ge,io:Lt,connect:Lt});let Nt;const ss=new Uint8Array(16);function rs(){if(!Nt&&(Nt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Nt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Nt(ss)}const z=[];for(let s=0;s<256;++s)z.push((s+256).toString(16).slice(1));function os(s,e=0){return z[s[e+0]]+z[s[e+1]]+z[s[e+2]]+z[s[e+3]]+"-"+z[s[e+4]]+z[s[e+5]]+"-"+z[s[e+6]]+z[s[e+7]]+"-"+z[s[e+8]]+z[s[e+9]]+"-"+z[s[e+10]]+z[s[e+11]]+z[s[e+12]]+z[s[e+13]]+z[s[e+14]]+z[s[e+15]]}const is=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ke={randomUUID:is};function as(s,e,t){if(ke.randomUUID&&!e&&!s)return ke.randomUUID();s=s||{};const n=s.random||(s.rng||rs)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){t=t||0;for(let r=0;r<16;++r)e[t+r]=n[r];return e}return os(n)}function cs(s,e){const t=e.map(r=>JSON.stringify(r)).join(" "),n=new Date().toISOString();return JSON.stringify({level:s,time:n,message:t})}function hs(s,e){const t=JSON.parse(s);return e.forEach(n=>delete t[n]),t}function ls(s){if(typeof s=="object"&&s!==null)return s;try{return JSON.parse(s)}catch{return{extraData:s}}}function us(s){const e=/\(([^)]+)\)/,t=s.match(e);if(t&&t[1]){const n=t[1].split(";");for(let r of n)if(r=r.trim(),r.startsWith("Windows")||r.startsWith("Macintosh")||r.startsWith("Linux"))return r}return"Unknown"}function Se(s){return(...e)=>new Promise((t,n)=>{try{const r=s(...e);t(r)}catch(r){n(r)}})}const ps={reconnection:!0,reconnectionDelay:5e3,reconnectionAttempts:10,upgrade:!1,transports:["websocket"],debug:!1},Vt={logToConsole:!0,overloadGlobalConsole:!1,socketEmitInterval:6e4},ot={CREATE:"Create",READ:"Read",UPDATE:"Update",DELETE:"Delete",CONVERT:"Convert",DOWNLOAD:"Download",UPLOAD:"Upload",ENCRYPT:"Encrypt",DECRYPT:"Decrypt",FILTER:"Filter",INPUT:"Input",OUTPUT:"Output",PLUGIN:"Plugin",LOGIN:"Login",LOGOUT:"Logout",REFRESH:"Refresh",CHECK:"Check",WEBHOOK:"Webhook",WSCONNECT:"WSConnect"},fs={Create:1,Read:2,Update:3,Delete:4,Convert:5,Download:6,Upload:7,Encrypt:8,Decrypt:9,Filter:10,Input:11,Output:12,Plugin:13,Login:14,Logout:15,Refresh:16,Check:17,Webhook:18,WSConnect:19},it={INFO:"info",WARNING:"warning",MODIFY:"modify",ERROR:"error",VIEW:"view"},Q={INFO:"info",WARNING:"warning",ERROR:"error",DEBUG:"debug"};let Z=console;class ds{constructor(e){X(this,"logToConsole"),X(this,"overloadGlobalConsole"),X(this,"system"),X(this,"socketEmitInterval"),X(this,"storageId"),X(this,"emitInProgress"),X(this,"queue"),X(this,"processing"),X(this,"storageInitialized"),X(this,"interval"),X(this,"logIndex"),X(this,"socket"),X(this,"requestUrl"),X(this,"staticObject",{}),X(this,"localObject",{}),X(this,"isGetItemAsync"),X(this,"isSetItemAsync"),X(this,"getItem"),X(this,"setItem"),X(this,"parseLog"),X(this,"_logMethod"),X(this,"_warnMethod"),X(this,"_errorMethod"),X(this,"_debugMethod");const{loggerOptions:t}=e;if(!t.system)throw new Error("Config property 'system' should be provided!");this.isGetItemAsync=t.isGetItemAsync||!1,this.isSetItemAsync=t.isSetItemAsync||!1,this.setupStorageFunctions(t.getItem,t.setItem,t.parseLog),this.system=t.system,this.socketEmitInterval=t.socketEmitInterval||Vt.socketEmitInterval,this.logToConsole=t.logToConsole!==void 0?t.logToConsole:Vt.logToConsole,this.overloadGlobalConsole=t.overloadGlobalConsole!==void 0?t.overloadGlobalConsole:Vt.overloadGlobalConsole,this.storageId=this.getStorageName(),this.queue=[],this.processing=!1,this.storageInitialized=!1,this.emitInProgress=!1,this.logIndex=0,this.init(e)}setupStorageFunctions(e,t,n){this.getItem=e&&typeof e=="function"?this.isGetItemAsync?e:Se(e):this.defaultGetItemFunction,this.setItem=t&&typeof t=="function"?this.isSetItemAsync?t:Se(t):this.defaultSetItemFunction,this.parseLog=n&&typeof n=="function"?n:cs}sendHttpRequest(e){if(!this.requestUrl)throw new Error("requestUrl is not provided");const t={Data:e};return fetch(this.requestUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}init(e){const{socket:t,url:n,requestUrl:r,socketOptions:o={}}=e;this._logMethod=Z.log.bind(Z),this._warnMethod=Z.warn.bind(Z),this._errorMethod=Z.error.bind(Z),this._debugMethod=Z.debug.bind(Z),this.initStorage().then(()=>{if(t)this.socket=t;else if(n)this.socket=this.createConnection(n,o);else if(r)this.requestUrl=r;else throw new Error("Must provide either a 'socket', 'requestUrl' or a 'url' for logger requests");this.interval=setInterval(async()=>{await this.emitLogs()},this.socketEmitInterval),this.overloadGlobalConsole&&this._overloadConsole()})}createConnection(e,t){let n={...ps};return t&&(n={...n,...t}),Lt(e,n)}async emitLogs(){if(!this.emitInProgress)try{const e=await this.getItem(this.storageId),t=JSON.parse(e||"{}"),n={...this.localObject,...t};if(!Object.keys(n).length)return;const r=[];this.emitInProgress=!0;const o=Object.keys(n);if(!o.length)return;if((!this.socket||!this.socket.connected)&&!this.requestUrl)throw new Error("Log request can't be sent. Socket is disconnected or requestUrl is not provided");const u=[];for(const c of o){const p=ls(n[c]),l={...this.staticObject,...p},i=this.populateSendingLog(l);i.Body&&typeof i.Body=="string"&&(i.Body=JSON.parse(i.Body)),this.socket?this.socket.emit("Log",i):this.requestUrl&&u.push(i),r.push(c)}u.length&&await this.sendHttpRequest(u);const h=await this.getItem(this.storageId);if(!h)return;const d=hs(h,r);this.localObject={},await this.setItem(this.storageId,JSON.stringify(d))}catch(e){this._errorMethod(e)}finally{this.emitInProgress=!1}}populateSendingLog(e){const t={...e},n=t.ActionName;return n&&(t.ActionID=fs[n]),t}setupStaticFields(e){this.staticObject={...e}}populateMetaData(){const e=new Date;let t;typeof window<"u"&&typeof window.document<"u"?t=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(t=self.navigator.userAgent);let n;return t&&(n=us(t)),{System:this.system,DateTime:e,UserAgent:t,OSVersion:n}}async stop(){!this.socket||!this.socket.connected||(clearInterval(this.interval),await this.emitLogs(),this.socket.disconnect())}async start(){var e;this.socket&&this.socket.connected||((e=this.socket)==null||e.connect(),this.interval=setInterval(async()=>{await this.emitLogs()},this.socketEmitInterval))}_overloadConsole(){Z=Object.assign(Z,{log:e=>{this.log(e)},warn:e=>{this.warn(e)},error:e=>{this.error(e)},debug:e=>{this.debug(e)}})}async initStorage(){const e=await this.getItem(this.storageId);(!e||typeof e!="string")&&(await this.setItem(this.storageId,JSON.stringify({})),this.storageInitialized=!0)}async resetStorage(){await this.setItem(this.storageId,JSON.stringify({}))}getStorageName(){const e=as();return this.system.toString().toUpperCase()+e+Date.now()}async processLog(...e){try{if(e.length<2)return;const t=e[0],n=e[1],r=this.formItemKey(t);if(!this.storageInitialized){this.localObject={...this.localObject,[r]:n};return}const o=await this.getItem(this.storageId);if(!o)return;const u=JSON.parse(o);u[r]=JSON.stringify(n),await this.setItem(this.storageId,JSON.stringify(u))}catch(t){this._errorMethod(t)}}async processQueue(){if(this.processing||this.queue.length===0)return;const e=this.queue.shift();e&&(this.processing=!0,await this.processLog(...e).finally(()=>{this.processing=!1,this.processQueue()}))}log(e){const t={...this.populateMetaData(),...e},n=["INFO",t];this.queue.push(n),this.logToConsole&&this._logMethod.apply(Z,[t]),this.processQueue()}warn(e){const t=["WARN",e];this.queue.push(t),this.logToConsole&&this._warnMethod.apply(Z,[e]),this.processQueue()}error(e){const t=["ERROR",e];this.queue.push(t),this.logToConsole&&this._errorMethod.apply(Z,[e]),this.processQueue()}debug(e){const t=["DEBUG",e];this.queue.push(t),this.logToConsole&&this._debugMethod.apply(Z,[e]),this.processQueue()}async defaultGetItemFunction(e){return localStorage.getItem(e)}async defaultSetItemFunction(e,t){try{localStorage.setItem(e,t)}catch(n){this._errorMethod(n)}}formItemKey(e){const t=new Date().toISOString();return this.logIndex++,`${e}-${this.system}-${t}-${this.logIndex}`}}class gs{constructor(e){K(this,"storageLogger");this.eventsSdkClass=e,this.eventsSdkClass=e}init(){if(!this.eventsSdkClass.options.useLogger)return;if(this.eventsSdkClass.options.storageLoggerInstance){this.storageLogger=this.eventsSdkClass.options.storageLoggerInstance;return}let e;this.eventsSdkClass.options.loggerSocketConnection&&(e=this.eventsSdkClass.options.loggerSocketConnection),this.eventsSdkClass.socketIoClass.ioFunction&&!e&&(e=this.eventsSdkClass.socketIoClass.ioFunction(this.eventsSdkClass.options.loggerServer,this.eventsSdkClass.options.loggerConnectOptions)),e&&(this.storageLogger=new ds({socket:e,loggerOptions:this.eventsSdkClass.options.loggerConfig}))}async start(){this.storageLogger&&await this.storageLogger.start()}stop(){this.storageLogger&&this.storageLogger.stop()}log(e){this.eventsSdkClass.options.useLogger&&(this.storageLogger?e.Level===Q.INFO?this.storageLogger.log(e):e.Level===Q.ERROR&&this.storageLogger.error(e):e.Level===Q.INFO?console.log(e):e.Level===Q.ERROR&&console.error(e))}sdkConnectionSuccess(){const e={...this.eventsSdkClass.options,token:"CENSORED",password:"CENSORED"};this.log({Message:`Sdk connected to the socket server ${this.eventsSdkClass.server&&this.eventsSdkClass.server.Domain?this.eventsSdkClass.server.Domain:this.eventsSdkClass.URL}`,Body:JSON.stringify(e,this.eventsSdkClass.getCircularReplacer()),ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Connection established",StatusCode:200,Level:Q.INFO,LogType:it.INFO})}sdkDisconnect(e){this.log({Message:`Sdk disconnected from the socket server ${this.eventsSdkClass.server&&this.eventsSdkClass.server.Domain?this.eventsSdkClass.server.Domain:this.eventsSdkClass.URL} (${e})`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Connection closed",StatusCode:200,Level:Q.INFO,LogType:it.INFO})}sdkAttemptToConnect(e){this.log({Message:`${this.eventsSdkClass.options.loggerConfig.system} is trying to connect to WS server ${e}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Switching Protocols",StatusCode:101,Level:Q.INFO,LogType:it.INFO})}sdkAttemptToConnectError(e){this.log({Message:`${e}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Connection error",StatusCode:500,Level:Q.ERROR,LogType:it.ERROR})}loginError(e,t,n,r){this.log({Message:`External login request error with the login type ${e} ${e===st.TOKEN?n:r}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"External login error",StatusCode:t||400,Level:Q.ERROR,LogType:it.ERROR})}getSettingsError(e,t){this.log({Message:`Get settings error with token ${e}, error: ${t}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:it.ERROR})}refreshTokenError(e,t,n){this.log({Message:`Refresh token error with old refresh token ${e}, url: ${t}, error: ${n}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:it.ERROR})}keepAliveEmit(){this.log({Message:`Keep alive event emitted with this token: ${this.eventsSdkClass.authClass.token}`,ActionName:ot.WSCONNECT,isShowClient:!1,Level:Q.INFO,LogType:it.INFO})}keepAliveResponse(e){this.log({Message:`Keep alive response: ${JSON.stringify(e)}`,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Successful",StatusCode:200,Level:Q.INFO,LogType:it.INFO})}eventLog(e,t){const n={[ut.FULL]:[],[ut.BOOTSTRAP]:[P.LOGIN_STATUS,P.LOGIN_SUCCESS,P.ALL_EXTENSION_STATUS,P.ALL_DIALER_STATUS],[ut.DEBUG_EXTENSIONS]:[P.ALL_EXTENSION_STATUS,P.EXTENSION_EVENT,P.EXTENSIONS_UPDATED],[ut.DEBUG_DIALER]:[P.ALL_DIALER_STATUS,P.DIALER_EVENT],[ut.DEBUG_QUEUE]:[P.QUEUE_EVENT]};this.eventsSdkClass.options.debugOption&&(n[this.eventsSdkClass.options.debugOption].includes(e)||this.eventsSdkClass.options.debugOption===ut.FULL)&&this.log({Message:`Event name: ${e}`,Body:t,ActionName:ot.WSCONNECT,isShowClient:!1,Status:"Successful",Level:Q.INFO,LogType:it.INFO})}}class ys{constructor(e){K(this,"listeners",{[P.ALL_EXTENSION_STATUS]:[],[P.ALL_DIALER_STATUS]:[],[P.ALL_USERS_STATUS]:[],[P.QUEUE_EVENT]:[],[P.EXTENSION_EVENT]:[],[P.DIALER_EVENT]:[],[P.LOGIN_SUCCESS]:[],[P.LOGIN_STATUS]:[],[P.KEEP_ALIVE_RESPONSE]:[],[P.ONLINE_STATUS_EVENT]:[],[P.EXTENSIONS_UPDATED]:[]});K(this,"allListeners",[]);this.eventsSdkClass=e,this.eventsSdkClass=e}on(e,t){e==="*"?this.allListeners.push(t):this.listeners[e].push(t)}off(e,t){if(e==="*")this.allListeners=this.allListeners.filter(n=>n!==t);else{const r=this.listeners[e].filter(o=>o!==t);this.listeners={...this.listeners,[e]:r}}}emit(e,t){this.eventsSdkClass.socketIoClass.lastEventTimestamp=new Date().getTime(),this.listeners[e].forEach(r=>r({name:e,data:t}));const n={name:e,data:t};this.allListeners.forEach(r=>r(n))}}class ms{constructor(e){K(this,"options");K(this,"servers",[]);K(this,"URLList",[]);K(this,"server");K(this,"URL");K(this,"socket");K(this,"mainServer");K(this,"alreadyAttemptedOtherServers",[]);K(this,"authClass",new en(this));K(this,"socketIoClass",new un(this));K(this,"loggerClass",new gs(this));K(this,"eventEmitterClass",new ys(this));K(this,"getCircularReplacer",()=>{const e=new WeakSet;return(t,n)=>{if(!(t==="socket"||t==="io"||t==="nsps")){if(typeof n=="object"&&n!==null){if(e.has(n))return;e.add(n)}return n}}});this.options={...nn,...e}}on(e,t){this.eventEmitterClass.on(e,t)}emit(e,...t){this.socketIoClass.io&&this.socketIoClass.io.emit(e,...t)}connect(e){e===at.MAIN&&this.findMainServer(),e===at.NEXT&&this.findNextServer(),this.socketIoClass.doReconnect=!0;try{this.loggerClass.init()}catch(t){console.error(t)}this.socketIoClass.initSocketConnection(),this.socketIoClass.initSocketEvents(),this.socketIoClass.initKeepAlive()}disconnect(){this.socketIoClass.doReconnect=!1,this.socketIoClass.closeAllConnections(),this.loggerClass.stop()}clearKeepAliveInterval(){this.socketIoClass.clearKeepAliveInterval()}findMainServer(){this.servers.length?(this.mainServer=this.servers.reduce((e,t)=>t.Priority>e.Priority?t:e),this.server=this.mainServer):this.URLList.length&&(this.URL=this.URLList[0])}findNextServer(){if(this.servers.length&&this.server)if(this.server.Priority===this.mainServer.Priority){let e=this.servers.filter(t=>t.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(t.Priority)+1===0);e.length||(this.alreadyAttemptedOtherServers=[],e=this.servers.filter(t=>t.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(t.Priority)+1===0)),e.length&&(this.server=e.reduce((t,n)=>n.Priority>t.Priority?n:t),this.alreadyAttemptedOtherServers.push(this.server.Priority))}else this.server=this.mainServer;else if(this.URLList.length)if(this.URL===this.URLList[0]){let e=this.URLList.filter(t=>t!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(t)+1===0);e.length||(this.alreadyAttemptedOtherServers=[],e=this.URLList.filter(t=>t!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(t)+1===0)),e.length&&(this.URL=e[0],this.alreadyAttemptedOtherServers.push(this.URL))}else this.URL=this.URLList[0]}async init(){const e=await this.authClass.login();return e&&this.authClass.onLoginResponse(e),!0}getCurrentMonitorServer(){return this.server}}exports.CallStatusEnum=Te;exports.CallTypeEnum=Ae;exports.ConnectionStatusEnum=pt;exports.DebugOption=ut;exports.DialerTypeEnum=Ne;exports.DirectionEnum=_e;exports.DoNotCallMeStatusCodeEnum=Oe;exports.EventsEnum=P;exports.ExtensionEventReasonEnum=Yt;exports.ExtensionHangupCauseEnum=Le;exports.LoginType=st;exports.QueueEventReasonEnum=Re;exports.ServerListenerEventsEnum=Qt;exports.ServerParameter=at;exports.default=ms;
19
19
  //# sourceMappingURL=voicenter-events-sdk.cjs.js.map