@wizai/agent-sip-sdk 0.1.11-alpha → 0.1.12-alpha

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.
@@ -4,4 +4,4 @@
4
4
  * Available under MIT License (MIT)
5
5
  * https://github.com/Yaffle/EventSource/
6
6
  */
7
- !function(e,t){!function(n){var r=n.setTimeout,i=n.clearTimeout,o=n.XMLHttpRequest,s=n.XDomainRequest,a=n.ActiveXObject,u=n.EventSource,l=n.document,c=n.Promise,h=n.fetch,f=n.Response,d=n.TextDecoder,p=n.TextEncoder,g=n.AbortController;if("undefined"==typeof window||void 0===l||"readyState"in l||null!=l.body||(l.readyState="loading",window.addEventListener("load",(function(e){l.readyState="complete"}),!1)),null==o&&null!=a&&(o=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==g){var m=h;h=function(e,t){var n=t.signal;return m(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then((function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}}))},g=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function _(){this.bitsNeeded=0,this.codePoint=0}_.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var r=65533,i="",o=this.bitsNeeded,s=this.codePoint,a=0;a<e.length;a+=1){var u=e[a];0!==o&&(u<128||u>191||!t(s<<6|63&u,o-6,n(o,s)))&&(o=0,s=r,i+=String.fromCharCode(s)),0===o?(u>=0&&u<=127?(o=0,s=u):u>=192&&u<=223?(o=6,s=31&u):u>=224&&u<=239?(o=12,s=15&u):u>=240&&u<=247?(o=18,s=7&u):(o=0,s=r),0===o||t(s,o,n(o,s))||(o=0,s=r)):(o-=6,s=s<<6|63&u),0===o&&(s<=65535?i+=String.fromCharCode(s):(i+=String.fromCharCode(55296+(s-65535-1>>10)),i+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=s,i};null!=d&&null!=p&&function(){try{return"test"===(new d).decode((new p).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(d=_);var A=function(){};function v(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=A,this.onload=A,this.onerror=A,this.onreadystatechange=A,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=A}function y(e){return e.replace(/[A-Z]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+32)}))}function T(e){for(var t=Object.create(null),n=e.split("\r\n"),r=0;r<n.length;r+=1){var i=n[r].split(": "),o=i.shift(),s=i.join(": ");t[y(o)]=s}this._map=t}function S(){}function E(e){this._headers=e}function C(){}function w(){this._listeners=Object.create(null)}function b(e){r((function(){throw e}),0)}function I(e){this.type=e,this.target=void 0}function R(e,t){I.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function O(e,t){I.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function D(e,t){I.call(this,e),this.error=t.error}v.prototype.open=function(e,t){this._abort(!0);var n=this,s=this._xhr,a=1,u=0;this._abort=function(e){0!==n._sendTimeout&&(i(n._sendTimeout),n._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=A,s.onerror=A,s.onabort=A,s.onprogress=A,s.onreadystatechange=A,s.abort(),0!==u&&(i(u),u=0),e||(n.readyState=4,n.onabort(null),n.onreadystatechange())),a=0};var l=function(){if(1===a){var e=0,t="",r=void 0;if("contentType"in s)e=200,t="OK",r=s.contentType;else try{e=s.status,t=s.statusText,r=s.getResponseHeader("Content-Type")}catch(n){e=0,t="",r=void 0}0!==e&&(a=2,n.readyState=2,n.status=e,n.statusText=t,n._contentType=r,n.onreadystatechange())}},c=function(){if(l(),2===a||3===a){a=3;var e="";try{e=s.responseText}catch(e){}n.readyState=3,n.responseText=e,n.onprogress()}},h=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:A}),c(),1===a||2===a||3===a){if(a=4,0!==u&&(i(u),u=0),n.readyState=4,"load"===e)n.onload(t);else if("error"===e)n.onerror(t);else{if("abort"!==e)throw new TypeError;n.onabort(t)}n.onreadystatechange()}},f=function(){u=r((function(){f()}),500),3===s.readyState&&c()};"onload"in s&&(s.onload=function(e){h("load",e)}),"onerror"in s&&(s.onerror=function(e){h("error",e)}),"onabort"in s&&(s.onabort=function(e){h("abort",e)}),"onprogress"in s&&(s.onprogress=c),"onreadystatechange"in s&&(s.onreadystatechange=function(e){!function(e){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",e):3===s.readyState?"onprogress"in s||c():2===s.readyState&&l())}(e)}),!("contentType"in s)&&"ontimeout"in o.prototype||(t+=(-1===t.indexOf("?")?"?":"&")+"padding=true"),s.open(e,t,!0),"readyState"in s&&(u=r((function(){f()}),0))},v.prototype.abort=function(){this._abort(!1)},v.prototype.getResponseHeader=function(e){return this._contentType},v.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},v.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},v.prototype.send=function(){if("ontimeout"in o.prototype&&("sendAsBinary"in o.prototype||"mozAnon"in o.prototype)||null==l||null==l.readyState||"complete"===l.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(e){throw e}}else{var t=this;t._sendTimeout=r((function(){t._sendTimeout=0,t.send()}),4)}},T.prototype.get=function(e){return this._map[y(e)]},null!=o&&null==o.HEADERS_RECEIVED&&(o.HEADERS_RECEIVED=2),S.prototype.open=function(e,t,n,r,i,s,a){e.open("GET",i);var u=0;for(var l in e.onprogress=function(){var t=e.responseText.slice(u);u+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===o.HEADERS_RECEIVED){var n=e.status,r=e.statusText,i=e.getResponseHeader("Content-Type"),s=e.getAllResponseHeaders();t(n,r,i,new T(s))}},e.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,l)&&e.setRequestHeader(l,a[l]);return e.send(),e},E.prototype.get=function(e){return this._headers.get(e)},C.prototype.open=function(e,t,n,r,i,o,s){var a=null,u=new g,l=u.signal,f=new d;return h(i,{headers:s,credentials:o?"include":"same-origin",signal:l,cache:"no-store"}).then((function(e){return a=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new E(e.headers)),new c((function(e,t){var r=function(){a.read().then((function(t){if(t.done)e(void 0);else{var i=f.decode(t.value,{stream:!0});n(i),r()}})).catch((function(e){t(e)}))};r()}))})).catch((function(e){return"AbortError"===e.name?void 0:e})).then((function(e){r(e)})),{abort:function(){null!=a&&a.cancel(),u.abort()}}},w.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,r=0;r<n;r+=1){var i=t[r];try{"function"==typeof i.handleEvent?i.handleEvent(e):i.call(this,e)}catch(e){b(e)}}},w.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];null==r&&(r=[],n[e]=r);for(var i=!1,o=0;o<r.length;o+=1)r[o]===t&&(i=!0);i||r.push(t)},w.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];if(null!=r){for(var i=[],o=0;o<r.length;o+=1)r[o]!==t&&i.push(r[o]);0===i.length?delete n[e]:n[e]=i}},R.prototype=Object.create(I.prototype),O.prototype=Object.create(I.prototype),D.prototype=Object.create(I.prototype);var k=-1,M=0,q=1,N=2,U=-1,x=0,P=1,L=2,B=3,F=/^text\/event\-stream(;.*)?$/i,H=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),G(n)},G=function(e){return Math.min(Math.max(e,1e3),18e6)},Y=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(e){b(e)}};function j(e,t){w.call(this),t=t||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,t,n){t=String(t);var a=Boolean(n.withCredentials),u=n.lastEventIdQueryParameterName||"lastEventId",l=G(1e3),c=H(n.heartbeatTimeout,45e3),h="",f=l,d=!1,p=0,g=n.headers||{},m=n.Transport,_=Q&&null==m?void 0:new v(null!=m?new m:null!=o&&"withCredentials"in o.prototype||null==s?new o:new s),A=null!=m&&"string"!=typeof m?new m:null==_?new C:new S,y=void 0,T=0,E=k,w="",b="",I="",j="",W=x,K=0,z=0,J=function(t,n,r,i){if(E===M)if(200===t&&null!=r&&F.test(r)){E=q,d=Date.now(),f=l,e.readyState=q;var o=new O("open",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onopen,o)}else{var s="";200!==t?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",X();o=new O("error",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onerror,o),console.error(s)}},V=function(t){if(E===q){for(var n=-1,o=0;o<t.length;o+=1){(u=t.charCodeAt(o))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(n=o)}var s=(-1!==n?j:"")+t.slice(0,n+1);j=(-1===n?j:"")+t.slice(n+1),""!==t&&(d=Date.now(),p+=t.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(W===U&&u==="\n".charCodeAt(0))W=x;else if(W===U&&(W=x),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(W!==x){W===P&&(z=a+1);var g=s.slice(K,z-1),m=s.slice(z+(z<a&&s.charCodeAt(z)===" ".charCodeAt(0)?1:0),a);"data"===g?(w+="\n",w+=m):"id"===g?b=m:"event"===g?I=m:"retry"===g?(l=H(m,l),f=l):"heartbeatTimeout"===g&&(c=H(m,c),0!==T&&(i(T),T=r((function(){$()}),c)))}if(W===x){if(""!==w){h=b,""===I&&(I="message");var _=new R(I,{data:w.slice(1),lastEventId:b});if(e.dispatchEvent(_),"open"===I?Y(e,e.onopen,_):"message"===I?Y(e,e.onmessage,_):"error"===I&&Y(e,e.onerror,_),E===N)return}w="",I=""}W=u==="\r".charCodeAt(0)?U:x}else W===x&&(K=a,W=P),W===P?u===":".charCodeAt(0)&&(z=a+1,W=L):W===L&&(W=B)}}},Z=function(t){if(E===q||E===M){E=k,0!==T&&(i(T),T=0),T=r((function(){$()}),f),f=G(Math.min(16*l,2*f)),e.readyState=M;var n=new D("error",{error:t});e.dispatchEvent(n),Y(e,e.onerror,n),null!=t&&console.error(t)}},X=function(){E=N,null!=y&&(y.abort(),y=void 0),0!==T&&(i(T),T=0),e.readyState=N},$=function(){if(T=0,E===k){d=!1,p=0,T=r((function(){$()}),c),E=M,w="",I="",b=h,j="",K=0,z=0,W=x;var n=t;if("data:"!==t.slice(0,5)&&"blob:"!==t.slice(0,5)&&""!==h){var i=t.indexOf("?");n=-1===i?t:t.slice(0,i+1)+t.slice(i+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,(function(e,t){return t===u?"":e})),n+=(-1===t.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var o=e.withCredentials,s={Accept:"text/event-stream"},a=e.headers;if(null!=a)for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(s[l]=a[l]);try{y=A.open(_,J,V,Z,n,o,s)}catch(e){throw X(),e}}else if(d||null==y){var f=Math.max((d||Date.now())+c-Date.now(),1);d=!1,T=r((function(){$()}),f)}else Z(new Error("No activity within "+c+" milliseconds. "+(E===M?"No response received.":p+" chars received.")+" Reconnecting.")),null!=y&&(y.abort(),y=void 0)};e.url=t,e.readyState=M,e.withCredentials=a,e.headers=g,e._close=X,$()}(this,e,t)}var Q=null!=h&&null!=f&&"body"in f.prototype;j.prototype=Object.create(w.prototype),j.prototype.CONNECTING=M,j.prototype.OPEN=q,j.prototype.CLOSED=N,j.prototype.close=function(){this._close()},j.CONNECTING=M,j.OPEN=q,j.CLOSED=N,j.prototype.withCredentials=void 0;var W,K=u;null==o||null!=u&&"withCredentials"in u.prototype||(K=j),W=function(e){e.EventSourcePolyfill=j,e.NativeEventSource=u,e.EventSource=K}(t),void 0!==W&&(e.exports=W)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:i:globalThis)}(hu,hu.exports);var fu,du,pu=hu.exports,gu={exports:{}},mu=o(gu.exports=function(){var e=1e3,t=6e4,n=36e5,r="millisecond",i="second",o="minute",s="hour",a="day",u="week",l="month",c="quarter",h="year",f="date",d="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},A={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?"+":"-")+_(r,2,"0")+":"+_(i,2,"0")},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),o=n-i<0,s=t.clone().add(r+(o?-1:1),l);return+(-(r+(n-i)/(o?i-s:s-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:h,w:u,d:a,D:f,h:s,m:o,s:i,ms:r,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},v="en",y={};y[v]=m;var T="$isDayjsObject",S=function(e){return e instanceof b||!(!e||!e[T])},E=function e(t,n,r){var i;if(!t)return v;if("string"==typeof t){var o=t.toLowerCase();y[o]&&(i=o),n&&(y[o]=n,i=o);var s=t.split("-");if(!i&&s.length>1)return e(s[0])}else{var a=t.name;y[a]=t,i=a}return!r&&i&&(v=i),i||!r&&v},C=function(e,t){if(S(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new b(n)},w=A;w.l=E,w.i=S,w.w=function(e,t){return C(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var b=function(){function m(e){this.$L=E(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[T]=!0}var _=m.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(w.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(p);if(r){var i=r[2]-1||0,o=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return w},_.isValid=function(){return!(this.$d.toString()===d)},_.isSame=function(e,t){var n=C(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return C(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<C(e)},_.$g=function(e,t,n){return w.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!w.u(t)||t,c=w.p(e),d=function(e,t){var i=w.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(a)},p=function(e,t){return w.w(n.toDate()[e].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},g=this.$W,m=this.$M,_=this.$D,A="set"+(this.$u?"UTC":"");switch(c){case h:return r?d(1,0):d(31,11);case l:return r?d(1,m):d(0,m+1);case u:var v=this.$locale().weekStart||0,y=(g<v?g+7:g)-v;return d(r?_-y:_+(6-y),m);case a:case f:return p(A+"Hours",0);case s:return p(A+"Minutes",1);case o:return p(A+"Seconds",2);case i:return p(A+"Milliseconds",3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,u=w.p(e),c="set"+(this.$u?"UTC":""),d=(n={},n[a]=c+"Date",n[f]=c+"Date",n[l]=c+"Month",n[h]=c+"FullYear",n[s]=c+"Hours",n[o]=c+"Minutes",n[i]=c+"Seconds",n[r]=c+"Milliseconds",n)[u],p=u===a?this.$D+(t-this.$W):t;if(u===l||u===h){var g=this.clone().set(f,1);g.$d[d](p),g.init(),this.$d=g.set(f,Math.min(this.$D,g.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[w.p(e)]()},_.add=function(r,c){var f,d=this;r=Number(r);var p=w.p(c),g=function(e){var t=C(d);return w.w(t.date(t.date()+Math.round(e*r)),d)};if(p===l)return this.set(l,this.$M+r);if(p===h)return this.set(h,this.$y+r);if(p===a)return g(1);if(p===u)return g(7);var m=(f={},f[o]=t,f[s]=n,f[i]=e,f)[p]||1,_=this.$d.getTime()+r*m;return w.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=e||"YYYY-MM-DDTHH:mm:ssZ",i=w.z(this),o=this.$H,s=this.$m,a=this.$M,u=n.weekdays,l=n.months,c=n.meridiem,h=function(e,n,i,o){return e&&(e[n]||e(t,r))||i[n].slice(0,o)},f=function(e){return w.s(o%12||12,e,"0")},p=c||function(e,t,n){var r=e<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(g,(function(e,r){return r||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return w.s(t.$y,4,"0");case"M":return a+1;case"MM":return w.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,l,3);case"MMMM":return h(l,a);case"D":return t.$D;case"DD":return w.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return h(n.weekdaysMin,t.$W,u,2);case"ddd":return h(n.weekdaysShort,t.$W,u,3);case"dddd":return u[t.$W];case"H":return String(o);case"HH":return w.s(o,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return p(o,s,!0);case"A":return p(o,s,!1);case"m":return String(s);case"mm":return w.s(s,2,"0");case"s":return String(t.$s);case"ss":return w.s(t.$s,2,"0");case"SSS":return w.s(t.$ms,3,"0");case"Z":return i}return null}(e)||i.replace(":","")}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,d){var p,g=this,m=w.p(f),_=C(r),A=(_.utcOffset()-this.utcOffset())*t,v=this-_,y=function(){return w.m(g,_)};switch(m){case h:p=y()/12;break;case l:p=y();break;case c:p=y()/3;break;case u:p=(v-A)/6048e5;break;case a:p=(v-A)/864e5;break;case s:p=v/n;break;case o:p=v/t;break;case i:p=v/e;break;default:p=v}return d?p:w.a(p)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return y[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=E(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return w.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},m}(),I=b.prototype;return C.prototype=I,[["$ms",r],["$s",i],["$m",o],["$H",s],["$W",a],["$M",l],["$y",h],["$D",f]].forEach((function(e){I[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),C.extend=function(e,t){return e.$i||(e(t,b,C),e.$i=!0),C},C.locale=E,C.isDayjs=S,C.unix=function(e){return C(1e3*e)},C.en=y[v],C.Ls=y,C.p={},C}()),_u="aks_agent_token",Au=function(){function r(e){this.baseUrl="",this.eventSource=null,this.retryCount=0,this.retryMap=new Map,this.token="",this.id=e.id,this.getSystemToken=e.getSystemToken,this.resetSSE=e.resetSSE,this.retryCount=e.retryCount||0,this.baseUrl=e.baseUrl||""}return r.prototype.validateToken=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,fetch("".concat(this.baseUrl,"/iam/token/validate?accountId=").concat(e),{method:"GET",headers:{authentication:r}}).then((function(e){return e.json()}))]}))}))},r.prototype.initToken=function(){return t(this,void 0,void 0,(function(){var e,t,r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.getSystemToken()];case 1:return(e=n.sent())?[4,this.validateToken(this.id,e)]:[2,{code:au.FAILED,data:null,message:"get system token failed"}];case 2:return(t=n.sent()).code===au.SUCCESS?(this.token=e,sessionStorage.setItem(_u,e),this.executePeriodically(this.refreshToken.bind(this),12e5),[2,{code:au.SUCCESS,data:null,message:t.message}]):[2,{code:au.FAILED,data:null,message:t.message}];case 3:return r=n.sent(),[2,{code:au.FAILED,data:null,message:(null==r?void 0:r.toString())||"system error"}];case 4:return[2]}}))}))},r.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var e=this;return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/iam/oauth2/refresh")}).then((function(t){t.token&&(e.token=t.token,sessionStorage.setItem(_u,t.token),e.eventSource&&e.resetSSE())}))]}))}))},r.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/status/list")})]}))}))},r.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/getAgentByUserId")})]}))}))},r.prototype.getAgentSetting=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getAgentSetting"),data:e})]}))}))},r.prototype.updateAgentHangup=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent/").concat(e),method:"PUT"})]}))}))},r.prototype.updateAgentTicket=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/voipPlatform/agent/ticket"),data:e})]}))}))},r.prototype.registerSSE=function(e){return t(this,void 0,void 0,(function(){var r,i,o,s,a,u=this;return n(this,(function(l){return r=e.agentId,i=e.onMessage,o=function(e){},s=new Promise((function(e){o=e})),a=this.token,this.eventSource=new pu.EventSourcePolyfill("".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_event?agentId=").concat(r),{headers:{Authentication:a,"Cache-Control":"no-cache",Connection:"keep-alive"},heartbeatTimeout:12e6}),this.eventSource.onmessage=i,this.eventSource.onopen=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!0),[2]}))}))},this.eventSource.onerror=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!1),[2]}))}))},[2,s]}))}))},r.prototype.closeSSE=function(e){return t(this,void 0,void 0,(function(){var t,r,i=this;return n(this,(function(n){return t=e.agentId,r=e.clearTicket,this.eventSource?[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_close?agentId=").concat(t,"&clearTicket=").concat(r)}).then((function(){i.eventSource.close(),i.eventSource=null}))]:[2]}))}))},r.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"PUT",url:"".concat(this.baseUrl,"/voipPlatform/agent/agentStatusSwitch"),data:e})]}))}))},r.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){return t=e.phone,r=e.line,[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agentOutBoundCall/dialer/startCall/").concat(t,"/").concat(r),method:"POST"})]}))}))},r.prototype.saveAgentResponseTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/call_record/callRecordAgent"),data:e})]}))}))},r.prototype.getCallTaskInfo=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getCallTaskName/").concat(e.callTaskId)})]}))}))},r.prototype.getAfterCallProcessTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/predictCall/afterCallProcessTime/").concat(e.callTaskId)})]}))}))},r.prototype.formatFormData=function(e){var t=new FormData;for(var n in e)e[n]&&t.append(n,e[n]);return t},r.prototype.agentAbnormalClose=function(e){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=this.formatFormData(e);return this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close"),data:t},!0)},r.prototype.sendBeacon=function(e){if("function"==typeof navigator.sendBeacon&&e.url){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=e.url,n=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(e,["url"]),r=this.formatFormData(n),i=navigator.sendBeacon(t,r);if(!i){e.lastSendResult=i;var o=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]");o.push(e),localStorage.setItem("aks_beacon_queue",JSON.stringify(o))}}},r.prototype.clearnSendBeaconQueue=function(){return t(this,void 0,void 0,(function(){var e,t;return n(this,(function(n){switch(n.label){case 0:return(e=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]")).length?[4,this.waitToken()]:[3,4];case 1:return n.sent()?[3,3]:[4,this.initToken()];case 2:if(n.sent().code!==au.SUCCESS)return[2];n.label=3;case 3:for(t=0;t<e.length-1;t++)this.sendBeacon(e[t]);n.label=4;case 4:return[2]}}))}))},r.prototype.getTokenWithFallback=function(){return this.token?this.token:sessionStorage.getItem(_u)||""},r.prototype.waitToken=function(e,t){var n=this;return void 0===e&&(e=3e3),void 0===t&&(t=200),new Promise((function(r){var i=setInterval((function(){((e-=t)<=0||n.token)&&(clearInterval(i),r(Boolean(n.token)))}),200)}))},r.prototype.request=function(r){return t(this,arguments,void 0,(function(r,i){var o,s,a,u=this;return void 0===i&&(i=!1),n(this,(function(l){switch(l.label){case 0:return!this.retryMap.has(r.url)&&this.retryCount&&this.retryMap.set(r.url,this.retryCount),this.token?[3,3]:[4,this.waitToken()];case 1:return l.sent()?[3,3]:[4,this.initToken()];case 2:if((o=l.sent()).code!==au.SUCCESS)return[2,{code:o.code,message:o.message,data:null}];l.label=3;case 3:return s={method:r.method||"GET",headers:e({"Content-Type":"application/json",authentication:this.token},r.headers)},i?(s.method=r.method,s.headers={authentication:this.token},s.body=r.data):"GET"!==(null===(a=s.method)||void 0===a?void 0:a.toLocaleUpperCase())&&(s.body=JSON.stringify(r.data)),[2,fetch(r.url,s).then((function(e){return t(u,void 0,void 0,(function(){var t,i;return n(this,(function(n){switch(n.label){case 0:return t=this.retryMap.get(r.url),401!==e.status?[3,3]:t?(this.retryMap.set(r.url,t-1),[4,this.initToken()]):[3,2];case 1:return(i=n.sent()).code===au.SUCCESS?[2,this.request(r)]:[2,i];case 2:return this.retryCount&&this.retryMap.delete(r.url),[2,{code:au.UNAUTHORIZED,message:"Unauthorized",data:null}];case 3:return[2,e.json()]}}))}))}))]}}))}))},r.prototype.executePeriodically=function(e,t){var n=Date.now()+t,r=function(){var i=Date.now();i>=n&&(e(),n+=t);var o=Math.max(0,n-i);setTimeout(r,o)};r()},r.getInstance=function(e){return!r.instance&&e&&(r.instance=new r(e)),r.instance},r.instance=null,r}();!function(e){e[e.OFFLINE=0]="OFFLINE",e[e.ONLINE=1]="ONLINE",e[e.HANGUP=4]="HANGUP"}(fu||(fu={})),function(e){e[e.ANSWER=1]="ANSWER",e[e.HANGUP=2]="HANGUP"}(du||(du={}));var vu=function(){function i(e){var t=this;this.sip={},this.api={},this.isSipInit=!1,this.isInitSuccess=!1,this.agentInfo={},this.initEvent={},this.agentEvent={},this.agentWaitingTime=0,this.agentResponseTime=0,this.timer=null,this.callDetails={},this.unloadingHandled=!1,this.baseUrl="",this.autoFinishACWTimer=null,this.baseUrl=(null==e?void 0:e.baseUrl)||"",this.api=Au.getInstance({id:e.id,getSystemToken:e.getSystemToken,resetSSE:this.resetSSE.bind(this),retryCount:e.retryCount,baseUrl:this.baseUrl}),this.sip=new cu({incomingCallCallback:this.incomingCall.bind(this),getMediaStream:null==e?void 0:e.getMediaStream}),this.sip.attchSessionEvent("ended",this.sessionEnded.bind(this)),this.sip.attchSessionEvent("failed",this.sessionFailed.bind(this)),this.init().then((function(){t.api.clearnSendBeaconQueue()}))}return i.prototype.init=function(){return t(this,void 0,void 0,(function(){var t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.initToken()];case 1:return(t=n.sent()).code!==au.SUCCESS?(r=e(e({},t),{code:uu.FAILED}),this.emitInitEvent("failed",r),this.isInitSuccess=!1,[2,r]):[4,this.getAgentStatus()];case 2:return(i=n.sent()).code!==uu.SUCCESS?(o=e(e({},i),{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED}),this.emitInitEvent("failed",o),this.isInitSuccess=!1,[2,o]):(s={code:uu.SUCCESS,data:null,message:"success"},this.emitInitEvent("success",s),this.isInitSuccess=!0,[2,s])}}))}))},i.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return[4,this.api.getAgentStatusList()];case 1:return(e=t.sent()).code===au.SUCCESS?[2,{code:uu.SUCCESS,data:e.data||[],message:e.message}]:[2,{code:uu.FAILED,data:null,message:e.message}]}}))}))},i.prototype.getTicket=function(){var e=window.sessionStorage.getItem("wiz-agent-ticket");return e||(e=r(),window.sessionStorage.setItem("wiz-agent-ticket",e)),e},i.prototype.getHostName=function(e){try{return new URL(e).hostname}catch(e){return""}},i.prototype.processSSEMessage=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t=JSON.parse(null==e?void 0:e.data)||{},r=this.agentInfo.statusName,-1===t.agentId?[3,2]:[4,this.offlineAgent(r)];case 1:n.sent(),1===t.status&&this.onlineAgent(r),n.label=2;case 2:return[2]}}))}))},i.prototype.resetSSE=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this.api.closeSSE({agentId:this.agentInfo.id,clearTicket:1})];case 1:return e.sent(),[4,this.api.registerSSE({agentId:this.agentInfo.id,onMessage:this.processSSEMessage.bind(this)})];case 2:return e.sent(),[2]}}))}))},i.prototype.createSSEAndOpensips=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return this.api.registerSSE({agentId:e,onMessage:this.processSSEMessage.bind(this)})?[3,2]:[4,this.api.updateAgentTicket({agentId:e,ticket:r,type:fu.OFFLINE})];case 1:return t.sent().code!==au.SUCCESS?[2,{code:uu.FAILED,message:"Registration of SSE failed and update Agent Ticket failed"}]:[2,{code:uu.FAILED,message:"Registration of SSE failed"}];case 2:return[4,this.waitSIPRegistered(7e3)];case 3:return t.sent()?[3,5]:[4,this.api.closeSSE({agentId:e,clearTicket:1})];case 4:return t.sent(),[2,{code:uu.FAILED,message:"SIP registration failed"}];case 5:return[2,{code:uu.SUCCESS,message:"success"}]}}))}))},i.prototype.waitSIPRegistered=function(){return t(this,arguments,void 0,(function(e){var t=this;return void 0===e&&(e=7e3),n(this,(function(n){return[2,new Promise((function(n){var r=!1,i=function(e){r||(r=!0,n(e))};t.sip.on("registered",(function(){return i(!0)})),t.sip.on("registrationFailed",(function(){return i(!1)})),setTimeout((function(){return i(!1)}),e),t.sip.start()}))]}))}))},i.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){var e,t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.getAgentInfo()];case 1:return"code"in(e=n.sent())&&e.code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:e.message}]:"data"in e&&(null===(s=e.data)||void 0===s?void 0:s[0])?(t=e.data[0],this.agentInfo=t,r=t.ticket,i=this.getTicket(),r&&r!==i?[2,{code:uu.LOCKED,data:t,message:"Agent ticket occupied, unable to perform agent online or offline."}]:(this.isSipInit||(o="sip:".concat(t.number,"@").concat(this.getHostName(t.realm)),this.sip.init({wssuri:t.realm,password:t.password,uri:o}),this.isSipInit=!0),[2,{code:uu.SUCCESS,data:t,message:e.message}])):[2,{code:uu.FAILED,data:null,message:"Agent not found"}]}}))}))},i.prototype.getAgentStatus=function(){return t(this,void 0,void 0,(function(){var e,t,i,o,s,a,u,l,c,h;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),[4,Promise.allSettled([this.getAgentInfo(),this.api.getAgentSetting({key:"callCenter"})])];case 1:return e=n.sent(),t=e.map((function(e){return"fulfilled"!==e.status?{code:au.FAILED,data:null,message:"system error"}:e.value})),i=t[0],"agentWaitingTime"in(o=t[1])&&(this.agentWaitingTime=o.agentWaitingTime||0),"code"in i&&i.code!==uu.SUCCESS?[2,{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:i.message}]:"data"in i&&i.data?(s=i.data,a=s.status,u=s.id,l=s.groupId,c={code:uu.SUCCESS,data:{id:u,groupId:l,status:a,subStatus:s.statusName},message:"success"},this.agentInfo=s,a===fu.OFFLINE?[2,c]:a!==fu.ONLINE?[3,4]:i.code===uu.LOCKED?[2,{code:uu.LOCKED,data:null,message:i.message}]:[4,this.api.agentAbnormalClose({id:u,groupId:l,trace:r()})]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:return n.sent(),[4,this.api.switchAgentStatus({id:u,groupId:l,status:fu.OFFLINE,subStatus:"offline"})];case 3:return(h=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:h.message}]:(c.data.status=fu.OFFLINE,c.data.subStatus="Offline",[2,c]);case 4:return[2,{code:uu.FAILED,data:null,message:"system error"}];case 5:return n.sent(),[2,{code:uu.FAILED,data:null,message:"system error"}];case 6:return[2]}}))}))},i.prototype.onlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==fu.ONLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.ONLINE,subStatus:e})];case 1:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:(f={code:uu.SUCCESS,data:{status:fu.ONLINE,subStatus:e},message:"Agent is already online"},this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 2:return r!==fu.OFFLINE?[3,6]:(s=this.getTicket(),[4,this.api.updateAgentTicket({agentId:i,ticket:s,type:fu.ONLINE})]);case 3:return(a=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:a.message}]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.ONLINE,subStatus:e})];case 4:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:[4,this.createSSEAndOpensips(i,s)];case 5:return l=n.sent(),c=l.code,h=l.message,c!==uu.SUCCESS?[2,{code:uu.FAILED,data:null,message:h}]:(f={code:c,data:{status:fu.ONLINE,subStatus:e},message:h},this.agentInfo.status=fu.ONLINE,this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 6:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.offlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==fu.OFFLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.OFFLINE,subStatus:e})];case 1:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(a={code:uu.SUCCESS,data:{status:fu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.agentInfo.statusName=e,this.emitAgentEvent("offline",a),[2,a]);case 2:return r!==fu.ONLINE?[3,4]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.OFFLINE,subStatus:e})];case 3:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(this.api.closeSSE({agentId:i,clearTicket:1}),this.sip.stop(!0),a={code:uu.SUCCESS,data:{status:fu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.emitAgentEvent("offline",a),this.agentInfo.status=fu.OFFLINE,this.agentInfo.statusName=e,[2,a]);case 4:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.isInitSuccess?[4,this.getAgentInfo()]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Registration failed. Seat online and offline cannot be performed."}];case 1:return(t=n.sent()).code!==uu.SUCCESS?[2,{code:t.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:t.message}]:(r=e.status,i=e.subStatus,r===fu.ONLINE?[2,this.onlineAgent(i)]:r===fu.OFFLINE?[2,this.offlineAgent(i)]:[2,{code:uu.FAILED,data:null,message:"system error"}])}}))}))},i.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r=this;return n(this,(function(n){return this.isInitSuccess?(t=this.agentInfo.outboundLineId)?[2,this.api.outboundCall({phone:e,line:t}).then((function(e){return e.code===au.SUCCESS?(r.sip.setCallType("outboundCall"),{code:uu.SUCCESS,data:e.data,message:e.message||e.msg}):{code:uu.FAILED,data:null,message:e.message||e.msg}}))]:[2,Promise.resolve({code:uu.FAILED,data:null,message:"Agent has no outbound line"})]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Outbound calls cannot be made."}]}))}))},i.prototype.autoFinishACW=function(){var e=this,t=Number(this.callDetails.afterCallProcessTime),n=function(){t<=0?e.finshACW():(t-=1,e.autoFinishACWTimer=setTimeout(n,1e3))};this.autoFinishACWTimer=setTimeout(n,1e3)},i.prototype.finshACW=function(){return t(this,void 0,void 0,(function(){var e,t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.autoFinishACWTimer&&(clearTimeout(this.autoFinishACWTimer),this.autoFinishACWTimer=null),e=this.agentInfo,t=e.id,r=e.groupId,[4,this.api.switchAgentStatus({id:t,groupId:r,status:fu.HANGUP})];case 1:return[2,{code:(i=n.sent()).code===au.SUCCESS?uu.SUCCESS:uu.FAILED,data:null,message:i.message}]}}))}))},i.prototype.sessionEnded=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.autoFinishACW(),[2]}))}))},i.prototype.sessionFailed=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.api.updateAgentHangup(this.agentInfo.id),[2]}))}))},i.prototype.openOnunload=function(){var e=this;window.onbeforeunload=function(e){e.returnValue="beforeunload"},window.onunload=function(){e.doForceOfflineCleanup()},this.unloadingHandled=!1},i.prototype.cancelOnunload=function(){window.onbeforeunload=function(){},window.onunload=function(){},this.unloadingHandled=!1},i.prototype.doForceOfflineCleanup=function(){if(!this.unloadingHandled){this.unloadingHandled=!0;var e="".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close");this.api.sendBeacon({url:e,id:this.agentInfo.id,groupId:this.agentInfo.groupId,trace:r()})}},i.prototype.saveAgentResponseTime=function(e){this.api.saveAgentResponseTime({callId:this.callDetails.callId,agentId:this.agentInfo.id,agentResponseTime:this.agentResponseTime,agentGroupId:this.agentInfo.groupId,resultType:e}),this.timer&&(clearInterval(this.timer),this.agentResponseTime=0)},i.prototype.hangup=function(){this.sip.hangup()},i.prototype.timingResTime=function(){var e=this;this.timer&&(clearInterval(this.timer),this.timer=null);var t=this.agentWaitingTime;this.agentResponseTime=0,this.timer=setInterval((function(){if(t<=0)return clearInterval((null==e?void 0:e.timer)||0),e.timer=null,void e.ignore();t-=1,e.agentResponseTime+=1}),1e3)},i.prototype.incomingCall=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f,d,p,g,m,_,A,v,y,T;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),t=e.request,r=(null===(_=null===(m=t.headers["Call-Param"])||void 0===m?void 0:m[0])||void 0===_?void 0:_.raw)||"",i=r?atob(r):"",o=JSON.parse(i||"{}"),s=(null===(v=null===(A=t.headers["Call-Task"])||void 0===A?void 0:A[0])||void 0===v?void 0:v.raw)||"",a=(null===(T=null===(y=t.headers["Call-Record-Id"])||void 0===y?void 0:y[0])||void 0===T?void 0:T.raw)||null,u=Object.fromEntries(Object.entries(o).filter((function(e){return""!==e[0]}))),l="",c="",s?[4,Promise.allSettled([this.api.getCallTaskInfo({callTaskId:s}),this.api.getAfterCallProcessTime({callTaskId:s})])]:[3,2];case 1:h=n.sent(),f=h[0],d=h[1],"fulfilled"===f.status&&(l=f.value.name||""),"fulfilled"===d.status&&(p=d.value).code===uu.SUCCESS&&(c=String(p.data||"")),n.label=2;case 2:return this.callDetails={callId:a||"",callType:this.sip.getCallType()||"",taskName:l,afterCallProcessTime:c,phone:u.phone||u.Phone||u.PHONE||"",contactId:u.contactId||u.ContactId||u.CONTACT_ID||"",extraJson:u},this.timingResTime(),[2,Promise.resolve({code:uu.SUCCESS,data:this.callDetails,message:"success"})];case 3:return g=n.sent(),[2,Promise.resolve({code:uu.FAILED,data:null,message:(null==g?void 0:g.toString())||"system error"})];case 4:return[2]}}))}))},i.prototype.answer=function(){this.sip.answer(),this.saveAgentResponseTime(du.ANSWER)},i.prototype.ignore=function(){this.sip.ignore(),this.saveAgentResponseTime(du.HANGUP)},i.prototype.mute=function(){this.sip.mute()},i.prototype.unmute=function(){this.sip.unmute()},i.prototype.attachInitEvent=function(e,t){t&&"function"==typeof t&&(this.initEvent[e]||(this.initEvent[e]=[]),this.initEvent[e].push(t))},i.prototype.removeInitEvent=function(e,t){var n=this.initEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitInitEvent=function(e,t){(this.initEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAgentEvent=function(e,t){t&&"function"==typeof t&&(this.agentEvent[e]||(this.agentEvent[e]=[]),this.agentEvent[e].push(t))},i.prototype.removeAgentEvent=function(e,t){var n=this.agentEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitAgentEvent=function(e,t){(this.agentEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAnswerEvent=function(e){this.sip.attachAnswerEvent(e)},i.prototype.removeAnswerEvent=function(e){this.sip.removeAnswerEvent(e)},i.prototype.attachNewMessageEvent=function(e){this.sip.attachNewMessageEvent(e)},i.prototype.removeNewMessageEvent=function(e){this.sip.removeNewMessageEvent(e)},i.prototype.attchSessionEvent=function(e,t){this.sip.attchSessionEvent(e,t)},i.prototype.removeSessionEvent=function(e,t){this.sip.removeSessionEvent(e,t)},i}();module.exports=vu;
7
+ !function(e,t){!function(n){var r=n.setTimeout,i=n.clearTimeout,o=n.XMLHttpRequest,s=n.XDomainRequest,a=n.ActiveXObject,u=n.EventSource,l=n.document,c=n.Promise,h=n.fetch,f=n.Response,d=n.TextDecoder,p=n.TextEncoder,g=n.AbortController;if("undefined"==typeof window||void 0===l||"readyState"in l||null!=l.body||(l.readyState="loading",window.addEventListener("load",(function(e){l.readyState="complete"}),!1)),null==o&&null!=a&&(o=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==g){var m=h;h=function(e,t){var n=t.signal;return m(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then((function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}}))},g=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function _(){this.bitsNeeded=0,this.codePoint=0}_.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var r=65533,i="",o=this.bitsNeeded,s=this.codePoint,a=0;a<e.length;a+=1){var u=e[a];0!==o&&(u<128||u>191||!t(s<<6|63&u,o-6,n(o,s)))&&(o=0,s=r,i+=String.fromCharCode(s)),0===o?(u>=0&&u<=127?(o=0,s=u):u>=192&&u<=223?(o=6,s=31&u):u>=224&&u<=239?(o=12,s=15&u):u>=240&&u<=247?(o=18,s=7&u):(o=0,s=r),0===o||t(s,o,n(o,s))||(o=0,s=r)):(o-=6,s=s<<6|63&u),0===o&&(s<=65535?i+=String.fromCharCode(s):(i+=String.fromCharCode(55296+(s-65535-1>>10)),i+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=s,i};null!=d&&null!=p&&function(){try{return"test"===(new d).decode((new p).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(d=_);var A=function(){};function v(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=A,this.onload=A,this.onerror=A,this.onreadystatechange=A,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=A}function y(e){return e.replace(/[A-Z]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+32)}))}function T(e){for(var t=Object.create(null),n=e.split("\r\n"),r=0;r<n.length;r+=1){var i=n[r].split(": "),o=i.shift(),s=i.join(": ");t[y(o)]=s}this._map=t}function S(){}function E(e){this._headers=e}function C(){}function w(){this._listeners=Object.create(null)}function b(e){r((function(){throw e}),0)}function I(e){this.type=e,this.target=void 0}function R(e,t){I.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function O(e,t){I.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function D(e,t){I.call(this,e),this.error=t.error}v.prototype.open=function(e,t){this._abort(!0);var n=this,s=this._xhr,a=1,u=0;this._abort=function(e){0!==n._sendTimeout&&(i(n._sendTimeout),n._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=A,s.onerror=A,s.onabort=A,s.onprogress=A,s.onreadystatechange=A,s.abort(),0!==u&&(i(u),u=0),e||(n.readyState=4,n.onabort(null),n.onreadystatechange())),a=0};var l=function(){if(1===a){var e=0,t="",r=void 0;if("contentType"in s)e=200,t="OK",r=s.contentType;else try{e=s.status,t=s.statusText,r=s.getResponseHeader("Content-Type")}catch(n){e=0,t="",r=void 0}0!==e&&(a=2,n.readyState=2,n.status=e,n.statusText=t,n._contentType=r,n.onreadystatechange())}},c=function(){if(l(),2===a||3===a){a=3;var e="";try{e=s.responseText}catch(e){}n.readyState=3,n.responseText=e,n.onprogress()}},h=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:A}),c(),1===a||2===a||3===a){if(a=4,0!==u&&(i(u),u=0),n.readyState=4,"load"===e)n.onload(t);else if("error"===e)n.onerror(t);else{if("abort"!==e)throw new TypeError;n.onabort(t)}n.onreadystatechange()}},f=function(){u=r((function(){f()}),500),3===s.readyState&&c()};"onload"in s&&(s.onload=function(e){h("load",e)}),"onerror"in s&&(s.onerror=function(e){h("error",e)}),"onabort"in s&&(s.onabort=function(e){h("abort",e)}),"onprogress"in s&&(s.onprogress=c),"onreadystatechange"in s&&(s.onreadystatechange=function(e){!function(e){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",e):3===s.readyState?"onprogress"in s||c():2===s.readyState&&l())}(e)}),!("contentType"in s)&&"ontimeout"in o.prototype||(t+=(-1===t.indexOf("?")?"?":"&")+"padding=true"),s.open(e,t,!0),"readyState"in s&&(u=r((function(){f()}),0))},v.prototype.abort=function(){this._abort(!1)},v.prototype.getResponseHeader=function(e){return this._contentType},v.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},v.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},v.prototype.send=function(){if("ontimeout"in o.prototype&&("sendAsBinary"in o.prototype||"mozAnon"in o.prototype)||null==l||null==l.readyState||"complete"===l.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(e){throw e}}else{var t=this;t._sendTimeout=r((function(){t._sendTimeout=0,t.send()}),4)}},T.prototype.get=function(e){return this._map[y(e)]},null!=o&&null==o.HEADERS_RECEIVED&&(o.HEADERS_RECEIVED=2),S.prototype.open=function(e,t,n,r,i,s,a){e.open("GET",i);var u=0;for(var l in e.onprogress=function(){var t=e.responseText.slice(u);u+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===o.HEADERS_RECEIVED){var n=e.status,r=e.statusText,i=e.getResponseHeader("Content-Type"),s=e.getAllResponseHeaders();t(n,r,i,new T(s))}},e.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,l)&&e.setRequestHeader(l,a[l]);return e.send(),e},E.prototype.get=function(e){return this._headers.get(e)},C.prototype.open=function(e,t,n,r,i,o,s){var a=null,u=new g,l=u.signal,f=new d;return h(i,{headers:s,credentials:o?"include":"same-origin",signal:l,cache:"no-store"}).then((function(e){return a=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new E(e.headers)),new c((function(e,t){var r=function(){a.read().then((function(t){if(t.done)e(void 0);else{var i=f.decode(t.value,{stream:!0});n(i),r()}})).catch((function(e){t(e)}))};r()}))})).catch((function(e){return"AbortError"===e.name?void 0:e})).then((function(e){r(e)})),{abort:function(){null!=a&&a.cancel(),u.abort()}}},w.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,r=0;r<n;r+=1){var i=t[r];try{"function"==typeof i.handleEvent?i.handleEvent(e):i.call(this,e)}catch(e){b(e)}}},w.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];null==r&&(r=[],n[e]=r);for(var i=!1,o=0;o<r.length;o+=1)r[o]===t&&(i=!0);i||r.push(t)},w.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];if(null!=r){for(var i=[],o=0;o<r.length;o+=1)r[o]!==t&&i.push(r[o]);0===i.length?delete n[e]:n[e]=i}},R.prototype=Object.create(I.prototype),O.prototype=Object.create(I.prototype),D.prototype=Object.create(I.prototype);var k=-1,M=0,q=1,N=2,U=-1,x=0,P=1,L=2,B=3,F=/^text\/event\-stream(;.*)?$/i,H=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),G(n)},G=function(e){return Math.min(Math.max(e,1e3),18e6)},Y=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(e){b(e)}};function j(e,t){w.call(this),t=t||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,t,n){t=String(t);var a=Boolean(n.withCredentials),u=n.lastEventIdQueryParameterName||"lastEventId",l=G(1e3),c=H(n.heartbeatTimeout,45e3),h="",f=l,d=!1,p=0,g=n.headers||{},m=n.Transport,_=Q&&null==m?void 0:new v(null!=m?new m:null!=o&&"withCredentials"in o.prototype||null==s?new o:new s),A=null!=m&&"string"!=typeof m?new m:null==_?new C:new S,y=void 0,T=0,E=k,w="",b="",I="",j="",W=x,K=0,z=0,J=function(t,n,r,i){if(E===M)if(200===t&&null!=r&&F.test(r)){E=q,d=Date.now(),f=l,e.readyState=q;var o=new O("open",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onopen,o)}else{var s="";200!==t?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",X();o=new O("error",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onerror,o),console.error(s)}},V=function(t){if(E===q){for(var n=-1,o=0;o<t.length;o+=1){(u=t.charCodeAt(o))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(n=o)}var s=(-1!==n?j:"")+t.slice(0,n+1);j=(-1===n?j:"")+t.slice(n+1),""!==t&&(d=Date.now(),p+=t.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(W===U&&u==="\n".charCodeAt(0))W=x;else if(W===U&&(W=x),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(W!==x){W===P&&(z=a+1);var g=s.slice(K,z-1),m=s.slice(z+(z<a&&s.charCodeAt(z)===" ".charCodeAt(0)?1:0),a);"data"===g?(w+="\n",w+=m):"id"===g?b=m:"event"===g?I=m:"retry"===g?(l=H(m,l),f=l):"heartbeatTimeout"===g&&(c=H(m,c),0!==T&&(i(T),T=r((function(){$()}),c)))}if(W===x){if(""!==w){h=b,""===I&&(I="message");var _=new R(I,{data:w.slice(1),lastEventId:b});if(e.dispatchEvent(_),"open"===I?Y(e,e.onopen,_):"message"===I?Y(e,e.onmessage,_):"error"===I&&Y(e,e.onerror,_),E===N)return}w="",I=""}W=u==="\r".charCodeAt(0)?U:x}else W===x&&(K=a,W=P),W===P?u===":".charCodeAt(0)&&(z=a+1,W=L):W===L&&(W=B)}}},Z=function(t){if(E===q||E===M){E=k,0!==T&&(i(T),T=0),T=r((function(){$()}),f),f=G(Math.min(16*l,2*f)),e.readyState=M;var n=new D("error",{error:t});e.dispatchEvent(n),Y(e,e.onerror,n),null!=t&&console.error(t)}},X=function(){E=N,null!=y&&(y.abort(),y=void 0),0!==T&&(i(T),T=0),e.readyState=N},$=function(){if(T=0,E===k){d=!1,p=0,T=r((function(){$()}),c),E=M,w="",I="",b=h,j="",K=0,z=0,W=x;var n=t;if("data:"!==t.slice(0,5)&&"blob:"!==t.slice(0,5)&&""!==h){var i=t.indexOf("?");n=-1===i?t:t.slice(0,i+1)+t.slice(i+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,(function(e,t){return t===u?"":e})),n+=(-1===t.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var o=e.withCredentials,s={Accept:"text/event-stream"},a=e.headers;if(null!=a)for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(s[l]=a[l]);try{y=A.open(_,J,V,Z,n,o,s)}catch(e){throw X(),e}}else if(d||null==y){var f=Math.max((d||Date.now())+c-Date.now(),1);d=!1,T=r((function(){$()}),f)}else Z(new Error("No activity within "+c+" milliseconds. "+(E===M?"No response received.":p+" chars received.")+" Reconnecting.")),null!=y&&(y.abort(),y=void 0)};e.url=t,e.readyState=M,e.withCredentials=a,e.headers=g,e._close=X,$()}(this,e,t)}var Q=null!=h&&null!=f&&"body"in f.prototype;j.prototype=Object.create(w.prototype),j.prototype.CONNECTING=M,j.prototype.OPEN=q,j.prototype.CLOSED=N,j.prototype.close=function(){this._close()},j.CONNECTING=M,j.OPEN=q,j.CLOSED=N,j.prototype.withCredentials=void 0;var W,K=u;null==o||null!=u&&"withCredentials"in u.prototype||(K=j),W=function(e){e.EventSourcePolyfill=j,e.NativeEventSource=u,e.EventSource=K}(t),void 0!==W&&(e.exports=W)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:i:globalThis)}(hu,hu.exports);var fu,du,pu=hu.exports,gu={exports:{}},mu=o(gu.exports=function(){var e=1e3,t=6e4,n=36e5,r="millisecond",i="second",o="minute",s="hour",a="day",u="week",l="month",c="quarter",h="year",f="date",d="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},A={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?"+":"-")+_(r,2,"0")+":"+_(i,2,"0")},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),o=n-i<0,s=t.clone().add(r+(o?-1:1),l);return+(-(r+(n-i)/(o?i-s:s-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:h,w:u,d:a,D:f,h:s,m:o,s:i,ms:r,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},v="en",y={};y[v]=m;var T="$isDayjsObject",S=function(e){return e instanceof b||!(!e||!e[T])},E=function e(t,n,r){var i;if(!t)return v;if("string"==typeof t){var o=t.toLowerCase();y[o]&&(i=o),n&&(y[o]=n,i=o);var s=t.split("-");if(!i&&s.length>1)return e(s[0])}else{var a=t.name;y[a]=t,i=a}return!r&&i&&(v=i),i||!r&&v},C=function(e,t){if(S(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new b(n)},w=A;w.l=E,w.i=S,w.w=function(e,t){return C(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var b=function(){function m(e){this.$L=E(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[T]=!0}var _=m.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(w.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(p);if(r){var i=r[2]-1||0,o=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return w},_.isValid=function(){return!(this.$d.toString()===d)},_.isSame=function(e,t){var n=C(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return C(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<C(e)},_.$g=function(e,t,n){return w.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!w.u(t)||t,c=w.p(e),d=function(e,t){var i=w.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(a)},p=function(e,t){return w.w(n.toDate()[e].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},g=this.$W,m=this.$M,_=this.$D,A="set"+(this.$u?"UTC":"");switch(c){case h:return r?d(1,0):d(31,11);case l:return r?d(1,m):d(0,m+1);case u:var v=this.$locale().weekStart||0,y=(g<v?g+7:g)-v;return d(r?_-y:_+(6-y),m);case a:case f:return p(A+"Hours",0);case s:return p(A+"Minutes",1);case o:return p(A+"Seconds",2);case i:return p(A+"Milliseconds",3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,u=w.p(e),c="set"+(this.$u?"UTC":""),d=(n={},n[a]=c+"Date",n[f]=c+"Date",n[l]=c+"Month",n[h]=c+"FullYear",n[s]=c+"Hours",n[o]=c+"Minutes",n[i]=c+"Seconds",n[r]=c+"Milliseconds",n)[u],p=u===a?this.$D+(t-this.$W):t;if(u===l||u===h){var g=this.clone().set(f,1);g.$d[d](p),g.init(),this.$d=g.set(f,Math.min(this.$D,g.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[w.p(e)]()},_.add=function(r,c){var f,d=this;r=Number(r);var p=w.p(c),g=function(e){var t=C(d);return w.w(t.date(t.date()+Math.round(e*r)),d)};if(p===l)return this.set(l,this.$M+r);if(p===h)return this.set(h,this.$y+r);if(p===a)return g(1);if(p===u)return g(7);var m=(f={},f[o]=t,f[s]=n,f[i]=e,f)[p]||1,_=this.$d.getTime()+r*m;return w.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=e||"YYYY-MM-DDTHH:mm:ssZ",i=w.z(this),o=this.$H,s=this.$m,a=this.$M,u=n.weekdays,l=n.months,c=n.meridiem,h=function(e,n,i,o){return e&&(e[n]||e(t,r))||i[n].slice(0,o)},f=function(e){return w.s(o%12||12,e,"0")},p=c||function(e,t,n){var r=e<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(g,(function(e,r){return r||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return w.s(t.$y,4,"0");case"M":return a+1;case"MM":return w.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,l,3);case"MMMM":return h(l,a);case"D":return t.$D;case"DD":return w.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return h(n.weekdaysMin,t.$W,u,2);case"ddd":return h(n.weekdaysShort,t.$W,u,3);case"dddd":return u[t.$W];case"H":return String(o);case"HH":return w.s(o,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return p(o,s,!0);case"A":return p(o,s,!1);case"m":return String(s);case"mm":return w.s(s,2,"0");case"s":return String(t.$s);case"ss":return w.s(t.$s,2,"0");case"SSS":return w.s(t.$ms,3,"0");case"Z":return i}return null}(e)||i.replace(":","")}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,d){var p,g=this,m=w.p(f),_=C(r),A=(_.utcOffset()-this.utcOffset())*t,v=this-_,y=function(){return w.m(g,_)};switch(m){case h:p=y()/12;break;case l:p=y();break;case c:p=y()/3;break;case u:p=(v-A)/6048e5;break;case a:p=(v-A)/864e5;break;case s:p=v/n;break;case o:p=v/t;break;case i:p=v/e;break;default:p=v}return d?p:w.a(p)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return y[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=E(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return w.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},m}(),I=b.prototype;return C.prototype=I,[["$ms",r],["$s",i],["$m",o],["$H",s],["$W",a],["$M",l],["$y",h],["$D",f]].forEach((function(e){I[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),C.extend=function(e,t){return e.$i||(e(t,b,C),e.$i=!0),C},C.locale=E,C.isDayjs=S,C.unix=function(e){return C(1e3*e)},C.en=y[v],C.Ls=y,C.p={},C}()),_u="aks_agent_token",Au=function(){function r(e){this.baseUrl="",this.eventSource=null,this.retryCount=0,this.retryMap=new Map,this.token="",this.id=e.id,this.getSystemToken=e.getSystemToken,this.resetSSE=e.resetSSE,this.retryCount=e.retryCount||0,this.baseUrl=e.baseUrl||""}return r.prototype.validateToken=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,fetch("".concat(this.baseUrl,"/iam/token/validate?accountId=").concat(e),{method:"GET",headers:{authentication:r}}).then((function(e){return e.json()}))]}))}))},r.prototype.initToken=function(){return t(this,void 0,void 0,(function(){var e,t,r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.getSystemToken()];case 1:return(e=n.sent())?[4,this.validateToken(this.id,e)]:[2,{code:au.FAILED,data:null,message:"get system token failed"}];case 2:return(t=n.sent()).code===au.SUCCESS?(this.token=e,sessionStorage.setItem(_u,e),this.executePeriodically(this.refreshToken.bind(this),12e5),[2,{code:au.SUCCESS,data:null,message:t.message}]):[2,{code:au.FAILED,data:null,message:t.message}];case 3:return r=n.sent(),[2,{code:au.FAILED,data:null,message:(null==r?void 0:r.toString())||"system error"}];case 4:return[2]}}))}))},r.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var e=this;return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/iam/oauth2/refresh")}).then((function(t){t.token&&(e.token=t.token,sessionStorage.setItem(_u,t.token),e.eventSource&&e.resetSSE())}))]}))}))},r.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/status/list")})]}))}))},r.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/getAgentByUserId")})]}))}))},r.prototype.getAgentSetting=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getAgentSetting"),data:e})]}))}))},r.prototype.updateAgentHangup=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent/").concat(e),method:"PUT"})]}))}))},r.prototype.updateAgentTicket=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/voipPlatform/agent/ticket"),data:e})]}))}))},r.prototype.registerSSE=function(e){return t(this,void 0,void 0,(function(){var r,i,o,s,a,u=this;return n(this,(function(l){return r=e.agentId,i=e.onMessage,o=function(e){},s=new Promise((function(e){o=e})),a=this.token,this.eventSource=new pu.EventSourcePolyfill("".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_event?agentId=").concat(r),{headers:{Authentication:a,"Cache-Control":"no-cache",Connection:"keep-alive"},heartbeatTimeout:12e6}),this.eventSource.onmessage=i,this.eventSource.onopen=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!0),[2]}))}))},this.eventSource.onerror=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!1),[2]}))}))},[2,s]}))}))},r.prototype.closeSSE=function(e){return t(this,void 0,void 0,(function(){var t,r,i=this;return n(this,(function(n){return t=e.agentId,r=e.clearTicket,this.eventSource?[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_close?agentId=").concat(t,"&clearTicket=").concat(r)}).then((function(){i.eventSource.close(),i.eventSource=null}))]:[2]}))}))},r.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"PUT",url:"".concat(this.baseUrl,"/voipPlatform/agent/agentStatusSwitch"),data:e})]}))}))},r.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){return t=e.phone,r=e.line,[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agentOutBoundCall/dialer/startCall/").concat(t,"/").concat(r),method:"POST"})]}))}))},r.prototype.saveAgentResponseTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/call_record/callRecordAgent"),data:e})]}))}))},r.prototype.getCallTaskInfo=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getCallTaskName/").concat(e.callTaskId)})]}))}))},r.prototype.getAfterCallProcessTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/predictCall/afterCallProcessTime/").concat(e.callTaskId)})]}))}))},r.prototype.formatFormData=function(e){var t=new FormData;for(var n in e)e[n]&&t.append(n,e[n]);return t},r.prototype.agentAbnormalClose=function(e){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=this.formatFormData(e);return this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close"),data:t},!0)},r.prototype.sendBeacon=function(e){if("function"==typeof navigator.sendBeacon&&e.url){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=e.url,n=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(e,["url"]),r=this.formatFormData(n),i=navigator.sendBeacon(t,r);if(!i){e.lastSendResult=i;var o=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]");o.push(e),localStorage.setItem("aks_beacon_queue",JSON.stringify(o))}}},r.prototype.clearnSendBeaconQueue=function(){return t(this,void 0,void 0,(function(){var e,t;return n(this,(function(n){switch(n.label){case 0:return(e=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]")).length?[4,this.waitToken()]:[3,4];case 1:return n.sent()?[3,3]:[4,this.initToken()];case 2:if(n.sent().code!==au.SUCCESS)return[2];n.label=3;case 3:for(t=0;t<e.length-1;t++)this.sendBeacon(e[t]);n.label=4;case 4:return[2]}}))}))},r.prototype.getTokenWithFallback=function(){return this.token?this.token:sessionStorage.getItem(_u)||""},r.prototype.waitToken=function(e,t){var n=this;return void 0===e&&(e=3e3),void 0===t&&(t=200),new Promise((function(r){var i=setInterval((function(){((e-=t)<=0||n.token)&&(clearInterval(i),r(Boolean(n.token)))}),200)}))},r.prototype.request=function(r){return t(this,arguments,void 0,(function(r,i){var o,s,a,u=this;return void 0===i&&(i=!1),n(this,(function(l){switch(l.label){case 0:return!this.retryMap.has(r.url)&&this.retryCount&&this.retryMap.set(r.url,this.retryCount),this.token?[3,3]:[4,this.waitToken()];case 1:return l.sent()?[3,3]:[4,this.initToken()];case 2:if((o=l.sent()).code!==au.SUCCESS)return[2,{code:o.code,message:o.message,data:null}];l.label=3;case 3:return s={method:r.method||"GET",headers:e({"Content-Type":"application/json",authentication:this.token},r.headers)},i?(s.method=r.method,s.headers={authentication:this.token},s.body=r.data):"GET"!==(null===(a=s.method)||void 0===a?void 0:a.toLocaleUpperCase())&&(s.body=JSON.stringify(r.data)),[2,fetch(r.url,s).then((function(e){return t(u,void 0,void 0,(function(){var t,i;return n(this,(function(n){switch(n.label){case 0:return t=this.retryMap.get(r.url),401!==e.status?[3,3]:t?(this.retryMap.set(r.url,t-1),[4,this.initToken()]):[3,2];case 1:return(i=n.sent()).code===au.SUCCESS?[2,this.request(r)]:[2,i];case 2:return this.retryCount&&this.retryMap.delete(r.url),[2,{code:au.UNAUTHORIZED,message:"Unauthorized",data:null}];case 3:return[2,e.json()]}}))}))}))]}}))}))},r.prototype.executePeriodically=function(e,t){var n=Date.now()+t,r=function(){var i=Date.now();i>=n&&(e(),n+=t);var o=Math.max(0,n-i);setTimeout(r,o)};r()},r.getInstance=function(e){return!r.instance&&e&&(r.instance=new r(e)),r.instance},r.instance=null,r}();!function(e){e[e.OFFLINE=0]="OFFLINE",e[e.ONLINE=1]="ONLINE",e[e.HANGUP=4]="HANGUP"}(fu||(fu={})),function(e){e[e.ANSWER=1]="ANSWER",e[e.HANGUP=2]="HANGUP"}(du||(du={}));var vu=function(){function i(e){var t=this;this.sip={},this.api={},this.isSipInit=!1,this.isInitSuccess=!1,this.agentInfo={},this.initEvent={},this.agentEvent={},this.agentWaitingTime=0,this.agentResponseTime=0,this.timer=null,this.callDetails={},this.unloadingHandled=!1,this.baseUrl="",this.autoFinishACWTimer=null,this.baseUrl=(null==e?void 0:e.baseUrl)||"",this.api=Au.getInstance({id:e.id,getSystemToken:e.getSystemToken,resetSSE:this.resetSSE.bind(this),retryCount:e.retryCount,baseUrl:this.baseUrl}),this.sip=new cu({incomingCallCallback:this.incomingCall.bind(this),getMediaStream:null==e?void 0:e.getMediaStream}),this.sip.attchSessionEvent("ended",this.sessionEnded.bind(this)),this.sip.attchSessionEvent("failed",this.sessionFailed.bind(this)),this.init().then((function(){t.api.clearnSendBeaconQueue()}))}return i.prototype.init=function(){return t(this,void 0,void 0,(function(){var t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.initToken()];case 1:return(t=n.sent()).code!==au.SUCCESS?(r=e(e({},t),{code:uu.FAILED}),this.emitInitEvent("failed",r),this.isInitSuccess=!1,[2,r]):[4,this.getAgentStatus()];case 2:return(i=n.sent()).code!==uu.SUCCESS?(o=e(e({},i),{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED}),this.emitInitEvent("failed",o),this.isInitSuccess=!1,[2,o]):(s={code:uu.SUCCESS,data:null,message:"success"},this.emitInitEvent("success",s),this.isInitSuccess=!0,[2,s])}}))}))},i.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return[4,this.api.getAgentStatusList()];case 1:return(e=t.sent()).code===au.SUCCESS?[2,{code:uu.SUCCESS,data:e.data||[],message:e.message}]:[2,{code:uu.FAILED,data:null,message:e.message}]}}))}))},i.prototype.getTicket=function(){var e=window.sessionStorage.getItem("wiz-agent-ticket");return e||(e=r(),window.sessionStorage.setItem("wiz-agent-ticket",e)),e},i.prototype.getHostName=function(e){try{return new URL(e).hostname}catch(e){return""}},i.prototype.processSSEMessage=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t=JSON.parse(null==e?void 0:e.data)||{},r=this.agentInfo.statusName,-1===t.agentId?[3,2]:[4,this.offlineAgent(r)];case 1:n.sent(),1===t.status&&this.onlineAgent(r),n.label=2;case 2:return[2]}}))}))},i.prototype.resetSSE=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this.api.closeSSE({agentId:this.agentInfo.id,clearTicket:1})];case 1:return e.sent(),[4,this.api.registerSSE({agentId:this.agentInfo.id,onMessage:this.processSSEMessage.bind(this)})];case 2:return e.sent(),[2]}}))}))},i.prototype.createSSEAndOpensips=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return this.api.registerSSE({agentId:e,onMessage:this.processSSEMessage.bind(this)})?[3,2]:[4,this.api.updateAgentTicket({agentId:e,ticket:r,type:fu.OFFLINE})];case 1:return t.sent().code!==au.SUCCESS?[2,{code:uu.FAILED,message:"Registration of SSE failed and update Agent Ticket failed"}]:[2,{code:uu.FAILED,message:"Registration of SSE failed"}];case 2:return[4,this.waitSIPRegistered(7e3)];case 3:return t.sent()?[3,5]:[4,this.api.closeSSE({agentId:e,clearTicket:1})];case 4:return t.sent(),[2,{code:uu.FAILED,message:"SIP registration failed"}];case 5:return[2,{code:uu.SUCCESS,message:"success"}]}}))}))},i.prototype.waitSIPRegistered=function(){return t(this,arguments,void 0,(function(e){var t=this;return void 0===e&&(e=7e3),n(this,(function(n){return[2,new Promise((function(n){var r=!1,i=function(e){r||(r=!0,n(e))};t.sip.on("registered",(function(){return i(!0)})),t.sip.on("registrationFailed",(function(){return i(!1)})),setTimeout((function(){return i(!1)}),e),t.sip.start()}))]}))}))},i.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){var e,t,r,i,o,s,a,u;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.getAgentInfo()];case 1:return"code"in(e=n.sent())&&e.code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:e.message}]:"data"in e&&(null===(u=e.data)||void 0===u?void 0:u[0])?(t=e.data[0],this.agentInfo=t,r=t.id,i=t.ticket,o=t.status,s=this.getTicket(),i?o!==fu.OFFLINE?[3,3]:[4,this.api.updateAgentTicket({agentId:r,ticket:"",type:fu.OFFLINE})]:[3,4]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:if(n.sent().code!==au.SUCCESS)return[2,{code:uu.FAILED,message:"Update Agent Ticket failed"}];i="",t.ticket="",this.agentInfo.ticket="",n.label=3;case 3:if(o===fu.ONLINE&&i!==s)return[2,{code:uu.LOCKED,data:t,message:"Agent ticket occupied, unable to perform agent online or offline."}];n.label=4;case 4:return this.isSipInit||(a="sip:".concat(t.number,"@").concat(this.getHostName(t.realm)),this.sip.init({wssuri:t.realm,password:t.password,uri:a}),this.isSipInit=!0),[2,{code:uu.SUCCESS,data:t,message:e.message}]}}))}))},i.prototype.getAgentStatus=function(){return t(this,void 0,void 0,(function(){var e,t,i,o,s,a,u,l,c,h;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),[4,Promise.allSettled([this.getAgentInfo(),this.api.getAgentSetting({key:"callCenter"})])];case 1:return e=n.sent(),t=e.map((function(e){return"fulfilled"!==e.status?{code:au.FAILED,data:null,message:"system error"}:e.value})),i=t[0],"agentWaitingTime"in(o=t[1])&&(this.agentWaitingTime=o.agentWaitingTime||0),"code"in i&&i.code!==uu.SUCCESS?[2,{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:i.message}]:"data"in i&&i.data?(s=i.data,a=s.status,u=s.id,l=s.groupId,c={code:uu.SUCCESS,data:{id:u,groupId:l,status:a,subStatus:s.statusName},message:"success"},this.agentInfo=s,a===fu.OFFLINE?[2,c]:a!==fu.ONLINE?[3,4]:i.code===uu.LOCKED?[2,{code:uu.LOCKED,data:null,message:i.message}]:[4,this.api.agentAbnormalClose({id:u,groupId:l,trace:r()})]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:return n.sent(),[4,this.api.switchAgentStatus({id:u,groupId:l,status:fu.OFFLINE,subStatus:"offline"})];case 3:return(h=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:h.message}]:(c.data.status=fu.OFFLINE,c.data.subStatus="Offline",[2,c]);case 4:return[2,{code:uu.FAILED,data:null,message:"system error"}];case 5:return n.sent(),[2,{code:uu.FAILED,data:null,message:"system error"}];case 6:return[2]}}))}))},i.prototype.onlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==fu.ONLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.ONLINE,subStatus:e})];case 1:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:(f={code:uu.SUCCESS,data:{status:fu.ONLINE,subStatus:e},message:"Agent is already online"},this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 2:return r!==fu.OFFLINE?[3,6]:(s=this.getTicket(),[4,this.api.updateAgentTicket({agentId:i,ticket:s,type:fu.ONLINE})]);case 3:return(a=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:a.message}]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.ONLINE,subStatus:e})];case 4:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:[4,this.createSSEAndOpensips(i,s)];case 5:return l=n.sent(),c=l.code,h=l.message,c!==uu.SUCCESS?[2,{code:uu.FAILED,data:null,message:h}]:(f={code:c,data:{status:fu.ONLINE,subStatus:e},message:h},this.agentInfo.status=fu.ONLINE,this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 6:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.offlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==fu.OFFLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.OFFLINE,subStatus:e})];case 1:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(a={code:uu.SUCCESS,data:{status:fu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.agentInfo.statusName=e,this.emitAgentEvent("offline",a),[2,a]);case 2:return r!==fu.ONLINE?[3,4]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:fu.OFFLINE,subStatus:e})];case 3:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(this.api.closeSSE({agentId:i,clearTicket:1}),this.sip.stop(!0),a={code:uu.SUCCESS,data:{status:fu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.emitAgentEvent("offline",a),this.agentInfo.status=fu.OFFLINE,this.agentInfo.statusName=e,[2,a]);case 4:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.isInitSuccess?[4,this.getAgentInfo()]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Registration failed. Seat online and offline cannot be performed."}];case 1:return(t=n.sent()).code!==uu.SUCCESS?[2,{code:t.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:t.message}]:(r=e.status,i=e.subStatus,r===fu.ONLINE?[2,this.onlineAgent(i)]:r===fu.OFFLINE?[2,this.offlineAgent(i)]:[2,{code:uu.FAILED,data:null,message:"system error"}])}}))}))},i.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r=this;return n(this,(function(n){return this.isInitSuccess?(t=this.agentInfo.outboundLineId)?[2,this.api.outboundCall({phone:e,line:t}).then((function(e){return e.code===au.SUCCESS?(r.sip.setCallType("outboundCall"),{code:uu.SUCCESS,data:e.data,message:e.message||e.msg}):{code:uu.FAILED,data:null,message:e.message||e.msg}}))]:[2,Promise.resolve({code:uu.FAILED,data:null,message:"Agent has no outbound line"})]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Outbound calls cannot be made."}]}))}))},i.prototype.autoFinishACW=function(){var e=this,t=Number(this.callDetails.afterCallProcessTime),n=function(){t<=0?e.finshACW():(t-=1,e.autoFinishACWTimer=setTimeout(n,1e3))};this.autoFinishACWTimer=setTimeout(n,1e3)},i.prototype.finshACW=function(){return t(this,void 0,void 0,(function(){var e,t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.autoFinishACWTimer&&(clearTimeout(this.autoFinishACWTimer),this.autoFinishACWTimer=null),e=this.agentInfo,t=e.id,r=e.groupId,[4,this.api.switchAgentStatus({id:t,groupId:r,status:fu.HANGUP})];case 1:return[2,{code:(i=n.sent()).code===au.SUCCESS?uu.SUCCESS:uu.FAILED,data:null,message:i.message}]}}))}))},i.prototype.sessionEnded=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.autoFinishACW(),[2]}))}))},i.prototype.sessionFailed=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.api.updateAgentHangup(this.agentInfo.id),[2]}))}))},i.prototype.openOnunload=function(){var e=this;window.onbeforeunload=function(e){e.returnValue="beforeunload"},window.onunload=function(){e.doForceOfflineCleanup()},this.unloadingHandled=!1},i.prototype.cancelOnunload=function(){window.onbeforeunload=function(){},window.onunload=function(){},this.unloadingHandled=!1},i.prototype.doForceOfflineCleanup=function(){if(!this.unloadingHandled){this.unloadingHandled=!0;var e="".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close");this.api.sendBeacon({url:e,id:this.agentInfo.id,groupId:this.agentInfo.groupId,trace:r()})}},i.prototype.saveAgentResponseTime=function(e){this.api.saveAgentResponseTime({callId:this.callDetails.callId,agentId:this.agentInfo.id,agentResponseTime:this.agentResponseTime,agentGroupId:this.agentInfo.groupId,resultType:e}),this.timer&&(clearInterval(this.timer),this.agentResponseTime=0)},i.prototype.hangup=function(){this.sip.hangup()},i.prototype.timingResTime=function(){var e=this;this.timer&&(clearInterval(this.timer),this.timer=null);var t=this.agentWaitingTime;this.agentResponseTime=0,this.timer=setInterval((function(){if(t<=0)return clearInterval((null==e?void 0:e.timer)||0),e.timer=null,void e.ignore();t-=1,e.agentResponseTime+=1}),1e3)},i.prototype.incomingCall=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f,d,p,g,m,_,A,v,y,T;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),t=e.request,r=(null===(_=null===(m=t.headers["Call-Param"])||void 0===m?void 0:m[0])||void 0===_?void 0:_.raw)||"",i=r?atob(r):"",o=JSON.parse(i||"{}"),s=(null===(v=null===(A=t.headers["Call-Task"])||void 0===A?void 0:A[0])||void 0===v?void 0:v.raw)||"",a=(null===(T=null===(y=t.headers["Call-Record-Id"])||void 0===y?void 0:y[0])||void 0===T?void 0:T.raw)||null,u=Object.fromEntries(Object.entries(o).filter((function(e){return""!==e[0]}))),l="",c="",s?[4,Promise.allSettled([this.api.getCallTaskInfo({callTaskId:s}),this.api.getAfterCallProcessTime({callTaskId:s})])]:[3,2];case 1:h=n.sent(),f=h[0],d=h[1],"fulfilled"===f.status&&(l=f.value.name||""),"fulfilled"===d.status&&(p=d.value).code===uu.SUCCESS&&(c=String(p.data||"")),n.label=2;case 2:return this.callDetails={callId:a||"",callType:this.sip.getCallType()||"",taskName:l,afterCallProcessTime:c,phone:u.phone||u.Phone||u.PHONE||"",contactId:u.contactId||u.ContactId||u.CONTACT_ID||"",extraJson:u},this.timingResTime(),[2,Promise.resolve({code:uu.SUCCESS,data:this.callDetails,message:"success"})];case 3:return g=n.sent(),[2,Promise.resolve({code:uu.FAILED,data:null,message:(null==g?void 0:g.toString())||"system error"})];case 4:return[2]}}))}))},i.prototype.answer=function(){this.sip.answer(),this.saveAgentResponseTime(du.ANSWER)},i.prototype.ignore=function(){this.sip.ignore(),this.saveAgentResponseTime(du.HANGUP)},i.prototype.mute=function(){this.sip.mute()},i.prototype.unmute=function(){this.sip.unmute()},i.prototype.attachInitEvent=function(e,t){t&&"function"==typeof t&&(this.initEvent[e]||(this.initEvent[e]=[]),this.initEvent[e].push(t))},i.prototype.removeInitEvent=function(e,t){var n=this.initEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitInitEvent=function(e,t){(this.initEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAgentEvent=function(e,t){t&&"function"==typeof t&&(this.agentEvent[e]||(this.agentEvent[e]=[]),this.agentEvent[e].push(t))},i.prototype.removeAgentEvent=function(e,t){var n=this.agentEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitAgentEvent=function(e,t){(this.agentEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAnswerEvent=function(e){this.sip.attachAnswerEvent(e)},i.prototype.removeAnswerEvent=function(e){this.sip.removeAnswerEvent(e)},i.prototype.attachNewMessageEvent=function(e){this.sip.attachNewMessageEvent(e)},i.prototype.removeNewMessageEvent=function(e){this.sip.removeNewMessageEvent(e)},i.prototype.attchSessionEvent=function(e,t){this.sip.attchSessionEvent(e,t)},i.prototype.removeSessionEvent=function(e,t){this.sip.removeSessionEvent(e,t)},i}();module.exports=vu;
@@ -4,4 +4,4 @@ var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.l
4
4
  * Available under MIT License (MIT)
5
5
  * https://github.com/Yaffle/EventSource/
6
6
  */
7
- cu=du,hu=du.exports,function(e){var t=e.setTimeout,n=e.clearTimeout,r=e.XMLHttpRequest,i=e.XDomainRequest,o=e.ActiveXObject,s=e.EventSource,a=e.document,u=e.Promise,l=e.fetch,c=e.Response,h=e.TextDecoder,f=e.TextEncoder,d=e.AbortController;if("undefined"==typeof window||void 0===a||"readyState"in a||null!=a.body||(a.readyState="loading",window.addEventListener("load",(function(e){a.readyState="complete"}),!1)),null==r&&null!=o&&(r=function(){return new o("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==d){var p=l;l=function(e,t){var n=t.signal;return p(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then((function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}}))},d=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function g(){this.bitsNeeded=0,this.codePoint=0}g.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var r=65533,i="",o=this.bitsNeeded,s=this.codePoint,a=0;a<e.length;a+=1){var u=e[a];0!==o&&(u<128||u>191||!t(s<<6|63&u,o-6,n(o,s)))&&(o=0,s=r,i+=String.fromCharCode(s)),0===o?(u>=0&&u<=127?(o=0,s=u):u>=192&&u<=223?(o=6,s=31&u):u>=224&&u<=239?(o=12,s=15&u):u>=240&&u<=247?(o=18,s=7&u):(o=0,s=r),0===o||t(s,o,n(o,s))||(o=0,s=r)):(o-=6,s=s<<6|63&u),0===o&&(s<=65535?i+=String.fromCharCode(s):(i+=String.fromCharCode(55296+(s-65535-1>>10)),i+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=s,i},null!=h&&null!=f&&function(){try{return"test"===(new h).decode((new f).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(h=g);var m=function(){};function _(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=m,this.onload=m,this.onerror=m,this.onreadystatechange=m,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=m}function A(e){return e.replace(/[A-Z]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+32)}))}function v(e){for(var t=Object.create(null),n=e.split("\r\n"),r=0;r<n.length;r+=1){var i=n[r].split(": "),o=i.shift(),s=i.join(": ");t[A(o)]=s}this._map=t}function y(){}function T(e){this._headers=e}function S(){}function E(){this._listeners=Object.create(null)}function C(e){t((function(){throw e}),0)}function w(e){this.type=e,this.target=void 0}function b(e,t){w.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function I(e,t){w.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function R(e,t){w.call(this,e),this.error=t.error}_.prototype.open=function(e,i){this._abort(!0);var o=this,s=this._xhr,a=1,u=0;this._abort=function(e){0!==o._sendTimeout&&(n(o._sendTimeout),o._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=m,s.onerror=m,s.onabort=m,s.onprogress=m,s.onreadystatechange=m,s.abort(),0!==u&&(n(u),u=0),e||(o.readyState=4,o.onabort(null),o.onreadystatechange())),a=0};var l=function(){if(1===a){var e=0,t="",n=void 0;if("contentType"in s)e=200,t="OK",n=s.contentType;else try{e=s.status,t=s.statusText,n=s.getResponseHeader("Content-Type")}catch(r){e=0,t="",n=void 0}0!==e&&(a=2,o.readyState=2,o.status=e,o.statusText=t,o._contentType=n,o.onreadystatechange())}},c=function(){if(l(),2===a||3===a){a=3;var e="";try{e=s.responseText}catch(e){}o.readyState=3,o.responseText=e,o.onprogress()}},h=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:m}),c(),1===a||2===a||3===a){if(a=4,0!==u&&(n(u),u=0),o.readyState=4,"load"===e)o.onload(t);else if("error"===e)o.onerror(t);else{if("abort"!==e)throw new TypeError;o.onabort(t)}o.onreadystatechange()}},f=function(){u=t((function(){f()}),500),3===s.readyState&&c()};"onload"in s&&(s.onload=function(e){h("load",e)}),"onerror"in s&&(s.onerror=function(e){h("error",e)}),"onabort"in s&&(s.onabort=function(e){h("abort",e)}),"onprogress"in s&&(s.onprogress=c),"onreadystatechange"in s&&(s.onreadystatechange=function(e){!function(e){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",e):3===s.readyState?"onprogress"in s||c():2===s.readyState&&l())}(e)}),!("contentType"in s)&&"ontimeout"in r.prototype||(i+=(-1===i.indexOf("?")?"?":"&")+"padding=true"),s.open(e,i,!0),"readyState"in s&&(u=t((function(){f()}),0))},_.prototype.abort=function(){this._abort(!1)},_.prototype.getResponseHeader=function(e){return this._contentType},_.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},_.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},_.prototype.send=function(){if("ontimeout"in r.prototype&&("sendAsBinary"in r.prototype||"mozAnon"in r.prototype)||null==a||null==a.readyState||"complete"===a.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(e){throw e}}else{var n=this;n._sendTimeout=t((function(){n._sendTimeout=0,n.send()}),4)}},v.prototype.get=function(e){return this._map[A(e)]},null!=r&&null==r.HEADERS_RECEIVED&&(r.HEADERS_RECEIVED=2),y.prototype.open=function(e,t,n,i,o,s,a){e.open("GET",o);var u=0;for(var l in e.onprogress=function(){var t=e.responseText.slice(u);u+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),i(new Error("NetworkError"))},e.onload=function(){i(null)},e.onabort=function(){i(null)},e.onreadystatechange=function(){if(e.readyState===r.HEADERS_RECEIVED){var n=e.status,i=e.statusText,o=e.getResponseHeader("Content-Type"),s=e.getAllResponseHeaders();t(n,i,o,new v(s))}},e.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,l)&&e.setRequestHeader(l,a[l]);return e.send(),e},T.prototype.get=function(e){return this._headers.get(e)},S.prototype.open=function(e,t,n,r,i,o,s){var a=null,c=new d,f=c.signal,p=new h;return l(i,{headers:s,credentials:o?"include":"same-origin",signal:f,cache:"no-store"}).then((function(e){return a=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new T(e.headers)),new u((function(e,t){var r=function(){a.read().then((function(t){if(t.done)e(void 0);else{var i=p.decode(t.value,{stream:!0});n(i),r()}})).catch((function(e){t(e)}))};r()}))})).catch((function(e){return"AbortError"===e.name?void 0:e})).then((function(e){r(e)})),{abort:function(){null!=a&&a.cancel(),c.abort()}}},E.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,r=0;r<n;r+=1){var i=t[r];try{"function"==typeof i.handleEvent?i.handleEvent(e):i.call(this,e)}catch(e){C(e)}}},E.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];null==r&&(r=[],n[e]=r);for(var i=!1,o=0;o<r.length;o+=1)r[o]===t&&(i=!0);i||r.push(t)},E.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];if(null!=r){for(var i=[],o=0;o<r.length;o+=1)r[o]!==t&&i.push(r[o]);0===i.length?delete n[e]:n[e]=i}},b.prototype=Object.create(w.prototype),I.prototype=Object.create(w.prototype),R.prototype=Object.create(w.prototype);var O=-1,D=0,k=1,M=2,q=-1,N=0,U=1,x=2,P=3,L=/^text\/event\-stream(;.*)?$/i,B=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),F(n)},F=function(e){return Math.min(Math.max(e,1e3),18e6)},H=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(e){C(e)}};function G(e,o){E.call(this),o=o||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,o,s){o=String(o);var a=Boolean(s.withCredentials),u=s.lastEventIdQueryParameterName||"lastEventId",l=F(1e3),c=B(s.heartbeatTimeout,45e3),h="",f=l,d=!1,p=0,g=s.headers||{},m=s.Transport,A=Y&&null==m?void 0:new _(null!=m?new m:null!=r&&"withCredentials"in r.prototype||null==i?new r:new i),v=null!=m&&"string"!=typeof m?new m:null==A?new S:new y,T=void 0,E=0,C=O,w="",G="",j="",Q="",W=N,K=0,z=0,J=function(t,n,r,i){if(C===D)if(200===t&&null!=r&&L.test(r)){C=k,d=Date.now(),f=l,e.readyState=k;var o=new I("open",{status:t,statusText:n,headers:i});e.dispatchEvent(o),H(e,e.onopen,o)}else{var s="";200!==t?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",X(),o=new I("error",{status:t,statusText:n,headers:i}),e.dispatchEvent(o),H(e,e.onerror,o),console.error(s)}},V=function(r){if(C===k){for(var i=-1,o=0;o<r.length;o+=1)(u=r.charCodeAt(o))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(i=o);var s=(-1!==i?Q:"")+r.slice(0,i+1);Q=(-1===i?Q:"")+r.slice(i+1),""!==r&&(d=Date.now(),p+=r.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(W===q&&u==="\n".charCodeAt(0))W=N;else if(W===q&&(W=N),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(W!==N){W===U&&(z=a+1);var g=s.slice(K,z-1),m=s.slice(z+(z<a&&s.charCodeAt(z)===" ".charCodeAt(0)?1:0),a);"data"===g?(w+="\n",w+=m):"id"===g?G=m:"event"===g?j=m:"retry"===g?(l=B(m,l),f=l):"heartbeatTimeout"===g&&(c=B(m,c),0!==E&&(n(E),E=t((function(){$()}),c)))}if(W===N){if(""!==w){h=G,""===j&&(j="message");var _=new b(j,{data:w.slice(1),lastEventId:G});if(e.dispatchEvent(_),"open"===j?H(e,e.onopen,_):"message"===j?H(e,e.onmessage,_):"error"===j&&H(e,e.onerror,_),C===M)return}w="",j=""}W=u==="\r".charCodeAt(0)?q:N}else W===N&&(K=a,W=U),W===U?u===":".charCodeAt(0)&&(z=a+1,W=x):W===x&&(W=P)}}},Z=function(r){if(C===k||C===D){C=O,0!==E&&(n(E),E=0),E=t((function(){$()}),f),f=F(Math.min(16*l,2*f)),e.readyState=D;var i=new R("error",{error:r});e.dispatchEvent(i),H(e,e.onerror,i),null!=r&&console.error(r)}},X=function(){C=M,null!=T&&(T.abort(),T=void 0),0!==E&&(n(E),E=0),e.readyState=M},$=function(){if(E=0,C===O){d=!1,p=0,E=t((function(){$()}),c),C=D,w="",j="",G=h,Q="",K=0,z=0,W=N;var n=o;if("data:"!==o.slice(0,5)&&"blob:"!==o.slice(0,5)&&""!==h){var r=o.indexOf("?");n=-1===r?o:o.slice(0,r+1)+o.slice(r+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,(function(e,t){return t===u?"":e})),n+=(-1===o.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var i=e.withCredentials,s={Accept:"text/event-stream"},a=e.headers;if(null!=a)for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(s[l]=a[l]);try{T=v.open(A,J,V,Z,n,i,s)}catch(e){throw X(),e}}else if(d||null==T){var f=Math.max((d||Date.now())+c-Date.now(),1);d=!1,E=t((function(){$()}),f)}else Z(new Error("No activity within "+c+" milliseconds. "+(C===D?"No response received.":p+" chars received.")+" Reconnecting.")),null!=T&&(T.abort(),T=void 0)};e.url=o,e.readyState=D,e.withCredentials=a,e.headers=g,e._close=X,$()}(this,e,o)}var Y=null!=l&&null!=c&&"body"in c.prototype;G.prototype=Object.create(E.prototype),G.prototype.CONNECTING=D,G.prototype.OPEN=k,G.prototype.CLOSED=M,G.prototype.close=function(){this._close()},G.CONNECTING=D,G.OPEN=k,G.CLOSED=M,G.prototype.withCredentials=void 0;var j,Q=s;null==r||null!=s&&"withCredentials"in s.prototype||(Q=G),j=function(e){e.EventSourcePolyfill=G,e.NativeEventSource=s,e.EventSource=Q}(hu),void 0!==j&&(cu.exports=j)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:i:globalThis);var pu,gu,mu=du.exports,_u={exports:{}},Au=o(_u.exports=function(){var e=1e3,t=6e4,n=36e5,r="millisecond",i="second",o="minute",s="hour",a="day",u="week",l="month",c="quarter",h="year",f="date",d="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},A={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?"+":"-")+_(r,2,"0")+":"+_(i,2,"0")},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),o=n-i<0,s=t.clone().add(r+(o?-1:1),l);return+(-(r+(n-i)/(o?i-s:s-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:h,w:u,d:a,D:f,h:s,m:o,s:i,ms:r,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},v="en",y={};y[v]=m;var T="$isDayjsObject",S=function(e){return e instanceof b||!(!e||!e[T])},E=function e(t,n,r){var i;if(!t)return v;if("string"==typeof t){var o=t.toLowerCase();y[o]&&(i=o),n&&(y[o]=n,i=o);var s=t.split("-");if(!i&&s.length>1)return e(s[0])}else{var a=t.name;y[a]=t,i=a}return!r&&i&&(v=i),i||!r&&v},C=function(e,t){if(S(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new b(n)},w=A;w.l=E,w.i=S,w.w=function(e,t){return C(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var b=function(){function m(e){this.$L=E(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[T]=!0}var _=m.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(w.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(p);if(r){var i=r[2]-1||0,o=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return w},_.isValid=function(){return!(this.$d.toString()===d)},_.isSame=function(e,t){var n=C(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return C(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<C(e)},_.$g=function(e,t,n){return w.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!w.u(t)||t,c=w.p(e),d=function(e,t){var i=w.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(a)},p=function(e,t){return w.w(n.toDate()[e].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},g=this.$W,m=this.$M,_=this.$D,A="set"+(this.$u?"UTC":"");switch(c){case h:return r?d(1,0):d(31,11);case l:return r?d(1,m):d(0,m+1);case u:var v=this.$locale().weekStart||0,y=(g<v?g+7:g)-v;return d(r?_-y:_+(6-y),m);case a:case f:return p(A+"Hours",0);case s:return p(A+"Minutes",1);case o:return p(A+"Seconds",2);case i:return p(A+"Milliseconds",3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,u=w.p(e),c="set"+(this.$u?"UTC":""),d=(n={},n[a]=c+"Date",n[f]=c+"Date",n[l]=c+"Month",n[h]=c+"FullYear",n[s]=c+"Hours",n[o]=c+"Minutes",n[i]=c+"Seconds",n[r]=c+"Milliseconds",n)[u],p=u===a?this.$D+(t-this.$W):t;if(u===l||u===h){var g=this.clone().set(f,1);g.$d[d](p),g.init(),this.$d=g.set(f,Math.min(this.$D,g.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[w.p(e)]()},_.add=function(r,c){var f,d=this;r=Number(r);var p=w.p(c),g=function(e){var t=C(d);return w.w(t.date(t.date()+Math.round(e*r)),d)};if(p===l)return this.set(l,this.$M+r);if(p===h)return this.set(h,this.$y+r);if(p===a)return g(1);if(p===u)return g(7);var m=(f={},f[o]=t,f[s]=n,f[i]=e,f)[p]||1,_=this.$d.getTime()+r*m;return w.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=e||"YYYY-MM-DDTHH:mm:ssZ",i=w.z(this),o=this.$H,s=this.$m,a=this.$M,u=n.weekdays,l=n.months,c=n.meridiem,h=function(e,n,i,o){return e&&(e[n]||e(t,r))||i[n].slice(0,o)},f=function(e){return w.s(o%12||12,e,"0")},p=c||function(e,t,n){var r=e<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(g,(function(e,r){return r||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return w.s(t.$y,4,"0");case"M":return a+1;case"MM":return w.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,l,3);case"MMMM":return h(l,a);case"D":return t.$D;case"DD":return w.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return h(n.weekdaysMin,t.$W,u,2);case"ddd":return h(n.weekdaysShort,t.$W,u,3);case"dddd":return u[t.$W];case"H":return String(o);case"HH":return w.s(o,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return p(o,s,!0);case"A":return p(o,s,!1);case"m":return String(s);case"mm":return w.s(s,2,"0");case"s":return String(t.$s);case"ss":return w.s(t.$s,2,"0");case"SSS":return w.s(t.$ms,3,"0");case"Z":return i}return null}(e)||i.replace(":","")}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,d){var p,g=this,m=w.p(f),_=C(r),A=(_.utcOffset()-this.utcOffset())*t,v=this-_,y=function(){return w.m(g,_)};switch(m){case h:p=y()/12;break;case l:p=y();break;case c:p=y()/3;break;case u:p=(v-A)/6048e5;break;case a:p=(v-A)/864e5;break;case s:p=v/n;break;case o:p=v/t;break;case i:p=v/e;break;default:p=v}return d?p:w.a(p)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return y[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=E(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return w.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},m}(),I=b.prototype;return C.prototype=I,[["$ms",r],["$s",i],["$m",o],["$H",s],["$W",a],["$M",l],["$y",h],["$D",f]].forEach((function(e){I[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),C.extend=function(e,t){return e.$i||(e(t,b,C),e.$i=!0),C},C.locale=E,C.isDayjs=S,C.unix=function(e){return C(1e3*e)},C.en=y[v],C.Ls=y,C.p={},C}()),vu="aks_agent_token",yu=function(){function r(e){this.baseUrl="",this.eventSource=null,this.retryCount=0,this.retryMap=new Map,this.token="",this.id=e.id,this.getSystemToken=e.getSystemToken,this.resetSSE=e.resetSSE,this.retryCount=e.retryCount||0,this.baseUrl=e.baseUrl||""}return r.prototype.validateToken=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,fetch("".concat(this.baseUrl,"/iam/token/validate?accountId=").concat(e),{method:"GET",headers:{authentication:r}}).then((function(e){return e.json()}))]}))}))},r.prototype.initToken=function(){return t(this,void 0,void 0,(function(){var e,t,r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.getSystemToken()];case 1:return(e=n.sent())?[4,this.validateToken(this.id,e)]:[2,{code:au.FAILED,data:null,message:"get system token failed"}];case 2:return(t=n.sent()).code===au.SUCCESS?(this.token=e,sessionStorage.setItem(vu,e),this.executePeriodically(this.refreshToken.bind(this),12e5),[2,{code:au.SUCCESS,data:null,message:t.message}]):[2,{code:au.FAILED,data:null,message:t.message}];case 3:return r=n.sent(),[2,{code:au.FAILED,data:null,message:(null==r?void 0:r.toString())||"system error"}];case 4:return[2]}}))}))},r.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var e=this;return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/iam/oauth2/refresh")}).then((function(t){t.token&&(e.token=t.token,sessionStorage.setItem(vu,t.token),e.eventSource&&e.resetSSE())}))]}))}))},r.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/status/list")})]}))}))},r.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/getAgentByUserId")})]}))}))},r.prototype.getAgentSetting=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getAgentSetting"),data:e})]}))}))},r.prototype.updateAgentHangup=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent/").concat(e),method:"PUT"})]}))}))},r.prototype.updateAgentTicket=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/voipPlatform/agent/ticket"),data:e})]}))}))},r.prototype.registerSSE=function(e){return t(this,void 0,void 0,(function(){var r,i,o,s,a,u=this;return n(this,(function(l){return r=e.agentId,i=e.onMessage,o=function(e){},s=new Promise((function(e){o=e})),a=this.token,this.eventSource=new mu.EventSourcePolyfill("".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_event?agentId=").concat(r),{headers:{Authentication:a,"Cache-Control":"no-cache",Connection:"keep-alive"},heartbeatTimeout:12e6}),this.eventSource.onmessage=i,this.eventSource.onopen=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!0),[2]}))}))},this.eventSource.onerror=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!1),[2]}))}))},[2,s]}))}))},r.prototype.closeSSE=function(e){return t(this,void 0,void 0,(function(){var t,r,i=this;return n(this,(function(n){return t=e.agentId,r=e.clearTicket,this.eventSource?[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_close?agentId=").concat(t,"&clearTicket=").concat(r)}).then((function(){i.eventSource.close(),i.eventSource=null}))]:[2]}))}))},r.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"PUT",url:"".concat(this.baseUrl,"/voipPlatform/agent/agentStatusSwitch"),data:e})]}))}))},r.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){return t=e.phone,r=e.line,[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agentOutBoundCall/dialer/startCall/").concat(t,"/").concat(r),method:"POST"})]}))}))},r.prototype.saveAgentResponseTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/call_record/callRecordAgent"),data:e})]}))}))},r.prototype.getCallTaskInfo=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getCallTaskName/").concat(e.callTaskId)})]}))}))},r.prototype.getAfterCallProcessTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/predictCall/afterCallProcessTime/").concat(e.callTaskId)})]}))}))},r.prototype.formatFormData=function(e){var t=new FormData;for(var n in e)e[n]&&t.append(n,e[n]);return t},r.prototype.agentAbnormalClose=function(e){e.createTime||(e.createTime=Au().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=Au().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=this.formatFormData(e);return this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close"),data:t},!0)},r.prototype.sendBeacon=function(e){if("function"==typeof navigator.sendBeacon&&e.url){e.createTime||(e.createTime=Au().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=Au().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=e.url,n=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(e,["url"]),r=this.formatFormData(n),i=navigator.sendBeacon(t,r);if(!i){e.lastSendResult=i;var o=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]");o.push(e),localStorage.setItem("aks_beacon_queue",JSON.stringify(o))}}},r.prototype.clearnSendBeaconQueue=function(){return t(this,void 0,void 0,(function(){var e,t;return n(this,(function(n){switch(n.label){case 0:return(e=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]")).length?[4,this.waitToken()]:[3,4];case 1:return n.sent()?[3,3]:[4,this.initToken()];case 2:if(n.sent().code!==au.SUCCESS)return[2];n.label=3;case 3:for(t=0;t<e.length-1;t++)this.sendBeacon(e[t]);n.label=4;case 4:return[2]}}))}))},r.prototype.getTokenWithFallback=function(){return this.token?this.token:sessionStorage.getItem(vu)||""},r.prototype.waitToken=function(e,t){var n=this;return void 0===e&&(e=3e3),void 0===t&&(t=200),new Promise((function(r){var i=setInterval((function(){((e-=t)<=0||n.token)&&(clearInterval(i),r(Boolean(n.token)))}),200)}))},r.prototype.request=function(r){return t(this,arguments,void 0,(function(r,i){var o,s,a,u=this;return void 0===i&&(i=!1),n(this,(function(l){switch(l.label){case 0:return!this.retryMap.has(r.url)&&this.retryCount&&this.retryMap.set(r.url,this.retryCount),this.token?[3,3]:[4,this.waitToken()];case 1:return l.sent()?[3,3]:[4,this.initToken()];case 2:if((o=l.sent()).code!==au.SUCCESS)return[2,{code:o.code,message:o.message,data:null}];l.label=3;case 3:return s={method:r.method||"GET",headers:e({"Content-Type":"application/json",authentication:this.token},r.headers)},i?(s.method=r.method,s.headers={authentication:this.token},s.body=r.data):"GET"!==(null===(a=s.method)||void 0===a?void 0:a.toLocaleUpperCase())&&(s.body=JSON.stringify(r.data)),[2,fetch(r.url,s).then((function(e){return t(u,void 0,void 0,(function(){var t,i;return n(this,(function(n){switch(n.label){case 0:return t=this.retryMap.get(r.url),401!==e.status?[3,3]:t?(this.retryMap.set(r.url,t-1),[4,this.initToken()]):[3,2];case 1:return(i=n.sent()).code===au.SUCCESS?[2,this.request(r)]:[2,i];case 2:return this.retryCount&&this.retryMap.delete(r.url),[2,{code:au.UNAUTHORIZED,message:"Unauthorized",data:null}];case 3:return[2,e.json()]}}))}))}))]}}))}))},r.prototype.executePeriodically=function(e,t){var n=Date.now()+t,r=function(){var i=Date.now();i>=n&&(e(),n+=t);var o=Math.max(0,n-i);setTimeout(r,o)};r()},r.getInstance=function(e){return!r.instance&&e&&(r.instance=new r(e)),r.instance},r.instance=null,r}();!function(e){e[e.OFFLINE=0]="OFFLINE",e[e.ONLINE=1]="ONLINE",e[e.HANGUP=4]="HANGUP"}(pu||(pu={})),function(e){e[e.ANSWER=1]="ANSWER",e[e.HANGUP=2]="HANGUP"}(gu||(gu={}));var Tu=function(){function i(e){var t=this;this.sip={},this.api={},this.isSipInit=!1,this.isInitSuccess=!1,this.agentInfo={},this.initEvent={},this.agentEvent={},this.agentWaitingTime=0,this.agentResponseTime=0,this.timer=null,this.callDetails={},this.unloadingHandled=!1,this.baseUrl="",this.autoFinishACWTimer=null,this.baseUrl=(null==e?void 0:e.baseUrl)||"",this.api=yu.getInstance({id:e.id,getSystemToken:e.getSystemToken,resetSSE:this.resetSSE.bind(this),retryCount:e.retryCount,baseUrl:this.baseUrl}),this.sip=new fu({incomingCallCallback:this.incomingCall.bind(this),getMediaStream:null==e?void 0:e.getMediaStream}),this.sip.attchSessionEvent("ended",this.sessionEnded.bind(this)),this.sip.attchSessionEvent("failed",this.sessionFailed.bind(this)),this.init().then((function(){t.api.clearnSendBeaconQueue()}))}return i.prototype.init=function(){return t(this,void 0,void 0,(function(){var t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.initToken()];case 1:return(t=n.sent()).code!==au.SUCCESS?(r=e(e({},t),{code:uu.FAILED}),this.emitInitEvent("failed",r),this.isInitSuccess=!1,[2,r]):[4,this.getAgentStatus()];case 2:return(i=n.sent()).code!==uu.SUCCESS?(o=e(e({},i),{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED}),this.emitInitEvent("failed",o),this.isInitSuccess=!1,[2,o]):(s={code:uu.SUCCESS,data:null,message:"success"},this.emitInitEvent("success",s),this.isInitSuccess=!0,[2,s])}}))}))},i.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return[4,this.api.getAgentStatusList()];case 1:return(e=t.sent()).code===au.SUCCESS?[2,{code:uu.SUCCESS,data:e.data||[],message:e.message}]:[2,{code:uu.FAILED,data:null,message:e.message}]}}))}))},i.prototype.getTicket=function(){var e=window.sessionStorage.getItem("wiz-agent-ticket");return e||(e=r(),window.sessionStorage.setItem("wiz-agent-ticket",e)),e},i.prototype.getHostName=function(e){try{return new URL(e).hostname}catch(e){return""}},i.prototype.processSSEMessage=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t=JSON.parse(null==e?void 0:e.data)||{},r=this.agentInfo.statusName,-1===t.agentId?[3,2]:[4,this.offlineAgent(r)];case 1:n.sent(),1===t.status&&this.onlineAgent(r),n.label=2;case 2:return[2]}}))}))},i.prototype.resetSSE=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this.api.closeSSE({agentId:this.agentInfo.id,clearTicket:1})];case 1:return e.sent(),[4,this.api.registerSSE({agentId:this.agentInfo.id,onMessage:this.processSSEMessage.bind(this)})];case 2:return e.sent(),[2]}}))}))},i.prototype.createSSEAndOpensips=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return this.api.registerSSE({agentId:e,onMessage:this.processSSEMessage.bind(this)})?[3,2]:[4,this.api.updateAgentTicket({agentId:e,ticket:r,type:pu.OFFLINE})];case 1:return t.sent().code!==au.SUCCESS?[2,{code:uu.FAILED,message:"Registration of SSE failed and update Agent Ticket failed"}]:[2,{code:uu.FAILED,message:"Registration of SSE failed"}];case 2:return[4,this.waitSIPRegistered(7e3)];case 3:return t.sent()?[3,5]:[4,this.api.closeSSE({agentId:e,clearTicket:1})];case 4:return t.sent(),[2,{code:uu.FAILED,message:"SIP registration failed"}];case 5:return[2,{code:uu.SUCCESS,message:"success"}]}}))}))},i.prototype.waitSIPRegistered=function(){return t(this,arguments,void 0,(function(e){var t=this;return void 0===e&&(e=7e3),n(this,(function(n){return[2,new Promise((function(n){var r=!1,i=function(e){r||(r=!0,n(e))};t.sip.on("registered",(function(){return i(!0)})),t.sip.on("registrationFailed",(function(){return i(!1)})),setTimeout((function(){return i(!1)}),e),t.sip.start()}))]}))}))},i.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){var e,t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.getAgentInfo()];case 1:return"code"in(e=n.sent())&&e.code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:e.message}]:"data"in e&&(null===(s=e.data)||void 0===s?void 0:s[0])?(t=e.data[0],this.agentInfo=t,r=t.ticket,i=this.getTicket(),r&&r!==i?[2,{code:uu.LOCKED,data:t,message:"Agent ticket occupied, unable to perform agent online or offline."}]:(this.isSipInit||(o="sip:".concat(t.number,"@").concat(this.getHostName(t.realm)),this.sip.init({wssuri:t.realm,password:t.password,uri:o}),this.isSipInit=!0),[2,{code:uu.SUCCESS,data:t,message:e.message}])):[2,{code:uu.FAILED,data:null,message:"Agent not found"}]}}))}))},i.prototype.getAgentStatus=function(){return t(this,void 0,void 0,(function(){var e,t,i,o,s,a,u,l,c,h;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),[4,Promise.allSettled([this.getAgentInfo(),this.api.getAgentSetting({key:"callCenter"})])];case 1:return e=n.sent(),t=e.map((function(e){return"fulfilled"!==e.status?{code:au.FAILED,data:null,message:"system error"}:e.value})),i=t[0],"agentWaitingTime"in(o=t[1])&&(this.agentWaitingTime=o.agentWaitingTime||0),"code"in i&&i.code!==uu.SUCCESS?[2,{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:i.message}]:"data"in i&&i.data?(s=i.data,a=s.status,u=s.id,l=s.groupId,c={code:uu.SUCCESS,data:{id:u,groupId:l,status:a,subStatus:s.statusName},message:"success"},this.agentInfo=s,a===pu.OFFLINE?[2,c]:a!==pu.ONLINE?[3,4]:i.code===uu.LOCKED?[2,{code:uu.LOCKED,data:null,message:i.message}]:[4,this.api.agentAbnormalClose({id:u,groupId:l,trace:r()})]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:return n.sent(),[4,this.api.switchAgentStatus({id:u,groupId:l,status:pu.OFFLINE,subStatus:"offline"})];case 3:return(h=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:h.message}]:(c.data.status=pu.OFFLINE,c.data.subStatus="Offline",[2,c]);case 4:return[2,{code:uu.FAILED,data:null,message:"system error"}];case 5:return n.sent(),[2,{code:uu.FAILED,data:null,message:"system error"}];case 6:return[2]}}))}))},i.prototype.onlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.ONLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 1:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:(f={code:uu.SUCCESS,data:{status:pu.ONLINE,subStatus:e},message:"Agent is already online"},this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 2:return r!==pu.OFFLINE?[3,6]:(s=this.getTicket(),[4,this.api.updateAgentTicket({agentId:i,ticket:s,type:pu.ONLINE})]);case 3:return(a=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:a.message}]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 4:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:[4,this.createSSEAndOpensips(i,s)];case 5:return l=n.sent(),c=l.code,h=l.message,c!==uu.SUCCESS?[2,{code:uu.FAILED,data:null,message:h}]:(f={code:c,data:{status:pu.ONLINE,subStatus:e},message:h},this.agentInfo.status=pu.ONLINE,this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 6:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.offlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.OFFLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 1:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.agentInfo.statusName=e,this.emitAgentEvent("offline",a),[2,a]);case 2:return r!==pu.ONLINE?[3,4]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 3:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(this.api.closeSSE({agentId:i,clearTicket:1}),this.sip.stop(!0),a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.emitAgentEvent("offline",a),this.agentInfo.status=pu.OFFLINE,this.agentInfo.statusName=e,[2,a]);case 4:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.isInitSuccess?[4,this.getAgentInfo()]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Registration failed. Seat online and offline cannot be performed."}];case 1:return(t=n.sent()).code!==uu.SUCCESS?[2,{code:t.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:t.message}]:(r=e.status,i=e.subStatus,r===pu.ONLINE?[2,this.onlineAgent(i)]:r===pu.OFFLINE?[2,this.offlineAgent(i)]:[2,{code:uu.FAILED,data:null,message:"system error"}])}}))}))},i.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r=this;return n(this,(function(n){return this.isInitSuccess?(t=this.agentInfo.outboundLineId)?[2,this.api.outboundCall({phone:e,line:t}).then((function(e){return e.code===au.SUCCESS?(r.sip.setCallType("outboundCall"),{code:uu.SUCCESS,data:e.data,message:e.message||e.msg}):{code:uu.FAILED,data:null,message:e.message||e.msg}}))]:[2,Promise.resolve({code:uu.FAILED,data:null,message:"Agent has no outbound line"})]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Outbound calls cannot be made."}]}))}))},i.prototype.autoFinishACW=function(){var e=this,t=Number(this.callDetails.afterCallProcessTime),n=function(){t<=0?e.finshACW():(t-=1,e.autoFinishACWTimer=setTimeout(n,1e3))};this.autoFinishACWTimer=setTimeout(n,1e3)},i.prototype.finshACW=function(){return t(this,void 0,void 0,(function(){var e,t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.autoFinishACWTimer&&(clearTimeout(this.autoFinishACWTimer),this.autoFinishACWTimer=null),e=this.agentInfo,t=e.id,r=e.groupId,[4,this.api.switchAgentStatus({id:t,groupId:r,status:pu.HANGUP})];case 1:return[2,{code:(i=n.sent()).code===au.SUCCESS?uu.SUCCESS:uu.FAILED,data:null,message:i.message}]}}))}))},i.prototype.sessionEnded=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.autoFinishACW(),[2]}))}))},i.prototype.sessionFailed=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.api.updateAgentHangup(this.agentInfo.id),[2]}))}))},i.prototype.openOnunload=function(){var e=this;window.onbeforeunload=function(e){e.returnValue="beforeunload"},window.onunload=function(){e.doForceOfflineCleanup()},this.unloadingHandled=!1},i.prototype.cancelOnunload=function(){window.onbeforeunload=function(){},window.onunload=function(){},this.unloadingHandled=!1},i.prototype.doForceOfflineCleanup=function(){if(!this.unloadingHandled){this.unloadingHandled=!0;var e="".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close");this.api.sendBeacon({url:e,id:this.agentInfo.id,groupId:this.agentInfo.groupId,trace:r()})}},i.prototype.saveAgentResponseTime=function(e){this.api.saveAgentResponseTime({callId:this.callDetails.callId,agentId:this.agentInfo.id,agentResponseTime:this.agentResponseTime,agentGroupId:this.agentInfo.groupId,resultType:e}),this.timer&&(clearInterval(this.timer),this.agentResponseTime=0)},i.prototype.hangup=function(){this.sip.hangup()},i.prototype.timingResTime=function(){var e=this;this.timer&&(clearInterval(this.timer),this.timer=null);var t=this.agentWaitingTime;this.agentResponseTime=0,this.timer=setInterval((function(){if(t<=0)return clearInterval((null==e?void 0:e.timer)||0),e.timer=null,void e.ignore();t-=1,e.agentResponseTime+=1}),1e3)},i.prototype.incomingCall=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f,d,p,g,m,_,A,v,y,T;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),t=e.request,r=(null===(_=null===(m=t.headers["Call-Param"])||void 0===m?void 0:m[0])||void 0===_?void 0:_.raw)||"",i=r?atob(r):"",o=JSON.parse(i||"{}"),s=(null===(v=null===(A=t.headers["Call-Task"])||void 0===A?void 0:A[0])||void 0===v?void 0:v.raw)||"",a=(null===(T=null===(y=t.headers["Call-Record-Id"])||void 0===y?void 0:y[0])||void 0===T?void 0:T.raw)||null,u=Object.fromEntries(Object.entries(o).filter((function(e){return""!==e[0]}))),l="",c="",s?[4,Promise.allSettled([this.api.getCallTaskInfo({callTaskId:s}),this.api.getAfterCallProcessTime({callTaskId:s})])]:[3,2];case 1:h=n.sent(),f=h[0],d=h[1],"fulfilled"===f.status&&(l=f.value.name||""),"fulfilled"===d.status&&(p=d.value).code===uu.SUCCESS&&(c=String(p.data||"")),n.label=2;case 2:return this.callDetails={callId:a||"",callType:this.sip.getCallType()||"",taskName:l,afterCallProcessTime:c,phone:u.phone||u.Phone||u.PHONE||"",contactId:u.contactId||u.ContactId||u.CONTACT_ID||"",extraJson:u},this.timingResTime(),[2,Promise.resolve({code:uu.SUCCESS,data:this.callDetails,message:"success"})];case 3:return g=n.sent(),[2,Promise.resolve({code:uu.FAILED,data:null,message:(null==g?void 0:g.toString())||"system error"})];case 4:return[2]}}))}))},i.prototype.answer=function(){this.sip.answer(),this.saveAgentResponseTime(gu.ANSWER)},i.prototype.ignore=function(){this.sip.ignore(),this.saveAgentResponseTime(gu.HANGUP)},i.prototype.mute=function(){this.sip.mute()},i.prototype.unmute=function(){this.sip.unmute()},i.prototype.attachInitEvent=function(e,t){t&&"function"==typeof t&&(this.initEvent[e]||(this.initEvent[e]=[]),this.initEvent[e].push(t))},i.prototype.removeInitEvent=function(e,t){var n=this.initEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitInitEvent=function(e,t){(this.initEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAgentEvent=function(e,t){t&&"function"==typeof t&&(this.agentEvent[e]||(this.agentEvent[e]=[]),this.agentEvent[e].push(t))},i.prototype.removeAgentEvent=function(e,t){var n=this.agentEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitAgentEvent=function(e,t){(this.agentEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAnswerEvent=function(e){this.sip.attachAnswerEvent(e)},i.prototype.removeAnswerEvent=function(e){this.sip.removeAnswerEvent(e)},i.prototype.attachNewMessageEvent=function(e){this.sip.attachNewMessageEvent(e)},i.prototype.removeNewMessageEvent=function(e){this.sip.removeNewMessageEvent(e)},i.prototype.attchSessionEvent=function(e,t){this.sip.attchSessionEvent(e,t)},i.prototype.removeSessionEvent=function(e,t){this.sip.removeSessionEvent(e,t)},i}();export{Tu as default};
7
+ cu=du,hu=du.exports,function(e){var t=e.setTimeout,n=e.clearTimeout,r=e.XMLHttpRequest,i=e.XDomainRequest,o=e.ActiveXObject,s=e.EventSource,a=e.document,u=e.Promise,l=e.fetch,c=e.Response,h=e.TextDecoder,f=e.TextEncoder,d=e.AbortController;if("undefined"==typeof window||void 0===a||"readyState"in a||null!=a.body||(a.readyState="loading",window.addEventListener("load",(function(e){a.readyState="complete"}),!1)),null==r&&null!=o&&(r=function(){return new o("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==d){var p=l;l=function(e,t){var n=t.signal;return p(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then((function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}}))},d=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function g(){this.bitsNeeded=0,this.codePoint=0}g.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var r=65533,i="",o=this.bitsNeeded,s=this.codePoint,a=0;a<e.length;a+=1){var u=e[a];0!==o&&(u<128||u>191||!t(s<<6|63&u,o-6,n(o,s)))&&(o=0,s=r,i+=String.fromCharCode(s)),0===o?(u>=0&&u<=127?(o=0,s=u):u>=192&&u<=223?(o=6,s=31&u):u>=224&&u<=239?(o=12,s=15&u):u>=240&&u<=247?(o=18,s=7&u):(o=0,s=r),0===o||t(s,o,n(o,s))||(o=0,s=r)):(o-=6,s=s<<6|63&u),0===o&&(s<=65535?i+=String.fromCharCode(s):(i+=String.fromCharCode(55296+(s-65535-1>>10)),i+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=s,i},null!=h&&null!=f&&function(){try{return"test"===(new h).decode((new f).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(h=g);var m=function(){};function _(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=m,this.onload=m,this.onerror=m,this.onreadystatechange=m,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=m}function A(e){return e.replace(/[A-Z]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+32)}))}function v(e){for(var t=Object.create(null),n=e.split("\r\n"),r=0;r<n.length;r+=1){var i=n[r].split(": "),o=i.shift(),s=i.join(": ");t[A(o)]=s}this._map=t}function y(){}function T(e){this._headers=e}function S(){}function E(){this._listeners=Object.create(null)}function C(e){t((function(){throw e}),0)}function w(e){this.type=e,this.target=void 0}function b(e,t){w.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function I(e,t){w.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function R(e,t){w.call(this,e),this.error=t.error}_.prototype.open=function(e,i){this._abort(!0);var o=this,s=this._xhr,a=1,u=0;this._abort=function(e){0!==o._sendTimeout&&(n(o._sendTimeout),o._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=m,s.onerror=m,s.onabort=m,s.onprogress=m,s.onreadystatechange=m,s.abort(),0!==u&&(n(u),u=0),e||(o.readyState=4,o.onabort(null),o.onreadystatechange())),a=0};var l=function(){if(1===a){var e=0,t="",n=void 0;if("contentType"in s)e=200,t="OK",n=s.contentType;else try{e=s.status,t=s.statusText,n=s.getResponseHeader("Content-Type")}catch(r){e=0,t="",n=void 0}0!==e&&(a=2,o.readyState=2,o.status=e,o.statusText=t,o._contentType=n,o.onreadystatechange())}},c=function(){if(l(),2===a||3===a){a=3;var e="";try{e=s.responseText}catch(e){}o.readyState=3,o.responseText=e,o.onprogress()}},h=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:m}),c(),1===a||2===a||3===a){if(a=4,0!==u&&(n(u),u=0),o.readyState=4,"load"===e)o.onload(t);else if("error"===e)o.onerror(t);else{if("abort"!==e)throw new TypeError;o.onabort(t)}o.onreadystatechange()}},f=function(){u=t((function(){f()}),500),3===s.readyState&&c()};"onload"in s&&(s.onload=function(e){h("load",e)}),"onerror"in s&&(s.onerror=function(e){h("error",e)}),"onabort"in s&&(s.onabort=function(e){h("abort",e)}),"onprogress"in s&&(s.onprogress=c),"onreadystatechange"in s&&(s.onreadystatechange=function(e){!function(e){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",e):3===s.readyState?"onprogress"in s||c():2===s.readyState&&l())}(e)}),!("contentType"in s)&&"ontimeout"in r.prototype||(i+=(-1===i.indexOf("?")?"?":"&")+"padding=true"),s.open(e,i,!0),"readyState"in s&&(u=t((function(){f()}),0))},_.prototype.abort=function(){this._abort(!1)},_.prototype.getResponseHeader=function(e){return this._contentType},_.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},_.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},_.prototype.send=function(){if("ontimeout"in r.prototype&&("sendAsBinary"in r.prototype||"mozAnon"in r.prototype)||null==a||null==a.readyState||"complete"===a.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(e){throw e}}else{var n=this;n._sendTimeout=t((function(){n._sendTimeout=0,n.send()}),4)}},v.prototype.get=function(e){return this._map[A(e)]},null!=r&&null==r.HEADERS_RECEIVED&&(r.HEADERS_RECEIVED=2),y.prototype.open=function(e,t,n,i,o,s,a){e.open("GET",o);var u=0;for(var l in e.onprogress=function(){var t=e.responseText.slice(u);u+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),i(new Error("NetworkError"))},e.onload=function(){i(null)},e.onabort=function(){i(null)},e.onreadystatechange=function(){if(e.readyState===r.HEADERS_RECEIVED){var n=e.status,i=e.statusText,o=e.getResponseHeader("Content-Type"),s=e.getAllResponseHeaders();t(n,i,o,new v(s))}},e.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,l)&&e.setRequestHeader(l,a[l]);return e.send(),e},T.prototype.get=function(e){return this._headers.get(e)},S.prototype.open=function(e,t,n,r,i,o,s){var a=null,c=new d,f=c.signal,p=new h;return l(i,{headers:s,credentials:o?"include":"same-origin",signal:f,cache:"no-store"}).then((function(e){return a=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new T(e.headers)),new u((function(e,t){var r=function(){a.read().then((function(t){if(t.done)e(void 0);else{var i=p.decode(t.value,{stream:!0});n(i),r()}})).catch((function(e){t(e)}))};r()}))})).catch((function(e){return"AbortError"===e.name?void 0:e})).then((function(e){r(e)})),{abort:function(){null!=a&&a.cancel(),c.abort()}}},E.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,r=0;r<n;r+=1){var i=t[r];try{"function"==typeof i.handleEvent?i.handleEvent(e):i.call(this,e)}catch(e){C(e)}}},E.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];null==r&&(r=[],n[e]=r);for(var i=!1,o=0;o<r.length;o+=1)r[o]===t&&(i=!0);i||r.push(t)},E.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];if(null!=r){for(var i=[],o=0;o<r.length;o+=1)r[o]!==t&&i.push(r[o]);0===i.length?delete n[e]:n[e]=i}},b.prototype=Object.create(w.prototype),I.prototype=Object.create(w.prototype),R.prototype=Object.create(w.prototype);var O=-1,D=0,k=1,M=2,q=-1,N=0,U=1,x=2,P=3,L=/^text\/event\-stream(;.*)?$/i,B=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),F(n)},F=function(e){return Math.min(Math.max(e,1e3),18e6)},H=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(e){C(e)}};function G(e,o){E.call(this),o=o||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,o,s){o=String(o);var a=Boolean(s.withCredentials),u=s.lastEventIdQueryParameterName||"lastEventId",l=F(1e3),c=B(s.heartbeatTimeout,45e3),h="",f=l,d=!1,p=0,g=s.headers||{},m=s.Transport,A=Y&&null==m?void 0:new _(null!=m?new m:null!=r&&"withCredentials"in r.prototype||null==i?new r:new i),v=null!=m&&"string"!=typeof m?new m:null==A?new S:new y,T=void 0,E=0,C=O,w="",G="",j="",Q="",W=N,K=0,z=0,J=function(t,n,r,i){if(C===D)if(200===t&&null!=r&&L.test(r)){C=k,d=Date.now(),f=l,e.readyState=k;var o=new I("open",{status:t,statusText:n,headers:i});e.dispatchEvent(o),H(e,e.onopen,o)}else{var s="";200!==t?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",X(),o=new I("error",{status:t,statusText:n,headers:i}),e.dispatchEvent(o),H(e,e.onerror,o),console.error(s)}},V=function(r){if(C===k){for(var i=-1,o=0;o<r.length;o+=1)(u=r.charCodeAt(o))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(i=o);var s=(-1!==i?Q:"")+r.slice(0,i+1);Q=(-1===i?Q:"")+r.slice(i+1),""!==r&&(d=Date.now(),p+=r.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(W===q&&u==="\n".charCodeAt(0))W=N;else if(W===q&&(W=N),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(W!==N){W===U&&(z=a+1);var g=s.slice(K,z-1),m=s.slice(z+(z<a&&s.charCodeAt(z)===" ".charCodeAt(0)?1:0),a);"data"===g?(w+="\n",w+=m):"id"===g?G=m:"event"===g?j=m:"retry"===g?(l=B(m,l),f=l):"heartbeatTimeout"===g&&(c=B(m,c),0!==E&&(n(E),E=t((function(){$()}),c)))}if(W===N){if(""!==w){h=G,""===j&&(j="message");var _=new b(j,{data:w.slice(1),lastEventId:G});if(e.dispatchEvent(_),"open"===j?H(e,e.onopen,_):"message"===j?H(e,e.onmessage,_):"error"===j&&H(e,e.onerror,_),C===M)return}w="",j=""}W=u==="\r".charCodeAt(0)?q:N}else W===N&&(K=a,W=U),W===U?u===":".charCodeAt(0)&&(z=a+1,W=x):W===x&&(W=P)}}},Z=function(r){if(C===k||C===D){C=O,0!==E&&(n(E),E=0),E=t((function(){$()}),f),f=F(Math.min(16*l,2*f)),e.readyState=D;var i=new R("error",{error:r});e.dispatchEvent(i),H(e,e.onerror,i),null!=r&&console.error(r)}},X=function(){C=M,null!=T&&(T.abort(),T=void 0),0!==E&&(n(E),E=0),e.readyState=M},$=function(){if(E=0,C===O){d=!1,p=0,E=t((function(){$()}),c),C=D,w="",j="",G=h,Q="",K=0,z=0,W=N;var n=o;if("data:"!==o.slice(0,5)&&"blob:"!==o.slice(0,5)&&""!==h){var r=o.indexOf("?");n=-1===r?o:o.slice(0,r+1)+o.slice(r+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,(function(e,t){return t===u?"":e})),n+=(-1===o.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var i=e.withCredentials,s={Accept:"text/event-stream"},a=e.headers;if(null!=a)for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(s[l]=a[l]);try{T=v.open(A,J,V,Z,n,i,s)}catch(e){throw X(),e}}else if(d||null==T){var f=Math.max((d||Date.now())+c-Date.now(),1);d=!1,E=t((function(){$()}),f)}else Z(new Error("No activity within "+c+" milliseconds. "+(C===D?"No response received.":p+" chars received.")+" Reconnecting.")),null!=T&&(T.abort(),T=void 0)};e.url=o,e.readyState=D,e.withCredentials=a,e.headers=g,e._close=X,$()}(this,e,o)}var Y=null!=l&&null!=c&&"body"in c.prototype;G.prototype=Object.create(E.prototype),G.prototype.CONNECTING=D,G.prototype.OPEN=k,G.prototype.CLOSED=M,G.prototype.close=function(){this._close()},G.CONNECTING=D,G.OPEN=k,G.CLOSED=M,G.prototype.withCredentials=void 0;var j,Q=s;null==r||null!=s&&"withCredentials"in s.prototype||(Q=G),j=function(e){e.EventSourcePolyfill=G,e.NativeEventSource=s,e.EventSource=Q}(hu),void 0!==j&&(cu.exports=j)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:i:globalThis);var pu,gu,mu=du.exports,_u={exports:{}},Au=o(_u.exports=function(){var e=1e3,t=6e4,n=36e5,r="millisecond",i="second",o="minute",s="hour",a="day",u="week",l="month",c="quarter",h="year",f="date",d="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},A={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?"+":"-")+_(r,2,"0")+":"+_(i,2,"0")},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),o=n-i<0,s=t.clone().add(r+(o?-1:1),l);return+(-(r+(n-i)/(o?i-s:s-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:h,w:u,d:a,D:f,h:s,m:o,s:i,ms:r,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},v="en",y={};y[v]=m;var T="$isDayjsObject",S=function(e){return e instanceof b||!(!e||!e[T])},E=function e(t,n,r){var i;if(!t)return v;if("string"==typeof t){var o=t.toLowerCase();y[o]&&(i=o),n&&(y[o]=n,i=o);var s=t.split("-");if(!i&&s.length>1)return e(s[0])}else{var a=t.name;y[a]=t,i=a}return!r&&i&&(v=i),i||!r&&v},C=function(e,t){if(S(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new b(n)},w=A;w.l=E,w.i=S,w.w=function(e,t){return C(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var b=function(){function m(e){this.$L=E(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[T]=!0}var _=m.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(w.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(p);if(r){var i=r[2]-1||0,o=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return w},_.isValid=function(){return!(this.$d.toString()===d)},_.isSame=function(e,t){var n=C(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return C(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<C(e)},_.$g=function(e,t,n){return w.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!w.u(t)||t,c=w.p(e),d=function(e,t){var i=w.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(a)},p=function(e,t){return w.w(n.toDate()[e].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},g=this.$W,m=this.$M,_=this.$D,A="set"+(this.$u?"UTC":"");switch(c){case h:return r?d(1,0):d(31,11);case l:return r?d(1,m):d(0,m+1);case u:var v=this.$locale().weekStart||0,y=(g<v?g+7:g)-v;return d(r?_-y:_+(6-y),m);case a:case f:return p(A+"Hours",0);case s:return p(A+"Minutes",1);case o:return p(A+"Seconds",2);case i:return p(A+"Milliseconds",3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,u=w.p(e),c="set"+(this.$u?"UTC":""),d=(n={},n[a]=c+"Date",n[f]=c+"Date",n[l]=c+"Month",n[h]=c+"FullYear",n[s]=c+"Hours",n[o]=c+"Minutes",n[i]=c+"Seconds",n[r]=c+"Milliseconds",n)[u],p=u===a?this.$D+(t-this.$W):t;if(u===l||u===h){var g=this.clone().set(f,1);g.$d[d](p),g.init(),this.$d=g.set(f,Math.min(this.$D,g.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[w.p(e)]()},_.add=function(r,c){var f,d=this;r=Number(r);var p=w.p(c),g=function(e){var t=C(d);return w.w(t.date(t.date()+Math.round(e*r)),d)};if(p===l)return this.set(l,this.$M+r);if(p===h)return this.set(h,this.$y+r);if(p===a)return g(1);if(p===u)return g(7);var m=(f={},f[o]=t,f[s]=n,f[i]=e,f)[p]||1,_=this.$d.getTime()+r*m;return w.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=e||"YYYY-MM-DDTHH:mm:ssZ",i=w.z(this),o=this.$H,s=this.$m,a=this.$M,u=n.weekdays,l=n.months,c=n.meridiem,h=function(e,n,i,o){return e&&(e[n]||e(t,r))||i[n].slice(0,o)},f=function(e){return w.s(o%12||12,e,"0")},p=c||function(e,t,n){var r=e<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(g,(function(e,r){return r||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return w.s(t.$y,4,"0");case"M":return a+1;case"MM":return w.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,l,3);case"MMMM":return h(l,a);case"D":return t.$D;case"DD":return w.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return h(n.weekdaysMin,t.$W,u,2);case"ddd":return h(n.weekdaysShort,t.$W,u,3);case"dddd":return u[t.$W];case"H":return String(o);case"HH":return w.s(o,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return p(o,s,!0);case"A":return p(o,s,!1);case"m":return String(s);case"mm":return w.s(s,2,"0");case"s":return String(t.$s);case"ss":return w.s(t.$s,2,"0");case"SSS":return w.s(t.$ms,3,"0");case"Z":return i}return null}(e)||i.replace(":","")}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,d){var p,g=this,m=w.p(f),_=C(r),A=(_.utcOffset()-this.utcOffset())*t,v=this-_,y=function(){return w.m(g,_)};switch(m){case h:p=y()/12;break;case l:p=y();break;case c:p=y()/3;break;case u:p=(v-A)/6048e5;break;case a:p=(v-A)/864e5;break;case s:p=v/n;break;case o:p=v/t;break;case i:p=v/e;break;default:p=v}return d?p:w.a(p)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return y[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=E(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return w.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},m}(),I=b.prototype;return C.prototype=I,[["$ms",r],["$s",i],["$m",o],["$H",s],["$W",a],["$M",l],["$y",h],["$D",f]].forEach((function(e){I[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),C.extend=function(e,t){return e.$i||(e(t,b,C),e.$i=!0),C},C.locale=E,C.isDayjs=S,C.unix=function(e){return C(1e3*e)},C.en=y[v],C.Ls=y,C.p={},C}()),vu="aks_agent_token",yu=function(){function r(e){this.baseUrl="",this.eventSource=null,this.retryCount=0,this.retryMap=new Map,this.token="",this.id=e.id,this.getSystemToken=e.getSystemToken,this.resetSSE=e.resetSSE,this.retryCount=e.retryCount||0,this.baseUrl=e.baseUrl||""}return r.prototype.validateToken=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,fetch("".concat(this.baseUrl,"/iam/token/validate?accountId=").concat(e),{method:"GET",headers:{authentication:r}}).then((function(e){return e.json()}))]}))}))},r.prototype.initToken=function(){return t(this,void 0,void 0,(function(){var e,t,r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.getSystemToken()];case 1:return(e=n.sent())?[4,this.validateToken(this.id,e)]:[2,{code:au.FAILED,data:null,message:"get system token failed"}];case 2:return(t=n.sent()).code===au.SUCCESS?(this.token=e,sessionStorage.setItem(vu,e),this.executePeriodically(this.refreshToken.bind(this),12e5),[2,{code:au.SUCCESS,data:null,message:t.message}]):[2,{code:au.FAILED,data:null,message:t.message}];case 3:return r=n.sent(),[2,{code:au.FAILED,data:null,message:(null==r?void 0:r.toString())||"system error"}];case 4:return[2]}}))}))},r.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var e=this;return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/iam/oauth2/refresh")}).then((function(t){t.token&&(e.token=t.token,sessionStorage.setItem(vu,t.token),e.eventSource&&e.resetSSE())}))]}))}))},r.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/status/list")})]}))}))},r.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/getAgentByUserId")})]}))}))},r.prototype.getAgentSetting=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getAgentSetting"),data:e})]}))}))},r.prototype.updateAgentHangup=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent/").concat(e),method:"PUT"})]}))}))},r.prototype.updateAgentTicket=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/voipPlatform/agent/ticket"),data:e})]}))}))},r.prototype.registerSSE=function(e){return t(this,void 0,void 0,(function(){var r,i,o,s,a,u=this;return n(this,(function(l){return r=e.agentId,i=e.onMessage,o=function(e){},s=new Promise((function(e){o=e})),a=this.token,this.eventSource=new mu.EventSourcePolyfill("".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_event?agentId=").concat(r),{headers:{Authentication:a,"Cache-Control":"no-cache",Connection:"keep-alive"},heartbeatTimeout:12e6}),this.eventSource.onmessage=i,this.eventSource.onopen=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!0),[2]}))}))},this.eventSource.onerror=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!1),[2]}))}))},[2,s]}))}))},r.prototype.closeSSE=function(e){return t(this,void 0,void 0,(function(){var t,r,i=this;return n(this,(function(n){return t=e.agentId,r=e.clearTicket,this.eventSource?[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_close?agentId=").concat(t,"&clearTicket=").concat(r)}).then((function(){i.eventSource.close(),i.eventSource=null}))]:[2]}))}))},r.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"PUT",url:"".concat(this.baseUrl,"/voipPlatform/agent/agentStatusSwitch"),data:e})]}))}))},r.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){return t=e.phone,r=e.line,[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agentOutBoundCall/dialer/startCall/").concat(t,"/").concat(r),method:"POST"})]}))}))},r.prototype.saveAgentResponseTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/call_record/callRecordAgent"),data:e})]}))}))},r.prototype.getCallTaskInfo=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getCallTaskName/").concat(e.callTaskId)})]}))}))},r.prototype.getAfterCallProcessTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/predictCall/afterCallProcessTime/").concat(e.callTaskId)})]}))}))},r.prototype.formatFormData=function(e){var t=new FormData;for(var n in e)e[n]&&t.append(n,e[n]);return t},r.prototype.agentAbnormalClose=function(e){e.createTime||(e.createTime=Au().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=Au().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=this.formatFormData(e);return this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close"),data:t},!0)},r.prototype.sendBeacon=function(e){if("function"==typeof navigator.sendBeacon&&e.url){e.createTime||(e.createTime=Au().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=Au().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=e.url,n=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(e,["url"]),r=this.formatFormData(n),i=navigator.sendBeacon(t,r);if(!i){e.lastSendResult=i;var o=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]");o.push(e),localStorage.setItem("aks_beacon_queue",JSON.stringify(o))}}},r.prototype.clearnSendBeaconQueue=function(){return t(this,void 0,void 0,(function(){var e,t;return n(this,(function(n){switch(n.label){case 0:return(e=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]")).length?[4,this.waitToken()]:[3,4];case 1:return n.sent()?[3,3]:[4,this.initToken()];case 2:if(n.sent().code!==au.SUCCESS)return[2];n.label=3;case 3:for(t=0;t<e.length-1;t++)this.sendBeacon(e[t]);n.label=4;case 4:return[2]}}))}))},r.prototype.getTokenWithFallback=function(){return this.token?this.token:sessionStorage.getItem(vu)||""},r.prototype.waitToken=function(e,t){var n=this;return void 0===e&&(e=3e3),void 0===t&&(t=200),new Promise((function(r){var i=setInterval((function(){((e-=t)<=0||n.token)&&(clearInterval(i),r(Boolean(n.token)))}),200)}))},r.prototype.request=function(r){return t(this,arguments,void 0,(function(r,i){var o,s,a,u=this;return void 0===i&&(i=!1),n(this,(function(l){switch(l.label){case 0:return!this.retryMap.has(r.url)&&this.retryCount&&this.retryMap.set(r.url,this.retryCount),this.token?[3,3]:[4,this.waitToken()];case 1:return l.sent()?[3,3]:[4,this.initToken()];case 2:if((o=l.sent()).code!==au.SUCCESS)return[2,{code:o.code,message:o.message,data:null}];l.label=3;case 3:return s={method:r.method||"GET",headers:e({"Content-Type":"application/json",authentication:this.token},r.headers)},i?(s.method=r.method,s.headers={authentication:this.token},s.body=r.data):"GET"!==(null===(a=s.method)||void 0===a?void 0:a.toLocaleUpperCase())&&(s.body=JSON.stringify(r.data)),[2,fetch(r.url,s).then((function(e){return t(u,void 0,void 0,(function(){var t,i;return n(this,(function(n){switch(n.label){case 0:return t=this.retryMap.get(r.url),401!==e.status?[3,3]:t?(this.retryMap.set(r.url,t-1),[4,this.initToken()]):[3,2];case 1:return(i=n.sent()).code===au.SUCCESS?[2,this.request(r)]:[2,i];case 2:return this.retryCount&&this.retryMap.delete(r.url),[2,{code:au.UNAUTHORIZED,message:"Unauthorized",data:null}];case 3:return[2,e.json()]}}))}))}))]}}))}))},r.prototype.executePeriodically=function(e,t){var n=Date.now()+t,r=function(){var i=Date.now();i>=n&&(e(),n+=t);var o=Math.max(0,n-i);setTimeout(r,o)};r()},r.getInstance=function(e){return!r.instance&&e&&(r.instance=new r(e)),r.instance},r.instance=null,r}();!function(e){e[e.OFFLINE=0]="OFFLINE",e[e.ONLINE=1]="ONLINE",e[e.HANGUP=4]="HANGUP"}(pu||(pu={})),function(e){e[e.ANSWER=1]="ANSWER",e[e.HANGUP=2]="HANGUP"}(gu||(gu={}));var Tu=function(){function i(e){var t=this;this.sip={},this.api={},this.isSipInit=!1,this.isInitSuccess=!1,this.agentInfo={},this.initEvent={},this.agentEvent={},this.agentWaitingTime=0,this.agentResponseTime=0,this.timer=null,this.callDetails={},this.unloadingHandled=!1,this.baseUrl="",this.autoFinishACWTimer=null,this.baseUrl=(null==e?void 0:e.baseUrl)||"",this.api=yu.getInstance({id:e.id,getSystemToken:e.getSystemToken,resetSSE:this.resetSSE.bind(this),retryCount:e.retryCount,baseUrl:this.baseUrl}),this.sip=new fu({incomingCallCallback:this.incomingCall.bind(this),getMediaStream:null==e?void 0:e.getMediaStream}),this.sip.attchSessionEvent("ended",this.sessionEnded.bind(this)),this.sip.attchSessionEvent("failed",this.sessionFailed.bind(this)),this.init().then((function(){t.api.clearnSendBeaconQueue()}))}return i.prototype.init=function(){return t(this,void 0,void 0,(function(){var t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.initToken()];case 1:return(t=n.sent()).code!==au.SUCCESS?(r=e(e({},t),{code:uu.FAILED}),this.emitInitEvent("failed",r),this.isInitSuccess=!1,[2,r]):[4,this.getAgentStatus()];case 2:return(i=n.sent()).code!==uu.SUCCESS?(o=e(e({},i),{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED}),this.emitInitEvent("failed",o),this.isInitSuccess=!1,[2,o]):(s={code:uu.SUCCESS,data:null,message:"success"},this.emitInitEvent("success",s),this.isInitSuccess=!0,[2,s])}}))}))},i.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return[4,this.api.getAgentStatusList()];case 1:return(e=t.sent()).code===au.SUCCESS?[2,{code:uu.SUCCESS,data:e.data||[],message:e.message}]:[2,{code:uu.FAILED,data:null,message:e.message}]}}))}))},i.prototype.getTicket=function(){var e=window.sessionStorage.getItem("wiz-agent-ticket");return e||(e=r(),window.sessionStorage.setItem("wiz-agent-ticket",e)),e},i.prototype.getHostName=function(e){try{return new URL(e).hostname}catch(e){return""}},i.prototype.processSSEMessage=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t=JSON.parse(null==e?void 0:e.data)||{},r=this.agentInfo.statusName,-1===t.agentId?[3,2]:[4,this.offlineAgent(r)];case 1:n.sent(),1===t.status&&this.onlineAgent(r),n.label=2;case 2:return[2]}}))}))},i.prototype.resetSSE=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this.api.closeSSE({agentId:this.agentInfo.id,clearTicket:1})];case 1:return e.sent(),[4,this.api.registerSSE({agentId:this.agentInfo.id,onMessage:this.processSSEMessage.bind(this)})];case 2:return e.sent(),[2]}}))}))},i.prototype.createSSEAndOpensips=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return this.api.registerSSE({agentId:e,onMessage:this.processSSEMessage.bind(this)})?[3,2]:[4,this.api.updateAgentTicket({agentId:e,ticket:r,type:pu.OFFLINE})];case 1:return t.sent().code!==au.SUCCESS?[2,{code:uu.FAILED,message:"Registration of SSE failed and update Agent Ticket failed"}]:[2,{code:uu.FAILED,message:"Registration of SSE failed"}];case 2:return[4,this.waitSIPRegistered(7e3)];case 3:return t.sent()?[3,5]:[4,this.api.closeSSE({agentId:e,clearTicket:1})];case 4:return t.sent(),[2,{code:uu.FAILED,message:"SIP registration failed"}];case 5:return[2,{code:uu.SUCCESS,message:"success"}]}}))}))},i.prototype.waitSIPRegistered=function(){return t(this,arguments,void 0,(function(e){var t=this;return void 0===e&&(e=7e3),n(this,(function(n){return[2,new Promise((function(n){var r=!1,i=function(e){r||(r=!0,n(e))};t.sip.on("registered",(function(){return i(!0)})),t.sip.on("registrationFailed",(function(){return i(!1)})),setTimeout((function(){return i(!1)}),e),t.sip.start()}))]}))}))},i.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){var e,t,r,i,o,s,a,u;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.getAgentInfo()];case 1:return"code"in(e=n.sent())&&e.code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:e.message}]:"data"in e&&(null===(u=e.data)||void 0===u?void 0:u[0])?(t=e.data[0],this.agentInfo=t,r=t.id,i=t.ticket,o=t.status,s=this.getTicket(),i?o!==pu.OFFLINE?[3,3]:[4,this.api.updateAgentTicket({agentId:r,ticket:"",type:pu.OFFLINE})]:[3,4]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:if(n.sent().code!==au.SUCCESS)return[2,{code:uu.FAILED,message:"Update Agent Ticket failed"}];i="",t.ticket="",this.agentInfo.ticket="",n.label=3;case 3:if(o===pu.ONLINE&&i!==s)return[2,{code:uu.LOCKED,data:t,message:"Agent ticket occupied, unable to perform agent online or offline."}];n.label=4;case 4:return this.isSipInit||(a="sip:".concat(t.number,"@").concat(this.getHostName(t.realm)),this.sip.init({wssuri:t.realm,password:t.password,uri:a}),this.isSipInit=!0),[2,{code:uu.SUCCESS,data:t,message:e.message}]}}))}))},i.prototype.getAgentStatus=function(){return t(this,void 0,void 0,(function(){var e,t,i,o,s,a,u,l,c,h;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),[4,Promise.allSettled([this.getAgentInfo(),this.api.getAgentSetting({key:"callCenter"})])];case 1:return e=n.sent(),t=e.map((function(e){return"fulfilled"!==e.status?{code:au.FAILED,data:null,message:"system error"}:e.value})),i=t[0],"agentWaitingTime"in(o=t[1])&&(this.agentWaitingTime=o.agentWaitingTime||0),"code"in i&&i.code!==uu.SUCCESS?[2,{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:i.message}]:"data"in i&&i.data?(s=i.data,a=s.status,u=s.id,l=s.groupId,c={code:uu.SUCCESS,data:{id:u,groupId:l,status:a,subStatus:s.statusName},message:"success"},this.agentInfo=s,a===pu.OFFLINE?[2,c]:a!==pu.ONLINE?[3,4]:i.code===uu.LOCKED?[2,{code:uu.LOCKED,data:null,message:i.message}]:[4,this.api.agentAbnormalClose({id:u,groupId:l,trace:r()})]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:return n.sent(),[4,this.api.switchAgentStatus({id:u,groupId:l,status:pu.OFFLINE,subStatus:"offline"})];case 3:return(h=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:h.message}]:(c.data.status=pu.OFFLINE,c.data.subStatus="Offline",[2,c]);case 4:return[2,{code:uu.FAILED,data:null,message:"system error"}];case 5:return n.sent(),[2,{code:uu.FAILED,data:null,message:"system error"}];case 6:return[2]}}))}))},i.prototype.onlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.ONLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 1:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:(f={code:uu.SUCCESS,data:{status:pu.ONLINE,subStatus:e},message:"Agent is already online"},this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 2:return r!==pu.OFFLINE?[3,6]:(s=this.getTicket(),[4,this.api.updateAgentTicket({agentId:i,ticket:s,type:pu.ONLINE})]);case 3:return(a=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:a.message}]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 4:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:[4,this.createSSEAndOpensips(i,s)];case 5:return l=n.sent(),c=l.code,h=l.message,c!==uu.SUCCESS?[2,{code:uu.FAILED,data:null,message:h}]:(f={code:c,data:{status:pu.ONLINE,subStatus:e},message:h},this.agentInfo.status=pu.ONLINE,this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 6:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.offlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.OFFLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 1:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.agentInfo.statusName=e,this.emitAgentEvent("offline",a),[2,a]);case 2:return r!==pu.ONLINE?[3,4]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 3:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(this.api.closeSSE({agentId:i,clearTicket:1}),this.sip.stop(!0),a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.emitAgentEvent("offline",a),this.agentInfo.status=pu.OFFLINE,this.agentInfo.statusName=e,[2,a]);case 4:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.isInitSuccess?[4,this.getAgentInfo()]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Registration failed. Seat online and offline cannot be performed."}];case 1:return(t=n.sent()).code!==uu.SUCCESS?[2,{code:t.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:t.message}]:(r=e.status,i=e.subStatus,r===pu.ONLINE?[2,this.onlineAgent(i)]:r===pu.OFFLINE?[2,this.offlineAgent(i)]:[2,{code:uu.FAILED,data:null,message:"system error"}])}}))}))},i.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r=this;return n(this,(function(n){return this.isInitSuccess?(t=this.agentInfo.outboundLineId)?[2,this.api.outboundCall({phone:e,line:t}).then((function(e){return e.code===au.SUCCESS?(r.sip.setCallType("outboundCall"),{code:uu.SUCCESS,data:e.data,message:e.message||e.msg}):{code:uu.FAILED,data:null,message:e.message||e.msg}}))]:[2,Promise.resolve({code:uu.FAILED,data:null,message:"Agent has no outbound line"})]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Outbound calls cannot be made."}]}))}))},i.prototype.autoFinishACW=function(){var e=this,t=Number(this.callDetails.afterCallProcessTime),n=function(){t<=0?e.finshACW():(t-=1,e.autoFinishACWTimer=setTimeout(n,1e3))};this.autoFinishACWTimer=setTimeout(n,1e3)},i.prototype.finshACW=function(){return t(this,void 0,void 0,(function(){var e,t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.autoFinishACWTimer&&(clearTimeout(this.autoFinishACWTimer),this.autoFinishACWTimer=null),e=this.agentInfo,t=e.id,r=e.groupId,[4,this.api.switchAgentStatus({id:t,groupId:r,status:pu.HANGUP})];case 1:return[2,{code:(i=n.sent()).code===au.SUCCESS?uu.SUCCESS:uu.FAILED,data:null,message:i.message}]}}))}))},i.prototype.sessionEnded=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.autoFinishACW(),[2]}))}))},i.prototype.sessionFailed=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.api.updateAgentHangup(this.agentInfo.id),[2]}))}))},i.prototype.openOnunload=function(){var e=this;window.onbeforeunload=function(e){e.returnValue="beforeunload"},window.onunload=function(){e.doForceOfflineCleanup()},this.unloadingHandled=!1},i.prototype.cancelOnunload=function(){window.onbeforeunload=function(){},window.onunload=function(){},this.unloadingHandled=!1},i.prototype.doForceOfflineCleanup=function(){if(!this.unloadingHandled){this.unloadingHandled=!0;var e="".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close");this.api.sendBeacon({url:e,id:this.agentInfo.id,groupId:this.agentInfo.groupId,trace:r()})}},i.prototype.saveAgentResponseTime=function(e){this.api.saveAgentResponseTime({callId:this.callDetails.callId,agentId:this.agentInfo.id,agentResponseTime:this.agentResponseTime,agentGroupId:this.agentInfo.groupId,resultType:e}),this.timer&&(clearInterval(this.timer),this.agentResponseTime=0)},i.prototype.hangup=function(){this.sip.hangup()},i.prototype.timingResTime=function(){var e=this;this.timer&&(clearInterval(this.timer),this.timer=null);var t=this.agentWaitingTime;this.agentResponseTime=0,this.timer=setInterval((function(){if(t<=0)return clearInterval((null==e?void 0:e.timer)||0),e.timer=null,void e.ignore();t-=1,e.agentResponseTime+=1}),1e3)},i.prototype.incomingCall=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f,d,p,g,m,_,A,v,y,T;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),t=e.request,r=(null===(_=null===(m=t.headers["Call-Param"])||void 0===m?void 0:m[0])||void 0===_?void 0:_.raw)||"",i=r?atob(r):"",o=JSON.parse(i||"{}"),s=(null===(v=null===(A=t.headers["Call-Task"])||void 0===A?void 0:A[0])||void 0===v?void 0:v.raw)||"",a=(null===(T=null===(y=t.headers["Call-Record-Id"])||void 0===y?void 0:y[0])||void 0===T?void 0:T.raw)||null,u=Object.fromEntries(Object.entries(o).filter((function(e){return""!==e[0]}))),l="",c="",s?[4,Promise.allSettled([this.api.getCallTaskInfo({callTaskId:s}),this.api.getAfterCallProcessTime({callTaskId:s})])]:[3,2];case 1:h=n.sent(),f=h[0],d=h[1],"fulfilled"===f.status&&(l=f.value.name||""),"fulfilled"===d.status&&(p=d.value).code===uu.SUCCESS&&(c=String(p.data||"")),n.label=2;case 2:return this.callDetails={callId:a||"",callType:this.sip.getCallType()||"",taskName:l,afterCallProcessTime:c,phone:u.phone||u.Phone||u.PHONE||"",contactId:u.contactId||u.ContactId||u.CONTACT_ID||"",extraJson:u},this.timingResTime(),[2,Promise.resolve({code:uu.SUCCESS,data:this.callDetails,message:"success"})];case 3:return g=n.sent(),[2,Promise.resolve({code:uu.FAILED,data:null,message:(null==g?void 0:g.toString())||"system error"})];case 4:return[2]}}))}))},i.prototype.answer=function(){this.sip.answer(),this.saveAgentResponseTime(gu.ANSWER)},i.prototype.ignore=function(){this.sip.ignore(),this.saveAgentResponseTime(gu.HANGUP)},i.prototype.mute=function(){this.sip.mute()},i.prototype.unmute=function(){this.sip.unmute()},i.prototype.attachInitEvent=function(e,t){t&&"function"==typeof t&&(this.initEvent[e]||(this.initEvent[e]=[]),this.initEvent[e].push(t))},i.prototype.removeInitEvent=function(e,t){var n=this.initEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitInitEvent=function(e,t){(this.initEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAgentEvent=function(e,t){t&&"function"==typeof t&&(this.agentEvent[e]||(this.agentEvent[e]=[]),this.agentEvent[e].push(t))},i.prototype.removeAgentEvent=function(e,t){var n=this.agentEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitAgentEvent=function(e,t){(this.agentEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAnswerEvent=function(e){this.sip.attachAnswerEvent(e)},i.prototype.removeAnswerEvent=function(e){this.sip.removeAnswerEvent(e)},i.prototype.attachNewMessageEvent=function(e){this.sip.attachNewMessageEvent(e)},i.prototype.removeNewMessageEvent=function(e){this.sip.removeNewMessageEvent(e)},i.prototype.attchSessionEvent=function(e,t){this.sip.attchSessionEvent(e,t)},i.prototype.removeSessionEvent=function(e,t){this.sip.removeSessionEvent(e,t)},i}();export{Tu as default};
@@ -4,4 +4,4 @@
4
4
  * Available under MIT License (MIT)
5
5
  * https://github.com/Yaffle/EventSource/
6
6
  */
7
- !function(e,t){!function(n){var r=n.setTimeout,i=n.clearTimeout,o=n.XMLHttpRequest,s=n.XDomainRequest,a=n.ActiveXObject,u=n.EventSource,l=n.document,c=n.Promise,h=n.fetch,f=n.Response,d=n.TextDecoder,p=n.TextEncoder,g=n.AbortController;if("undefined"==typeof window||void 0===l||"readyState"in l||null!=l.body||(l.readyState="loading",window.addEventListener("load",(function(e){l.readyState="complete"}),!1)),null==o&&null!=a&&(o=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==g){var m=h;h=function(e,t){var n=t.signal;return m(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then((function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}}))},g=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function _(){this.bitsNeeded=0,this.codePoint=0}_.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var r=65533,i="",o=this.bitsNeeded,s=this.codePoint,a=0;a<e.length;a+=1){var u=e[a];0!==o&&(u<128||u>191||!t(s<<6|63&u,o-6,n(o,s)))&&(o=0,s=r,i+=String.fromCharCode(s)),0===o?(u>=0&&u<=127?(o=0,s=u):u>=192&&u<=223?(o=6,s=31&u):u>=224&&u<=239?(o=12,s=15&u):u>=240&&u<=247?(o=18,s=7&u):(o=0,s=r),0===o||t(s,o,n(o,s))||(o=0,s=r)):(o-=6,s=s<<6|63&u),0===o&&(s<=65535?i+=String.fromCharCode(s):(i+=String.fromCharCode(55296+(s-65535-1>>10)),i+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=s,i};null!=d&&null!=p&&function(){try{return"test"===(new d).decode((new p).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(d=_);var A=function(){};function v(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=A,this.onload=A,this.onerror=A,this.onreadystatechange=A,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=A}function y(e){return e.replace(/[A-Z]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+32)}))}function T(e){for(var t=Object.create(null),n=e.split("\r\n"),r=0;r<n.length;r+=1){var i=n[r].split(": "),o=i.shift(),s=i.join(": ");t[y(o)]=s}this._map=t}function S(){}function E(e){this._headers=e}function C(){}function w(){this._listeners=Object.create(null)}function b(e){r((function(){throw e}),0)}function I(e){this.type=e,this.target=void 0}function R(e,t){I.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function O(e,t){I.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function D(e,t){I.call(this,e),this.error=t.error}v.prototype.open=function(e,t){this._abort(!0);var n=this,s=this._xhr,a=1,u=0;this._abort=function(e){0!==n._sendTimeout&&(i(n._sendTimeout),n._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=A,s.onerror=A,s.onabort=A,s.onprogress=A,s.onreadystatechange=A,s.abort(),0!==u&&(i(u),u=0),e||(n.readyState=4,n.onabort(null),n.onreadystatechange())),a=0};var l=function(){if(1===a){var e=0,t="",r=void 0;if("contentType"in s)e=200,t="OK",r=s.contentType;else try{e=s.status,t=s.statusText,r=s.getResponseHeader("Content-Type")}catch(n){e=0,t="",r=void 0}0!==e&&(a=2,n.readyState=2,n.status=e,n.statusText=t,n._contentType=r,n.onreadystatechange())}},c=function(){if(l(),2===a||3===a){a=3;var e="";try{e=s.responseText}catch(e){}n.readyState=3,n.responseText=e,n.onprogress()}},h=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:A}),c(),1===a||2===a||3===a){if(a=4,0!==u&&(i(u),u=0),n.readyState=4,"load"===e)n.onload(t);else if("error"===e)n.onerror(t);else{if("abort"!==e)throw new TypeError;n.onabort(t)}n.onreadystatechange()}},f=function(){u=r((function(){f()}),500),3===s.readyState&&c()};"onload"in s&&(s.onload=function(e){h("load",e)}),"onerror"in s&&(s.onerror=function(e){h("error",e)}),"onabort"in s&&(s.onabort=function(e){h("abort",e)}),"onprogress"in s&&(s.onprogress=c),"onreadystatechange"in s&&(s.onreadystatechange=function(e){!function(e){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",e):3===s.readyState?"onprogress"in s||c():2===s.readyState&&l())}(e)}),!("contentType"in s)&&"ontimeout"in o.prototype||(t+=(-1===t.indexOf("?")?"?":"&")+"padding=true"),s.open(e,t,!0),"readyState"in s&&(u=r((function(){f()}),0))},v.prototype.abort=function(){this._abort(!1)},v.prototype.getResponseHeader=function(e){return this._contentType},v.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},v.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},v.prototype.send=function(){if("ontimeout"in o.prototype&&("sendAsBinary"in o.prototype||"mozAnon"in o.prototype)||null==l||null==l.readyState||"complete"===l.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(e){throw e}}else{var t=this;t._sendTimeout=r((function(){t._sendTimeout=0,t.send()}),4)}},T.prototype.get=function(e){return this._map[y(e)]},null!=o&&null==o.HEADERS_RECEIVED&&(o.HEADERS_RECEIVED=2),S.prototype.open=function(e,t,n,r,i,s,a){e.open("GET",i);var u=0;for(var l in e.onprogress=function(){var t=e.responseText.slice(u);u+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===o.HEADERS_RECEIVED){var n=e.status,r=e.statusText,i=e.getResponseHeader("Content-Type"),s=e.getAllResponseHeaders();t(n,r,i,new T(s))}},e.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,l)&&e.setRequestHeader(l,a[l]);return e.send(),e},E.prototype.get=function(e){return this._headers.get(e)},C.prototype.open=function(e,t,n,r,i,o,s){var a=null,u=new g,l=u.signal,f=new d;return h(i,{headers:s,credentials:o?"include":"same-origin",signal:l,cache:"no-store"}).then((function(e){return a=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new E(e.headers)),new c((function(e,t){var r=function(){a.read().then((function(t){if(t.done)e(void 0);else{var i=f.decode(t.value,{stream:!0});n(i),r()}})).catch((function(e){t(e)}))};r()}))})).catch((function(e){return"AbortError"===e.name?void 0:e})).then((function(e){r(e)})),{abort:function(){null!=a&&a.cancel(),u.abort()}}},w.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,r=0;r<n;r+=1){var i=t[r];try{"function"==typeof i.handleEvent?i.handleEvent(e):i.call(this,e)}catch(e){b(e)}}},w.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];null==r&&(r=[],n[e]=r);for(var i=!1,o=0;o<r.length;o+=1)r[o]===t&&(i=!0);i||r.push(t)},w.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];if(null!=r){for(var i=[],o=0;o<r.length;o+=1)r[o]!==t&&i.push(r[o]);0===i.length?delete n[e]:n[e]=i}},R.prototype=Object.create(I.prototype),O.prototype=Object.create(I.prototype),D.prototype=Object.create(I.prototype);var k=-1,M=0,q=1,N=2,U=-1,x=0,P=1,L=2,B=3,F=/^text\/event\-stream(;.*)?$/i,H=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),G(n)},G=function(e){return Math.min(Math.max(e,1e3),18e6)},Y=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(e){b(e)}};function j(e,t){w.call(this),t=t||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,t,n){t=String(t);var a=Boolean(n.withCredentials),u=n.lastEventIdQueryParameterName||"lastEventId",l=G(1e3),c=H(n.heartbeatTimeout,45e3),h="",f=l,d=!1,p=0,g=n.headers||{},m=n.Transport,_=Q&&null==m?void 0:new v(null!=m?new m:null!=o&&"withCredentials"in o.prototype||null==s?new o:new s),A=null!=m&&"string"!=typeof m?new m:null==_?new C:new S,y=void 0,T=0,E=k,w="",b="",I="",j="",W=x,K=0,z=0,J=function(t,n,r,i){if(E===M)if(200===t&&null!=r&&F.test(r)){E=q,d=Date.now(),f=l,e.readyState=q;var o=new O("open",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onopen,o)}else{var s="";200!==t?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",X();o=new O("error",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onerror,o),console.error(s)}},V=function(t){if(E===q){for(var n=-1,o=0;o<t.length;o+=1){(u=t.charCodeAt(o))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(n=o)}var s=(-1!==n?j:"")+t.slice(0,n+1);j=(-1===n?j:"")+t.slice(n+1),""!==t&&(d=Date.now(),p+=t.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(W===U&&u==="\n".charCodeAt(0))W=x;else if(W===U&&(W=x),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(W!==x){W===P&&(z=a+1);var g=s.slice(K,z-1),m=s.slice(z+(z<a&&s.charCodeAt(z)===" ".charCodeAt(0)?1:0),a);"data"===g?(w+="\n",w+=m):"id"===g?b=m:"event"===g?I=m:"retry"===g?(l=H(m,l),f=l):"heartbeatTimeout"===g&&(c=H(m,c),0!==T&&(i(T),T=r((function(){$()}),c)))}if(W===x){if(""!==w){h=b,""===I&&(I="message");var _=new R(I,{data:w.slice(1),lastEventId:b});if(e.dispatchEvent(_),"open"===I?Y(e,e.onopen,_):"message"===I?Y(e,e.onmessage,_):"error"===I&&Y(e,e.onerror,_),E===N)return}w="",I=""}W=u==="\r".charCodeAt(0)?U:x}else W===x&&(K=a,W=P),W===P?u===":".charCodeAt(0)&&(z=a+1,W=L):W===L&&(W=B)}}},Z=function(t){if(E===q||E===M){E=k,0!==T&&(i(T),T=0),T=r((function(){$()}),f),f=G(Math.min(16*l,2*f)),e.readyState=M;var n=new D("error",{error:t});e.dispatchEvent(n),Y(e,e.onerror,n),null!=t&&console.error(t)}},X=function(){E=N,null!=y&&(y.abort(),y=void 0),0!==T&&(i(T),T=0),e.readyState=N},$=function(){if(T=0,E===k){d=!1,p=0,T=r((function(){$()}),c),E=M,w="",I="",b=h,j="",K=0,z=0,W=x;var n=t;if("data:"!==t.slice(0,5)&&"blob:"!==t.slice(0,5)&&""!==h){var i=t.indexOf("?");n=-1===i?t:t.slice(0,i+1)+t.slice(i+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,(function(e,t){return t===u?"":e})),n+=(-1===t.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var o=e.withCredentials,s={Accept:"text/event-stream"},a=e.headers;if(null!=a)for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(s[l]=a[l]);try{y=A.open(_,J,V,Z,n,o,s)}catch(e){throw X(),e}}else if(d||null==y){var f=Math.max((d||Date.now())+c-Date.now(),1);d=!1,T=r((function(){$()}),f)}else Z(new Error("No activity within "+c+" milliseconds. "+(E===M?"No response received.":p+" chars received.")+" Reconnecting.")),null!=y&&(y.abort(),y=void 0)};e.url=t,e.readyState=M,e.withCredentials=a,e.headers=g,e._close=X,$()}(this,e,t)}var Q=null!=h&&null!=f&&"body"in f.prototype;j.prototype=Object.create(w.prototype),j.prototype.CONNECTING=M,j.prototype.OPEN=q,j.prototype.CLOSED=N,j.prototype.close=function(){this._close()},j.CONNECTING=M,j.OPEN=q,j.CLOSED=N,j.prototype.withCredentials=void 0;var W,K=u;null==o||null!=u&&"withCredentials"in u.prototype||(K=j),W=function(e){e.EventSourcePolyfill=j,e.NativeEventSource=u,e.EventSource=K}(t),void 0!==W&&(e.exports=W)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:i:globalThis)}(hu,hu.exports);var fu=hu.exports,du={exports:{}};!function(e){e.exports=function(){var e=1e3,t=6e4,n=36e5,r="millisecond",i="second",o="minute",s="hour",a="day",u="week",l="month",c="quarter",h="year",f="date",d="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},A={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?"+":"-")+_(r,2,"0")+":"+_(i,2,"0")},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),o=n-i<0,s=t.clone().add(r+(o?-1:1),l);return+(-(r+(n-i)/(o?i-s:s-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:h,w:u,d:a,D:f,h:s,m:o,s:i,ms:r,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},v="en",y={};y[v]=m;var T="$isDayjsObject",S=function(e){return e instanceof b||!(!e||!e[T])},E=function e(t,n,r){var i;if(!t)return v;if("string"==typeof t){var o=t.toLowerCase();y[o]&&(i=o),n&&(y[o]=n,i=o);var s=t.split("-");if(!i&&s.length>1)return e(s[0])}else{var a=t.name;y[a]=t,i=a}return!r&&i&&(v=i),i||!r&&v},C=function(e,t){if(S(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new b(n)},w=A;w.l=E,w.i=S,w.w=function(e,t){return C(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var b=function(){function m(e){this.$L=E(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[T]=!0}var _=m.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(w.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(p);if(r){var i=r[2]-1||0,o=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return w},_.isValid=function(){return!(this.$d.toString()===d)},_.isSame=function(e,t){var n=C(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return C(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<C(e)},_.$g=function(e,t,n){return w.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!w.u(t)||t,c=w.p(e),d=function(e,t){var i=w.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(a)},p=function(e,t){return w.w(n.toDate()[e].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},g=this.$W,m=this.$M,_=this.$D,A="set"+(this.$u?"UTC":"");switch(c){case h:return r?d(1,0):d(31,11);case l:return r?d(1,m):d(0,m+1);case u:var v=this.$locale().weekStart||0,y=(g<v?g+7:g)-v;return d(r?_-y:_+(6-y),m);case a:case f:return p(A+"Hours",0);case s:return p(A+"Minutes",1);case o:return p(A+"Seconds",2);case i:return p(A+"Milliseconds",3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,u=w.p(e),c="set"+(this.$u?"UTC":""),d=(n={},n[a]=c+"Date",n[f]=c+"Date",n[l]=c+"Month",n[h]=c+"FullYear",n[s]=c+"Hours",n[o]=c+"Minutes",n[i]=c+"Seconds",n[r]=c+"Milliseconds",n)[u],p=u===a?this.$D+(t-this.$W):t;if(u===l||u===h){var g=this.clone().set(f,1);g.$d[d](p),g.init(),this.$d=g.set(f,Math.min(this.$D,g.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[w.p(e)]()},_.add=function(r,c){var f,d=this;r=Number(r);var p=w.p(c),g=function(e){var t=C(d);return w.w(t.date(t.date()+Math.round(e*r)),d)};if(p===l)return this.set(l,this.$M+r);if(p===h)return this.set(h,this.$y+r);if(p===a)return g(1);if(p===u)return g(7);var m=(f={},f[o]=t,f[s]=n,f[i]=e,f)[p]||1,_=this.$d.getTime()+r*m;return w.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=e||"YYYY-MM-DDTHH:mm:ssZ",i=w.z(this),o=this.$H,s=this.$m,a=this.$M,u=n.weekdays,l=n.months,c=n.meridiem,h=function(e,n,i,o){return e&&(e[n]||e(t,r))||i[n].slice(0,o)},f=function(e){return w.s(o%12||12,e,"0")},p=c||function(e,t,n){var r=e<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(g,(function(e,r){return r||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return w.s(t.$y,4,"0");case"M":return a+1;case"MM":return w.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,l,3);case"MMMM":return h(l,a);case"D":return t.$D;case"DD":return w.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return h(n.weekdaysMin,t.$W,u,2);case"ddd":return h(n.weekdaysShort,t.$W,u,3);case"dddd":return u[t.$W];case"H":return String(o);case"HH":return w.s(o,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return p(o,s,!0);case"A":return p(o,s,!1);case"m":return String(s);case"mm":return w.s(s,2,"0");case"s":return String(t.$s);case"ss":return w.s(t.$s,2,"0");case"SSS":return w.s(t.$ms,3,"0");case"Z":return i}return null}(e)||i.replace(":","")}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,d){var p,g=this,m=w.p(f),_=C(r),A=(_.utcOffset()-this.utcOffset())*t,v=this-_,y=function(){return w.m(g,_)};switch(m){case h:p=y()/12;break;case l:p=y();break;case c:p=y()/3;break;case u:p=(v-A)/6048e5;break;case a:p=(v-A)/864e5;break;case s:p=v/n;break;case o:p=v/t;break;case i:p=v/e;break;default:p=v}return d?p:w.a(p)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return y[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=E(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return w.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},m}(),I=b.prototype;return C.prototype=I,[["$ms",r],["$s",i],["$m",o],["$H",s],["$W",a],["$M",l],["$y",h],["$D",f]].forEach((function(e){I[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),C.extend=function(e,t){return e.$i||(e(t,b,C),e.$i=!0),C},C.locale=E,C.isDayjs=S,C.unix=function(e){return C(1e3*e)},C.en=y[v],C.Ls=y,C.p={},C}()}(du);var pu,gu,mu=o(du.exports),_u="aks_agent_token",Au=function(){function r(e){this.baseUrl="",this.eventSource=null,this.retryCount=0,this.retryMap=new Map,this.token="",this.id=e.id,this.getSystemToken=e.getSystemToken,this.resetSSE=e.resetSSE,this.retryCount=e.retryCount||0,this.baseUrl=e.baseUrl||""}return r.prototype.validateToken=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,fetch("".concat(this.baseUrl,"/iam/token/validate?accountId=").concat(e),{method:"GET",headers:{authentication:r}}).then((function(e){return e.json()}))]}))}))},r.prototype.initToken=function(){return t(this,void 0,void 0,(function(){var e,t,r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.getSystemToken()];case 1:return(e=n.sent())?[4,this.validateToken(this.id,e)]:[2,{code:au.FAILED,data:null,message:"get system token failed"}];case 2:return(t=n.sent()).code===au.SUCCESS?(this.token=e,sessionStorage.setItem(_u,e),this.executePeriodically(this.refreshToken.bind(this),12e5),[2,{code:au.SUCCESS,data:null,message:t.message}]):[2,{code:au.FAILED,data:null,message:t.message}];case 3:return r=n.sent(),[2,{code:au.FAILED,data:null,message:(null==r?void 0:r.toString())||"system error"}];case 4:return[2]}}))}))},r.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var e=this;return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/iam/oauth2/refresh")}).then((function(t){t.token&&(e.token=t.token,sessionStorage.setItem(_u,t.token),e.eventSource&&e.resetSSE())}))]}))}))},r.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/status/list")})]}))}))},r.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/getAgentByUserId")})]}))}))},r.prototype.getAgentSetting=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getAgentSetting"),data:e})]}))}))},r.prototype.updateAgentHangup=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent/").concat(e),method:"PUT"})]}))}))},r.prototype.updateAgentTicket=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/voipPlatform/agent/ticket"),data:e})]}))}))},r.prototype.registerSSE=function(e){return t(this,void 0,void 0,(function(){var r,i,o,s,a,u=this;return n(this,(function(l){return r=e.agentId,i=e.onMessage,o=function(e){},s=new Promise((function(e){o=e})),a=this.token,this.eventSource=new fu.EventSourcePolyfill("".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_event?agentId=").concat(r),{headers:{Authentication:a,"Cache-Control":"no-cache",Connection:"keep-alive"},heartbeatTimeout:12e6}),this.eventSource.onmessage=i,this.eventSource.onopen=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!0),[2]}))}))},this.eventSource.onerror=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!1),[2]}))}))},[2,s]}))}))},r.prototype.closeSSE=function(e){return t(this,void 0,void 0,(function(){var t,r,i=this;return n(this,(function(n){return t=e.agentId,r=e.clearTicket,this.eventSource?[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_close?agentId=").concat(t,"&clearTicket=").concat(r)}).then((function(){i.eventSource.close(),i.eventSource=null}))]:[2]}))}))},r.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"PUT",url:"".concat(this.baseUrl,"/voipPlatform/agent/agentStatusSwitch"),data:e})]}))}))},r.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){return t=e.phone,r=e.line,[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agentOutBoundCall/dialer/startCall/").concat(t,"/").concat(r),method:"POST"})]}))}))},r.prototype.saveAgentResponseTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/call_record/callRecordAgent"),data:e})]}))}))},r.prototype.getCallTaskInfo=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getCallTaskName/").concat(e.callTaskId)})]}))}))},r.prototype.getAfterCallProcessTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/predictCall/afterCallProcessTime/").concat(e.callTaskId)})]}))}))},r.prototype.formatFormData=function(e){var t=new FormData;for(var n in e)e[n]&&t.append(n,e[n]);return t},r.prototype.agentAbnormalClose=function(e){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=this.formatFormData(e);return this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close"),data:t},!0)},r.prototype.sendBeacon=function(e){if("function"==typeof navigator.sendBeacon&&e.url){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=e.url,n=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(e,["url"]),r=this.formatFormData(n),i=navigator.sendBeacon(t,r);if(!i){e.lastSendResult=i;var o=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]");o.push(e),localStorage.setItem("aks_beacon_queue",JSON.stringify(o))}}},r.prototype.clearnSendBeaconQueue=function(){return t(this,void 0,void 0,(function(){var e,t;return n(this,(function(n){switch(n.label){case 0:return(e=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]")).length?[4,this.waitToken()]:[3,4];case 1:return n.sent()?[3,3]:[4,this.initToken()];case 2:if(n.sent().code!==au.SUCCESS)return[2];n.label=3;case 3:for(t=0;t<e.length-1;t++)this.sendBeacon(e[t]);n.label=4;case 4:return[2]}}))}))},r.prototype.getTokenWithFallback=function(){return this.token?this.token:sessionStorage.getItem(_u)||""},r.prototype.waitToken=function(e,t){var n=this;return void 0===e&&(e=3e3),void 0===t&&(t=200),new Promise((function(r){var i=setInterval((function(){((e-=t)<=0||n.token)&&(clearInterval(i),r(Boolean(n.token)))}),200)}))},r.prototype.request=function(r){return t(this,arguments,void 0,(function(r,i){var o,s,a,u=this;return void 0===i&&(i=!1),n(this,(function(l){switch(l.label){case 0:return!this.retryMap.has(r.url)&&this.retryCount&&this.retryMap.set(r.url,this.retryCount),this.token?[3,3]:[4,this.waitToken()];case 1:return l.sent()?[3,3]:[4,this.initToken()];case 2:if((o=l.sent()).code!==au.SUCCESS)return[2,{code:o.code,message:o.message,data:null}];l.label=3;case 3:return s={method:r.method||"GET",headers:e({"Content-Type":"application/json",authentication:this.token},r.headers)},i?(s.method=r.method,s.headers={authentication:this.token},s.body=r.data):"GET"!==(null===(a=s.method)||void 0===a?void 0:a.toLocaleUpperCase())&&(s.body=JSON.stringify(r.data)),[2,fetch(r.url,s).then((function(e){return t(u,void 0,void 0,(function(){var t,i;return n(this,(function(n){switch(n.label){case 0:return t=this.retryMap.get(r.url),401!==e.status?[3,3]:t?(this.retryMap.set(r.url,t-1),[4,this.initToken()]):[3,2];case 1:return(i=n.sent()).code===au.SUCCESS?[2,this.request(r)]:[2,i];case 2:return this.retryCount&&this.retryMap.delete(r.url),[2,{code:au.UNAUTHORIZED,message:"Unauthorized",data:null}];case 3:return[2,e.json()]}}))}))}))]}}))}))},r.prototype.executePeriodically=function(e,t){var n=Date.now()+t,r=function(){var i=Date.now();i>=n&&(e(),n+=t);var o=Math.max(0,n-i);setTimeout(r,o)};r()},r.getInstance=function(e){return!r.instance&&e&&(r.instance=new r(e)),r.instance},r.instance=null,r}();!function(e){e[e.OFFLINE=0]="OFFLINE",e[e.ONLINE=1]="ONLINE",e[e.HANGUP=4]="HANGUP"}(pu||(pu={})),function(e){e[e.ANSWER=1]="ANSWER",e[e.HANGUP=2]="HANGUP"}(gu||(gu={}));var vu=function(){function i(e){var t=this;this.sip={},this.api={},this.isSipInit=!1,this.isInitSuccess=!1,this.agentInfo={},this.initEvent={},this.agentEvent={},this.agentWaitingTime=0,this.agentResponseTime=0,this.timer=null,this.callDetails={},this.unloadingHandled=!1,this.baseUrl="",this.autoFinishACWTimer=null,this.baseUrl=(null==e?void 0:e.baseUrl)||"",this.api=Au.getInstance({id:e.id,getSystemToken:e.getSystemToken,resetSSE:this.resetSSE.bind(this),retryCount:e.retryCount,baseUrl:this.baseUrl}),this.sip=new cu({incomingCallCallback:this.incomingCall.bind(this),getMediaStream:null==e?void 0:e.getMediaStream}),this.sip.attchSessionEvent("ended",this.sessionEnded.bind(this)),this.sip.attchSessionEvent("failed",this.sessionFailed.bind(this)),this.init().then((function(){t.api.clearnSendBeaconQueue()}))}return i.prototype.init=function(){return t(this,void 0,void 0,(function(){var t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.initToken()];case 1:return(t=n.sent()).code!==au.SUCCESS?(r=e(e({},t),{code:uu.FAILED}),this.emitInitEvent("failed",r),this.isInitSuccess=!1,[2,r]):[4,this.getAgentStatus()];case 2:return(i=n.sent()).code!==uu.SUCCESS?(o=e(e({},i),{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED}),this.emitInitEvent("failed",o),this.isInitSuccess=!1,[2,o]):(s={code:uu.SUCCESS,data:null,message:"success"},this.emitInitEvent("success",s),this.isInitSuccess=!0,[2,s])}}))}))},i.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return[4,this.api.getAgentStatusList()];case 1:return(e=t.sent()).code===au.SUCCESS?[2,{code:uu.SUCCESS,data:e.data||[],message:e.message}]:[2,{code:uu.FAILED,data:null,message:e.message}]}}))}))},i.prototype.getTicket=function(){var e=window.sessionStorage.getItem("wiz-agent-ticket");return e||(e=r(),window.sessionStorage.setItem("wiz-agent-ticket",e)),e},i.prototype.getHostName=function(e){try{return new URL(e).hostname}catch(e){return""}},i.prototype.processSSEMessage=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t=JSON.parse(null==e?void 0:e.data)||{},r=this.agentInfo.statusName,-1===t.agentId?[3,2]:[4,this.offlineAgent(r)];case 1:n.sent(),1===t.status&&this.onlineAgent(r),n.label=2;case 2:return[2]}}))}))},i.prototype.resetSSE=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this.api.closeSSE({agentId:this.agentInfo.id,clearTicket:1})];case 1:return e.sent(),[4,this.api.registerSSE({agentId:this.agentInfo.id,onMessage:this.processSSEMessage.bind(this)})];case 2:return e.sent(),[2]}}))}))},i.prototype.createSSEAndOpensips=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return this.api.registerSSE({agentId:e,onMessage:this.processSSEMessage.bind(this)})?[3,2]:[4,this.api.updateAgentTicket({agentId:e,ticket:r,type:pu.OFFLINE})];case 1:return t.sent().code!==au.SUCCESS?[2,{code:uu.FAILED,message:"Registration of SSE failed and update Agent Ticket failed"}]:[2,{code:uu.FAILED,message:"Registration of SSE failed"}];case 2:return[4,this.waitSIPRegistered(7e3)];case 3:return t.sent()?[3,5]:[4,this.api.closeSSE({agentId:e,clearTicket:1})];case 4:return t.sent(),[2,{code:uu.FAILED,message:"SIP registration failed"}];case 5:return[2,{code:uu.SUCCESS,message:"success"}]}}))}))},i.prototype.waitSIPRegistered=function(){return t(this,arguments,void 0,(function(e){var t=this;return void 0===e&&(e=7e3),n(this,(function(n){return[2,new Promise((function(n){var r=!1,i=function(e){r||(r=!0,n(e))};t.sip.on("registered",(function(){return i(!0)})),t.sip.on("registrationFailed",(function(){return i(!1)})),setTimeout((function(){return i(!1)}),e),t.sip.start()}))]}))}))},i.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){var e,t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.getAgentInfo()];case 1:return"code"in(e=n.sent())&&e.code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:e.message}]:"data"in e&&(null===(s=e.data)||void 0===s?void 0:s[0])?(t=e.data[0],this.agentInfo=t,r=t.ticket,i=this.getTicket(),r&&r!==i?[2,{code:uu.LOCKED,data:t,message:"Agent ticket occupied, unable to perform agent online or offline."}]:(this.isSipInit||(o="sip:".concat(t.number,"@").concat(this.getHostName(t.realm)),this.sip.init({wssuri:t.realm,password:t.password,uri:o}),this.isSipInit=!0),[2,{code:uu.SUCCESS,data:t,message:e.message}])):[2,{code:uu.FAILED,data:null,message:"Agent not found"}]}}))}))},i.prototype.getAgentStatus=function(){return t(this,void 0,void 0,(function(){var e,t,i,o,s,a,u,l,c,h;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),[4,Promise.allSettled([this.getAgentInfo(),this.api.getAgentSetting({key:"callCenter"})])];case 1:return e=n.sent(),t=e.map((function(e){return"fulfilled"!==e.status?{code:au.FAILED,data:null,message:"system error"}:e.value})),i=t[0],"agentWaitingTime"in(o=t[1])&&(this.agentWaitingTime=o.agentWaitingTime||0),"code"in i&&i.code!==uu.SUCCESS?[2,{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:i.message}]:"data"in i&&i.data?(s=i.data,a=s.status,u=s.id,l=s.groupId,c={code:uu.SUCCESS,data:{id:u,groupId:l,status:a,subStatus:s.statusName},message:"success"},this.agentInfo=s,a===pu.OFFLINE?[2,c]:a!==pu.ONLINE?[3,4]:i.code===uu.LOCKED?[2,{code:uu.LOCKED,data:null,message:i.message}]:[4,this.api.agentAbnormalClose({id:u,groupId:l,trace:r()})]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:return n.sent(),[4,this.api.switchAgentStatus({id:u,groupId:l,status:pu.OFFLINE,subStatus:"offline"})];case 3:return(h=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:h.message}]:(c.data.status=pu.OFFLINE,c.data.subStatus="Offline",[2,c]);case 4:return[2,{code:uu.FAILED,data:null,message:"system error"}];case 5:return n.sent(),[2,{code:uu.FAILED,data:null,message:"system error"}];case 6:return[2]}}))}))},i.prototype.onlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.ONLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 1:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:(f={code:uu.SUCCESS,data:{status:pu.ONLINE,subStatus:e},message:"Agent is already online"},this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 2:return r!==pu.OFFLINE?[3,6]:(s=this.getTicket(),[4,this.api.updateAgentTicket({agentId:i,ticket:s,type:pu.ONLINE})]);case 3:return(a=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:a.message}]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 4:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:[4,this.createSSEAndOpensips(i,s)];case 5:return l=n.sent(),c=l.code,h=l.message,c!==uu.SUCCESS?[2,{code:uu.FAILED,data:null,message:h}]:(f={code:c,data:{status:pu.ONLINE,subStatus:e},message:h},this.agentInfo.status=pu.ONLINE,this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 6:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.offlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.OFFLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 1:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.agentInfo.statusName=e,this.emitAgentEvent("offline",a),[2,a]);case 2:return r!==pu.ONLINE?[3,4]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 3:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(this.api.closeSSE({agentId:i,clearTicket:1}),this.sip.stop(!0),a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.emitAgentEvent("offline",a),this.agentInfo.status=pu.OFFLINE,this.agentInfo.statusName=e,[2,a]);case 4:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.isInitSuccess?[4,this.getAgentInfo()]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Registration failed. Seat online and offline cannot be performed."}];case 1:return(t=n.sent()).code!==uu.SUCCESS?[2,{code:t.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:t.message}]:(r=e.status,i=e.subStatus,r===pu.ONLINE?[2,this.onlineAgent(i)]:r===pu.OFFLINE?[2,this.offlineAgent(i)]:[2,{code:uu.FAILED,data:null,message:"system error"}])}}))}))},i.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r=this;return n(this,(function(n){return this.isInitSuccess?(t=this.agentInfo.outboundLineId)?[2,this.api.outboundCall({phone:e,line:t}).then((function(e){return e.code===au.SUCCESS?(r.sip.setCallType("outboundCall"),{code:uu.SUCCESS,data:e.data,message:e.message||e.msg}):{code:uu.FAILED,data:null,message:e.message||e.msg}}))]:[2,Promise.resolve({code:uu.FAILED,data:null,message:"Agent has no outbound line"})]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Outbound calls cannot be made."}]}))}))},i.prototype.autoFinishACW=function(){var e=this,t=Number(this.callDetails.afterCallProcessTime),n=function(){t<=0?e.finshACW():(t-=1,e.autoFinishACWTimer=setTimeout(n,1e3))};this.autoFinishACWTimer=setTimeout(n,1e3)},i.prototype.finshACW=function(){return t(this,void 0,void 0,(function(){var e,t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.autoFinishACWTimer&&(clearTimeout(this.autoFinishACWTimer),this.autoFinishACWTimer=null),e=this.agentInfo,t=e.id,r=e.groupId,[4,this.api.switchAgentStatus({id:t,groupId:r,status:pu.HANGUP})];case 1:return[2,{code:(i=n.sent()).code===au.SUCCESS?uu.SUCCESS:uu.FAILED,data:null,message:i.message}]}}))}))},i.prototype.sessionEnded=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.autoFinishACW(),[2]}))}))},i.prototype.sessionFailed=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.api.updateAgentHangup(this.agentInfo.id),[2]}))}))},i.prototype.openOnunload=function(){var e=this;window.onbeforeunload=function(e){e.returnValue="beforeunload"},window.onunload=function(){e.doForceOfflineCleanup()},this.unloadingHandled=!1},i.prototype.cancelOnunload=function(){window.onbeforeunload=function(){},window.onunload=function(){},this.unloadingHandled=!1},i.prototype.doForceOfflineCleanup=function(){if(!this.unloadingHandled){this.unloadingHandled=!0;var e="".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close");this.api.sendBeacon({url:e,id:this.agentInfo.id,groupId:this.agentInfo.groupId,trace:r()})}},i.prototype.saveAgentResponseTime=function(e){this.api.saveAgentResponseTime({callId:this.callDetails.callId,agentId:this.agentInfo.id,agentResponseTime:this.agentResponseTime,agentGroupId:this.agentInfo.groupId,resultType:e}),this.timer&&(clearInterval(this.timer),this.agentResponseTime=0)},i.prototype.hangup=function(){this.sip.hangup()},i.prototype.timingResTime=function(){var e=this;this.timer&&(clearInterval(this.timer),this.timer=null);var t=this.agentWaitingTime;this.agentResponseTime=0,this.timer=setInterval((function(){if(t<=0)return clearInterval((null==e?void 0:e.timer)||0),e.timer=null,void e.ignore();t-=1,e.agentResponseTime+=1}),1e3)},i.prototype.incomingCall=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f,d,p,g,m,_,A,v,y,T;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),t=e.request,r=(null===(_=null===(m=t.headers["Call-Param"])||void 0===m?void 0:m[0])||void 0===_?void 0:_.raw)||"",i=r?atob(r):"",o=JSON.parse(i||"{}"),s=(null===(v=null===(A=t.headers["Call-Task"])||void 0===A?void 0:A[0])||void 0===v?void 0:v.raw)||"",a=(null===(T=null===(y=t.headers["Call-Record-Id"])||void 0===y?void 0:y[0])||void 0===T?void 0:T.raw)||null,u=Object.fromEntries(Object.entries(o).filter((function(e){return""!==e[0]}))),l="",c="",s?[4,Promise.allSettled([this.api.getCallTaskInfo({callTaskId:s}),this.api.getAfterCallProcessTime({callTaskId:s})])]:[3,2];case 1:h=n.sent(),f=h[0],d=h[1],"fulfilled"===f.status&&(l=f.value.name||""),"fulfilled"===d.status&&(p=d.value).code===uu.SUCCESS&&(c=String(p.data||"")),n.label=2;case 2:return this.callDetails={callId:a||"",callType:this.sip.getCallType()||"",taskName:l,afterCallProcessTime:c,phone:u.phone||u.Phone||u.PHONE||"",contactId:u.contactId||u.ContactId||u.CONTACT_ID||"",extraJson:u},this.timingResTime(),[2,Promise.resolve({code:uu.SUCCESS,data:this.callDetails,message:"success"})];case 3:return g=n.sent(),[2,Promise.resolve({code:uu.FAILED,data:null,message:(null==g?void 0:g.toString())||"system error"})];case 4:return[2]}}))}))},i.prototype.answer=function(){this.sip.answer(),this.saveAgentResponseTime(gu.ANSWER)},i.prototype.ignore=function(){this.sip.ignore(),this.saveAgentResponseTime(gu.HANGUP)},i.prototype.mute=function(){this.sip.mute()},i.prototype.unmute=function(){this.sip.unmute()},i.prototype.attachInitEvent=function(e,t){t&&"function"==typeof t&&(this.initEvent[e]||(this.initEvent[e]=[]),this.initEvent[e].push(t))},i.prototype.removeInitEvent=function(e,t){var n=this.initEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitInitEvent=function(e,t){(this.initEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAgentEvent=function(e,t){t&&"function"==typeof t&&(this.agentEvent[e]||(this.agentEvent[e]=[]),this.agentEvent[e].push(t))},i.prototype.removeAgentEvent=function(e,t){var n=this.agentEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitAgentEvent=function(e,t){(this.agentEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAnswerEvent=function(e){this.sip.attachAnswerEvent(e)},i.prototype.removeAnswerEvent=function(e){this.sip.removeAnswerEvent(e)},i.prototype.attachNewMessageEvent=function(e){this.sip.attachNewMessageEvent(e)},i.prototype.removeNewMessageEvent=function(e){this.sip.removeNewMessageEvent(e)},i.prototype.attchSessionEvent=function(e,t){this.sip.attchSessionEvent(e,t)},i.prototype.removeSessionEvent=function(e,t){this.sip.removeSessionEvent(e,t)},i}();return vu}));
7
+ !function(e,t){!function(n){var r=n.setTimeout,i=n.clearTimeout,o=n.XMLHttpRequest,s=n.XDomainRequest,a=n.ActiveXObject,u=n.EventSource,l=n.document,c=n.Promise,h=n.fetch,f=n.Response,d=n.TextDecoder,p=n.TextEncoder,g=n.AbortController;if("undefined"==typeof window||void 0===l||"readyState"in l||null!=l.body||(l.readyState="loading",window.addEventListener("load",(function(e){l.readyState="complete"}),!1)),null==o&&null!=a&&(o=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==g){var m=h;h=function(e,t){var n=t.signal;return m(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then((function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}}))},g=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function _(){this.bitsNeeded=0,this.codePoint=0}_.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var r=65533,i="",o=this.bitsNeeded,s=this.codePoint,a=0;a<e.length;a+=1){var u=e[a];0!==o&&(u<128||u>191||!t(s<<6|63&u,o-6,n(o,s)))&&(o=0,s=r,i+=String.fromCharCode(s)),0===o?(u>=0&&u<=127?(o=0,s=u):u>=192&&u<=223?(o=6,s=31&u):u>=224&&u<=239?(o=12,s=15&u):u>=240&&u<=247?(o=18,s=7&u):(o=0,s=r),0===o||t(s,o,n(o,s))||(o=0,s=r)):(o-=6,s=s<<6|63&u),0===o&&(s<=65535?i+=String.fromCharCode(s):(i+=String.fromCharCode(55296+(s-65535-1>>10)),i+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=o,this.codePoint=s,i};null!=d&&null!=p&&function(){try{return"test"===(new d).decode((new p).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(d=_);var A=function(){};function v(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=A,this.onload=A,this.onerror=A,this.onreadystatechange=A,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=A}function y(e){return e.replace(/[A-Z]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+32)}))}function T(e){for(var t=Object.create(null),n=e.split("\r\n"),r=0;r<n.length;r+=1){var i=n[r].split(": "),o=i.shift(),s=i.join(": ");t[y(o)]=s}this._map=t}function S(){}function E(e){this._headers=e}function C(){}function w(){this._listeners=Object.create(null)}function b(e){r((function(){throw e}),0)}function I(e){this.type=e,this.target=void 0}function R(e,t){I.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function O(e,t){I.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function D(e,t){I.call(this,e),this.error=t.error}v.prototype.open=function(e,t){this._abort(!0);var n=this,s=this._xhr,a=1,u=0;this._abort=function(e){0!==n._sendTimeout&&(i(n._sendTimeout),n._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=A,s.onerror=A,s.onabort=A,s.onprogress=A,s.onreadystatechange=A,s.abort(),0!==u&&(i(u),u=0),e||(n.readyState=4,n.onabort(null),n.onreadystatechange())),a=0};var l=function(){if(1===a){var e=0,t="",r=void 0;if("contentType"in s)e=200,t="OK",r=s.contentType;else try{e=s.status,t=s.statusText,r=s.getResponseHeader("Content-Type")}catch(n){e=0,t="",r=void 0}0!==e&&(a=2,n.readyState=2,n.status=e,n.statusText=t,n._contentType=r,n.onreadystatechange())}},c=function(){if(l(),2===a||3===a){a=3;var e="";try{e=s.responseText}catch(e){}n.readyState=3,n.responseText=e,n.onprogress()}},h=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:A}),c(),1===a||2===a||3===a){if(a=4,0!==u&&(i(u),u=0),n.readyState=4,"load"===e)n.onload(t);else if("error"===e)n.onerror(t);else{if("abort"!==e)throw new TypeError;n.onabort(t)}n.onreadystatechange()}},f=function(){u=r((function(){f()}),500),3===s.readyState&&c()};"onload"in s&&(s.onload=function(e){h("load",e)}),"onerror"in s&&(s.onerror=function(e){h("error",e)}),"onabort"in s&&(s.onabort=function(e){h("abort",e)}),"onprogress"in s&&(s.onprogress=c),"onreadystatechange"in s&&(s.onreadystatechange=function(e){!function(e){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",e):3===s.readyState?"onprogress"in s||c():2===s.readyState&&l())}(e)}),!("contentType"in s)&&"ontimeout"in o.prototype||(t+=(-1===t.indexOf("?")?"?":"&")+"padding=true"),s.open(e,t,!0),"readyState"in s&&(u=r((function(){f()}),0))},v.prototype.abort=function(){this._abort(!1)},v.prototype.getResponseHeader=function(e){return this._contentType},v.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},v.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},v.prototype.send=function(){if("ontimeout"in o.prototype&&("sendAsBinary"in o.prototype||"mozAnon"in o.prototype)||null==l||null==l.readyState||"complete"===l.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(e){throw e}}else{var t=this;t._sendTimeout=r((function(){t._sendTimeout=0,t.send()}),4)}},T.prototype.get=function(e){return this._map[y(e)]},null!=o&&null==o.HEADERS_RECEIVED&&(o.HEADERS_RECEIVED=2),S.prototype.open=function(e,t,n,r,i,s,a){e.open("GET",i);var u=0;for(var l in e.onprogress=function(){var t=e.responseText.slice(u);u+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===o.HEADERS_RECEIVED){var n=e.status,r=e.statusText,i=e.getResponseHeader("Content-Type"),s=e.getAllResponseHeaders();t(n,r,i,new T(s))}},e.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,l)&&e.setRequestHeader(l,a[l]);return e.send(),e},E.prototype.get=function(e){return this._headers.get(e)},C.prototype.open=function(e,t,n,r,i,o,s){var a=null,u=new g,l=u.signal,f=new d;return h(i,{headers:s,credentials:o?"include":"same-origin",signal:l,cache:"no-store"}).then((function(e){return a=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new E(e.headers)),new c((function(e,t){var r=function(){a.read().then((function(t){if(t.done)e(void 0);else{var i=f.decode(t.value,{stream:!0});n(i),r()}})).catch((function(e){t(e)}))};r()}))})).catch((function(e){return"AbortError"===e.name?void 0:e})).then((function(e){r(e)})),{abort:function(){null!=a&&a.cancel(),u.abort()}}},w.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,r=0;r<n;r+=1){var i=t[r];try{"function"==typeof i.handleEvent?i.handleEvent(e):i.call(this,e)}catch(e){b(e)}}},w.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];null==r&&(r=[],n[e]=r);for(var i=!1,o=0;o<r.length;o+=1)r[o]===t&&(i=!0);i||r.push(t)},w.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];if(null!=r){for(var i=[],o=0;o<r.length;o+=1)r[o]!==t&&i.push(r[o]);0===i.length?delete n[e]:n[e]=i}},R.prototype=Object.create(I.prototype),O.prototype=Object.create(I.prototype),D.prototype=Object.create(I.prototype);var k=-1,M=0,q=1,N=2,U=-1,x=0,P=1,L=2,B=3,F=/^text\/event\-stream(;.*)?$/i,H=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),G(n)},G=function(e){return Math.min(Math.max(e,1e3),18e6)},Y=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(e){b(e)}};function j(e,t){w.call(this),t=t||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,t,n){t=String(t);var a=Boolean(n.withCredentials),u=n.lastEventIdQueryParameterName||"lastEventId",l=G(1e3),c=H(n.heartbeatTimeout,45e3),h="",f=l,d=!1,p=0,g=n.headers||{},m=n.Transport,_=Q&&null==m?void 0:new v(null!=m?new m:null!=o&&"withCredentials"in o.prototype||null==s?new o:new s),A=null!=m&&"string"!=typeof m?new m:null==_?new C:new S,y=void 0,T=0,E=k,w="",b="",I="",j="",W=x,K=0,z=0,J=function(t,n,r,i){if(E===M)if(200===t&&null!=r&&F.test(r)){E=q,d=Date.now(),f=l,e.readyState=q;var o=new O("open",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onopen,o)}else{var s="";200!==t?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",X();o=new O("error",{status:t,statusText:n,headers:i});e.dispatchEvent(o),Y(e,e.onerror,o),console.error(s)}},V=function(t){if(E===q){for(var n=-1,o=0;o<t.length;o+=1){(u=t.charCodeAt(o))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(n=o)}var s=(-1!==n?j:"")+t.slice(0,n+1);j=(-1===n?j:"")+t.slice(n+1),""!==t&&(d=Date.now(),p+=t.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(W===U&&u==="\n".charCodeAt(0))W=x;else if(W===U&&(W=x),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(W!==x){W===P&&(z=a+1);var g=s.slice(K,z-1),m=s.slice(z+(z<a&&s.charCodeAt(z)===" ".charCodeAt(0)?1:0),a);"data"===g?(w+="\n",w+=m):"id"===g?b=m:"event"===g?I=m:"retry"===g?(l=H(m,l),f=l):"heartbeatTimeout"===g&&(c=H(m,c),0!==T&&(i(T),T=r((function(){$()}),c)))}if(W===x){if(""!==w){h=b,""===I&&(I="message");var _=new R(I,{data:w.slice(1),lastEventId:b});if(e.dispatchEvent(_),"open"===I?Y(e,e.onopen,_):"message"===I?Y(e,e.onmessage,_):"error"===I&&Y(e,e.onerror,_),E===N)return}w="",I=""}W=u==="\r".charCodeAt(0)?U:x}else W===x&&(K=a,W=P),W===P?u===":".charCodeAt(0)&&(z=a+1,W=L):W===L&&(W=B)}}},Z=function(t){if(E===q||E===M){E=k,0!==T&&(i(T),T=0),T=r((function(){$()}),f),f=G(Math.min(16*l,2*f)),e.readyState=M;var n=new D("error",{error:t});e.dispatchEvent(n),Y(e,e.onerror,n),null!=t&&console.error(t)}},X=function(){E=N,null!=y&&(y.abort(),y=void 0),0!==T&&(i(T),T=0),e.readyState=N},$=function(){if(T=0,E===k){d=!1,p=0,T=r((function(){$()}),c),E=M,w="",I="",b=h,j="",K=0,z=0,W=x;var n=t;if("data:"!==t.slice(0,5)&&"blob:"!==t.slice(0,5)&&""!==h){var i=t.indexOf("?");n=-1===i?t:t.slice(0,i+1)+t.slice(i+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,(function(e,t){return t===u?"":e})),n+=(-1===t.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var o=e.withCredentials,s={Accept:"text/event-stream"},a=e.headers;if(null!=a)for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(s[l]=a[l]);try{y=A.open(_,J,V,Z,n,o,s)}catch(e){throw X(),e}}else if(d||null==y){var f=Math.max((d||Date.now())+c-Date.now(),1);d=!1,T=r((function(){$()}),f)}else Z(new Error("No activity within "+c+" milliseconds. "+(E===M?"No response received.":p+" chars received.")+" Reconnecting.")),null!=y&&(y.abort(),y=void 0)};e.url=t,e.readyState=M,e.withCredentials=a,e.headers=g,e._close=X,$()}(this,e,t)}var Q=null!=h&&null!=f&&"body"in f.prototype;j.prototype=Object.create(w.prototype),j.prototype.CONNECTING=M,j.prototype.OPEN=q,j.prototype.CLOSED=N,j.prototype.close=function(){this._close()},j.CONNECTING=M,j.OPEN=q,j.CLOSED=N,j.prototype.withCredentials=void 0;var W,K=u;null==o||null!=u&&"withCredentials"in u.prototype||(K=j),W=function(e){e.EventSourcePolyfill=j,e.NativeEventSource=u,e.EventSource=K}(t),void 0!==W&&(e.exports=W)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:i:globalThis)}(hu,hu.exports);var fu=hu.exports,du={exports:{}};!function(e){e.exports=function(){var e=1e3,t=6e4,n=36e5,r="millisecond",i="second",o="minute",s="hour",a="day",u="week",l="month",c="quarter",h="year",f="date",d="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],n=e%100;return"["+e+(t[(n-20)%10]||t[n]||t[0])+"]"}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:""+Array(t+1-r.length).join(n)+e},A={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?"+":"-")+_(r,2,"0")+":"+_(i,2,"0")},m:function e(t,n){if(t.date()<n.date())return-e(n,t);var r=12*(n.year()-t.year())+(n.month()-t.month()),i=t.clone().add(r,l),o=n-i<0,s=t.clone().add(r+(o?-1:1),l);return+(-(r+(n-i)/(o?i-s:s-i))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:l,y:h,w:u,d:a,D:f,h:s,m:o,s:i,ms:r,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},v="en",y={};y[v]=m;var T="$isDayjsObject",S=function(e){return e instanceof b||!(!e||!e[T])},E=function e(t,n,r){var i;if(!t)return v;if("string"==typeof t){var o=t.toLowerCase();y[o]&&(i=o),n&&(y[o]=n,i=o);var s=t.split("-");if(!i&&s.length>1)return e(s[0])}else{var a=t.name;y[a]=t,i=a}return!r&&i&&(v=i),i||!r&&v},C=function(e,t){if(S(e))return e.clone();var n="object"==typeof t?t:{};return n.date=e,n.args=arguments,new b(n)},w=A;w.l=E,w.i=S,w.w=function(e,t){return C(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var b=function(){function m(e){this.$L=E(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[T]=!0}var _=m.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(null===t)return new Date(NaN);if(w.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var r=t.match(p);if(r){var i=r[2]-1||0,o=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,o)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return w},_.isValid=function(){return!(this.$d.toString()===d)},_.isSame=function(e,t){var n=C(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return C(e)<this.startOf(t)},_.isBefore=function(e,t){return this.endOf(t)<C(e)},_.$g=function(e,t,n){return w.u(e)?this[t]:this.set(n,e)},_.unix=function(){return Math.floor(this.valueOf()/1e3)},_.valueOf=function(){return this.$d.getTime()},_.startOf=function(e,t){var n=this,r=!!w.u(t)||t,c=w.p(e),d=function(e,t){var i=w.w(n.$u?Date.UTC(n.$y,t,e):new Date(n.$y,t,e),n);return r?i:i.endOf(a)},p=function(e,t){return w.w(n.toDate()[e].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(t)),n)},g=this.$W,m=this.$M,_=this.$D,A="set"+(this.$u?"UTC":"");switch(c){case h:return r?d(1,0):d(31,11);case l:return r?d(1,m):d(0,m+1);case u:var v=this.$locale().weekStart||0,y=(g<v?g+7:g)-v;return d(r?_-y:_+(6-y),m);case a:case f:return p(A+"Hours",0);case s:return p(A+"Minutes",1);case o:return p(A+"Seconds",2);case i:return p(A+"Milliseconds",3);default:return this.clone()}},_.endOf=function(e){return this.startOf(e,!1)},_.$set=function(e,t){var n,u=w.p(e),c="set"+(this.$u?"UTC":""),d=(n={},n[a]=c+"Date",n[f]=c+"Date",n[l]=c+"Month",n[h]=c+"FullYear",n[s]=c+"Hours",n[o]=c+"Minutes",n[i]=c+"Seconds",n[r]=c+"Milliseconds",n)[u],p=u===a?this.$D+(t-this.$W):t;if(u===l||u===h){var g=this.clone().set(f,1);g.$d[d](p),g.init(),this.$d=g.set(f,Math.min(this.$D,g.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},_.set=function(e,t){return this.clone().$set(e,t)},_.get=function(e){return this[w.p(e)]()},_.add=function(r,c){var f,d=this;r=Number(r);var p=w.p(c),g=function(e){var t=C(d);return w.w(t.date(t.date()+Math.round(e*r)),d)};if(p===l)return this.set(l,this.$M+r);if(p===h)return this.set(h,this.$y+r);if(p===a)return g(1);if(p===u)return g(7);var m=(f={},f[o]=t,f[s]=n,f[i]=e,f)[p]||1,_=this.$d.getTime()+r*m;return w.w(_,this)},_.subtract=function(e,t){return this.add(-1*e,t)},_.format=function(e){var t=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=e||"YYYY-MM-DDTHH:mm:ssZ",i=w.z(this),o=this.$H,s=this.$m,a=this.$M,u=n.weekdays,l=n.months,c=n.meridiem,h=function(e,n,i,o){return e&&(e[n]||e(t,r))||i[n].slice(0,o)},f=function(e){return w.s(o%12||12,e,"0")},p=c||function(e,t,n){var r=e<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(g,(function(e,r){return r||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return w.s(t.$y,4,"0");case"M":return a+1;case"MM":return w.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,l,3);case"MMMM":return h(l,a);case"D":return t.$D;case"DD":return w.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return h(n.weekdaysMin,t.$W,u,2);case"ddd":return h(n.weekdaysShort,t.$W,u,3);case"dddd":return u[t.$W];case"H":return String(o);case"HH":return w.s(o,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return p(o,s,!0);case"A":return p(o,s,!1);case"m":return String(s);case"mm":return w.s(s,2,"0");case"s":return String(t.$s);case"ss":return w.s(t.$s,2,"0");case"SSS":return w.s(t.$ms,3,"0");case"Z":return i}return null}(e)||i.replace(":","")}))},_.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},_.diff=function(r,f,d){var p,g=this,m=w.p(f),_=C(r),A=(_.utcOffset()-this.utcOffset())*t,v=this-_,y=function(){return w.m(g,_)};switch(m){case h:p=y()/12;break;case l:p=y();break;case c:p=y()/3;break;case u:p=(v-A)/6048e5;break;case a:p=(v-A)/864e5;break;case s:p=v/n;break;case o:p=v/t;break;case i:p=v/e;break;default:p=v}return d?p:w.a(p)},_.daysInMonth=function(){return this.endOf(l).$D},_.$locale=function(){return y[this.$L]},_.locale=function(e,t){if(!e)return this.$L;var n=this.clone(),r=E(e,t,!0);return r&&(n.$L=r),n},_.clone=function(){return w.w(this.$d,this)},_.toDate=function(){return new Date(this.valueOf())},_.toJSON=function(){return this.isValid()?this.toISOString():null},_.toISOString=function(){return this.$d.toISOString()},_.toString=function(){return this.$d.toUTCString()},m}(),I=b.prototype;return C.prototype=I,[["$ms",r],["$s",i],["$m",o],["$H",s],["$W",a],["$M",l],["$y",h],["$D",f]].forEach((function(e){I[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),C.extend=function(e,t){return e.$i||(e(t,b,C),e.$i=!0),C},C.locale=E,C.isDayjs=S,C.unix=function(e){return C(1e3*e)},C.en=y[v],C.Ls=y,C.p={},C}()}(du);var pu,gu,mu=o(du.exports),_u="aks_agent_token",Au=function(){function r(e){this.baseUrl="",this.eventSource=null,this.retryCount=0,this.retryMap=new Map,this.token="",this.id=e.id,this.getSystemToken=e.getSystemToken,this.resetSSE=e.resetSSE,this.retryCount=e.retryCount||0,this.baseUrl=e.baseUrl||""}return r.prototype.validateToken=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,fetch("".concat(this.baseUrl,"/iam/token/validate?accountId=").concat(e),{method:"GET",headers:{authentication:r}}).then((function(e){return e.json()}))]}))}))},r.prototype.initToken=function(){return t(this,void 0,void 0,(function(){var e,t,r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.getSystemToken()];case 1:return(e=n.sent())?[4,this.validateToken(this.id,e)]:[2,{code:au.FAILED,data:null,message:"get system token failed"}];case 2:return(t=n.sent()).code===au.SUCCESS?(this.token=e,sessionStorage.setItem(_u,e),this.executePeriodically(this.refreshToken.bind(this),12e5),[2,{code:au.SUCCESS,data:null,message:t.message}]):[2,{code:au.FAILED,data:null,message:t.message}];case 3:return r=n.sent(),[2,{code:au.FAILED,data:null,message:(null==r?void 0:r.toString())||"system error"}];case 4:return[2]}}))}))},r.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var e=this;return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/iam/oauth2/refresh")}).then((function(t){t.token&&(e.token=t.token,sessionStorage.setItem(_u,t.token),e.eventSource&&e.resetSSE())}))]}))}))},r.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/status/list")})]}))}))},r.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return[2,this.request({url:"".concat(this.baseUrl,"/voipPlatform/agent/getAgentByUserId")})]}))}))},r.prototype.getAgentSetting=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getAgentSetting"),data:e})]}))}))},r.prototype.updateAgentHangup=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent/").concat(e),method:"PUT"})]}))}))},r.prototype.updateAgentTicket=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/voipPlatform/agent/ticket"),data:e})]}))}))},r.prototype.registerSSE=function(e){return t(this,void 0,void 0,(function(){var r,i,o,s,a,u=this;return n(this,(function(l){return r=e.agentId,i=e.onMessage,o=function(e){},s=new Promise((function(e){o=e})),a=this.token,this.eventSource=new fu.EventSourcePolyfill("".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_event?agentId=").concat(r),{headers:{Authentication:a,"Cache-Control":"no-cache",Connection:"keep-alive"},heartbeatTimeout:12e6}),this.eventSource.onmessage=i,this.eventSource.onopen=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!0),[2]}))}))},this.eventSource.onerror=function(){return t(u,void 0,void 0,(function(){return n(this,(function(e){return o(!1),[2]}))}))},[2,s]}))}))},r.prototype.closeSSE=function(e){return t(this,void 0,void 0,(function(){var t,r,i=this;return n(this,(function(n){return t=e.agentId,r=e.clearTicket,this.eventSource?[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_close?agentId=").concat(t,"&clearTicket=").concat(r)}).then((function(){i.eventSource.close(),i.eventSource=null}))]:[2]}))}))},r.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"PUT",url:"".concat(this.baseUrl,"/voipPlatform/agent/agentStatusSwitch"),data:e})]}))}))},r.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){return t=e.phone,r=e.line,[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/agentOutBoundCall/dialer/startCall/").concat(t,"/").concat(r),method:"POST"})]}))}))},r.prototype.saveAgentResponseTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/call_record/callRecordAgent"),data:e})]}))}))},r.prototype.getCallTaskInfo=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/call_tasks/getCallTaskName/").concat(e.callTaskId)})]}))}))},r.prototype.getAfterCallProcessTime=function(e){return t(this,void 0,void 0,(function(){return n(this,(function(t){return[2,this.request({url:"".concat(this.baseUrl,"/crm/v1/predictCall/afterCallProcessTime/").concat(e.callTaskId)})]}))}))},r.prototype.formatFormData=function(e){var t=new FormData;for(var n in e)e[n]&&t.append(n,e[n]);return t},r.prototype.agentAbnormalClose=function(e){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=this.formatFormData(e);return this.request({method:"POST",url:"".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close"),data:t},!0)},r.prototype.sendBeacon=function(e){if("function"==typeof navigator.sendBeacon&&e.url){e.createTime||(e.createTime=mu().format("yyyy-MM-DD HH:mm:ss")),e.sendTime=mu().format("yyyy-MM-DD HH:mm:ss"),e.Authentication=this.getTokenWithFallback();var t=e.url,n=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}(e,["url"]),r=this.formatFormData(n),i=navigator.sendBeacon(t,r);if(!i){e.lastSendResult=i;var o=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]");o.push(e),localStorage.setItem("aks_beacon_queue",JSON.stringify(o))}}},r.prototype.clearnSendBeaconQueue=function(){return t(this,void 0,void 0,(function(){var e,t;return n(this,(function(n){switch(n.label){case 0:return(e=JSON.parse(localStorage.getItem("aks_beacon_queue")||"[]")).length?[4,this.waitToken()]:[3,4];case 1:return n.sent()?[3,3]:[4,this.initToken()];case 2:if(n.sent().code!==au.SUCCESS)return[2];n.label=3;case 3:for(t=0;t<e.length-1;t++)this.sendBeacon(e[t]);n.label=4;case 4:return[2]}}))}))},r.prototype.getTokenWithFallback=function(){return this.token?this.token:sessionStorage.getItem(_u)||""},r.prototype.waitToken=function(e,t){var n=this;return void 0===e&&(e=3e3),void 0===t&&(t=200),new Promise((function(r){var i=setInterval((function(){((e-=t)<=0||n.token)&&(clearInterval(i),r(Boolean(n.token)))}),200)}))},r.prototype.request=function(r){return t(this,arguments,void 0,(function(r,i){var o,s,a,u=this;return void 0===i&&(i=!1),n(this,(function(l){switch(l.label){case 0:return!this.retryMap.has(r.url)&&this.retryCount&&this.retryMap.set(r.url,this.retryCount),this.token?[3,3]:[4,this.waitToken()];case 1:return l.sent()?[3,3]:[4,this.initToken()];case 2:if((o=l.sent()).code!==au.SUCCESS)return[2,{code:o.code,message:o.message,data:null}];l.label=3;case 3:return s={method:r.method||"GET",headers:e({"Content-Type":"application/json",authentication:this.token},r.headers)},i?(s.method=r.method,s.headers={authentication:this.token},s.body=r.data):"GET"!==(null===(a=s.method)||void 0===a?void 0:a.toLocaleUpperCase())&&(s.body=JSON.stringify(r.data)),[2,fetch(r.url,s).then((function(e){return t(u,void 0,void 0,(function(){var t,i;return n(this,(function(n){switch(n.label){case 0:return t=this.retryMap.get(r.url),401!==e.status?[3,3]:t?(this.retryMap.set(r.url,t-1),[4,this.initToken()]):[3,2];case 1:return(i=n.sent()).code===au.SUCCESS?[2,this.request(r)]:[2,i];case 2:return this.retryCount&&this.retryMap.delete(r.url),[2,{code:au.UNAUTHORIZED,message:"Unauthorized",data:null}];case 3:return[2,e.json()]}}))}))}))]}}))}))},r.prototype.executePeriodically=function(e,t){var n=Date.now()+t,r=function(){var i=Date.now();i>=n&&(e(),n+=t);var o=Math.max(0,n-i);setTimeout(r,o)};r()},r.getInstance=function(e){return!r.instance&&e&&(r.instance=new r(e)),r.instance},r.instance=null,r}();!function(e){e[e.OFFLINE=0]="OFFLINE",e[e.ONLINE=1]="ONLINE",e[e.HANGUP=4]="HANGUP"}(pu||(pu={})),function(e){e[e.ANSWER=1]="ANSWER",e[e.HANGUP=2]="HANGUP"}(gu||(gu={}));var vu=function(){function i(e){var t=this;this.sip={},this.api={},this.isSipInit=!1,this.isInitSuccess=!1,this.agentInfo={},this.initEvent={},this.agentEvent={},this.agentWaitingTime=0,this.agentResponseTime=0,this.timer=null,this.callDetails={},this.unloadingHandled=!1,this.baseUrl="",this.autoFinishACWTimer=null,this.baseUrl=(null==e?void 0:e.baseUrl)||"",this.api=Au.getInstance({id:e.id,getSystemToken:e.getSystemToken,resetSSE:this.resetSSE.bind(this),retryCount:e.retryCount,baseUrl:this.baseUrl}),this.sip=new cu({incomingCallCallback:this.incomingCall.bind(this),getMediaStream:null==e?void 0:e.getMediaStream}),this.sip.attchSessionEvent("ended",this.sessionEnded.bind(this)),this.sip.attchSessionEvent("failed",this.sessionFailed.bind(this)),this.init().then((function(){t.api.clearnSendBeaconQueue()}))}return i.prototype.init=function(){return t(this,void 0,void 0,(function(){var t,r,i,o,s;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.initToken()];case 1:return(t=n.sent()).code!==au.SUCCESS?(r=e(e({},t),{code:uu.FAILED}),this.emitInitEvent("failed",r),this.isInitSuccess=!1,[2,r]):[4,this.getAgentStatus()];case 2:return(i=n.sent()).code!==uu.SUCCESS?(o=e(e({},i),{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED}),this.emitInitEvent("failed",o),this.isInitSuccess=!1,[2,o]):(s={code:uu.SUCCESS,data:null,message:"success"},this.emitInitEvent("success",s),this.isInitSuccess=!0,[2,s])}}))}))},i.prototype.getAgentStatusList=function(){return t(this,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return[4,this.api.getAgentStatusList()];case 1:return(e=t.sent()).code===au.SUCCESS?[2,{code:uu.SUCCESS,data:e.data||[],message:e.message}]:[2,{code:uu.FAILED,data:null,message:e.message}]}}))}))},i.prototype.getTicket=function(){var e=window.sessionStorage.getItem("wiz-agent-ticket");return e||(e=r(),window.sessionStorage.setItem("wiz-agent-ticket",e)),e},i.prototype.getHostName=function(e){try{return new URL(e).hostname}catch(e){return""}},i.prototype.processSSEMessage=function(e){return t(this,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return t=JSON.parse(null==e?void 0:e.data)||{},r=this.agentInfo.statusName,-1===t.agentId?[3,2]:[4,this.offlineAgent(r)];case 1:n.sent(),1===t.status&&this.onlineAgent(r),n.label=2;case 2:return[2]}}))}))},i.prototype.resetSSE=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this.api.closeSSE({agentId:this.agentInfo.id,clearTicket:1})];case 1:return e.sent(),[4,this.api.registerSSE({agentId:this.agentInfo.id,onMessage:this.processSSEMessage.bind(this)})];case 2:return e.sent(),[2]}}))}))},i.prototype.createSSEAndOpensips=function(e,r){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return this.api.registerSSE({agentId:e,onMessage:this.processSSEMessage.bind(this)})?[3,2]:[4,this.api.updateAgentTicket({agentId:e,ticket:r,type:pu.OFFLINE})];case 1:return t.sent().code!==au.SUCCESS?[2,{code:uu.FAILED,message:"Registration of SSE failed and update Agent Ticket failed"}]:[2,{code:uu.FAILED,message:"Registration of SSE failed"}];case 2:return[4,this.waitSIPRegistered(7e3)];case 3:return t.sent()?[3,5]:[4,this.api.closeSSE({agentId:e,clearTicket:1})];case 4:return t.sent(),[2,{code:uu.FAILED,message:"SIP registration failed"}];case 5:return[2,{code:uu.SUCCESS,message:"success"}]}}))}))},i.prototype.waitSIPRegistered=function(){return t(this,arguments,void 0,(function(e){var t=this;return void 0===e&&(e=7e3),n(this,(function(n){return[2,new Promise((function(n){var r=!1,i=function(e){r||(r=!0,n(e))};t.sip.on("registered",(function(){return i(!0)})),t.sip.on("registrationFailed",(function(){return i(!1)})),setTimeout((function(){return i(!1)}),e),t.sip.start()}))]}))}))},i.prototype.getAgentInfo=function(){return t(this,void 0,void 0,(function(){var e,t,r,i,o,s,a,u;return n(this,(function(n){switch(n.label){case 0:return[4,this.api.getAgentInfo()];case 1:return"code"in(e=n.sent())&&e.code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:e.message}]:"data"in e&&(null===(u=e.data)||void 0===u?void 0:u[0])?(t=e.data[0],this.agentInfo=t,r=t.id,i=t.ticket,o=t.status,s=this.getTicket(),i?o!==pu.OFFLINE?[3,3]:[4,this.api.updateAgentTicket({agentId:r,ticket:"",type:pu.OFFLINE})]:[3,4]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:if(n.sent().code!==au.SUCCESS)return[2,{code:uu.FAILED,message:"Update Agent Ticket failed"}];i="",t.ticket="",this.agentInfo.ticket="",n.label=3;case 3:if(o===pu.ONLINE&&i!==s)return[2,{code:uu.LOCKED,data:t,message:"Agent ticket occupied, unable to perform agent online or offline."}];n.label=4;case 4:return this.isSipInit||(a="sip:".concat(t.number,"@").concat(this.getHostName(t.realm)),this.sip.init({wssuri:t.realm,password:t.password,uri:a}),this.isSipInit=!0),[2,{code:uu.SUCCESS,data:t,message:e.message}]}}))}))},i.prototype.getAgentStatus=function(){return t(this,void 0,void 0,(function(){var e,t,i,o,s,a,u,l,c,h;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,5,,6]),[4,Promise.allSettled([this.getAgentInfo(),this.api.getAgentSetting({key:"callCenter"})])];case 1:return e=n.sent(),t=e.map((function(e){return"fulfilled"!==e.status?{code:au.FAILED,data:null,message:"system error"}:e.value})),i=t[0],"agentWaitingTime"in(o=t[1])&&(this.agentWaitingTime=o.agentWaitingTime||0),"code"in i&&i.code!==uu.SUCCESS?[2,{code:i.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:i.message}]:"data"in i&&i.data?(s=i.data,a=s.status,u=s.id,l=s.groupId,c={code:uu.SUCCESS,data:{id:u,groupId:l,status:a,subStatus:s.statusName},message:"success"},this.agentInfo=s,a===pu.OFFLINE?[2,c]:a!==pu.ONLINE?[3,4]:i.code===uu.LOCKED?[2,{code:uu.LOCKED,data:null,message:i.message}]:[4,this.api.agentAbnormalClose({id:u,groupId:l,trace:r()})]):[2,{code:uu.FAILED,data:null,message:"Agent not found"}];case 2:return n.sent(),[4,this.api.switchAgentStatus({id:u,groupId:l,status:pu.OFFLINE,subStatus:"offline"})];case 3:return(h=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:h.message}]:(c.data.status=pu.OFFLINE,c.data.subStatus="Offline",[2,c]);case 4:return[2,{code:uu.FAILED,data:null,message:"system error"}];case 5:return n.sent(),[2,{code:uu.FAILED,data:null,message:"system error"}];case 6:return[2]}}))}))},i.prototype.onlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.ONLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 1:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:(f={code:uu.SUCCESS,data:{status:pu.ONLINE,subStatus:e},message:"Agent is already online"},this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 2:return r!==pu.OFFLINE?[3,6]:(s=this.getTicket(),[4,this.api.updateAgentTicket({agentId:i,ticket:s,type:pu.ONLINE})]);case 3:return(a=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:a.message}]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.ONLINE,subStatus:e})];case 4:return(u=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:u.message}]:[4,this.createSSEAndOpensips(i,s)];case 5:return l=n.sent(),c=l.code,h=l.message,c!==uu.SUCCESS?[2,{code:uu.FAILED,data:null,message:h}]:(f={code:c,data:{status:pu.ONLINE,subStatus:e},message:h},this.agentInfo.status=pu.ONLINE,this.agentInfo.statusName=e,this.emitAgentEvent("online",f),[2,f]);case 6:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.offlineAgent=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:return t=this.agentInfo,r=t.status,i=t.id,o=t.groupId,r!==pu.OFFLINE?[3,2]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 1:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.agentInfo.statusName=e,this.emitAgentEvent("offline",a),[2,a]);case 2:return r!==pu.ONLINE?[3,4]:[4,this.api.switchAgentStatus({id:i,groupId:o,status:pu.OFFLINE,subStatus:e})];case 3:return(s=n.sent()).code!==au.SUCCESS?[2,{code:uu.FAILED,data:null,message:s.message}]:(this.api.closeSSE({agentId:i,clearTicket:1}),this.sip.stop(!0),a={code:uu.SUCCESS,data:{status:pu.OFFLINE,subStatus:e},message:"Agent is already offline"},this.emitAgentEvent("offline",a),this.agentInfo.status=pu.OFFLINE,this.agentInfo.statusName=e,[2,a]);case 4:return[2,{code:uu.FAILED,data:null,message:"Agent Status is not valid"}]}}))}))},i.prototype.switchAgentStatus=function(e){return t(this,void 0,void 0,(function(){var t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.isInitSuccess?[4,this.getAgentInfo()]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Registration failed. Seat online and offline cannot be performed."}];case 1:return(t=n.sent()).code!==uu.SUCCESS?[2,{code:t.code===uu.LOCKED?uu.LOCKED:uu.FAILED,data:null,message:t.message}]:(r=e.status,i=e.subStatus,r===pu.ONLINE?[2,this.onlineAgent(i)]:r===pu.OFFLINE?[2,this.offlineAgent(i)]:[2,{code:uu.FAILED,data:null,message:"system error"}])}}))}))},i.prototype.outboundCall=function(e){return t(this,void 0,void 0,(function(){var t,r=this;return n(this,(function(n){return this.isInitSuccess?(t=this.agentInfo.outboundLineId)?[2,this.api.outboundCall({phone:e,line:t}).then((function(e){return e.code===au.SUCCESS?(r.sip.setCallType("outboundCall"),{code:uu.SUCCESS,data:e.data,message:e.message||e.msg}):{code:uu.FAILED,data:null,message:e.message||e.msg}}))]:[2,Promise.resolve({code:uu.FAILED,data:null,message:"Agent has no outbound line"})]:[2,{code:uu.FAILED,data:null,message:"SIP Registration failed, Outbound calls cannot be made."}]}))}))},i.prototype.autoFinishACW=function(){var e=this,t=Number(this.callDetails.afterCallProcessTime),n=function(){t<=0?e.finshACW():(t-=1,e.autoFinishACWTimer=setTimeout(n,1e3))};this.autoFinishACWTimer=setTimeout(n,1e3)},i.prototype.finshACW=function(){return t(this,void 0,void 0,(function(){var e,t,r,i;return n(this,(function(n){switch(n.label){case 0:return this.autoFinishACWTimer&&(clearTimeout(this.autoFinishACWTimer),this.autoFinishACWTimer=null),e=this.agentInfo,t=e.id,r=e.groupId,[4,this.api.switchAgentStatus({id:t,groupId:r,status:pu.HANGUP})];case 1:return[2,{code:(i=n.sent()).code===au.SUCCESS?uu.SUCCESS:uu.FAILED,data:null,message:i.message}]}}))}))},i.prototype.sessionEnded=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.autoFinishACW(),[2]}))}))},i.prototype.sessionFailed=function(){return t(this,void 0,void 0,(function(){return n(this,(function(e){return this.api.updateAgentHangup(this.agentInfo.id),[2]}))}))},i.prototype.openOnunload=function(){var e=this;window.onbeforeunload=function(e){e.returnValue="beforeunload"},window.onunload=function(){e.doForceOfflineCleanup()},this.unloadingHandled=!1},i.prototype.cancelOnunload=function(){window.onbeforeunload=function(){},window.onunload=function(){},this.unloadingHandled=!1},i.prototype.doForceOfflineCleanup=function(){if(!this.unloadingHandled){this.unloadingHandled=!0;var e="".concat(this.baseUrl,"/crm/v1/agent_command/regist_agent_abnormal_close");this.api.sendBeacon({url:e,id:this.agentInfo.id,groupId:this.agentInfo.groupId,trace:r()})}},i.prototype.saveAgentResponseTime=function(e){this.api.saveAgentResponseTime({callId:this.callDetails.callId,agentId:this.agentInfo.id,agentResponseTime:this.agentResponseTime,agentGroupId:this.agentInfo.groupId,resultType:e}),this.timer&&(clearInterval(this.timer),this.agentResponseTime=0)},i.prototype.hangup=function(){this.sip.hangup()},i.prototype.timingResTime=function(){var e=this;this.timer&&(clearInterval(this.timer),this.timer=null);var t=this.agentWaitingTime;this.agentResponseTime=0,this.timer=setInterval((function(){if(t<=0)return clearInterval((null==e?void 0:e.timer)||0),e.timer=null,void e.ignore();t-=1,e.agentResponseTime+=1}),1e3)},i.prototype.incomingCall=function(e){return t(this,void 0,void 0,(function(){var t,r,i,o,s,a,u,l,c,h,f,d,p,g,m,_,A,v,y,T;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),t=e.request,r=(null===(_=null===(m=t.headers["Call-Param"])||void 0===m?void 0:m[0])||void 0===_?void 0:_.raw)||"",i=r?atob(r):"",o=JSON.parse(i||"{}"),s=(null===(v=null===(A=t.headers["Call-Task"])||void 0===A?void 0:A[0])||void 0===v?void 0:v.raw)||"",a=(null===(T=null===(y=t.headers["Call-Record-Id"])||void 0===y?void 0:y[0])||void 0===T?void 0:T.raw)||null,u=Object.fromEntries(Object.entries(o).filter((function(e){return""!==e[0]}))),l="",c="",s?[4,Promise.allSettled([this.api.getCallTaskInfo({callTaskId:s}),this.api.getAfterCallProcessTime({callTaskId:s})])]:[3,2];case 1:h=n.sent(),f=h[0],d=h[1],"fulfilled"===f.status&&(l=f.value.name||""),"fulfilled"===d.status&&(p=d.value).code===uu.SUCCESS&&(c=String(p.data||"")),n.label=2;case 2:return this.callDetails={callId:a||"",callType:this.sip.getCallType()||"",taskName:l,afterCallProcessTime:c,phone:u.phone||u.Phone||u.PHONE||"",contactId:u.contactId||u.ContactId||u.CONTACT_ID||"",extraJson:u},this.timingResTime(),[2,Promise.resolve({code:uu.SUCCESS,data:this.callDetails,message:"success"})];case 3:return g=n.sent(),[2,Promise.resolve({code:uu.FAILED,data:null,message:(null==g?void 0:g.toString())||"system error"})];case 4:return[2]}}))}))},i.prototype.answer=function(){this.sip.answer(),this.saveAgentResponseTime(gu.ANSWER)},i.prototype.ignore=function(){this.sip.ignore(),this.saveAgentResponseTime(gu.HANGUP)},i.prototype.mute=function(){this.sip.mute()},i.prototype.unmute=function(){this.sip.unmute()},i.prototype.attachInitEvent=function(e,t){t&&"function"==typeof t&&(this.initEvent[e]||(this.initEvent[e]=[]),this.initEvent[e].push(t))},i.prototype.removeInitEvent=function(e,t){var n=this.initEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitInitEvent=function(e,t){(this.initEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAgentEvent=function(e,t){t&&"function"==typeof t&&(this.agentEvent[e]||(this.agentEvent[e]=[]),this.agentEvent[e].push(t))},i.prototype.removeAgentEvent=function(e,t){var n=this.agentEvent[e];if(n&&n.length)for(var r=0;r<n.length;r++)if(n[r]===t){n.splice(r,1);break}},i.prototype.emitAgentEvent=function(e,t){(this.agentEvent[e]||[]).forEach((function(e){e(t)}))},i.prototype.attachAnswerEvent=function(e){this.sip.attachAnswerEvent(e)},i.prototype.removeAnswerEvent=function(e){this.sip.removeAnswerEvent(e)},i.prototype.attachNewMessageEvent=function(e){this.sip.attachNewMessageEvent(e)},i.prototype.removeNewMessageEvent=function(e){this.sip.removeNewMessageEvent(e)},i.prototype.attchSessionEvent=function(e,t){this.sip.attchSessionEvent(e,t)},i.prototype.removeSessionEvent=function(e,t){this.sip.removeSessionEvent(e,t)},i}();return vu}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wizai/agent-sip-sdk",
3
- "version": "0.1.11-alpha",
3
+ "version": "0.1.12-alpha",
4
4
  "description": "Manages SIP clients and agent status, simplifying calls and events.",
5
5
  "main": "lib/agent-sip-sdk-cjs.js",
6
6
  "module": "lib/agent-sip-sdk-es.js",