@voicenter-team/events-sdk 0.0.109 → 0.0.111
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 +6 -6
- package/dist/voicenter-events-sdk.cjs.js.map +1 -1
- package/dist/voicenter-events-sdk.d.ts +77 -6
- package/dist/voicenter-events-sdk.es.js +2 -2
- 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 +1 -1
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
`+x+ee.join(`,
|
|
16
16
|
`+x)+`
|
|
17
17
|
`+ke+"}":"{"+ee.join(",")+"}":"{}";return B.pop(),Se}};u.stringify=function(E,_,w){var D,S,x,B;if(typeof _=="function"||typeof _=="object"&&_){if((B=d.call(_))==s)S=_;else if(B==v){x={};for(var N,M=0,z=_.length;z>M;N=_[M++],B=d.call(N),(B==y||B==p)&&(x[N]=1));}}if(w)if((B=d.call(w))==p){if((w-=w%1)>0)for(D="",w>10&&(w=10);D.length<w;D+=" ");}else B==y&&(D=w.length<=10?w:w.slice(0,10));return R("",(N={},N[""]=E,N),S,x,D,"",[])}}if(!o("json-parse")){var k,$,G=String.fromCharCode,J={92:"\\",34:'"',47:"/",98:"\b",116:" ",110:`
|
|
18
|
-
`,102:"\f",114:"\r"},V=function(){throw k=$=null,SyntaxError()},W=function(){for(var E,_,w,D,S,x=$,B=x.length;B>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 E=P?x.charAt(k):x[k],k++,E;case 34:for(E="@",k++;B>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:E+=J[S],k++;break;case 117:for(_=++k,w=k+4;w>k;k++)S=x.charCodeAt(k),S>=48&&57>=S||S>=97&&102>=S||S>=65&&70>=S||V();E+=G("0x"+x.slice(_,k));break;default:V()}else{if(S==34)break;for(S=x.charCodeAt(k),_=k;S>=32&&S!=92&&S!=34;)S=x.charCodeAt(++k);E+=x.slice(_,k)}if(x.charCodeAt(k)==34)return k++,E;V();default:if(_=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;B>k&&(S=x.charCodeAt(k),S>=48&&57>=S);k++);if(x.charCodeAt(k)==46){for(w=++k;B>w&&(S=x.charCodeAt(w),S>=48&&57>=S);w++);w==k&&V(),k=w}if(S=x.charCodeAt(k),S==101||S==69){for(S=x.charCodeAt(++k),(S==43||S==45)&&k++,w=k;B>w&&(S=x.charCodeAt(w),S>=48&&57>=S);w++);w==k&&V(),k=w}return+x.slice(_,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"$"},oe=function(E){var _,w;if(E=="$"&&V(),typeof E=="string"){if((P?E.charAt(0):E[0])=="@")return E.slice(1);if(E=="["){for(_=[];E=W(),E!="]";w||(w=!0))w&&(E==","?(E=W(),E=="]"&&V()):V()),E==","&&V(),_.push(oe(E));return _}if(E=="{"){for(_={};E=W(),E!="}";w||(w=!0))w&&(E==","?(E=W(),E=="}"&&V()):V()),(E==","||typeof E!="string"||(P?E.charAt(0):E[0])!="@"||W()!=":")&&V(),_[E.slice(1)]=oe(W());return _}V()}return E},Be=function(E,_,w){var D=De(E,_,w);D===l?delete E[_]:E[_]=D},De=function(E,_,w){var D,S=E[_];if(typeof S=="object"&&S)if(d.call(S)==v)for(D=S.length;D--;)Be(S,D,w);else f(S,function(x){Be(S,x,w)});return w.call(E,_,S)};u.parse=function(E,_){var w,D;return k=0,$=""+E,w=oe(W()),W()!="$"&&V(),k=$=null,_&&d.call(_)==s?De((D={},D[""]=w,D),"",_):w}}}})(this)},{}],48:[function(a,t){function e(r,o){var h=[];o=o||0;for(var f=o||0;f<r.length;f++)h[f-o]=r[f];return h}t.exports=e},{}]},{},[1])(1)}const Ge=Object.assign({"./v1_3_7.js":Object.freeze(Object.defineProperty({__proto__:null,default:$e},Symbol.toStringTag,{value:"Module"}))}),ze=/v\d+_\d+_\d+/;function Je(a){return typeof a=="function"}const ue=Object.entries(Ge).reduce((a,t)=>{var o;const e=t[1].default,r=(o=t[0].match(ze))==null?void 0:o[0];return Je(e)&&r&&(a[r]=e()),a},{}),Ne=a=>{if(a in ue)return ue[a];throw new Error(`Socket version ${a} not found`)},We={...ue,getSocketVersion:Ne,makeSocketVersion:(a,...t)=>Ne(a)(...t)};var Le=(a=>(a.RINGING="Ringing",a.TALKING="Talking",a.DIALING="Dialing",a.HOLD="Hold",a))(Le||{}),_e=(a=>(a.INCOMING="Incoming",a.OUTGOING="Outgoing",a))(_e||{}),se=(a=>(a.CONNECTED="connected",a.DISCONNECTED="disconnected",a.TRYING_TO_CONNECT="tryingToConnect",a))(se||{}),Oe=(a=>(a.AUTOMATIC="Automatic",a.IVR="IVR",a))(Oe||{}),Re=(a=>(a.INCOMINC="Incoming",a.OUTGOING="Outgoing",a.SPY="Spy",a.CLICK2CALL="Click2Call",a))(Re||{}),Ie=(a=>(a.RESPONSE_FROM_API_VALID="RESPONSE_FROM_API_VALID",a.RESPONSE_FROM_API_INVALID="RESPONSE_FROM_API_INVALID",a))(Ie||{}),j=(a=>(a.ALL_DIALER_STATUS="AllDialersStatus",a.ALL_EXTENSION_STATUS="AllExtensionsStatus",a.ALL_USERS_STATUS="AllUsersStatus",a.CONNECT="connect",a.DISCONNECT="disconnect",a.CONNECT_ERROR_EVENT="connect_error",a.EXTENSION_EVENT="ExtensionEvent",a.KEEP_ALIVE="keepalive",a.KEEP_ALIVE_RESPONSE="keepaliveResponse",a.LOGIN_STATUS="loginStatus",a.LOGIN_SUCCESS="loginSuccess",a.QUEUE_EVENT="QueueEvent",a.ONLINE_STATUS_EVENT="onlineStatusEvent",a.DIALER_EVENT="DialerEvent",a.EXTENSIONS_UPDATED="ExtensionsUpdated",a))(j||{}),pe=(a=>(a.NEWCALL="NEWCALL",a.ANSWER="ANSWER",a.HOLD="HOLD",a.UNHOLD="UNHOLD",a.HANGUP="HANGUP",a.USER_STATUS_UPDATE="userStatusUpdate",a))(pe||{}),xe=(a=>(a.NORMAL_HANGUP="Normal hangup",a.USER_BUSY="User busy",a.CALL_REJECTED="Call Rejected",a.UNALLOCATED_NUMBER="Unallocated (unassigned) number",a.UNKNOWN="Unknown",a.NO_USER_RESPONDING="No user responding",a.USER_ALERTING="User alerting, no answer",a.ANSWERED_ELSEWHERE="Answered elsewhere",a))(xe||{}),Ue=(a=>(a.ANSWER="ANSWER",a.ABANDONED="ABANDONED",a.EXIT="EXIT",a.JOIN="JOIN",a))(Ue||{});class ce{static mapExtensionEvent(t){var f,l;const e=t.reason;let r,o;t.data.currentCall&&(o=this.mapExtensionCall(t,t.data.currentCall));const h=this.mapExtensionData(t,t.data);return e===pe.HANGUP?r={...t,reason:e,data:{...h,currentCall:o?{...o,duration:o.callAnswered_UTC_CLIENT?Date.now()-o.callAnswered_UTC_CLIENT:0}:void 0,calls:(f=t.data.calls)==null?void 0:f.map(d=>{const i=this.mapExtensionCall(t,d);return{...i,duration:i.callAnswered_UTC_CLIENT?Date.now()-i.callAnswered_UTC_CLIENT:0}})}}:r={...t,data:{...h,currentCall:o,calls:(l=t.data.calls)==null?void 0:l.map(d=>this.mapExtensionCall(t,d))},reason:e},r}static mapAllExtensionStatus(t){return{...t,extensions:t.extensions.map(e=>{var r;return{...this.mapExtensionData(t,e),currentCall:e.currentCall?this.mapExtensionCall(t,e.currentCall):void 0,calls:(r=e.calls)==null?void 0:r.map(o=>this.mapExtensionCall(t,o))}})}}static mapExtensionData(t,e){return this.configureUTCForObject(e,[{key:"lastAnsweredCallEventEpoch",format:"sec"},{key:"lastCallEventEpoch",format:"sec"},{key:"lastHangupCallEpoch",format:"sec"},{key:"representativeUpdated",format:"ms"}],t.servertime,t.servertimeoffset)}static mapExtensionCall(t,e){return this.configureUTCForObject(e,[{key:"callAnswered",format:"sec"},{key:"callStarted",format:"sec"}],t.servertime,t.servertimeoffset)}static mapQueueCall(t,e){return this.configureUTCForObject(e,[{key:"JoinTimeStamp",format:"sec"},{key:"VHJoinTimeStamp",format:"sec"}],t.servertime,t.servertimeoffset)}static mapLoginStatusEvent(t){return{...t,queues:t.queues.map(e=>({...e,Calls:e.Calls.map(r=>this.mapQueueCall(t,r))}))}}static mapQueueEvent(t){return{...t,data:{...t.data,Calls:t.data.Calls.map(e=>this.mapQueueCall(t,e))}}}static assignProperty(t,e,r){t[e]=r}static configureUTCForObject(t,e,r,o){const h=(r-o*60)*1e3,f=Date.now()-h,l={};return e.forEach(d=>{const i=t[d.key],u=d.key;if(i!==0&&typeof i=="number"&&!isNaN(i)){let c=i;d.format==="ms"&&(c=Math.floor(c/1e3));const s=(c-o*60)*1e3;this.assignProperty(l,`${u}_UTC`,s),this.assignProperty(l,`${u}_UTC_CLIENT`,s+f)}else this.assignProperty(l,`${u}_UTC`,0),this.assignProperty(l,`${u}_UTC_CLIENT`,0)}),{...t,...l}}}var fe=(a=>(a.UPDATE_MONITORED_EXTENSIONS="updateMonitoredExtensions",a.KEEP_ALIVE="keepalive",a))(fe||{});class He{constructor(t){K(this,"io");K(this,"ioFunction");K(this,"lastEventTimestamp",new Date().getTime());K(this,"doReconnect",!0);K(this,"connectionState","disconnected");K(this,"keepAliveInterval");K(this,"reconnectTimeout");K(this,"networkReconnectTimeout");K(this,"reconnectionTime",Ae.reconnectionDelay);K(this,"maxReconnectionDelay",120);K(this,"networkCleanup",[]);this.eventsSdkClass=t,this.reconnectionTime=t.options.reconnectionDelay,this.setupNetworkListeners()}setupNetworkListeners(){const t=()=>this.closeAllConnections(),e=()=>this.handleNetworkOnline();typeof window<"u"&&(window.addEventListener("offline",t),window.addEventListener("online",e),this.networkCleanup.push(()=>window.removeEventListener("offline",t),()=>window.removeEventListener("online",e))),typeof self<"u"&&typeof window>"u"&&typeof global>"u"&&(self.addEventListener("offline",t),self.addEventListener("online",e),this.networkCleanup.push(()=>self.removeEventListener("offline",t),()=>self.removeEventListener("online",e)))}handleNetworkOnline(){this.networkReconnectTimeout&&clearTimeout(this.networkReconnectTimeout),this.networkReconnectTimeout=setTimeout(()=>{this.connectionState==="disconnected"&&this.doReconnect&&this.eventsSdkClass.connect(ne.NEXT)},500)}getSocketIoFunction(t){const e=t.split("v="),r="v".concat(e[e.length-1]).replaceAll(".","_");this.ioFunction=We.getSocketVersion(r)}initSocketConnection(){if(this.connectionState!=="disconnected")return;this.connectionState="connecting";const t=this.eventsSdkClass.authClass.token,e=this.eventsSdkClass.options.protocol,r=this.eventsSdkClass.server;try{const o=r?r.Domain:this.eventsSdkClass.URL,h=r?`${e}://${o}`:this.eventsSdkClass.URL,f={reconnection:!1,upgrade:!1,transports:["websocket"],forceNew:!0,query:{token:t},timeout:this.eventsSdkClass.options.timeout};if(this.ioFunction&&h)this.io=this.ioFunction(h,f),this.initSocketEvents(),this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{attemptToConnect:h,connectionStatus:se.TRYING_TO_CONNECT}),this.eventsSdkClass.loggerClass.sdkAttemptToConnect(o);else throw new Error("Socket server url not defined")}catch(o){this.connectionState="disconnected",this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(o)}}clearKeepAliveInterval(){this.keepAliveInterval&&(clearInterval(this.keepAliveInterval),this.keepAliveInterval=void 0)}initKeepAlive(){this.clearKeepAliveInterval(),this.keepAliveInterval=setInterval(async()=>{new Date().getTime()>this.lastEventTimestamp+this.eventsSdkClass.options.keepAliveTimeout&&this.io&&this.connectionState==="connected"&&this.eventsSdkClass.authClass.token&&(this.eventsSdkClass.emit(fe.KEEP_ALIVE,this.eventsSdkClass.authClass.token),this.eventsSdkClass.loggerClass.keepAliveEmit())},this.eventsSdkClass.options.keepAliveTimeout)}async closeAllConnections(){if(this.clearKeepAliveInterval(),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0),this.networkReconnectTimeout&&(clearTimeout(this.networkReconnectTimeout),this.networkReconnectTimeout=void 0),this.io){const t=this.io;this.io=void 0;try{await Promise.race([new Promise(e=>{t.on("disconnect",()=>e()),t.removeAllListeners(),t.close(),t.disconnect()}),new Promise(e=>setTimeout(e,1e3))])}catch{}}this.connectionState="disconnected",this.eventsSdkClass.loggerClass.stop(),re.clearSessionStorage()}initSocketEvents(){this.io&&(this.io.removeAllListeners(),this.io.on(j.LOGIN_SUCCESS,t=>this.onLoginSuccessEvent(t,j.LOGIN_SUCCESS)).on(j.QUEUE_EVENT,t=>this.onQueueEvent(t,j.QUEUE_EVENT)).on(j.EXTENSION_EVENT,t=>this.onExtensionEvent(t,j.EXTENSION_EVENT)).on(j.DIALER_EVENT,t=>this.onDialerEvent(t,j.DIALER_EVENT)).on(j.LOGIN_STATUS,t=>this.onLoginStatusEvent(t,j.LOGIN_STATUS)).on(j.ALL_EXTENSION_STATUS,t=>this.onAllExtensionStatus(t,j.ALL_EXTENSION_STATUS)).on(j.ALL_DIALER_STATUS,t=>this.onAllDialerStatus(t,j.ALL_DIALER_STATUS)).on(j.KEEP_ALIVE_RESPONSE,t=>this.onKeepAliveResponse(t)).on(j.EXTENSIONS_UPDATED,t=>this.onExtensionsUpdatedEvent(t,j.EXTENSIONS_UPDATED)).on(j.CONNECT,()=>this.onConnect()).on(j.DISCONNECT,t=>this.onDisconnect(t)).on(j.CONNECT_ERROR_EVENT,t=>this.onConnectError(t)))}updateEventTimestamp(){this.lastEventTimestamp=new Date().getTime()}onLoginSuccessEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onQueueEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,ce.mapQueueEvent(t))}onExtensionEvent(t,e){this.updateEventTimestamp();const r=ce.mapExtensionEvent(t);r&&(this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,r))}onDialerEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onLoginStatusEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,ce.mapLoginStatusEvent(t))}onAllExtensionStatus(t,e){this.updateEventTimestamp();const r=ce.mapAllExtensionStatus(t);this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,r)}onAllDialerStatus(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onKeepAliveResponse(t){if(this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.keepAliveResponse(t),t.errorCode){this.closeAllConnections().then(()=>{this.doReconnect&&this.connectionState==="disconnected"&&this.scheduleReconnect()});return}}onExtensionsUpdatedEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onConnect(){this.connectionState="connected",this.reconnectionTime=this.eventsSdkClass.options.reconnectionDelay,this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0),this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.CONNECTED}),this.eventsSdkClass.loggerClass.start().then(()=>{this.eventsSdkClass.loggerClass.sdkConnectionSuccess()})}scheduleReconnect(){!this.doReconnect||this.reconnectTimeout||(this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.TRYING_TO_CONNECT}),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=void 0,this.reconnectionTime=Math.min(this.reconnectionTime*2,this.maxReconnectionDelay),this.reconnectionTime>this.maxReconnectionDelay&&(this.reconnectionTime=this.eventsSdkClass.options.reconnectionDelay),this.eventsSdkClass.connect(ne.NEXT)},this.reconnectionTime*1e3))}onDisconnect(t){if(this.connectionState="disconnected",this.eventsSdkClass.loggerClass.sdkDisconnect([t]),!this.doReconnect){this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.DISCONNECTED});return}this.closeAllConnections(),this.scheduleReconnect()}onConnectError(t){this.connectionState="disconnected",this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(t),this.doReconnect?this.scheduleReconnect():this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.DISCONNECTED})}async destroy(){this.doReconnect=!1,this.networkCleanup.forEach(t=>t()),await this.closeAllConnections()}}class Ye{constructor(t){K(this,"storageLogger");this.eventsSdkClass=t,this.eventsSdkClass=t}init(){if(!this.eventsSdkClass.options.useLogger)return;if(this.eventsSdkClass.options.storageLoggerInstance){this.storageLogger=this.eventsSdkClass.options.storageLoggerInstance;return}let t;this.eventsSdkClass.options.loggerSocketConnection&&(t=this.eventsSdkClass.options.loggerSocketConnection),this.eventsSdkClass.socketIoClass.ioFunction&&!t&&(t=this.eventsSdkClass.socketIoClass.ioFunction(this.eventsSdkClass.options.loggerServer,this.eventsSdkClass.options.loggerConnectOptions)),t&&(this.storageLogger=new F({socket:t,loggerOptions:this.eventsSdkClass.options.loggerConfig}))}async start(){this.storageLogger&&await this.storageLogger.start()}async stop(){this.storageLogger&&await this.storageLogger.stop()}log(t){if(this.eventsSdkClass.options.useLogger)if(this.storageLogger)switch(t.Level){case F.LevelEnum.INFO:this.storageLogger.log(t);break;case F.LevelEnum.DEBUG:this.storageLogger.debug(t);break;case F.LevelEnum.WARNING:this.storageLogger.warn(t);break;case F.LevelEnum.ERROR:this.storageLogger.error(t)}else t.Level===F.LevelEnum.INFO?console.log(t):t.Level===F.LevelEnum.ERROR&&console.error(t)}sdkConnectionSuccess(){const t={...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(t,this.eventsSdkClass.getCircularReplacer()),ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Connection established",StatusCode:200,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}sdkDisconnect(t){this.log({Message:`Sdk disconnected from the socket server ${this.eventsSdkClass.server&&this.eventsSdkClass.server.Domain?this.eventsSdkClass.server.Domain:this.eventsSdkClass.URL} (${t})`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Connection closed",StatusCode:200,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}sdkAttemptToConnect(t){this.log({Message:`${this.eventsSdkClass.options.loggerConfig.system} is trying to connect to WS server ${t}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Switching Protocols",StatusCode:101,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}sdkAttemptToConnectError(t){this.log({Message:`${t}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Connection error",StatusCode:500,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}loginError(t,e,r,o){this.log({Message:`External login request error with the login type ${t} ${t===Z.TOKEN?r:o}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"External login error",StatusCode:e||400,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}getSettingsError(t,e){this.log({Message:`Get settings error with token ${t}, error: ${e}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}refreshTokenError(t,e,r){this.log({Message:`Refresh token error with old refresh token ${t}, url: ${e}, error: ${r}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}keepAliveEmit(){this.log({Message:`Keep alive event emitted with this token: ${this.eventsSdkClass.authClass.token}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}keepAliveResponse(t){this.log({Message:`Keep alive response: ${JSON.stringify(t)}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Successful",StatusCode:200,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}eventLog(t,e){const r={[te.FULL]:[],[te.BOOTSTRAP]:[j.LOGIN_STATUS,j.LOGIN_SUCCESS,j.ALL_EXTENSION_STATUS,j.ALL_DIALER_STATUS],[te.DEBUG_EXTENSIONS]:[j.ALL_EXTENSION_STATUS,j.EXTENSION_EVENT,j.EXTENSIONS_UPDATED],[te.DEBUG_DIALER]:[j.ALL_DIALER_STATUS,j.DIALER_EVENT],[te.DEBUG_QUEUE]:[j.QUEUE_EVENT]};this.eventsSdkClass.options.debugOption&&(r[this.eventsSdkClass.options.debugOption].includes(t)||this.eventsSdkClass.options.debugOption===te.FULL)&&this.log({Message:`Event name: ${t}`,Body:{...this.getStaticData(),...e},ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Successful",Level:F.LevelEnum.DEBUG,LogType:F.LogTypeEnum.INFO})}getStaticData(){return{SocketId:this.eventsSdkClass.socketIoClass&&this.eventsSdkClass.socketIoClass.io?this.eventsSdkClass.socketIoClass.io.id:""}}}class Qe{constructor(t){K(this,"listeners",{[j.ALL_EXTENSION_STATUS]:[],[j.ALL_DIALER_STATUS]:[],[j.ALL_USERS_STATUS]:[],[j.QUEUE_EVENT]:[],[j.EXTENSION_EVENT]:[],[j.DIALER_EVENT]:[],[j.LOGIN_SUCCESS]:[],[j.LOGIN_STATUS]:[],[j.KEEP_ALIVE_RESPONSE]:[],[j.ONLINE_STATUS_EVENT]:[],[j.EXTENSIONS_UPDATED]:[]});K(this,"allListeners",[]);this.eventsSdkClass=t,this.eventsSdkClass=t}on(t,e){t==="*"?this.allListeners.push(e):this.listeners[t].push(e)}off(t,e){if(t==="*")this.allListeners=this.allListeners.filter(r=>r!==e);else{const o=this.listeners[t].filter(h=>h!==e);this.listeners={...this.listeners,[t]:o}}}emit(t,e){this.eventsSdkClass.socketIoClass.lastEventTimestamp=new Date().getTime(),this.listeners[t].forEach(o=>o({name:t,data:e}));const r={name:t,data:e};this.allListeners.forEach(o=>o(r))}}class Ze{constructor(t){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 Xe(this));K(this,"socketIoClass");K(this,"loggerClass",new Ye(this));K(this,"eventEmitterClass",new Qe(this));K(this,"getCircularReplacer",()=>{const t=new WeakSet;return(e,r)=>{if(!(e==="socket"||e==="io"||e==="nsps")){if(typeof r=="object"&&r!==null){if(t.has(r))return;t.add(r)}return r}}});this.options={...Ae,...t},this.socketIoClass=new He(this)}on(t,e){this.eventEmitterClass.on(t,e)}emit(t,...e){this.socketIoClass.io&&this.socketIoClass.io.emit(t,...e)}connect(t){t===ne.MAIN&&this.findMainServer(),t===ne.NEXT&&this.findNextServer(),this.socketIoClass.doReconnect=!0;try{this.loggerClass.init()}catch(e){console.error(e)}this.socketIoClass.initSocketConnection(),this.socketIoClass.initKeepAlive()}async disconnect(){this.socketIoClass.doReconnect=!1,await this.socketIoClass.closeAllConnections(),await this.loggerClass.stop()}clearKeepAliveInterval(){this.socketIoClass.clearKeepAliveInterval()}findMainServer(){this.servers.length?(this.mainServer=this.servers.reduce((t,e)=>e.Priority>t.Priority?e:t),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 t=this.servers.filter(e=>e.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(e.Priority)+1===0);t.length||(this.alreadyAttemptedOtherServers=[],t=this.servers.filter(e=>e.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(e.Priority)+1===0)),t.length&&(this.server=t.reduce((e,r)=>r.Priority>e.Priority?r:e),this.alreadyAttemptedOtherServers.push(this.server.Priority))}else this.server=this.mainServer;else if(this.URLList.length)if(this.URL===this.URLList[0]){let t=this.URLList.filter(e=>e!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(e)+1===0);t.length||(this.alreadyAttemptedOtherServers=[],t=this.URLList.filter(e=>e!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(e)+1===0)),t.length&&(this.URL=t[0],this.alreadyAttemptedOtherServers.push(this.URL))}else this.URL=this.URLList[0]}async init(){const t=await this.authClass.login();return t&&this.authClass.onLoginResponse(t),!0}getCurrentMonitorServer(){return this.server}}X.CallStatusEnum=Le,X.CallTypeEnum=_e,X.ConnectionStatusEnum=se,X.DebugOption=te,X.DialerTypeEnum=Oe,X.DirectionEnum=Re,X.DoNotCallMeStatusCodeEnum=Ie,X.EventsEnum=j,X.ExtensionEventReasonEnum=pe,X.ExtensionHangupCauseEnum=xe,X.LoginType=Z,X.QueueEventReasonEnum=Ue,X.ServerListenerEventsEnum=fe,X.ServerParameter=ne,X.default=Ze,Object.defineProperties(X,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
18
|
+
`,102:"\f",114:"\r"},V=function(){throw k=$=null,SyntaxError()},W=function(){for(var E,_,w,D,S,x=$,B=x.length;B>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 E=P?x.charAt(k):x[k],k++,E;case 34:for(E="@",k++;B>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:E+=J[S],k++;break;case 117:for(_=++k,w=k+4;w>k;k++)S=x.charCodeAt(k),S>=48&&57>=S||S>=97&&102>=S||S>=65&&70>=S||V();E+=G("0x"+x.slice(_,k));break;default:V()}else{if(S==34)break;for(S=x.charCodeAt(k),_=k;S>=32&&S!=92&&S!=34;)S=x.charCodeAt(++k);E+=x.slice(_,k)}if(x.charCodeAt(k)==34)return k++,E;V();default:if(_=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;B>k&&(S=x.charCodeAt(k),S>=48&&57>=S);k++);if(x.charCodeAt(k)==46){for(w=++k;B>w&&(S=x.charCodeAt(w),S>=48&&57>=S);w++);w==k&&V(),k=w}if(S=x.charCodeAt(k),S==101||S==69){for(S=x.charCodeAt(++k),(S==43||S==45)&&k++,w=k;B>w&&(S=x.charCodeAt(w),S>=48&&57>=S);w++);w==k&&V(),k=w}return+x.slice(_,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"$"},oe=function(E){var _,w;if(E=="$"&&V(),typeof E=="string"){if((P?E.charAt(0):E[0])=="@")return E.slice(1);if(E=="["){for(_=[];E=W(),E!="]";w||(w=!0))w&&(E==","?(E=W(),E=="]"&&V()):V()),E==","&&V(),_.push(oe(E));return _}if(E=="{"){for(_={};E=W(),E!="}";w||(w=!0))w&&(E==","?(E=W(),E=="}"&&V()):V()),(E==","||typeof E!="string"||(P?E.charAt(0):E[0])!="@"||W()!=":")&&V(),_[E.slice(1)]=oe(W());return _}V()}return E},Be=function(E,_,w){var D=De(E,_,w);D===l?delete E[_]:E[_]=D},De=function(E,_,w){var D,S=E[_];if(typeof S=="object"&&S)if(d.call(S)==v)for(D=S.length;D--;)Be(S,D,w);else f(S,function(x){Be(S,x,w)});return w.call(E,_,S)};u.parse=function(E,_){var w,D;return k=0,$=""+E,w=oe(W()),W()!="$"&&V(),k=$=null,_&&d.call(_)==s?De((D={},D[""]=w,D),"",_):w}}}})(this)},{}],48:[function(a,t){function e(r,o){var h=[];o=o||0;for(var f=o||0;f<r.length;f++)h[f-o]=r[f];return h}t.exports=e},{}]},{},[1])(1)}const Ge=Object.assign({"./v1_3_7.js":Object.freeze(Object.defineProperty({__proto__:null,default:$e},Symbol.toStringTag,{value:"Module"}))}),ze=/v\d+_\d+_\d+/;function Je(a){return typeof a=="function"}const ue=Object.entries(Ge).reduce((a,t)=>{var o;const e=t[1].default,r=(o=t[0].match(ze))==null?void 0:o[0];return Je(e)&&r&&(a[r]=e()),a},{}),Ne=a=>{if(a in ue)return ue[a];throw new Error(`Socket version ${a} not found`)},We={...ue,getSocketVersion:Ne,makeSocketVersion:(a,...t)=>Ne(a)(...t)};var Le=(a=>(a.RINGING="Ringing",a.TALKING="Talking",a.DIALING="Dialing",a.HOLD="Hold",a))(Le||{}),_e=(a=>(a.INCOMING="Incoming",a.OUTGOING="Outgoing",a))(_e||{}),se=(a=>(a.CONNECTED="connected",a.DISCONNECTED="disconnected",a.TRYING_TO_CONNECT="tryingToConnect",a))(se||{}),Oe=(a=>(a.AUTOMATIC="Automatic",a.IVR="IVR",a))(Oe||{}),Re=(a=>(a.INCOMINC="Incoming",a.OUTGOING="Outgoing",a.SPY="Spy",a.CLICK2CALL="Click2Call",a))(Re||{}),Ie=(a=>(a.RESPONSE_FROM_API_VALID="RESPONSE_FROM_API_VALID",a.RESPONSE_FROM_API_INVALID="RESPONSE_FROM_API_INVALID",a))(Ie||{}),j=(a=>(a.ALL_DIALER_STATUS="AllDialersStatus",a.ALL_EXTENSION_STATUS="AllExtensionsStatus",a.ALL_USERS_STATUS="AllUsersStatus",a.CONNECT="connect",a.DISCONNECT="disconnect",a.CONNECT_ERROR_EVENT="connect_error",a.EXTENSION_EVENT="ExtensionEvent",a.KEEP_ALIVE="keepalive",a.KEEP_ALIVE_RESPONSE="keepaliveResponse",a.LOGIN_STATUS="loginStatus",a.LOGIN_SUCCESS="loginSuccess",a.QUEUE_EVENT="QueueEvent",a.ONLINE_STATUS_EVENT="onlineStatusEvent",a.DIALER_EVENT="DialerEvent",a.EXTENSIONS_UPDATED="ExtensionsUpdated",a))(j||{}),pe=(a=>(a.NEWCALL="NEWCALL",a.ANSWER="ANSWER",a.HOLD="HOLD",a.UNHOLD="UNHOLD",a.HANGUP="HANGUP",a.USER_STATUS_UPDATE="userStatusUpdate",a))(pe||{}),xe=(a=>(a.NORMAL_HANGUP="Normal hangup",a.USER_BUSY="User busy",a.CALL_REJECTED="Call Rejected",a.UNALLOCATED_NUMBER="Unallocated (unassigned) number",a.UNKNOWN="Unknown",a.NO_USER_RESPONDING="No user responding",a.USER_ALERTING="User alerting, no answer",a.ANSWERED_ELSEWHERE="Answered elsewhere",a))(xe||{}),Ue=(a=>(a.ANSWER="ANSWER",a.ABANDONED="ABANDONED",a.EXIT="EXIT",a.JOIN="JOIN",a))(Ue||{});class ce{static mapExtensionEvent(t){var f,l;const e=t.reason;let r,o;t.data.currentCall&&(o=this.mapExtensionCall(t,t.data.currentCall));const h=this.mapExtensionData(t,t.data);return e===pe.HANGUP?r={...t,reason:e,data:{...h,currentCall:o?{...o,duration:o.callAnswered_UTC_CLIENT?Date.now()-o.callAnswered_UTC_CLIENT:0}:void 0,calls:(f=t.data.calls)==null?void 0:f.map(d=>{const i=this.mapExtensionCall(t,d);return{...i,duration:i.callAnswered_UTC_CLIENT?Date.now()-i.callAnswered_UTC_CLIENT:0}})}}:r={...t,data:{...h,currentCall:o,calls:(l=t.data.calls)==null?void 0:l.map(d=>this.mapExtensionCall(t,d))},reason:e},r}static mapAllExtensionStatus(t){return{...t,extensions:t.extensions.map(e=>{var r;return{...this.mapExtensionData(t,e),currentCall:e.currentCall?this.mapExtensionCall(t,e.currentCall):void 0,calls:(r=e.calls)==null?void 0:r.map(o=>this.mapExtensionCall(t,o))}})}}static mapExtensionData(t,e){return this.configureUTCForObject(e,[{key:"lastAnsweredCallEventEpoch",format:"sec"},{key:"lastCallEventEpoch",format:"sec"},{key:"lastHangupCallEpoch",format:"sec"},{key:"representativeUpdated",format:"ms"}],t.servertime,t.servertimeoffset)}static mapExtensionCall(t,e){return this.configureUTCForObject(e,[{key:"callAnswered",format:"sec"},{key:"callStarted",format:"sec"}],t.servertime,t.servertimeoffset)}static mapQueueCall(t,e){return this.configureUTCForObject(e,[{key:"JoinTimeStamp",format:"sec"},{key:"VHJoinTimeStamp",format:"sec"}],t.servertime,t.servertimeoffset)}static mapLoginStatusEvent(t){return{...t,queues:t.queues.map(e=>({...e,Calls:e.Calls.map(r=>this.mapQueueCall(t,r))}))}}static mapQueueEvent(t){return{...t,data:{...t.data,Calls:t.data.Calls.map(e=>this.mapQueueCall(t,e))}}}static assignProperty(t,e,r){t[e]=r}static configureUTCForObject(t,e,r,o){const h=(r-o*60)*1e3,f=Date.now()-h,l={};return e.forEach(d=>{const i=t[d.key],u=d.key;if(i!==0&&typeof i=="number"&&!isNaN(i)){let c=i;d.format==="ms"&&(c=Math.floor(c/1e3));const s=(c-o*60)*1e3;this.assignProperty(l,`${u}_UTC`,s),this.assignProperty(l,`${u}_UTC_CLIENT`,s+f)}else this.assignProperty(l,`${u}_UTC`,0),this.assignProperty(l,`${u}_UTC_CLIENT`,0)}),{...t,...l}}}var fe=(a=>(a.UPDATE_MONITORED_EXTENSIONS="updateMonitoredExtensions",a.KEEP_ALIVE="keepalive",a))(fe||{});class He{constructor(t){K(this,"io");K(this,"ioFunction");K(this,"lastEventTimestamp",new Date().getTime());K(this,"doReconnect",!0);K(this,"connectionState","disconnected");K(this,"keepAliveInterval");K(this,"reconnectTimeout");K(this,"networkReconnectTimeout");K(this,"reconnectionTime",Ae.reconnectionDelay);K(this,"maxReconnectionDelay",120);K(this,"networkCleanup",[]);this.eventsSdkClass=t,this.reconnectionTime=t.options.reconnectionDelay,this.setupNetworkListeners()}setupNetworkListeners(){const t=()=>this.closeAllConnections(),e=()=>this.handleNetworkOnline();typeof window<"u"&&"addEventListener"in window&&typeof window.addEventListener=="function"?(window.addEventListener("offline",t),window.addEventListener("online",e),this.networkCleanup.push(()=>window.removeEventListener("offline",t),()=>window.removeEventListener("online",e))):typeof self<"u"&&"addEventListener"in self&&typeof self.addEventListener=="function"&&(self.addEventListener("offline",t),self.addEventListener("online",e),this.networkCleanup.push(()=>self.removeEventListener("offline",t),()=>self.removeEventListener("online",e)))}handleNetworkOnline(){this.networkReconnectTimeout&&clearTimeout(this.networkReconnectTimeout),this.networkReconnectTimeout=setTimeout(()=>{this.connectionState==="disconnected"&&this.doReconnect&&this.eventsSdkClass.connect(ne.NEXT)},500)}getSocketIoFunction(t){const e=t.split("v="),r="v".concat(e[e.length-1]).replaceAll(".","_");this.ioFunction=We.getSocketVersion(r)}initSocketConnection(){if(this.connectionState!=="disconnected")return;this.connectionState="connecting";const t=this.eventsSdkClass.authClass.token,e=this.eventsSdkClass.options.protocol,r=this.eventsSdkClass.server;try{const o=r?r.Domain:this.eventsSdkClass.URL,h=r?`${e}://${o}`:this.eventsSdkClass.URL,f={reconnection:!1,upgrade:!1,transports:["websocket"],forceNew:!0,query:{token:t},timeout:this.eventsSdkClass.options.timeout};if(this.ioFunction&&h)this.io=this.ioFunction(h,f),this.initSocketEvents(),this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{attemptToConnect:h,connectionStatus:se.TRYING_TO_CONNECT}),this.eventsSdkClass.loggerClass.sdkAttemptToConnect(o);else throw new Error("Socket server url not defined")}catch(o){this.connectionState="disconnected",this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(o)}}clearKeepAliveInterval(){this.keepAliveInterval&&(clearInterval(this.keepAliveInterval),this.keepAliveInterval=void 0)}initKeepAlive(){this.clearKeepAliveInterval(),this.keepAliveInterval=setInterval(async()=>{new Date().getTime()>this.lastEventTimestamp+this.eventsSdkClass.options.keepAliveTimeout&&this.io&&this.connectionState==="connected"&&this.eventsSdkClass.authClass.token&&(this.eventsSdkClass.emit(fe.KEEP_ALIVE,this.eventsSdkClass.authClass.token),this.eventsSdkClass.loggerClass.keepAliveEmit())},this.eventsSdkClass.options.keepAliveTimeout)}async closeAllConnections(){if(this.clearKeepAliveInterval(),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0),this.networkReconnectTimeout&&(clearTimeout(this.networkReconnectTimeout),this.networkReconnectTimeout=void 0),this.io){const t=this.io;this.io=void 0;try{await Promise.race([new Promise(e=>{t.on("disconnect",()=>e()),t.removeAllListeners(),t.close(),t.disconnect()}),new Promise(e=>setTimeout(e,1e3))])}catch{}}this.connectionState="disconnected",this.eventsSdkClass.loggerClass.stop(),re.clearSessionStorage()}initSocketEvents(){this.io&&(this.io.removeAllListeners(),this.io.on(j.LOGIN_SUCCESS,t=>this.onLoginSuccessEvent(t,j.LOGIN_SUCCESS)).on(j.QUEUE_EVENT,t=>this.onQueueEvent(t,j.QUEUE_EVENT)).on(j.EXTENSION_EVENT,t=>this.onExtensionEvent(t,j.EXTENSION_EVENT)).on(j.DIALER_EVENT,t=>this.onDialerEvent(t,j.DIALER_EVENT)).on(j.LOGIN_STATUS,t=>this.onLoginStatusEvent(t,j.LOGIN_STATUS)).on(j.ALL_EXTENSION_STATUS,t=>this.onAllExtensionStatus(t,j.ALL_EXTENSION_STATUS)).on(j.ALL_DIALER_STATUS,t=>this.onAllDialerStatus(t,j.ALL_DIALER_STATUS)).on(j.KEEP_ALIVE_RESPONSE,t=>this.onKeepAliveResponse(t)).on(j.EXTENSIONS_UPDATED,t=>this.onExtensionsUpdatedEvent(t,j.EXTENSIONS_UPDATED)).on(j.CONNECT,()=>this.onConnect()).on(j.DISCONNECT,t=>this.onDisconnect(t)).on(j.CONNECT_ERROR_EVENT,t=>this.onConnectError(t)))}updateEventTimestamp(){this.lastEventTimestamp=new Date().getTime()}onLoginSuccessEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onQueueEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,ce.mapQueueEvent(t))}onExtensionEvent(t,e){this.updateEventTimestamp();const r=ce.mapExtensionEvent(t);r&&(this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,r))}onDialerEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onLoginStatusEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,ce.mapLoginStatusEvent(t))}onAllExtensionStatus(t,e){this.updateEventTimestamp();const r=ce.mapAllExtensionStatus(t);this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,r)}onAllDialerStatus(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onKeepAliveResponse(t){if(this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.keepAliveResponse(t),t.errorCode){this.closeAllConnections().then(()=>{this.doReconnect&&this.connectionState==="disconnected"&&this.scheduleReconnect()});return}}onExtensionsUpdatedEvent(t,e){this.updateEventTimestamp(),this.eventsSdkClass.loggerClass.eventLog(e,t),this.eventsSdkClass.eventEmitterClass.emit(e,t)}onConnect(){this.connectionState="connected",this.reconnectionTime=this.eventsSdkClass.options.reconnectionDelay,this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0),this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.CONNECTED}),this.eventsSdkClass.loggerClass.start().then(()=>{this.eventsSdkClass.loggerClass.sdkConnectionSuccess()})}scheduleReconnect(){!this.doReconnect||this.reconnectTimeout||(this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.TRYING_TO_CONNECT}),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=void 0,this.reconnectionTime=Math.min(this.reconnectionTime*2,this.maxReconnectionDelay),this.reconnectionTime>this.maxReconnectionDelay&&(this.reconnectionTime=this.eventsSdkClass.options.reconnectionDelay),this.eventsSdkClass.connect(ne.NEXT)},this.reconnectionTime*1e3))}onDisconnect(t){if(this.connectionState="disconnected",this.eventsSdkClass.loggerClass.sdkDisconnect([t]),!this.doReconnect){this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.DISCONNECTED});return}this.closeAllConnections(),this.scheduleReconnect()}onConnectError(t){this.connectionState="disconnected",this.eventsSdkClass.loggerClass.sdkAttemptToConnectError(t),this.doReconnect?this.scheduleReconnect():this.eventsSdkClass.eventEmitterClass.emit(j.ONLINE_STATUS_EVENT,{connectionStatus:se.DISCONNECTED})}async destroy(){this.doReconnect=!1,this.networkCleanup.forEach(t=>t()),await this.closeAllConnections()}}class Ye{constructor(t){K(this,"storageLogger");this.eventsSdkClass=t,this.eventsSdkClass=t}init(){if(!this.eventsSdkClass.options.useLogger)return;if(this.eventsSdkClass.options.storageLoggerInstance){this.storageLogger=this.eventsSdkClass.options.storageLoggerInstance;return}let t;this.eventsSdkClass.options.loggerSocketConnection&&(t=this.eventsSdkClass.options.loggerSocketConnection),this.eventsSdkClass.socketIoClass.ioFunction&&!t&&(t=this.eventsSdkClass.socketIoClass.ioFunction(this.eventsSdkClass.options.loggerServer,this.eventsSdkClass.options.loggerConnectOptions)),t&&(this.storageLogger=new F({socket:t,loggerOptions:this.eventsSdkClass.options.loggerConfig}))}async start(){this.storageLogger&&await this.storageLogger.start()}async stop(){this.storageLogger&&await this.storageLogger.stop()}log(t){if(this.eventsSdkClass.options.useLogger)if(this.storageLogger)switch(t.Level){case F.LevelEnum.INFO:this.storageLogger.log(t);break;case F.LevelEnum.DEBUG:this.storageLogger.debug(t);break;case F.LevelEnum.WARNING:this.storageLogger.warn(t);break;case F.LevelEnum.ERROR:this.storageLogger.error(t)}else t.Level===F.LevelEnum.INFO?console.log(t):t.Level===F.LevelEnum.ERROR&&console.error(t)}sdkConnectionSuccess(){const t={...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(t,this.eventsSdkClass.getCircularReplacer()),ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Connection established",StatusCode:200,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}sdkDisconnect(t){this.log({Message:`Sdk disconnected from the socket server ${this.eventsSdkClass.server&&this.eventsSdkClass.server.Domain?this.eventsSdkClass.server.Domain:this.eventsSdkClass.URL} (${t})`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Connection closed",StatusCode:200,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}sdkAttemptToConnect(t){this.log({Message:`${this.eventsSdkClass.options.loggerConfig.system} is trying to connect to WS server ${t}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Switching Protocols",StatusCode:101,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}sdkAttemptToConnectError(t){this.log({Message:`${t}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Connection error",StatusCode:500,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}loginError(t,e,r,o){this.log({Message:`External login request error with the login type ${t} ${t===Z.TOKEN?r:o}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"External login error",StatusCode:e||400,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}getSettingsError(t,e){this.log({Message:`Get settings error with token ${t}, error: ${e}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}refreshTokenError(t,e,r){this.log({Message:`Refresh token error with old refresh token ${t}, url: ${e}, error: ${r}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Get settings error",StatusCode:400,Level:F.LevelEnum.ERROR,LogType:F.LogTypeEnum.ERROR})}keepAliveEmit(){this.log({Message:`Keep alive event emitted with this token: ${this.eventsSdkClass.authClass.token}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}keepAliveResponse(t){this.log({Message:`Keep alive response: ${JSON.stringify(t)}`,ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Successful",StatusCode:200,Level:F.LevelEnum.INFO,LogType:F.LogTypeEnum.INFO})}eventLog(t,e){const r={[te.FULL]:[],[te.BOOTSTRAP]:[j.LOGIN_STATUS,j.LOGIN_SUCCESS,j.ALL_EXTENSION_STATUS,j.ALL_DIALER_STATUS],[te.DEBUG_EXTENSIONS]:[j.ALL_EXTENSION_STATUS,j.EXTENSION_EVENT,j.EXTENSIONS_UPDATED],[te.DEBUG_DIALER]:[j.ALL_DIALER_STATUS,j.DIALER_EVENT],[te.DEBUG_QUEUE]:[j.QUEUE_EVENT]};this.eventsSdkClass.options.debugOption&&(r[this.eventsSdkClass.options.debugOption].includes(t)||this.eventsSdkClass.options.debugOption===te.FULL)&&this.log({Message:`Event name: ${t}`,Body:{...this.getStaticData(),...e},ActionName:F.ActionNameEnum.WSCONNECT,isShowClient:!1,Status:"Successful",Level:F.LevelEnum.DEBUG,LogType:F.LogTypeEnum.INFO})}getStaticData(){return{SocketId:this.eventsSdkClass.socketIoClass&&this.eventsSdkClass.socketIoClass.io?this.eventsSdkClass.socketIoClass.io.id:""}}}class Qe{constructor(t){K(this,"listeners",{[j.ALL_EXTENSION_STATUS]:[],[j.ALL_DIALER_STATUS]:[],[j.ALL_USERS_STATUS]:[],[j.QUEUE_EVENT]:[],[j.EXTENSION_EVENT]:[],[j.DIALER_EVENT]:[],[j.LOGIN_SUCCESS]:[],[j.LOGIN_STATUS]:[],[j.KEEP_ALIVE_RESPONSE]:[],[j.ONLINE_STATUS_EVENT]:[],[j.EXTENSIONS_UPDATED]:[]});K(this,"allListeners",[]);this.eventsSdkClass=t,this.eventsSdkClass=t}on(t,e){t==="*"?this.allListeners.push(e):this.listeners[t].push(e)}off(t,e){if(t==="*")this.allListeners=this.allListeners.filter(r=>r!==e);else{const o=this.listeners[t].filter(h=>h!==e);this.listeners={...this.listeners,[t]:o}}}emit(t,e){this.eventsSdkClass.socketIoClass.lastEventTimestamp=new Date().getTime(),this.listeners[t].forEach(o=>o({name:t,data:e}));const r={name:t,data:e};this.allListeners.forEach(o=>o(r))}}class Ze{constructor(t){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 Xe(this));K(this,"socketIoClass");K(this,"loggerClass",new Ye(this));K(this,"eventEmitterClass",new Qe(this));K(this,"getCircularReplacer",()=>{const t=new WeakSet;return(e,r)=>{if(!(e==="socket"||e==="io"||e==="nsps")){if(typeof r=="object"&&r!==null){if(t.has(r))return;t.add(r)}return r}}});this.options={...Ae,...t},this.socketIoClass=new He(this)}on(t,e){this.eventEmitterClass.on(t,e)}emit(t,...e){this.socketIoClass.io&&this.socketIoClass.io.emit(t,...e)}connect(t){t===ne.MAIN&&this.findMainServer(),t===ne.NEXT&&this.findNextServer(),this.socketIoClass.doReconnect=!0;try{this.loggerClass.init()}catch(e){console.error(e)}this.socketIoClass.initSocketConnection(),this.socketIoClass.initKeepAlive()}async disconnect(){this.socketIoClass.doReconnect=!1,await this.socketIoClass.closeAllConnections(),await this.loggerClass.stop()}clearKeepAliveInterval(){this.socketIoClass.clearKeepAliveInterval()}findMainServer(){this.servers.length?(this.mainServer=this.servers.reduce((t,e)=>e.Priority>t.Priority?e:t),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 t=this.servers.filter(e=>e.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(e.Priority)+1===0);t.length||(this.alreadyAttemptedOtherServers=[],t=this.servers.filter(e=>e.Priority!==this.mainServer.Priority&&this.alreadyAttemptedOtherServers.indexOf(e.Priority)+1===0)),t.length&&(this.server=t.reduce((e,r)=>r.Priority>e.Priority?r:e),this.alreadyAttemptedOtherServers.push(this.server.Priority))}else this.server=this.mainServer;else if(this.URLList.length)if(this.URL===this.URLList[0]){let t=this.URLList.filter(e=>e!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(e)+1===0);t.length||(this.alreadyAttemptedOtherServers=[],t=this.URLList.filter(e=>e!==this.URLList[0]&&this.alreadyAttemptedOtherServers.indexOf(e)+1===0)),t.length&&(this.URL=t[0],this.alreadyAttemptedOtherServers.push(this.URL))}else this.URL=this.URLList[0]}async init(){const t=await this.authClass.login();return t&&this.authClass.onLoginResponse(t),!0}getCurrentMonitorServer(){return this.server}}X.CallStatusEnum=Le,X.CallTypeEnum=_e,X.ConnectionStatusEnum=se,X.DebugOption=te,X.DialerTypeEnum=Oe,X.DirectionEnum=Re,X.DoNotCallMeStatusCodeEnum=Ie,X.EventsEnum=j,X.ExtensionEventReasonEnum=pe,X.ExtensionHangupCauseEnum=xe,X.LoginType=Z,X.QueueEventReasonEnum=Ue,X.ServerListenerEventsEnum=fe,X.ServerParameter=ne,X.default=Ze,Object.defineProperties(X,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
19
19
|
//# sourceMappingURL=voicenter-events-sdk.umd.js.map
|