@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.
- package/dist/voicenter-events-sdk.cjs.js +1 -1
- package/dist/voicenter-events-sdk.cjs.js.map +1 -1
- package/dist/voicenter-events-sdk.d.ts +23 -21
- package/dist/voicenter-events-sdk.es.js +16 -13
- package/dist/voicenter-events-sdk.es.js.map +1 -1
- package/dist/voicenter-events-sdk.iife.js +1 -1
- package/dist/voicenter-events-sdk.iife.js.map +1 -1
- package/dist/voicenter-events-sdk.umd.js +1 -1
- package/dist/voicenter-events-sdk.umd.js.map +1 -1
- package/package.json +2 -2
|
@@ -15,5 +15,5 @@ var VoicenterEventsSDK=function($,ut){"use strict";var gs=Object.defineProperty;
|
|
|
15
15
|
`+x+pt.join(`,
|
|
16
16
|
`+x)+`
|
|
17
17
|
`+oe+"}":"{"+pt.join(",")+"}":"{}";return U.pop(),ie}};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,Y={92:"\\",34:'"',47:"/",98:"\b",116:" ",110:`
|
|
18
|
-
`,102:"\f",114:"\r"},V=function(){throw k=W=null,SyntaxError()},tt=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)V();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+=Y[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||V();w+=G("0x"+x.slice(O,k));break;default:V()}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;V();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)&&V(),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&&V(),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&&V(),k=C}return+x.slice(O,k)}if(D&&V(),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;V()}return"$"},bt=function(w){var O,C;if(w=="$"&&V(),typeof w=="string"){if((j?w.charAt(0):w[0])=="@")return w.slice(1);if(w=="["){for(O=[];w=tt(),w!="]";C||(C=!0))C&&(w==","?(w=tt(),w=="]"&&V()):V()),w==","&&V(),O.push(bt(w));return O}if(w=="{"){for(O={};w=tt(),w!="}";C||(C=!0))C&&(w==","?(w=tt(),w=="}"&&V()):V()),(w==","||typeof w!="string"||(j?w.charAt(0):w[0])!="@"||tt()!=":")&&V(),O[w.slice(1)]=bt(tt());return O}V()}return w},Je=function(w,O,C){var D=Xe(w,O,C);D===h?delete w[O]:w[O]=D},Xe=function(w,O,C){var D,S=w[O];if(typeof S=="object"&&S)if(d.call(S)==y)for(D=S.length;D--;)Je(S,D,C);else u(S,function(x){Je(S,x,C)});return C.call(w,O,S)};p.parse=function(w,O){var C,D;return k=0,W=""+w,C=bt(tt()),tt()!="$"&&V(),k=W=null,O&&d.call(O)==i?Xe((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 sn=Object.assign({"./v1_3_7.js":Object.freeze(Object.defineProperty({__proto__:null,default:nn},Symbol.toStringTag,{value:"Module"}))}),rn=/v\d+_\d+_\d+/;function on(s){return typeof s=="function"}const Dt=Object.entries(sn).reduce((s,e)=>{var r;const t=e[1].default,n=(r=e[0].match(rn))==null?void 0:r[0];return on(t)&&n&&(s[n]=t()),s},{}),pe=s=>{if(s in Dt)return Dt[s];throw new Error(`Socket version ${s} not found`)},an={...Dt,getSocketVersion:pe,makeSocketVersion:(s,...e)=>pe(s)(...e)};var fe=(s=>(s.RINGING="Ringing",s.TALKING="Talking",s.DIALING="Dialing",s.HOLD="Hold",s))(fe||{}),de=(s=>(s.INCOMING="Incoming",s.OUTGOING="Outgoing",s))(de||{}),dt=(s=>(s.CONNECTED="connected",s.DISCONNECTED="disconnected",s.TRYING_TO_CONNECT="tryingToConnect",s))(dt||{}),ge=(s=>(s.AUTOMATIC="Automatic",s.IVR="IVR",s))(ge||{}),ye=(s=>(s.INCOMINC="Incoming",s.OUTGOING="Outgoing",s.SPY="Spy",s.CLICK2CALL="Click2Call",s))(ye||{}),me=(s=>(s.RESPONSE_FROM_API_VALID="RESPONSE_FROM_API_VALID",s.RESPONSE_FROM_API_INVALID="RESPONSE_FROM_API_INVALID",s))(me||{}),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||{}),Pt=(s=>(s.NEWCALL="NEWCALL",s.ANSWER="ANSWER",s.HOLD="HOLD",s.UNHOLD="UNHOLD",s.HANGUP="HANGUP",s.USER_STATUS_UPDATE="userStatusUpdate",s))(Pt||{}),ve=(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))(ve||{}),ke=(s=>(s.ANSWER="ANSWER",s.ABANDONED="ABANDONED",s.EXIT="EXIT",s.JOIN="JOIN",s))(ke||{});class Et{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===Pt.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 jt=(s=>(s.UPDATE_MONITORED_EXTENSIONS="updateMonitoredExtensions",s.KEEP_ALIVE="keepalive",s))(jt||{});class cn{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(it.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(it.NEXT)},5e3)}))}getSocketIoFunction(e){const t=e.split("v="),n="v".concat(t[t.length-1]).replaceAll(".","_");this.ioFunction=an.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:dt.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(jt.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(),vt.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,Et.mapQueueEvent(e))}onExtensionEvent(e,t){const n=Et.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,Et.mapLoginStatusEvent(e))}onAllExtensionStatus(e,t){const n=Et.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:dt.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?dt.TRYING_TO_CONNECT:dt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkDisconnect([e]),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>120&&(this.reconnectionTime=20),this.eventsSdkClass.connect(it.NEXT)},this.reconnectionTime*1e3))}onConnectError(e){this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:this.doReconnect?dt.TRYING_TO_CONNECT:dt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(e),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>60&&(this.reconnectionTime=20),this.eventsSdkClass.connect(it.NEXT)},this.reconnectionTime*1e3)}}var hn=Object.defineProperty,ln=(s,e,t)=>e in s?hn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,X=(s,e,t)=>(ln(s,typeof e!="symbol"?e+"":e,t),t);const at=Object.create(null);at.open="0",at.close="1",at.ping="2",at.pong="3",at.message="4",at.upgrade="5",at.noop="6";const Tt=Object.create(null);Object.keys(at).forEach(s=>{Tt[at[s]]=s});const qt={type:"error",data:"parser error"},Se=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",be=typeof ArrayBuffer=="function",we=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,Ft=({type:s,data:e},t,n)=>Se&&e instanceof Blob?t?n(e):Ce(e,n):be&&(e instanceof ArrayBuffer||we(e))?t?n(e):Ce(new Blob([e]),n):n(at[s]+(e||"")),Ce=(s,e)=>{const t=new FileReader;return t.onload=function(){const n=t.result.split(",")[1];e("b"+(n||""))},t.readAsDataURL(s)};function Ee(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}let Mt;function un(s,e){if(Se&&s.data instanceof Blob)return s.data.arrayBuffer().then(Ee).then(e);if(be&&(s.data instanceof ArrayBuffer||we(s.data)))return e(Ee(s.data));Ft(s,!1,t=>{Mt||(Mt=new TextEncoder),e(Mt.encode(t))})}const Te="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",kt=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<Te.length;s++)kt[Te.charCodeAt(s)]=s;const pn=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=kt[s.charCodeAt(n)],u=kt[s.charCodeAt(n+1)],h=kt[s.charCodeAt(n+2)],d=kt[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},fn=typeof ArrayBuffer=="function",Vt=(s,e)=>{if(typeof s!="string")return{type:"message",data:Ae(s,e)};const t=s.charAt(0);return t==="b"?{type:"message",data:dn(s.substring(1),e)}:Tt[t]?s.length>1?{type:Tt[t],data:s.substring(1)}:{type:Tt[t]}:qt},dn=(s,e)=>{if(fn){const t=pn(s);return Ae(t,e)}else return{base64:!0,data:s}},Ae=(s,e)=>{switch(e){case"blob":return s instanceof Blob?s:new Blob([s]);case"arraybuffer":default:return s instanceof ArrayBuffer?s:s.buffer}},Ne="",gn=(s,e)=>{const t=s.length,n=new Array(t);let r=0;s.forEach((o,u)=>{Ft(o,!1,h=>{n[u]=h,++r===t&&e(n.join(Ne))})})},yn=(s,e)=>{const t=s.split(Ne),n=[];for(let r=0;r<t.length;r++){const o=Vt(t[r],e);if(n.push(o),o.type==="error")break}return n};function mn(){return new TransformStream({transform(s,e){un(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 Kt;function At(s){return s.reduce((e,t)=>e+t.length,0)}function Nt(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 vn(s,e){Kt||(Kt=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(At(t)<1)break;const d=Nt(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(At(t)<2)break;const d=Nt(t,2);r=new DataView(d.buffer,d.byteOffset,d.length).getUint16(0),n=3}else if(n===2){if(At(t)<8)break;const d=Nt(t,8),c=new DataView(d.buffer,d.byteOffset,d.length),p=c.getUint32(0);if(p>Math.pow(2,21)-1){h.enqueue(qt);break}r=p*Math.pow(2,32)+c.getUint32(4),n=3}else{if(At(t)<r)break;const d=Nt(t,r);h.enqueue(Vt(o?d:Kt.decode(d),e)),n=0}if(r===0||r>s){h.enqueue(qt);break}}}})}const _e=4;function z(s){if(s)return kn(s)}function kn(s){for(var e in z.prototype)s[e]=z.prototype[e];return s}z.prototype.on=z.prototype.addEventListener=function(s,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(e),this},z.prototype.once=function(s,e){function t(){this.off(s,t),e.apply(this,arguments)}return t.fn=e,this.on(s,t),this},z.prototype.off=z.prototype.removeListener=z.prototype.removeAllListeners=z.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},z.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},z.prototype.emitReserved=z.prototype.emit,z.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]},z.prototype.hasListeners=function(s){return!!this.listeners(s).length};const nt=typeof self<"u"?self:typeof window<"u"?window:Function("return this")();function Oe(s,...e){return e.reduce((t,n)=>(s.hasOwnProperty(n)&&(t[n]=s[n]),t),{})}const Sn=nt.setTimeout,bn=nt.clearTimeout;function _t(s,e){e.useNativeTimers?(s.setTimeoutFn=Sn.bind(nt),s.clearTimeoutFn=bn.bind(nt)):(s.setTimeoutFn=nt.setTimeout.bind(nt),s.clearTimeoutFn=nt.clearTimeout.bind(nt))}const wn=1.33;function Cn(s){return typeof s=="string"?En(s):Math.ceil((s.byteLength||s.size)*wn)}function En(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 Tn(s){let e="";for(let t in s)s.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(s[t]));return e}function An(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 Nn extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}class Wt extends z{constructor(e){super(),this.writable=!1,_t(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,n){return super.emitReserved("error",new Nn(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=Vt(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=Tn(e);return t.length?"?"+t:""}}const Le="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),Gt=64,_n={};let Re=0,Ot=0,Ie;function xe(s){let e="";do e=Le[s%Gt]+e,s=Math.floor(s/Gt);while(s>0);return e}function Be(){const s=xe(+new Date);return s!==Ie?(Re=0,Ie=s):s+"."+xe(Re++)}for(;Ot<Gt;Ot++)_n[Le[Ot]]=Ot;let Ue=!1;try{Ue=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const On=Ue;function De(s){const e=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||On))return new XMLHttpRequest}catch{}if(!e)try{return new nt[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function Ln(){}const Rn=function(){return new De({xdomain:!1}).responseType!=null}();class In extends Wt{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=Rn&&!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)};yn(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,gn(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]=Be()),!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 z{constructor(e,t){super(),_t(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=Oe(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd;const n=this.xhr=new De(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=Ln,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()}}if(ct.requestsCount=0,ct.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",Pe);else if(typeof addEventListener=="function"){const s="onpagehide"in nt?"pagehide":"unload";addEventListener(s,Pe,!1)}}function Pe(){for(let s in ct.requests)ct.requests.hasOwnProperty(s)&&ct.requests[s].abort()}const Jt=typeof Promise=="function"&&typeof Promise.resolve=="function"?s=>Promise.resolve().then(s):(s,e)=>e(s,0),Lt=nt.WebSocket||nt.MozWebSocket,je=!0,xn="arraybuffer",qe=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Bn extends Wt{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=qe?{}:Oe(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=je&&!qe?t?new Lt(e,t):new Lt(e):new Lt(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;Ft(n,this.supportsBinary,o=>{try{je&&this.ws.send(o)}catch{}r&&Jt(()=>{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]=Be()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}check(){return!!Lt}}class Un extends Wt{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=vn(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=mn();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&&Jt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this.transport)===null||e===void 0||e.close()}}const Dn={websocket:Bn,webtransport:Un,polling:In},Pn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,jn=["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=Pn.exec(s||""),o={},u=14;for(;u--;)o[jn[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=qn(o,o.path),o.queryKey=Fn(o,o.query),o}function qn(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 Fn(s,e){const t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(n,r,o){r&&(t[r]=o)}),t}let Fe=class mt extends z{constructor(e,t={}){super(),this.binaryType=xn,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),_t(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=An(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=_e,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 Dn[e](n)}open(){let e;if(this.opts.rememberUpgrade&&mt.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;mt.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;mt.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",mt.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+=Cn(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){mt.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}};Fe.protocol=_e;function Mn(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 Vn=typeof ArrayBuffer=="function",Kn=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s.buffer instanceof ArrayBuffer,Me=Object.prototype.toString,Wn=typeof Blob=="function"||typeof Blob<"u"&&Me.call(Blob)==="[object BlobConstructor]",Gn=typeof File=="function"||typeof File<"u"&&Me.call(File)==="[object FileConstructor]";function $t(s){return Vn&&(s instanceof ArrayBuffer||Kn(s))||Wn&&s instanceof Blob||Gn&&s instanceof File}function Rt(s,e){if(!s||typeof s!="object")return!1;if(Array.isArray(s)){for(let t=0,n=s.length;t<n;t++)if(Rt(s[t]))return!0;return!1}if($t(s))return!0;if(s.toJSON&&typeof s.toJSON=="function"&&arguments.length===1)return Rt(s.toJSON(),!0);for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)&&Rt(s[t]))return!0;return!1}function Jn(s){const e=[],t=s.data,n=s;return n.data=zt(t,e),n.attachments=e.length,{packet:n,buffers:e}}function zt(s,e){if(!s)return s;if($t(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]=zt(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]=zt(s[n],e));return t}return s}function Xn(s,e){return s.data=Ht(s.data,e),delete s.attachments,s}function Ht(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]=Ht(s[t],e);else if(typeof s=="object")for(const t in s)Object.prototype.hasOwnProperty.call(s,t)&&(s[t]=Ht(s[t],e));return s}const $n=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],zn=5;var M;(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"})(M||(M={}));class Hn{constructor(e){this.replacer=e}encode(e){return(e.type===M.EVENT||e.type===M.ACK)&&Rt(e)?this.encodeAsBinary({type:e.type===M.EVENT?M.BINARY_EVENT:M.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return(e.type===M.BINARY_EVENT||e.type===M.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=Jn(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 Yt extends z{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===M.BINARY_EVENT;n||t.type===M.BINARY_ACK?(t.type=n?M.EVENT:M.ACK,this.reconstructor=new Yn(t),t.attachments===0&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else if($t(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(M[n.type]===void 0)throw new Error("unknown packet type "+n.type);if(n.type===M.BINARY_EVENT||n.type===M.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(Yt.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 M.CONNECT:return Ve(t);case M.DISCONNECT:return t===void 0;case M.CONNECT_ERROR:return typeof t=="string"||Ve(t);case M.EVENT:case M.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&$n.indexOf(t[0])===-1);case M.ACK:case M.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Yn{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=Xn(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Qn=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Yt,Encoder:Hn,get PacketType(){return M},protocol:zn},Symbol.toStringTag,{value:"Module"}));function ot(s,e,t){return s.on(e,t),function(){s.off(e,t)}}const Zn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Ke extends z{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=[ot(e,"open",this.onopen.bind(this)),ot(e,"packet",this.onpacket.bind(this)),ot(e,"error",this.onerror.bind(this)),ot(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(Zn.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:M.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:M.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 M.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 M.EVENT:case M.BINARY_EVENT:this.onevent(e);break;case M.ACK:case M.BINARY_ACK:this.onack(e);break;case M.DISCONNECT:this.ondisconnect();break;case M.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:M.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:M.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 yt(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}yt.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},yt.prototype.reset=function(){this.attempts=0},yt.prototype.setMin=function(s){this.ms=s},yt.prototype.setMax=function(s){this.max=s},yt.prototype.setJitter=function(s){this.jitter=s};class Qt extends z{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,_t(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 yt({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||Qn;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 Fe(this.uri,this.opts);const t=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const r=ot(t,"open",function(){n.onopen(),e&&e()}),o=h=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",h),e?e(h):this.maybeReconnectOnOpen()},u=ot(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(ot(e,"ping",this.onping.bind(this)),ot(e,"data",this.ondata.bind(this)),ot(e,"error",this.onerror.bind(this)),ot(e,"close",this.onclose.bind(this)),ot(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){Jt(()=>{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 Ke(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 St={};function It(s,e){typeof s=="object"&&(e=s,s=void 0),e=e||{};const t=Mn(s,e.path||"/socket.io"),n=t.source,r=t.id,o=t.path,u=St[r]&&o in St[r].nsps,h=e.forceNew||e["force new connection"]||e.multiplex===!1||u;let d;return h?d=new Qt(n,e):(St[r]||(St[r]=new Qt(n,e)),d=St[r]),t.query&&!e.query&&(e.query=t.queryKey),d.socket(t.path,e)}Object.assign(It,{Manager:Qt,Socket:Ke,io:It,connect:It});let xt;const ts=new Uint8Array(16);function es(){if(!xt&&(xt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!xt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return xt(ts)}const H=[];for(let s=0;s<256;++s)H.push((s+256).toString(16).slice(1));function ns(s,e=0){return H[s[e+0]]+H[s[e+1]]+H[s[e+2]]+H[s[e+3]]+"-"+H[s[e+4]]+H[s[e+5]]+"-"+H[s[e+6]]+H[s[e+7]]+"-"+H[s[e+8]]+H[s[e+9]]+"-"+H[s[e+10]]+H[s[e+11]]+H[s[e+12]]+H[s[e+13]]+H[s[e+14]]+H[s[e+15]]}const ss=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),We={randomUUID:ss};function rs(s,e,t){if(We.randomUUID&&!e&&!s)return We.randomUUID();s=s||{};const n=s.random||(s.rng||es)();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 ns(n)}function os(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 is(s,e){const t=JSON.parse(s);return e.forEach(n=>delete t[n]),t}function as(s){if(typeof s=="object"&&s!==null)return s;try{return JSON.parse(s)}catch{return{extraData:s}}}function cs(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 Ge(s){return(...e)=>new Promise((t,n)=>{try{const r=s(...e);t(r)}catch(r){n(r)}})}const hs={reconnection:!0,reconnectionDelay:5e3,reconnectionAttempts:10,upgrade:!1,transports:["websocket"],debug:!1},Zt={logToConsole:!0,overloadGlobalConsole:!1,socketEmitInterval:6e4},ht={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"},ls={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},lt={INFO:"info",WARNING:"warning",MODIFY:"modify",ERROR:"error",VIEW:"view"},Q={INFO:"info",WARNING:"warning",ERROR:"error",DEBUG:"debug"};let Z=console;class us{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||Zt.socketEmitInterval,this.logToConsole=t.logToConsole!==void 0?t.logToConsole:Zt.logToConsole,this.overloadGlobalConsole=t.overloadGlobalConsole!==void 0?t.overloadGlobalConsole:Zt.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:Ge(e):this.defaultGetItemFunction,this.setItem=t&&typeof t=="function"?this.isSetItemAsync?t:Ge(t):this.defaultSetItemFunction,this.parseLog=n&&typeof n=="function"?n:os}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={...hs,...t};return It(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=as(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=is(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=ls[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=cs(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=rs();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 ps{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 us({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:ht.WSCONNECT,isShowClient:!1,Status:"Connection established",StatusCode:200,Level:Q.INFO,LogType:lt.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:ht.WSCONNECT,isShowClient:!1,Status:"Connection closed",StatusCode:200,Level:Q.INFO,LogType:lt.INFO})}sdkAttemptToConnect(e){this.log({Message:`${this.eventsSdkClass.options.loggerConfig.system} is trying to connect to WS server ${e}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Switching Protocols",StatusCode:101,Level:Q.INFO,LogType:lt.INFO})}sdkAttemptToConnectError(e){this.log({Message:`${e}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Connection error",StatusCode:500,Level:Q.ERROR,LogType:lt.ERROR})}loginError(e,t,n,r){this.log({Message:`External login request error with the login type ${e} ${e===rt.TOKEN?n:r}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"External login error",StatusCode:t||400,Level:Q.ERROR,LogType:lt.ERROR})}getSettingsError(e,t){this.log({Message:`Get settings error with token ${e}, error: ${t}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:lt.ERROR})}refreshTokenError(e,t,n){this.log({Message:`Refresh token error with old refresh token ${e}, url: ${t}, error: ${n}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:lt.ERROR})}keepAliveEmit(){this.log({Message:`Keep alive event emitted with this token: ${this.eventsSdkClass.authClass.token}`,ActionName:ht.WSCONNECT,isShowClient:!1,Level:Q.INFO,LogType:lt.INFO})}keepAliveResponse(e){this.log({Message:`Keep alive response: ${JSON.stringify(e)}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Successful",StatusCode:200,Level:Q.INFO,LogType:lt.INFO})}eventLog(e,t){const n={[ft.FULL]:[],[ft.BOOTSTRAP]:[P.LOGIN_STATUS,P.LOGIN_SUCCESS,P.ALL_EXTENSION_STATUS,P.ALL_DIALER_STATUS],[ft.DEBUG_EXTENSIONS]:[P.ALL_EXTENSION_STATUS,P.EXTENSION_EVENT,P.EXTENSIONS_UPDATED],[ft.DEBUG_DIALER]:[P.ALL_DIALER_STATUS,P.DIALER_EVENT],[ft.DEBUG_QUEUE]:[P.QUEUE_EVENT]};this.eventsSdkClass.options.debugOption&&(n[this.eventsSdkClass.options.debugOption].includes(e)||this.eventsSdkClass.options.debugOption===ft.FULL)&&this.log({Message:`Event name: ${e}`,Body:t,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Successful",Level:Q.INFO,LogType:lt.INFO})}}class fs{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 ds{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 tn(this));K(this,"socketIoClass",new cn(this));K(this,"loggerClass",new ps(this));K(this,"eventEmitterClass",new fs(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={...en,...e}}on(e,t){this.eventEmitterClass.on(e,t)}emit(e,...t){this.socketIoClass.io&&this.socketIoClass.io.emit(e,...t)}connect(e){e===it.MAIN&&this.findMainServer(),e===it.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}}return $.CallStatusEnum=fe,$.CallTypeEnum=de,$.ConnectionStatusEnum=dt,$.DebugOption=ft,$.DialerTypeEnum=ge,$.DirectionEnum=ye,$.DoNotCallMeStatusCodeEnum=me,$.EventsEnum=P,$.ExtensionEventReasonEnum=Pt,$.ExtensionHangupCauseEnum=ve,$.LoginType=rt,$.QueueEventReasonEnum=ke,$.ServerListenerEventsEnum=jt,$.ServerParameter=it,$.default=ds,Object.defineProperties($,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),$}({},ws);
|
|
18
|
+
`,102:"\f",114:"\r"},V=function(){throw k=W=null,SyntaxError()},tt=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)V();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+=Y[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||V();w+=G("0x"+x.slice(O,k));break;default:V()}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;V();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)&&V(),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&&V(),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&&V(),k=C}return+x.slice(O,k)}if(D&&V(),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;V()}return"$"},bt=function(w){var O,C;if(w=="$"&&V(),typeof w=="string"){if((j?w.charAt(0):w[0])=="@")return w.slice(1);if(w=="["){for(O=[];w=tt(),w!="]";C||(C=!0))C&&(w==","?(w=tt(),w=="]"&&V()):V()),w==","&&V(),O.push(bt(w));return O}if(w=="{"){for(O={};w=tt(),w!="}";C||(C=!0))C&&(w==","?(w=tt(),w=="}"&&V()):V()),(w==","||typeof w!="string"||(j?w.charAt(0):w[0])!="@"||tt()!=":")&&V(),O[w.slice(1)]=bt(tt());return O}V()}return w},Je=function(w,O,C){var D=Xe(w,O,C);D===h?delete w[O]:w[O]=D},Xe=function(w,O,C){var D,S=w[O];if(typeof S=="object"&&S)if(d.call(S)==y)for(D=S.length;D--;)Je(S,D,C);else u(S,function(x){Je(S,x,C)});return C.call(w,O,S)};p.parse=function(w,O){var C,D;return k=0,W=""+w,C=bt(tt()),tt()!="$"&&V(),k=W=null,O&&d.call(O)==i?Xe((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 sn=Object.assign({"./v1_3_7.js":Object.freeze(Object.defineProperty({__proto__:null,default:nn},Symbol.toStringTag,{value:"Module"}))}),rn=/v\d+_\d+_\d+/;function on(s){return typeof s=="function"}const Dt=Object.entries(sn).reduce((s,e)=>{var r;const t=e[1].default,n=(r=e[0].match(rn))==null?void 0:r[0];return on(t)&&n&&(s[n]=t()),s},{}),pe=s=>{if(s in Dt)return Dt[s];throw new Error(`Socket version ${s} not found`)},an={...Dt,getSocketVersion:pe,makeSocketVersion:(s,...e)=>pe(s)(...e)};var fe=(s=>(s.RINGING="Ringing",s.TALKING="Talking",s.DIALING="Dialing",s.HOLD="Hold",s))(fe||{}),de=(s=>(s.INCOMING="Incoming",s.OUTGOING="Outgoing",s))(de||{}),dt=(s=>(s.CONNECTED="connected",s.DISCONNECTED="disconnected",s.TRYING_TO_CONNECT="tryingToConnect",s))(dt||{}),ge=(s=>(s.AUTOMATIC="Automatic",s.IVR="IVR",s))(ge||{}),ye=(s=>(s.INCOMINC="Incoming",s.OUTGOING="Outgoing",s.SPY="Spy",s.CLICK2CALL="Click2Call",s))(ye||{}),me=(s=>(s.RESPONSE_FROM_API_VALID="RESPONSE_FROM_API_VALID",s.RESPONSE_FROM_API_INVALID="RESPONSE_FROM_API_INVALID",s))(me||{}),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||{}),Pt=(s=>(s.NEWCALL="NEWCALL",s.ANSWER="ANSWER",s.HOLD="HOLD",s.UNHOLD="UNHOLD",s.HANGUP="HANGUP",s.USER_STATUS_UPDATE="userStatusUpdate",s))(Pt||{}),ve=(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))(ve||{}),ke=(s=>(s.ANSWER="ANSWER",s.ABANDONED="ABANDONED",s.EXIT="EXIT",s.JOIN="JOIN",s))(ke||{});class Et{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===Pt.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 jt=(s=>(s.UPDATE_MONITORED_EXTENSIONS="updateMonitoredExtensions",s.KEEP_ALIVE="keepalive",s))(jt||{});class cn{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(it.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(it.NEXT)},5e3)}))}getSocketIoFunction(e){const t=e.split("v="),n="v".concat(t[t.length-1]).replaceAll(".","_");this.ioFunction=an.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:dt.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(jt.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(),vt.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,Et.mapQueueEvent(e))}onExtensionEvent(e,t){const n=Et.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,Et.mapLoginStatusEvent(e))}onAllExtensionStatus(e,t){const n=Et.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:dt.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?dt.TRYING_TO_CONNECT:dt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkDisconnect([e]),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>120&&(this.reconnectionTime=20),this.eventsSdkClass.connect(it.NEXT)},this.reconnectionTime*1e3))}onConnectError(e){this.eventsSdkClass.eventEmitterClass.emit(P.ONLINE_STATUS_EVENT,{connectionStatus:this.doReconnect?dt.TRYING_TO_CONNECT:dt.DISCONNECTED}),this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(e),this.keepReconnectTimeout=setTimeout(()=>{this.reconnectionTime=this.reconnectionTime+20,this.reconnectionTime>60&&(this.reconnectionTime=20),this.eventsSdkClass.connect(it.NEXT)},this.reconnectionTime*1e3)}}var hn=Object.defineProperty,ln=(s,e,t)=>e in s?hn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,X=(s,e,t)=>(ln(s,typeof e!="symbol"?e+"":e,t),t);const at=Object.create(null);at.open="0",at.close="1",at.ping="2",at.pong="3",at.message="4",at.upgrade="5",at.noop="6";const Tt=Object.create(null);Object.keys(at).forEach(s=>{Tt[at[s]]=s});const qt={type:"error",data:"parser error"},Se=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",be=typeof ArrayBuffer=="function",we=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,Ft=({type:s,data:e},t,n)=>Se&&e instanceof Blob?t?n(e):Ce(e,n):be&&(e instanceof ArrayBuffer||we(e))?t?n(e):Ce(new Blob([e]),n):n(at[s]+(e||"")),Ce=(s,e)=>{const t=new FileReader;return t.onload=function(){const n=t.result.split(",")[1];e("b"+(n||""))},t.readAsDataURL(s)};function Ee(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}let Mt;function un(s,e){if(Se&&s.data instanceof Blob)return s.data.arrayBuffer().then(Ee).then(e);if(be&&(s.data instanceof ArrayBuffer||we(s.data)))return e(Ee(s.data));Ft(s,!1,t=>{Mt||(Mt=new TextEncoder),e(Mt.encode(t))})}const Te="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",kt=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<Te.length;s++)kt[Te.charCodeAt(s)]=s;const pn=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=kt[s.charCodeAt(n)],u=kt[s.charCodeAt(n+1)],h=kt[s.charCodeAt(n+2)],d=kt[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},fn=typeof ArrayBuffer=="function",Vt=(s,e)=>{if(typeof s!="string")return{type:"message",data:Ae(s,e)};const t=s.charAt(0);return t==="b"?{type:"message",data:dn(s.substring(1),e)}:Tt[t]?s.length>1?{type:Tt[t],data:s.substring(1)}:{type:Tt[t]}:qt},dn=(s,e)=>{if(fn){const t=pn(s);return Ae(t,e)}else return{base64:!0,data:s}},Ae=(s,e)=>{switch(e){case"blob":return s instanceof Blob?s:new Blob([s]);case"arraybuffer":default:return s instanceof ArrayBuffer?s:s.buffer}},Ne="",gn=(s,e)=>{const t=s.length,n=new Array(t);let r=0;s.forEach((o,u)=>{Ft(o,!1,h=>{n[u]=h,++r===t&&e(n.join(Ne))})})},yn=(s,e)=>{const t=s.split(Ne),n=[];for(let r=0;r<t.length;r++){const o=Vt(t[r],e);if(n.push(o),o.type==="error")break}return n};function mn(){return new TransformStream({transform(s,e){un(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 Kt;function At(s){return s.reduce((e,t)=>e+t.length,0)}function Nt(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 vn(s,e){Kt||(Kt=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(At(t)<1)break;const d=Nt(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(At(t)<2)break;const d=Nt(t,2);r=new DataView(d.buffer,d.byteOffset,d.length).getUint16(0),n=3}else if(n===2){if(At(t)<8)break;const d=Nt(t,8),c=new DataView(d.buffer,d.byteOffset,d.length),p=c.getUint32(0);if(p>Math.pow(2,21)-1){h.enqueue(qt);break}r=p*Math.pow(2,32)+c.getUint32(4),n=3}else{if(At(t)<r)break;const d=Nt(t,r);h.enqueue(Vt(o?d:Kt.decode(d),e)),n=0}if(r===0||r>s){h.enqueue(qt);break}}}})}const _e=4;function z(s){if(s)return kn(s)}function kn(s){for(var e in z.prototype)s[e]=z.prototype[e];return s}z.prototype.on=z.prototype.addEventListener=function(s,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(e),this},z.prototype.once=function(s,e){function t(){this.off(s,t),e.apply(this,arguments)}return t.fn=e,this.on(s,t),this},z.prototype.off=z.prototype.removeListener=z.prototype.removeAllListeners=z.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},z.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},z.prototype.emitReserved=z.prototype.emit,z.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]},z.prototype.hasListeners=function(s){return!!this.listeners(s).length};const nt=typeof self<"u"?self:typeof window<"u"?window:Function("return this")();function Oe(s,...e){return e.reduce((t,n)=>(s.hasOwnProperty(n)&&(t[n]=s[n]),t),{})}const Sn=nt.setTimeout,bn=nt.clearTimeout;function _t(s,e){e.useNativeTimers?(s.setTimeoutFn=Sn.bind(nt),s.clearTimeoutFn=bn.bind(nt)):(s.setTimeoutFn=nt.setTimeout.bind(nt),s.clearTimeoutFn=nt.clearTimeout.bind(nt))}const wn=1.33;function Cn(s){return typeof s=="string"?En(s):Math.ceil((s.byteLength||s.size)*wn)}function En(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 Tn(s){let e="";for(let t in s)s.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(s[t]));return e}function An(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 Nn extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}class Wt extends z{constructor(e){super(),this.writable=!1,_t(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,n){return super.emitReserved("error",new Nn(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=Vt(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=Tn(e);return t.length?"?"+t:""}}const Le="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),Gt=64,_n={};let Re=0,Ot=0,Ie;function xe(s){let e="";do e=Le[s%Gt]+e,s=Math.floor(s/Gt);while(s>0);return e}function Be(){const s=xe(+new Date);return s!==Ie?(Re=0,Ie=s):s+"."+xe(Re++)}for(;Ot<Gt;Ot++)_n[Le[Ot]]=Ot;let Ue=!1;try{Ue=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const On=Ue;function De(s){const e=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||On))return new XMLHttpRequest}catch{}if(!e)try{return new nt[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function Ln(){}const Rn=function(){return new De({xdomain:!1}).responseType!=null}();class In extends Wt{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=Rn&&!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)};yn(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,gn(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]=Be()),!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 z{constructor(e,t){super(),_t(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=Oe(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd;const n=this.xhr=new De(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=Ln,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()}}if(ct.requestsCount=0,ct.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",Pe);else if(typeof addEventListener=="function"){const s="onpagehide"in nt?"pagehide":"unload";addEventListener(s,Pe,!1)}}function Pe(){for(let s in ct.requests)ct.requests.hasOwnProperty(s)&&ct.requests[s].abort()}const Jt=typeof Promise=="function"&&typeof Promise.resolve=="function"?s=>Promise.resolve().then(s):(s,e)=>e(s,0),Lt=nt.WebSocket||nt.MozWebSocket,je=!0,xn="arraybuffer",qe=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Bn extends Wt{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=qe?{}:Oe(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=je&&!qe?t?new Lt(e,t):new Lt(e):new Lt(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;Ft(n,this.supportsBinary,o=>{try{je&&this.ws.send(o)}catch{}r&&Jt(()=>{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]=Be()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}check(){return!!Lt}}class Un extends Wt{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=vn(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=mn();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&&Jt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this.transport)===null||e===void 0||e.close()}}const Dn={websocket:Bn,webtransport:Un,polling:In},Pn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,jn=["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=Pn.exec(s||""),o={},u=14;for(;u--;)o[jn[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=qn(o,o.path),o.queryKey=Fn(o,o.query),o}function qn(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 Fn(s,e){const t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(n,r,o){r&&(t[r]=o)}),t}let Fe=class mt extends z{constructor(e,t={}){super(),this.binaryType=xn,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),_t(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=An(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=_e,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 Dn[e](n)}open(){let e;if(this.opts.rememberUpgrade&&mt.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;mt.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;mt.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",mt.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+=Cn(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){mt.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}};Fe.protocol=_e;function Mn(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 Vn=typeof ArrayBuffer=="function",Kn=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s.buffer instanceof ArrayBuffer,Me=Object.prototype.toString,Wn=typeof Blob=="function"||typeof Blob<"u"&&Me.call(Blob)==="[object BlobConstructor]",Gn=typeof File=="function"||typeof File<"u"&&Me.call(File)==="[object FileConstructor]";function $t(s){return Vn&&(s instanceof ArrayBuffer||Kn(s))||Wn&&s instanceof Blob||Gn&&s instanceof File}function Rt(s,e){if(!s||typeof s!="object")return!1;if(Array.isArray(s)){for(let t=0,n=s.length;t<n;t++)if(Rt(s[t]))return!0;return!1}if($t(s))return!0;if(s.toJSON&&typeof s.toJSON=="function"&&arguments.length===1)return Rt(s.toJSON(),!0);for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)&&Rt(s[t]))return!0;return!1}function Jn(s){const e=[],t=s.data,n=s;return n.data=zt(t,e),n.attachments=e.length,{packet:n,buffers:e}}function zt(s,e){if(!s)return s;if($t(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]=zt(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]=zt(s[n],e));return t}return s}function Xn(s,e){return s.data=Ht(s.data,e),delete s.attachments,s}function Ht(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]=Ht(s[t],e);else if(typeof s=="object")for(const t in s)Object.prototype.hasOwnProperty.call(s,t)&&(s[t]=Ht(s[t],e));return s}const $n=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],zn=5;var M;(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"})(M||(M={}));class Hn{constructor(e){this.replacer=e}encode(e){return(e.type===M.EVENT||e.type===M.ACK)&&Rt(e)?this.encodeAsBinary({type:e.type===M.EVENT?M.BINARY_EVENT:M.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return(e.type===M.BINARY_EVENT||e.type===M.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=Jn(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 Yt extends z{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===M.BINARY_EVENT;n||t.type===M.BINARY_ACK?(t.type=n?M.EVENT:M.ACK,this.reconstructor=new Yn(t),t.attachments===0&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else if($t(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(M[n.type]===void 0)throw new Error("unknown packet type "+n.type);if(n.type===M.BINARY_EVENT||n.type===M.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(Yt.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 M.CONNECT:return Ve(t);case M.DISCONNECT:return t===void 0;case M.CONNECT_ERROR:return typeof t=="string"||Ve(t);case M.EVENT:case M.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&$n.indexOf(t[0])===-1);case M.ACK:case M.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Yn{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=Xn(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Qn=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Yt,Encoder:Hn,get PacketType(){return M},protocol:zn},Symbol.toStringTag,{value:"Module"}));function ot(s,e,t){return s.on(e,t),function(){s.off(e,t)}}const Zn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Ke extends z{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=[ot(e,"open",this.onopen.bind(this)),ot(e,"packet",this.onpacket.bind(this)),ot(e,"error",this.onerror.bind(this)),ot(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(Zn.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:M.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:M.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 M.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 M.EVENT:case M.BINARY_EVENT:this.onevent(e);break;case M.ACK:case M.BINARY_ACK:this.onack(e);break;case M.DISCONNECT:this.ondisconnect();break;case M.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:M.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:M.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 yt(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}yt.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},yt.prototype.reset=function(){this.attempts=0},yt.prototype.setMin=function(s){this.ms=s},yt.prototype.setMax=function(s){this.max=s},yt.prototype.setJitter=function(s){this.jitter=s};class Qt extends z{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,_t(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 yt({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||Qn;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 Fe(this.uri,this.opts);const t=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const r=ot(t,"open",function(){n.onopen(),e&&e()}),o=h=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",h),e?e(h):this.maybeReconnectOnOpen()},u=ot(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(ot(e,"ping",this.onping.bind(this)),ot(e,"data",this.ondata.bind(this)),ot(e,"error",this.onerror.bind(this)),ot(e,"close",this.onclose.bind(this)),ot(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){Jt(()=>{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 Ke(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 St={};function It(s,e){typeof s=="object"&&(e=s,s=void 0),e=e||{};const t=Mn(s,e.path||"/socket.io"),n=t.source,r=t.id,o=t.path,u=St[r]&&o in St[r].nsps,h=e.forceNew||e["force new connection"]||e.multiplex===!1||u;let d;return h?d=new Qt(n,e):(St[r]||(St[r]=new Qt(n,e)),d=St[r]),t.query&&!e.query&&(e.query=t.queryKey),d.socket(t.path,e)}Object.assign(It,{Manager:Qt,Socket:Ke,io:It,connect:It});let xt;const ts=new Uint8Array(16);function es(){if(!xt&&(xt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!xt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return xt(ts)}const H=[];for(let s=0;s<256;++s)H.push((s+256).toString(16).slice(1));function ns(s,e=0){return H[s[e+0]]+H[s[e+1]]+H[s[e+2]]+H[s[e+3]]+"-"+H[s[e+4]]+H[s[e+5]]+"-"+H[s[e+6]]+H[s[e+7]]+"-"+H[s[e+8]]+H[s[e+9]]+"-"+H[s[e+10]]+H[s[e+11]]+H[s[e+12]]+H[s[e+13]]+H[s[e+14]]+H[s[e+15]]}const ss=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),We={randomUUID:ss};function rs(s,e,t){if(We.randomUUID&&!e&&!s)return We.randomUUID();s=s||{};const n=s.random||(s.rng||es)();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 ns(n)}function os(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 is(s,e){const t=JSON.parse(s);return e.forEach(n=>delete t[n]),t}function as(s){if(typeof s=="object"&&s!==null)return s;try{return JSON.parse(s)}catch{return{extraData:s}}}function cs(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 Ge(s){return(...e)=>new Promise((t,n)=>{try{const r=s(...e);t(r)}catch(r){n(r)}})}const hs={reconnection:!0,reconnectionDelay:5e3,reconnectionAttempts:10,upgrade:!1,transports:["websocket"],debug:!1},Zt={logToConsole:!0,overloadGlobalConsole:!1,socketEmitInterval:6e4},ht={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"},ls={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},lt={INFO:"info",WARNING:"warning",MODIFY:"modify",ERROR:"error",VIEW:"view"},Q={INFO:"info",WARNING:"warning",ERROR:"error",DEBUG:"debug"};let Z=console;class us{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||Zt.socketEmitInterval,this.logToConsole=t.logToConsole!==void 0?t.logToConsole:Zt.logToConsole,this.overloadGlobalConsole=t.overloadGlobalConsole!==void 0?t.overloadGlobalConsole:Zt.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:Ge(e):this.defaultGetItemFunction,this.setItem=t&&typeof t=="function"?this.isSetItemAsync?t:Ge(t):this.defaultSetItemFunction,this.parseLog=n&&typeof n=="function"?n:os}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={...hs};return t&&(n={...n,...t}),It(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=as(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=is(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=ls[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=cs(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=rs();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 ps{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 us({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:ht.WSCONNECT,isShowClient:!1,Status:"Connection established",StatusCode:200,Level:Q.INFO,LogType:lt.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:ht.WSCONNECT,isShowClient:!1,Status:"Connection closed",StatusCode:200,Level:Q.INFO,LogType:lt.INFO})}sdkAttemptToConnect(e){this.log({Message:`${this.eventsSdkClass.options.loggerConfig.system} is trying to connect to WS server ${e}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Switching Protocols",StatusCode:101,Level:Q.INFO,LogType:lt.INFO})}sdkAttemptToConnectError(e){this.log({Message:`${e}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Connection error",StatusCode:500,Level:Q.ERROR,LogType:lt.ERROR})}loginError(e,t,n,r){this.log({Message:`External login request error with the login type ${e} ${e===rt.TOKEN?n:r}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"External login error",StatusCode:t||400,Level:Q.ERROR,LogType:lt.ERROR})}getSettingsError(e,t){this.log({Message:`Get settings error with token ${e}, error: ${t}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:lt.ERROR})}refreshTokenError(e,t,n){this.log({Message:`Refresh token error with old refresh token ${e}, url: ${t}, error: ${n}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:Q.ERROR,LogType:lt.ERROR})}keepAliveEmit(){this.log({Message:`Keep alive event emitted with this token: ${this.eventsSdkClass.authClass.token}`,ActionName:ht.WSCONNECT,isShowClient:!1,Level:Q.INFO,LogType:lt.INFO})}keepAliveResponse(e){this.log({Message:`Keep alive response: ${JSON.stringify(e)}`,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Successful",StatusCode:200,Level:Q.INFO,LogType:lt.INFO})}eventLog(e,t){const n={[ft.FULL]:[],[ft.BOOTSTRAP]:[P.LOGIN_STATUS,P.LOGIN_SUCCESS,P.ALL_EXTENSION_STATUS,P.ALL_DIALER_STATUS],[ft.DEBUG_EXTENSIONS]:[P.ALL_EXTENSION_STATUS,P.EXTENSION_EVENT,P.EXTENSIONS_UPDATED],[ft.DEBUG_DIALER]:[P.ALL_DIALER_STATUS,P.DIALER_EVENT],[ft.DEBUG_QUEUE]:[P.QUEUE_EVENT]};this.eventsSdkClass.options.debugOption&&(n[this.eventsSdkClass.options.debugOption].includes(e)||this.eventsSdkClass.options.debugOption===ft.FULL)&&this.log({Message:`Event name: ${e}`,Body:t,ActionName:ht.WSCONNECT,isShowClient:!1,Status:"Successful",Level:Q.INFO,LogType:lt.INFO})}}class fs{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 ds{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 tn(this));K(this,"socketIoClass",new cn(this));K(this,"loggerClass",new ps(this));K(this,"eventEmitterClass",new fs(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={...en,...e}}on(e,t){this.eventEmitterClass.on(e,t)}emit(e,...t){this.socketIoClass.io&&this.socketIoClass.io.emit(e,...t)}connect(e){e===it.MAIN&&this.findMainServer(),e===it.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}}return $.CallStatusEnum=fe,$.CallTypeEnum=de,$.ConnectionStatusEnum=dt,$.DebugOption=ft,$.DialerTypeEnum=ge,$.DirectionEnum=ye,$.DoNotCallMeStatusCodeEnum=me,$.EventsEnum=P,$.ExtensionEventReasonEnum=Pt,$.ExtensionHangupCauseEnum=ve,$.LoginType=rt,$.QueueEventReasonEnum=ke,$.ServerListenerEventsEnum=jt,$.ServerParameter=it,$.default=ds,Object.defineProperties($,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),$}({},ws);
|
|
19
19
|
//# sourceMappingURL=voicenter-events-sdk.iife.js.map
|