ysyt-agent-sdk 1.1.26 → 1.1.27

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.
@@ -14,4 +14,5 @@ export declare const DeviceMap: {
14
14
  3: string;
15
15
  };
16
16
  export declare const isNumber: (str: string) => boolean;
17
+ export declare const isBase64: (str: string) => boolean;
17
18
  export {};
@@ -524,7 +524,7 @@ const Zt=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
524
524
  * @copyright Chen, Yi-Cyuan 2014-2023
525
525
  * @license MIT
526
526
  */
527
- Bs=Ts,function(){var t="input is invalid type",s="object"==typeof window,i=s?window:{};i.JS_MD5_NO_WINDOW&&(s=!1);var n=!s&&"object"==typeof self,o=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?i=Qs:n&&(i=self);var r,a=!i.JS_MD5_NO_COMMON_JS&&Bs.exports,V=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),l=[128,32768,8388608,-2147483648],h=[0,8,16,24],g=["hex","array","digest","buffer","arrayBuffer","base64"],q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[];if(V){var p=new ArrayBuffer(68);r=new Uint8Array(p),d=new Uint32Array(p)}var u=Array.isArray;!i.JS_MD5_NO_NODE_JS&&u||(u=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var m=ArrayBuffer.isView;!V||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&m||(m=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var C=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(t);if(V&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!u(A)&&!m(A))throw new Error(t);return[A,!1]},E=function(A){return function(e){return new w(!0).update(e)[A]()}},I=function(s){var n,o=A,r=e.Buffer;return n=r.from&&!i.JS_MD5_NO_BUFFER_FROM?r.from:function(A){return new r(A)},function(A){if("string"==typeof A)return o.createHash("md5").update(A,"utf8").digest("hex");if(null==A)throw new Error(t);return A.constructor===ArrayBuffer&&(A=new Uint8Array(A)),u(A)||m(A)||A.constructor===r?o.createHash("md5").update(n(A)).digest("hex"):s(A)}},M=function(A){return function(e,t){return new f(e,!0).update(t)[A]()}};function w(A){if(A)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=r;else if(V){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function f(A,e){var t,s=C(A);if(A=s[0],s[1]){var i,n=[],o=A.length,r=0;for(t=0;t<o;++t)(i=A.charCodeAt(t))<128?n[r++]=i:i<2048?(n[r++]=192|i>>>6,n[r++]=128|63&i):i<55296||i>=57344?(n[r++]=224|i>>>12,n[r++]=128|i>>>6&63,n[r++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),n[r++]=240|i>>>18,n[r++]=128|i>>>12&63,n[r++]=128|i>>>6&63,n[r++]=128|63&i);A=n}A.length>64&&(A=new w(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}w.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}w.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=C(A);A=e[0];for(var t,s,i=e[1],n=0,o=A.length,r=this.blocks,a=this.buffer8;n<o;){if(this.hashed&&(this.hashed=!1,r[0]=r[16],r[16]=r[1]=r[2]=r[3]=r[4]=r[5]=r[6]=r[7]=r[8]=r[9]=r[10]=r[11]=r[12]=r[13]=r[14]=r[15]=0),i)if(V)for(s=this.start;n<o&&s<64;++n)(t=A.charCodeAt(n))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++n)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;n<o&&s<64;++n)(t=A.charCodeAt(n))<128?r[s>>>2]|=t<<h[3&s++]:t<2048?(r[s>>>2]|=(192|t>>>6)<<h[3&s++],r[s>>>2]|=(128|63&t)<<h[3&s++]):t<55296||t>=57344?(r[s>>>2]|=(224|t>>>12)<<h[3&s++],r[s>>>2]|=(128|t>>>6&63)<<h[3&s++],r[s>>>2]|=(128|63&t)<<h[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++n)),r[s>>>2]|=(240|t>>>18)<<h[3&s++],r[s>>>2]|=(128|t>>>12&63)<<h[3&s++],r[s>>>2]|=(128|t>>>6&63)<<h[3&s++],r[s>>>2]|=(128|63&t)<<h[3&s++]);else if(V)for(s=this.start;n<o&&s<64;++n)a[s++]=A[n];else for(s=this.start;n<o&&s<64;++n)r[s>>>2]|=A[n]<<h[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},w.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=l[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},w.prototype.hash=function(){var A,e,t,s,i,n,o=this.blocks;this.first?e=((e=((A=((A=o[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+o[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+o[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+o[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+o[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+o[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+o[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+o[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+o[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+o[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+o[10]-42063)<<17|t>>>15)+s|0)&(s^A))+o[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+o[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+o[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[1]-165796510)<<5|A>>>27)+e|0)^e))+o[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[11]+643717713)<<14|t>>>18)+s|0)^s))+o[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[5]-701558691)<<5|A>>>27)+e|0)^e))+o[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[15]-660478335)<<14|t>>>18)+s|0)^s))+o[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[9]+568446438)<<5|A>>>27)+e|0)^e))+o[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[3]-187363961)<<14|t>>>18)+s|0)^s))+o[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[13]-1444681467)<<5|A>>>27)+e|0)^e))+o[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[7]+1735328473)<<14|t>>>18)+s|0)^s))+o[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[5]-378558)<<4|A>>>28)+e|0))+o[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[11]+1839030562)<<16|t>>>16)+s|0))+o[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[1]-1530992060)<<4|A>>>28)+e|0))+o[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[7]-155497632)<<16|t>>>16)+s|0))+o[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[13]+681279174)<<4|A>>>28)+e|0))+o[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[3]-722521979)<<16|t>>>16)+s|0))+o[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[9]-640364487)<<4|A>>>28)+e|0))+o[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[15]+530742520)<<16|t>>>16)+s|0))+o[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[0]-198630844)<<6|A>>>26)+e|0)|~t))+o[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[14]-1416354905)<<15|t>>>17)+s|0)|~A))+o[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[12]+1700485571)<<6|A>>>26)+e|0)|~t))+o[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[10]-1051523)<<15|t>>>17)+s|0)|~A))+o[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[8]+1873313359)<<6|A>>>26)+e|0)|~t))+o[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[6]-1560198380)<<15|t>>>17)+s|0)|~A))+o[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[4]-145523070)<<6|A>>>26)+e|0)|~t))+o[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[2]+718787259)<<15|t>>>17)+s|0)|~A))+o[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},w.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return c[A>>>4&15]+c[15&A]+c[A>>>12&15]+c[A>>>8&15]+c[A>>>20&15]+c[A>>>16&15]+c[A>>>28&15]+c[A>>>24&15]+c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[s>>>4&15]+c[15&s]+c[s>>>12&15]+c[s>>>8&15]+c[s>>>20&15]+c[s>>>16&15]+c[s>>>28&15]+c[s>>>24&15]},w.prototype.toString=w.prototype.hex,w.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},w.prototype.array=w.prototype.digest,w.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},w.prototype.buffer=w.prototype.arrayBuffer,w.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),n=0;n<15;)A=i[n++],e=i[n++],t=i[n++],s+=q[A>>>2]+q[63&(A<<4|e>>>4)]+q[63&(e<<2|t>>>6)]+q[63&t];return A=i[n],s+=q[A>>>2]+q[A<<4&63]+"=="},f.prototype=new w,f.prototype.finalize=function(){if(w.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();w.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),w.prototype.finalize.call(this)}};var B=function(){var A=E("hex");o&&(A=I(A)),A.create=function(){return new w},A.update=function(e){return A.create().update(e)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=E(t)}return A}();B.md5=B,B.md5.hmac=function(){var A=M("hex");A.create=function(A){return new f(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=M(t)}return A}(),a?Bs.exports=B:i.md5=B}();var ys=Ts.exports;const Ds=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${ys.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Rs=A=>/^\d+$/.test(A),Us="/v1/aicc/bmserver",ks="/v1/aicc/ccs";let Gs="",Fs="",Ys="",xs="";function vs(){const A=Ds(Fs,Ys);return Ss.create({prefixUrl:`${Gs}`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{if(-1!==t.url.indexOf("heartbeat"))return t;const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}async function Zs(A,e){const t=vs(),s="api/"+A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const Os=A=>Zs(`${ks}/state/change`,A),Ns=()=>async function(A,e){const t=vs(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}("/heartbeat",{});class Ks{constructor(){this.roleData={agentInfo:()=>{if(!Ve.agentInfo?.agent_no)throw new Error(JSON.stringify({code:1,msg:"请先登录"}))},requestInfo:A=>{if(!A.data)throw new Error(JSON.stringify({code:1,msg:'Parameter "data" is required'}))},changeDevice:A=>{if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "device" is required'}));const{answer_devices:e}=Ve.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error(JSON.stringify({code:1,msg:"当前状态不支持"}))},changeState:(A,e)=>{if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "state" is required'}));if(!e)throw new Error(JSON.stringify({code:1,msg:'Parameter "state_name" is required'}));if(2===A&&("通话中"===e||"整理"===e))throw new Error(JSON.stringify({code:1,msg:"当前状态不支持"}));if(![1,2].includes(A))throw new Error(JSON.stringify({code:1,msg:"当前状态不支持"}))},setAgentExplicit:A=>{const{out_display_select_switch:e,out_display_data:t}=Ve.agentInfo;if(1!==e)throw new Error(JSON.stringify({code:1,msg:"当前坐席设置未开启允许指定外显"}));if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "number" is required'}));if(!(t||"").split("#").includes(A))throw new Error(JSON.stringify({code:1,msg:"当前外显号码不存在"}))}}}formatDate(A){return`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")} ${String(A.getHours()).padStart(2,"0")}:${String(A.getMinutes()).padStart(2,"0")}:${String(A.getSeconds()).padStart(2,"0")}`}async _agentLogin(A){try{const t=await(e={agent_no:A},Zs(`${ks}/agent/login`,e));Ve.agentInfo=t.data}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}var e}async _changeState(A){try{Ve.autoStateTimer&&(clearTimeout(Ve.autoStateTimer),Ve.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e,{agent_no:n}=Ve.agentInfo;await Os({agent_no:n,state_name:i,state:s}),s===exports.AgentStatus.IDLE?le.updateActionConfigs(ft):s===exports.AgentStatus.BUSY&&le.updateActionConfigs(Bt),Ve.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async _getInCallCrmDetail(A){try{const{phone:e}=A.data,t={};Rs(e)?t.phone=e:t.trace_id=e;const s=await(A=>Zs(`${Us}/crm/popups`,A))({...t});A.success?.(s)}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async changeDevice(A){try{if(le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;1===s&&le.updateAnswerDevice(s),this.roleData.changeDevice(s);const{agent_no:i}=Ve.agentInfo;await(A=>Zs(`${ks}/device/change`,A))({agent_no:i,answer_device:s}),le.updateAnswerDevice(s);const n=le.get("actionConfigs");le.updateActionConfigs(n),2===s&&Ve.stateObject.state===exports.AgentStatus.UNREGISTERED&&await this._changeState({data:{...Ve.stateBeforeChange,state_name:Ve.stateBeforeChange.state===exports.AgentStatus.IDLE?"空闲":"忙碌"}}),t?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async changeState(A){try{if(le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));Ve.autoStateTimer&&(clearTimeout(Ve.autoStateTimer),Ve.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:n}=Ve.agentInfo;await Os({agent_no:n,state_name:i,state:s}),(Ve.stateObject.state===exports.AgentStatus.IDLE||Ve.stateObject.state===exports.AgentStatus.BUSY&&"整理"!==i)&&(Ve.stateBeforeChange=Ve.stateObject),s===exports.AgentStatus.IDLE?le.updateActionConfigs(ft):s===exports.AgentStatus.BUSY&&le.updateActionConfigs(Bt),Ve.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async getIdleAgentList(A){const{agent_no:e}=Ve.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Zs(`${ks}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async getAgentState(A){try{const e=await Zs(`${Us}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).filter(A=>"通话中"!==A.state_name&&"整理"!==A.state_name&&"未注册"!==A.state_name&&"离线接听"!==A.state_name).map(A=>({state:A.state,state_name:A.state_name})).reverse();A.success?.({...e,data:t})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async setAgentExplicit(A){try{this.roleData.agentInfo(),this.roleData.requestInfo(A),this.roleData.setAgentExplicit(A.data.number);const{agent_id:e}=Ve.agentInfo;await(A=>Zs(`${Us}/agent/update`,A))({agent_id:e,out_display_number:A.data.number}),le.updateSelectOutNumber(A.data.number),A.success?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async checkAgentLogin(A){try{this.roleData.requestInfo(A);const{agent_no:e}=A.data;if(!e)throw new Error(JSON.stringify({code:1,msg:'Parameter "agent_no" is required'}));const t=await(A=>Zs(`${ks}/agent/islogin`,A))({agent_no:e});A.success?.(t)}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async getCallRecord(A){try{this.roleData.agentInfo();const{success:e}=A,t=new Date,s=new Date(t.getFullYear(),t.getMonth(),t.getDate(),0,0,0),i=new Date(t.getFullYear(),t.getMonth(),t.getDate(),23,59,59),n=[this.formatDate(s),this.formatDate(i)],{agent_no:o}=Ve.agentInfo,r=await(A=>Zs(`${Us}/agent/recordpage`,A))({start_time:n[0],end_time:n[1],page_no:1,page_size:10,agent_no:o}),{code:a,msg:V,data:c}=r;e?.({code:a,msg:V,data:c})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async logout(A){this.roleData.agentInfo();try{const{agent_no:e}=Ve.agentInfo,{data:t,success:s}=A;await(A=>Zs(`${ks}/agent/logout`,A))({...t,agent_no:e}),s?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async listenCall(A){try{const{agent_no:e}=Ve.agentInfo,{data:t,success:s}=A;if(this.roleData.agentInfo(),this.roleData.requestInfo(A),!t.monitored_agent_no)throw new Error(JSON.stringify({code:1,msg:'Parameter "monitored_agent_no" is required'}));await(A=>Zs(`${ks}/call/monitor`,A))({...t,monitor_agent_no:e}),Ve.monitoredAgentNo=t.monitored_agent_no,s?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async earCall(A){try{const{agentInfo:e,monitoredAgentNo:t}=Ve,{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Zs(`${ks}/call/whisper`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async stopEarCall(A){try{const{agentInfo:e,earSpeakAgent:t}=Ve;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前没有正在耳语的坐席"}));const{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;await(A=>Zs(`${ks}/call/stopwhisper`,A))({monitor_agent_no:s,monitored_agent_no:t}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async forceInsert(A){try{const{agentInfo:e,monitoredAgentNo:t}=Ve,{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Zs(`${ks}/call/bargein`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async forceDisconnect(A){try{const{agentInfo:e,monitoredAgentNo:t}=Ve,{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Zs(`${ks}/call/intercept`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}}let bs=class extends Et{constructor(){super(...arguments),this.type="info",this.content="",this.duration=3e3}static{this.styles=Ce`
527
+ Bs=Ts,function(){var t="input is invalid type",s="object"==typeof window,i=s?window:{};i.JS_MD5_NO_WINDOW&&(s=!1);var n=!s&&"object"==typeof self,o=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?i=Qs:n&&(i=self);var r,a=!i.JS_MD5_NO_COMMON_JS&&Bs.exports,V=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),l=[128,32768,8388608,-2147483648],h=[0,8,16,24],g=["hex","array","digest","buffer","arrayBuffer","base64"],q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[];if(V){var p=new ArrayBuffer(68);r=new Uint8Array(p),d=new Uint32Array(p)}var u=Array.isArray;!i.JS_MD5_NO_NODE_JS&&u||(u=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var m=ArrayBuffer.isView;!V||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&m||(m=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var C=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(t);if(V&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!u(A)&&!m(A))throw new Error(t);return[A,!1]},E=function(A){return function(e){return new w(!0).update(e)[A]()}},I=function(s){var n,o=A,r=e.Buffer;return n=r.from&&!i.JS_MD5_NO_BUFFER_FROM?r.from:function(A){return new r(A)},function(A){if("string"==typeof A)return o.createHash("md5").update(A,"utf8").digest("hex");if(null==A)throw new Error(t);return A.constructor===ArrayBuffer&&(A=new Uint8Array(A)),u(A)||m(A)||A.constructor===r?o.createHash("md5").update(n(A)).digest("hex"):s(A)}},M=function(A){return function(e,t){return new f(e,!0).update(t)[A]()}};function w(A){if(A)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=r;else if(V){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function f(A,e){var t,s=C(A);if(A=s[0],s[1]){var i,n=[],o=A.length,r=0;for(t=0;t<o;++t)(i=A.charCodeAt(t))<128?n[r++]=i:i<2048?(n[r++]=192|i>>>6,n[r++]=128|63&i):i<55296||i>=57344?(n[r++]=224|i>>>12,n[r++]=128|i>>>6&63,n[r++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),n[r++]=240|i>>>18,n[r++]=128|i>>>12&63,n[r++]=128|i>>>6&63,n[r++]=128|63&i);A=n}A.length>64&&(A=new w(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}w.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}w.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=C(A);A=e[0];for(var t,s,i=e[1],n=0,o=A.length,r=this.blocks,a=this.buffer8;n<o;){if(this.hashed&&(this.hashed=!1,r[0]=r[16],r[16]=r[1]=r[2]=r[3]=r[4]=r[5]=r[6]=r[7]=r[8]=r[9]=r[10]=r[11]=r[12]=r[13]=r[14]=r[15]=0),i)if(V)for(s=this.start;n<o&&s<64;++n)(t=A.charCodeAt(n))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++n)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;n<o&&s<64;++n)(t=A.charCodeAt(n))<128?r[s>>>2]|=t<<h[3&s++]:t<2048?(r[s>>>2]|=(192|t>>>6)<<h[3&s++],r[s>>>2]|=(128|63&t)<<h[3&s++]):t<55296||t>=57344?(r[s>>>2]|=(224|t>>>12)<<h[3&s++],r[s>>>2]|=(128|t>>>6&63)<<h[3&s++],r[s>>>2]|=(128|63&t)<<h[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++n)),r[s>>>2]|=(240|t>>>18)<<h[3&s++],r[s>>>2]|=(128|t>>>12&63)<<h[3&s++],r[s>>>2]|=(128|t>>>6&63)<<h[3&s++],r[s>>>2]|=(128|63&t)<<h[3&s++]);else if(V)for(s=this.start;n<o&&s<64;++n)a[s++]=A[n];else for(s=this.start;n<o&&s<64;++n)r[s>>>2]|=A[n]<<h[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},w.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=l[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},w.prototype.hash=function(){var A,e,t,s,i,n,o=this.blocks;this.first?e=((e=((A=((A=o[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+o[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+o[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+o[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+o[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+o[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+o[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+o[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+o[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+o[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+o[10]-42063)<<17|t>>>15)+s|0)&(s^A))+o[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+o[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+o[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[1]-165796510)<<5|A>>>27)+e|0)^e))+o[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[11]+643717713)<<14|t>>>18)+s|0)^s))+o[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[5]-701558691)<<5|A>>>27)+e|0)^e))+o[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[15]-660478335)<<14|t>>>18)+s|0)^s))+o[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[9]+568446438)<<5|A>>>27)+e|0)^e))+o[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[3]-187363961)<<14|t>>>18)+s|0)^s))+o[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[13]-1444681467)<<5|A>>>27)+e|0)^e))+o[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[7]+1735328473)<<14|t>>>18)+s|0)^s))+o[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[5]-378558)<<4|A>>>28)+e|0))+o[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[11]+1839030562)<<16|t>>>16)+s|0))+o[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[1]-1530992060)<<4|A>>>28)+e|0))+o[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[7]-155497632)<<16|t>>>16)+s|0))+o[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[13]+681279174)<<4|A>>>28)+e|0))+o[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[3]-722521979)<<16|t>>>16)+s|0))+o[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((n=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[9]-640364487)<<4|A>>>28)+e|0))+o[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(n^e)+o[15]+530742520)<<16|t>>>16)+s|0))+o[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[0]-198630844)<<6|A>>>26)+e|0)|~t))+o[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[14]-1416354905)<<15|t>>>17)+s|0)|~A))+o[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[12]+1700485571)<<6|A>>>26)+e|0)|~t))+o[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[10]-1051523)<<15|t>>>17)+s|0)|~A))+o[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[8]+1873313359)<<6|A>>>26)+e|0)|~t))+o[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[6]-1560198380)<<15|t>>>17)+s|0)|~A))+o[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[4]-145523070)<<6|A>>>26)+e|0)|~t))+o[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[2]+718787259)<<15|t>>>17)+s|0)|~A))+o[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},w.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return c[A>>>4&15]+c[15&A]+c[A>>>12&15]+c[A>>>8&15]+c[A>>>20&15]+c[A>>>16&15]+c[A>>>28&15]+c[A>>>24&15]+c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[s>>>4&15]+c[15&s]+c[s>>>12&15]+c[s>>>8&15]+c[s>>>20&15]+c[s>>>16&15]+c[s>>>28&15]+c[s>>>24&15]},w.prototype.toString=w.prototype.hex,w.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},w.prototype.array=w.prototype.digest,w.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},w.prototype.buffer=w.prototype.arrayBuffer,w.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),n=0;n<15;)A=i[n++],e=i[n++],t=i[n++],s+=q[A>>>2]+q[63&(A<<4|e>>>4)]+q[63&(e<<2|t>>>6)]+q[63&t];return A=i[n],s+=q[A>>>2]+q[A<<4&63]+"=="},f.prototype=new w,f.prototype.finalize=function(){if(w.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();w.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),w.prototype.finalize.call(this)}};var B=function(){var A=E("hex");o&&(A=I(A)),A.create=function(){return new w},A.update=function(e){return A.create().update(e)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=E(t)}return A}();B.md5=B,B.md5.hmac=function(){var A=M("hex");A.create=function(A){return new f(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=M(t)}return A}(),a?Bs.exports=B:i.md5=B}();var ys=Ts.exports;const Ds=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${ys.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Rs=A=>/^[A-Za-z0-9+/]+={0,2}$/.test(A),Us="/v1/aicc/bmserver",ks="/v1/aicc/ccs";let Gs="",Fs="",Ys="",xs="";function vs(){const A=Ds(Fs,Ys);return Ss.create({prefixUrl:`${Gs}`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{if(-1!==t.url.indexOf("heartbeat"))return t;const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}async function Zs(A,e){const t=vs(),s="api/"+A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const Os=A=>Zs(`${ks}/state/change`,A),Ns=()=>async function(A,e){const t=vs(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}("/heartbeat",{});class Ks{constructor(){this.roleData={agentInfo:()=>{if(!Ve.agentInfo?.agent_no)throw new Error(JSON.stringify({code:1,msg:"请先登录"}))},requestInfo:A=>{if(!A.data)throw new Error(JSON.stringify({code:1,msg:'Parameter "data" is required'}))},changeDevice:A=>{if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "device" is required'}));const{answer_devices:e}=Ve.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error(JSON.stringify({code:1,msg:"当前状态不支持"}))},changeState:(A,e)=>{if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "state" is required'}));if(!e)throw new Error(JSON.stringify({code:1,msg:'Parameter "state_name" is required'}));if(2===A&&("通话中"===e||"整理"===e))throw new Error(JSON.stringify({code:1,msg:"当前状态不支持"}));if(![1,2].includes(A))throw new Error(JSON.stringify({code:1,msg:"当前状态不支持"}))},setAgentExplicit:A=>{const{out_display_select_switch:e,out_display_data:t}=Ve.agentInfo;if(1!==e)throw new Error(JSON.stringify({code:1,msg:"当前坐席设置未开启允许指定外显"}));if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "number" is required'}));if(!(t||"").split("#").includes(A))throw new Error(JSON.stringify({code:1,msg:"当前外显号码不存在"}))}}}formatDate(A){return`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")} ${String(A.getHours()).padStart(2,"0")}:${String(A.getMinutes()).padStart(2,"0")}:${String(A.getSeconds()).padStart(2,"0")}`}async _agentLogin(A){try{const t=await(e={agent_no:A},Zs(`${ks}/agent/login`,e));Ve.agentInfo=t.data}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}var e}async _changeState(A){try{Ve.autoStateTimer&&(clearTimeout(Ve.autoStateTimer),Ve.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e,{agent_no:n}=Ve.agentInfo;await Os({agent_no:n,state_name:i,state:s}),s===exports.AgentStatus.IDLE?le.updateActionConfigs(ft):s===exports.AgentStatus.BUSY&&le.updateActionConfigs(Bt),Ve.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async _getInCallCrmDetail(A){try{const{phone:e}=A.data,t={};Rs(e)?t.phone=e:t.trace_id=e;const s=await(A=>Zs(`${Us}/crm/popups`,A))({...t});A.success?.(s)}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async changeDevice(A){try{if(le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;1===s&&le.updateAnswerDevice(s),this.roleData.changeDevice(s);const{agent_no:i}=Ve.agentInfo;await(A=>Zs(`${ks}/device/change`,A))({agent_no:i,answer_device:s}),le.updateAnswerDevice(s);const n=le.get("actionConfigs");le.updateActionConfigs(n),2===s&&Ve.stateObject.state===exports.AgentStatus.UNREGISTERED&&await this._changeState({data:{...Ve.stateBeforeChange,state_name:Ve.stateBeforeChange.state===exports.AgentStatus.IDLE?"空闲":"忙碌"}}),t?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async changeState(A){try{if(le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));Ve.autoStateTimer&&(clearTimeout(Ve.autoStateTimer),Ve.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:n}=Ve.agentInfo;await Os({agent_no:n,state_name:i,state:s}),(Ve.stateObject.state===exports.AgentStatus.IDLE||Ve.stateObject.state===exports.AgentStatus.BUSY&&"整理"!==i)&&(Ve.stateBeforeChange=Ve.stateObject),s===exports.AgentStatus.IDLE?le.updateActionConfigs(ft):s===exports.AgentStatus.BUSY&&le.updateActionConfigs(Bt),Ve.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async getIdleAgentList(A){const{agent_no:e}=Ve.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Zs(`${ks}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async getAgentState(A){try{const e=await Zs(`${Us}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).filter(A=>"通话中"!==A.state_name&&"整理"!==A.state_name&&"未注册"!==A.state_name&&"离线接听"!==A.state_name).map(A=>({state:A.state,state_name:A.state_name})).reverse();A.success?.({...e,data:t})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async setAgentExplicit(A){try{this.roleData.agentInfo(),this.roleData.requestInfo(A),this.roleData.setAgentExplicit(A.data.number);const{agent_id:e}=Ve.agentInfo;await(A=>Zs(`${Us}/agent/update`,A))({agent_id:e,out_display_number:A.data.number}),le.updateSelectOutNumber(A.data.number),A.success?.({code:0,msg:"请求成功"})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async checkAgentLogin(A){try{this.roleData.requestInfo(A);const{agent_no:e}=A.data;if(!e)throw new Error(JSON.stringify({code:1,msg:'Parameter "agent_no" is required'}));const t=await(A=>Zs(`${ks}/agent/islogin`,A))({agent_no:e});A.success?.(t)}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async getCallRecord(A){try{this.roleData.agentInfo();const{success:e}=A,t=new Date,s=new Date(t.getFullYear(),t.getMonth(),t.getDate(),0,0,0),i=new Date(t.getFullYear(),t.getMonth(),t.getDate(),23,59,59),n=[this.formatDate(s),this.formatDate(i)],{agent_no:o}=Ve.agentInfo,r=await(A=>Zs(`${Us}/agent/recordpage`,A))({start_time:n[0],end_time:n[1],page_no:1,page_size:10,agent_no:o}),{code:a,msg:V,data:c}=r;e?.({code:a,msg:V,data:c})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async logout(A){this.roleData.agentInfo();try{const{agent_no:e}=Ve.agentInfo,{data:t,success:s}=A;await(A=>Zs(`${ks}/agent/logout`,A))({...t,agent_no:e}),s?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async listenCall(A){try{const{agent_no:e}=Ve.agentInfo,{data:t,success:s}=A;if(this.roleData.agentInfo(),this.roleData.requestInfo(A),!t.monitored_agent_no)throw new Error(JSON.stringify({code:1,msg:'Parameter "monitored_agent_no" is required'}));await(A=>Zs(`${ks}/call/monitor`,A))({...t,monitor_agent_no:e}),Ve.monitoredAgentNo=t.monitored_agent_no,s?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async earCall(A){try{const{agentInfo:e,monitoredAgentNo:t}=Ve,{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Zs(`${ks}/call/whisper`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async stopEarCall(A){try{const{agentInfo:e,earSpeakAgent:t}=Ve;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前没有正在耳语的坐席"}));const{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;await(A=>Zs(`${ks}/call/stopwhisper`,A))({monitor_agent_no:s,monitored_agent_no:t}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async forceInsert(A){try{const{agentInfo:e,monitoredAgentNo:t}=Ve,{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Zs(`${ks}/call/bargein`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}async forceDisconnect(A){try{const{agentInfo:e,monitoredAgentNo:t}=Ve,{agent_no:s}=e;this.roleData.agentInfo();const{success:i}=A;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Zs(`${ks}/call/intercept`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(A){throw ae.emit(exports.EventName.FAIL_NOTIFICATION,JSON.parse(A.message).msg),A}}}let bs=class extends Et{constructor(){super(...arguments),this.type="info",this.content="",this.duration=3e3}static{this.styles=Ce`
528
528
  :host {
529
529
  display: block;
530
530
  margin-top: 10px;
@@ -911,4 +911,4 @@ Bs=Ts,function(){var t="input is invalid type",s="object"==typeof window,i=s?win
911
911
  `:""}
912
912
  </div>
913
913
  </my-popover>
914
- `;mt(s,this.rttHTML)}}class Ps{static requestPermission(){"Notification"in window&&"default"===Notification.permission&&Notification.requestPermission()}static async requestMediaPermissions(){try{const A=await navigator.mediaDevices.enumerateDevices();if(A.some(A=>"audioinput"===A.kind&&""!==A.label))return null;return await navigator.mediaDevices.getUserMedia({audio:!0})}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t,s){if("Notification"in window&&"granted"===Notification.permission){const i=new Notification(A,{body:e,tag:`xy-global-notification${(new Date).getTime()}`,renotify:!0});i.onclick=()=>{window.focus(),i.close(),t?.()},setTimeout(()=>i.close(),1e3*(s||3))}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}const zs=console.log,Xs=(...A)=>{Ve.logBuiltinEnabled&&zs(...A)};let _s=null;class $s{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Ks,this.sipClient=null,this.pendingMessages=new Map,this.initWebSocket()}static getInstance({url:A,sipClient:e}){if(!_s){if(!A)throw new Error("WebSocket 尚未初始化");_s=new $s(A),_s.sipClient=e}return _s}stateIdleChange(){const{state:A}=Ve.stateObject;A!==exports.AgentStatus.IDLE&&(Ve.stateBeforeChange,this.apiClient._changeState({data:{...Ve.stateBeforeChange,state_name:Ve.stateBeforeChange.state===exports.AgentStatus.IDLE?"空闲":"忙碌"}}))}inCallAutoAnswer(){const{soft_device_auto_answer:A,auto_answer_time:e}=Ve.agentInfo,t=1===A,s=le.get("direction");if(t&&s===exports.DirectionEnum.INCOMING){const A=Number(e)||0;A>0&&(Ve.autoAnswerTimer=setTimeout(()=>{this.sipClient?.answerCall(),Ve.autoAnswerTimer=null},1e3*A))}}async getCustomerInfo(A){try{await this.apiClient._getInCallCrmDetail({data:{phone:A},success:A=>{le.updateCustomerInfo(A.data||{phone:A.data.phone,is_vip:0,customer_name:"未知客户",city:"未知",province:"未知",contact_count:0,in_contact_count:0,trace_id:A.data.trace_id,contact_count_month:0,in_contact_count_month:0})}})}catch(A){}}putAgentState(A,e){if(!A)return;if(5===e)return void this.stateIdleChange();Ve.sessionId="";const{post_call_process_time:t}=Ve.agentInfo,s=t||0;if(Ve.autoStateTimer&&(clearTimeout(Ve.autoStateTimer),Ve.autoStateTimer=null),le.updateCustomerInfo(void 0),s>0){const{state:A}=Ve.stateObject;if(A===exports.AgentStatus.IDLE)return;this.apiClient._changeState({data:{state:exports.AgentStatus.BUSY,state_name:"整理"}}),Ve.autoStateTimer=setTimeout(()=>{Ve.autoStateTimer=null,this.stateIdleChange()},1e3*s)}else this.stateIdleChange()}stateBusyChange(){Ve.sessionId="",clearTimeout(Ve.autoStateTimer),le.updateCustomerInfo(void 0),this.apiClient._changeState({data:{state:exports.AgentStatus.BUSY,state_name:"忙碌"}})}initWebSocket(){if(1===this.ws?.readyState)return;const A=Ds(Fs,Ys);this.ws=new WebSocket(this.url+A),this.ws.onopen=()=>{const A=(new Date).getTime();this.sendMessage({type:0,msg_id:A}),this.pendingMessages.set(A,performance.now()),this.startHeartbeat(),this.manualClose=!1},this.ws.onmessage=async A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:n,msg_id:o}=e;if(0===t&&o){const A=this.pendingMessages.get(o),e=performance.now()-A;Ve.latency=parseFloat(e.toFixed(2)),this.pendingMessages.delete(o)}if(0!==t&&Xs("%cWebSocket 收到消息:","color: blue; font-weight: bold;",e),t!==exports.WebsocketTypeEnum.OUT_CALL&&t!==exports.WebsocketTypeEnum.PREVIEW_OUT_CALL||(0!==i?(le.reset(),ae.emit(exports.CallSipCallEventEnum.OUT_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n),le.updateActionConfigs(ft),setTimeout(()=>{le.updateCustomerInfo(void 0)},500),this.stateIdleChange()):0===i&&(ae.emit(exports.CallSipCallEventEnum.OUT_SUCCESS),clearTimeout(Ve.autoStateTimer))),t===exports.WebsocketTypeEnum.AGENT_STATE){const{state:A,state_name:e}=s;Ve.stateObject={state:A,state_name:e},"振铃中"===e&&le.updateDisplayText(exports.DisplayTextEnum.AGENT_RINGING),A===exports.AgentStatus.UNREGISTERED&&le.updateActionConfigs(wt),A===exports.AgentStatus.IDLE&&Ve.stateObject.state===exports.AgentStatus.UNREGISTERED&&le.updateActionConfigs(ft),ae.emit(exports.CallSipCallEventEnum.AGENT_STATE,{state:A,state_name:e})}if(t===exports.WebsocketTypeEnum.OUT_CALL_INCOMING_CALL){try{await this.getCustomerInfo(s.trace_id||s.customer_phone)}catch(A){console.error(A)}s.preview_task_id?ae.emit(exports.CallSipCallEventEnum.PREVIEW_OUT_INCOMING_CALL,{customer_phone:s.customer_phone,session_id:s.session_id,preview_task_id:s.preview_task_id,trace_id:s.trace_id}):ae.emit(exports.CallSipCallEventEnum.OUT_INCOMING_CALL,{customer_phone:s.customer_phone,session_id:s.session_id,trace_id:s.trace_id}),Ve.sessionId=s.session_id,le.updateActionConfigs(St)}if(t===exports.WebsocketTypeEnum.OUT_CALL_END)if(le.updateDisplayText(""),1===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.OUT_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)le.reset(),ae.emit(exports.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),this.putAgentState(!0),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no){le.get("isCalling")&&(le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(Qt))}else if(3===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.TRANSFER_END,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no){ae.emit(exports.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),ae.emit(exports.EventName.FAIL_NOTIFICATION,"转接失败");const A=le.get("direction");A===exports.DirectionEnum.OUTGOING?le.updateActionConfigs(Qt):A===exports.DirectionEnum.INCOMING&&le.updateActionConfigs(Ut)}else 5===s.device_type&&s.agent_no===Ve.agentInfo.agent_no&&(this.putAgentState(!0,5),Ve.monitoredAgentNo="",Ve.earSpeakAgent="",le.reset(),ae.emit(exports.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft));if(t===exports.WebsocketTypeEnum.OUT_CALL_RINGING&&1===s.type&&(ae.emit(exports.CallSipCallEventEnum.OUT_RINGING,{session_id:Ve.sessionId,type:s.type}),le.updateDisplayText(exports.DisplayTextEnum.RINGING)),t===exports.WebsocketTypeEnum.OUT_CALL_ANSWER&&(clearTimeout(Ve.autoStateTimer),le.updateIsCalling(!0),ae.emit(exports.CallSipCallEventEnum.OUT_OFF_ANSWER,{session_id:Ve.sessionId}),le.updateOutCallIsAnswer(!0),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(Qt)),t===exports.WebsocketTypeEnum.CONSULT_RINGING&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_RINGING,{session_id:s.session_id}),le.updateDisplayText(exports.DisplayTextEnum.AGENT_RINGING),le.updateActionConfigs([]),clearTimeout(Ve.autoStateTimer)),t===exports.WebsocketTypeEnum.CONSULT_ANSWER&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_OFF_HOOK,{session_id:s.session_id}),le.updateConsultIsAnswer(!0),le.updateDisplayText(exports.DisplayTextEnum.CONSULTING),le.updateActionConfigs(Tt)),t===exports.WebsocketTypeEnum.CONSULT_FAIL&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_FAILED,{custom_reason:s.custom_reason}),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(Qt)),t===exports.WebsocketTypeEnum.CONSULT_CALL_IN&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_INCOMING,{agent_no:s.agent_no,agent_mane:s.agent_name,session_id:s.session_id}),Ve.sessionId=s.session_id,le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.CONSULT),le.updateDisplayText(exports.DisplayTextEnum.CONSULT_CALL_IN),le.updateActionConfigs(Rt),Ve.enableBrowserAlert&&Ps.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{agent_mane:s.agent_name,agent_no:s.agent_no})},Ve.browserAlertTime)),t===exports.WebsocketTypeEnum.CONSULT_CALL_IN_SUCCESS&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_CALL_IN_SUCCESS,{session_id:s.session_id}),le.updateConsultIsAnswer(!0),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(yt)),t===exports.WebsocketTypeEnum.CONSULT_RETURN_CALL_SUCCESS&&("success"===s.status?(le.updateConsultIsAnswer(!1),ae.emit(exports.CallSipCallEventEnum.CONSULT_RETURN_CALL_SUCCESS),le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP),le.updateActionConfigs(Qt)):ae.emit(exports.EventName.FAIL_NOTIFICATION,"媒体失败")),t===exports.WebsocketTypeEnum.MUTE&&(0===i?(le.updateIsMuted(!0),ae.emit(exports.CallSipCallEventEnum.MUTE_SUCCESS),le.updateDisplayText(exports.DisplayTextEnum.MUTING)):(ae.emit(exports.CallSipCallEventEnum.MUTE_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.UNMUTE&&(0===i?(le.updateIsMuted(!1),ae.emit(exports.CallSipCallEventEnum.UNMUTE_SUCCESS),le.updateDisplayText(exports.DisplayTextEnum.CALLING)):(ae.emit(exports.CallSipCallEventEnum.UNMUTE_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CALL_HOLD&&(0===i?(le.updateIsHold(!0),le.updateDisplayText(exports.DisplayTextEnum.HOLDING),ae.emit(exports.CallSipCallEventEnum.HOLD_SUCCESS)):(ae.emit(exports.CallSipCallEventEnum.HOLD_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CALL_UNHOLD&&(0===i?(le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateIsHold(!1),ae.emit(exports.CallSipCallEventEnum.UNHOLD_SUCCESS)):(ae.emit(exports.CallSipCallEventEnum.UNHOLD_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CONSULT_TRANSFER&&(0===i?ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_SUCCESS):(ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CONSULT_TRANSFER_FAILED&&ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,s.status),t===exports.WebsocketTypeEnum.CONSULT_TRANSFER_OFF_HOOK&&(le.updateDirection(exports.DirectionEnum.INCOMING),le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_OFF_HOOK),le.updateActionConfigs(Ut),le.updateIncomingIsAnswer(!0),le.updateConsultIsAnswer(!1)),t===exports.WebsocketTypeEnum.INCOMING_CALL){clearTimeout(Ve.autoStateTimer),Ve.sessionId=s.session_id;try{await this.getCustomerInfo(s.trace_id||s.customer_phone)}catch(A){console.error(A)}le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.INCOMING),this.inCallAutoAnswer(),le.updateDisplayText(exports.DisplayTextEnum.INCOMING_CALL),1===s.direction&&ae.emit(exports.CallSipCallEventEnum.INCOMING_CALL,{customer_phone:s.customer_phone,trace_id:s.trace_id,session_id:s.session_id}),3===s.direction&&(ae.emit(exports.CallSipCallEventEnum.PREDICT_INCOMING_CALL,{customer_phone:s.customer_phone,trace_id:s.trace_id,session_id:s.session_id}),this.sipClient?.answerCall()),le.updateActionConfigs(Rt),Ve.enableBrowserAlert&&Ps.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})},Ve.browserAlertTime)}if(t===exports.WebsocketTypeEnum.INCOMING_CALL_OFF_HOOK&&(le.updateIncomingIsAnswer(!0),ae.emit(exports.CallSipCallEventEnum.INCOMING_CALL_OFF_HOOK,{session_id:Ve.sessionId}),le.updateActionConfigs(Ut),le.updateDisplayText(exports.DisplayTextEnum.CALLING)),t===exports.WebsocketTypeEnum.INCOMING_CALL_END)if(le.updateDisplayText(""),1===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.INCOMING_CALL_END,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)le.reset(),ae.emit(exports.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),this.putAgentState(!0),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no)le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(Qt);else if(3===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.TRANSFER_END,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no){ae.emit(exports.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),ae.emit(exports.EventName.FAIL_NOTIFICATION,"转接失败");const A=le.get("direction");A===exports.DirectionEnum.OUTGOING?le.updateActionConfigs(Qt):A===exports.DirectionEnum.INCOMING&&le.updateActionConfigs(Ut)}else 5===s.device_type&&s.agent_no===Ve.agentInfo.agent_no&&(this.putAgentState(!0,5),Ve.monitoredAgentNo="",Ve.earSpeakAgent="",le.reset(),ae.emit(exports.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft));if(t===exports.WebsocketTypeEnum.SATISFACTION_EVALUATION&&(0===i?ae.emit(exports.CallSipCallEventEnum.SATISFACTION_EVALUATION_SUCCESS):(ae.emit(exports.CallSipCallEventEnum.SATISFACTION_EVALUATION_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CONSULT_THREE_WAY&&(0!==i?(ae.emit(exports.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n)):0===i&&le.updateIsMeeting(!0)),t===exports.WebsocketTypeEnum.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(le.updateDirection(exports.DirectionEnum.MEETING),le.updateDisplayText(exports.DisplayTextEnum.MEETING),le.updateActionConfigs(Dt),ae.emit(exports.CallSipCallEventEnum.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(exports.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),le.updateIsMeeting(!1))),t===exports.WebsocketTypeEnum.TRANSFER_INCOMING_CALL&&(clearTimeout(Ve.autoStateTimer),s.agent_no===Ve.agentInfo.agent_no?(le.updateDisplayText(exports.DisplayTextEnum.TRANSFERRING),ae.emit(exports.CallSipCallEventEnum.TRANSFER_PROGRESS),le.updateActionConfigs([]),le.updateTransferIsAnswer(!0)):(Ve.sessionId=s.session_id,ae.emit(exports.CallSipCallEventEnum.TRANSFER_INCOMING_CALL,{agent_no:s.agent_no,agent_name:s.agent_name,session_id:s.session_id}),le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.TRANSFER),le.updateDisplayText(exports.DisplayTextEnum.TRANSFER_INCOMING_CALL),le.updateActionConfigs(Rt),Ve.enableBrowserAlert&&Ps.show("📞 转接来电",`坐席 [${s.agent_no}] 正在转接...`,()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{agent_no:s.agent_no})},Ve.browserAlertTime))),t===exports.WebsocketTypeEnum.TRANSFER_OFF_HOOK&&(ae.emit(exports.CallSipCallEventEnum.TRANSFER_OFF_HOOK,{session_id:Ve.sessionId}),le.updateTransferIsAnswer(!1),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(Ut)),t===exports.WebsocketTypeEnum.TRANSFER_FAILED&&"failed"===s.status){ae.emit(exports.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),ae.emit(exports.EventName.FAIL_NOTIFICATION,"转接失败");const A=le.get("direction");A===exports.DirectionEnum.OUTGOING?le.updateActionConfigs(Qt):A===exports.DirectionEnum.INCOMING&&le.updateActionConfigs(Ut)}t===exports.WebsocketTypeEnum.KICK_OFFLINE&&ae.emit(exports.EventName.KICK_OFF),t===exports.WebsocketTypeEnum.CONTINUOUS_NOT_ANSWER&&(ae.emit(exports.EventName.FAIL_NOTIFICATION,`已连续 ${s.miss_count} 次未接, 设置忙碌`),this.stateBusyChange()),t===exports.WebsocketTypeEnum.SIGN_OUT&&ae.emit(exports.EventName.SIGN_OUT),t===exports.WebsocketTypeEnum.SIGN_IN_SWITCH_DEVICE&&ae.emit(exports.EventName.SIGN_IN_SWITCH_DEVICE,s),t===exports.WebsocketTypeEnum.LISTEN_INCOMING_CALL&&(clearTimeout(Ve.autoStateTimer),Ve.sessionId=s.session_id,le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.INCOMING),this.inCallAutoAnswer(),le.updateDisplayText(exports.DisplayTextEnum.LISTENING),le.updateActionConfigs(Rt),ae.emit(exports.CallSipCallEventEnum.LISTEN_INCOMING_CALL,{session_id:s.session_id}),Ve.enableBrowserAlert&&Ps.show("📞 监听来电","正在来电...",()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})},Ve.browserAlertTime)),t===exports.WebsocketTypeEnum.LISTEN_INCOMING_CALL_OFF_HOOK&&(Ve.monitoredAgentNo=s.monitored_agent_no,Ve.earSpeakAgent="",le.updateIncomingIsAnswer(!0),ae.emit(exports.CallSipCallEventEnum.LISTEN_INCOMING_CALL_OFF_HOOK,{session_id:Ve.sessionId,monitored_agent_no:s.monitored_agent_no}),le.updateActionConfigs(kt),le.updateDisplayText(exports.DisplayTextEnum.CALLING)),t===exports.WebsocketTypeEnum.LISTEN_CALL_FAILED&&"failed"===s.status&&(ae.emit(exports.CallSipCallEventEnum.LISTEN_CALL_FAILED),Ve.monitoredAgentNo=""),t===exports.WebsocketTypeEnum.EAR_SPEECH&&("success"===s.status?(s.monitored_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(Gt),ae.emit(exports.CallSipCallEventEnum.EAR_SPEECH_BE_SUCCESS)),s.monitor_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(Ft),ae.emit(exports.CallSipCallEventEnum.EAR_SPEECH_SUCCESS,{monitored_agent_no:s.monitored_agent_no,monitor_agent_no:s.monitor_agent_no}),Ve.earSpeakAgent=s.monitored_agent_no)):ae.emit(exports.CallSipCallEventEnum.EAR_SPEECH_FAILED)),t===exports.WebsocketTypeEnum.STOP_EAR_SPEECH&&("success"===s.status?(s.monitored_agent_no===Ve.agentInfo.agent_no&&le.updateActionConfigs(Ut),s.monitor_agent_no===Ve.agentInfo.agent_no&&le.updateActionConfigs(kt),Ve.earSpeakAgent="",ae.emit(exports.CallSipCallEventEnum.STOP_EAR_SPEECH_SUCCESS)):ae.emit(exports.CallSipCallEventEnum.STOP_EAR_SPEECH_FAILED)),t===exports.WebsocketTypeEnum.CALL_FORCE_INSERT&&("success"===s.status?(s.monitored_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(xt),ae.emit(exports.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS,{monitored_agent_no:s.monitored_agent_no,monitor_agent_no:s.monitor_agent_no})),s.monitor_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(Yt),ae.emit(exports.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS_LISTENER,{monitored_agent_no:s.monitored_agent_no,monitor_agent_no:s.monitor_agent_no}))):ae.emit(exports.CallSipCallEventEnum.CALL_FORCE_INSERT_FAILED))},this.ws.onclose=()=>{this.stopHeartbeat(),this.manualClose||setTimeout(()=>this.initWebSocket(),this.reconnectDelay)},this.ws.onerror=()=>{this.ws?.close()}}startHeartbeat(){const A=new Blob(["\n let timer;\n self.onmessage = function (e) {\n if (e.data === 'start') {\n timer = setInterval(() => {\n self.postMessage('heartbeat');\n }, 5000);\n } else if (e.data === 'stop') {\n clearInterval(timer);\n }\n };\n "],{type:"application/javascript"}),e=URL.createObjectURL(A);this.heartbeatWorker=new Worker(e),this.heartbeatWorker.onmessage=()=>{const A=(new Date).getTime();this.sendMessage({type:0,msg_id:A}),this.pendingMessages.set(A,performance.now())},this.heartbeatWorker.postMessage("start")}stopHeartbeat(){this.heartbeatWorker&&(this.heartbeatWorker.postMessage("stop"),this.heartbeatWorker.terminate(),this.heartbeatWorker=null)}sendMessage(A){this.ws?.readyState===WebSocket.OPEN?(this.ws.send(JSON.stringify(A)),0!==A.type&&Xs("%cWebSocket 发送消息:","color: green; font-weight: bold;",A)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}reconnect(){this.initWebSocket()}static __internalClose(){_s&&(_s.close(),_s=null)}static __internalSend(A){if(!_s)throw new Error("WebSocket 尚未初始化");_s.sendMessage(A)}}class Ai{constructor(A){this.sipClient=null,this.sipClient=A}roleMute(){const A=le.get("isCalling"),e=Ve.sessionId;if(!A)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));if(!e)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}))}holdCall(){this.roleMute();const A=le.get("isHold"),{sessionId:e}=Ve;if(!e)return;if(!le.get("actionConfigs").includes("hold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿保持"}));if(A)throw new Error(JSON.stringify({code:1,msg:"当前已处于保持状态"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CALL_HOLD,data:{session_id:e}})}unholdCall(){this.roleMute();const{isHold:A}=le.getState(),{sessionId:e}=Ve;if(!le.get("actionConfigs").includes("unhold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取消保持"}));if(e){if(!A)throw new Error(JSON.stringify({code:1,msg:"当前未处于保持状态"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CALL_UNHOLD,data:{session_id:e}})}}sendDTMF(A){if(1!==le.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));if(!le.get("actionConfigs").includes("dtmf"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿发送按键"}));const{isCalling:e}=le.getState();if(!e)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));this.sipClient.sendDTMF(A)}cancelCall(){if(!le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const A=Ve.sessionId;ae.emit(exports.CallSipCallEventEnum.REJECT,{session_id:A}),$s.__internalSend({type:exports.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:A}})}async consultCall(A){this.roleMute();const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=le.getState(),n=Ve.sessionId;if(!le.get("actionConfigs").includes("consult"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询"}));if(s)throw new Error(JSON.stringify({code:1,msg:"当前正在咨询"}));if(!(e||t||i))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));if(!n)throw new Error(JSON.stringify({code:1,msg:"sessionId不存在"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_REQUEST,data:{session_id:n,consultation_agent_no:A}})}async answerCall(){if(1!==le.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));await this.sipClient.answerCall()}makeCall(A){const e={};Rs(A)?e.customer_phone=A:e.trace_id=A;const t=le.get("isCalling"),s=le.get("selectOutNumber")||"";if(t)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));if("string"!=typeof A||""===A.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.OUTGOING),$s.__internalSend({type:exports.WebsocketTypeEnum.OUT_CALL,data:{...e,caller:s}})}previewCall(A,e){const t={};Rs(A)?t.customer_phone=A:t.trace_id=A;const s=le.get("isCalling"),i=le.get("selectOutNumber")||"";if(s)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));if("string"!=typeof A||""===A.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.OUTGOING),$s.__internalSend({type:exports.WebsocketTypeEnum.PREVIEW_OUT_CALL,data:{...t,caller:i,preview_task_id:e}})}async hangup(){if(!le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const A=Ve.sessionId;$s.__internalSend({type:exports.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:A}})}mute(){this.roleMute();const A=le.get("actionConfigs"),e=le.get("isMuted"),t=Ve.sessionId;if(e)throw new Error(JSON.stringify({code:1,msg:"当前未处于静音状态"}));if(!A.includes("mute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:exports.WebsocketTypeEnum.MUTE,data:{session_id:t}})}unmute(){this.roleMute();const A=le.get("actionConfigs"),e=le.get("isMuted"),t=Ve.sessionId;if(!e)throw new Error(JSON.stringify({code:1,msg:"当前未处于未静音状态"}));if(!A.includes("unmute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:exports.WebsocketTypeEnum.UNMUTE,data:{session_id:t}})}consultTransfer(){this.roleMute();const A=le.get("consultIsAnswer"),e=Ve.sessionId;if(!le.get("actionConfigs").includes("consult_transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询转移"}));if(!A)throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_TRANSFER,data:{session_id:e}})}satisfactionEvaluation(){this.roleMute();const A=Ve.sessionId;if(!le.get("actionConfigs").includes("satisfaction"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用满意度评价"}));$s.__internalSend({type:exports.WebsocketTypeEnum.SATISFACTION_EVALUATION,data:{session_id:A}})}startConference(){this.roleMute();if(!le.get("actionConfigs").includes("conference"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用三方会议"}));const A=Ve.sessionId;if(!le.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_THREE_WAY,data:{session_id:A}})}consultRetrieve(){this.roleMute();if(!le.get("actionConfigs").includes("consult_retrieve"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取回通话"}));const A=Ve.sessionId;if(!le.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_RETURN_CALL,data:{session_id:A}})}async transferAgent(A){this.roleMute();if(!le.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));const{transferIsAnswer:e}=le.getState(),t=Ve.sessionId;if(e)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:exports.WebsocketTypeEnum.TRANSFER,data:{session_id:t,transfer_type:0,transfer_dest:A}})}async transferOutline(A){this.roleMute();if(!le.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));if(!A)throw new Error(JSON.stringify({code:1,msg:"号码不能为空"}));if(!/^\d+$/.test(A))throw new Error(JSON.stringify({code:1,msg:"号码格式错误"}));const{transferIsAnswer:e}=le.getState(),t=Ve.sessionId;if(e)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));if(e)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:exports.WebsocketTypeEnum.TRANSFER,data:{session_id:t,transfer_type:2,transfer_dest:A}})}}var ei;class ti{static{this._instance=null}#A=null;#e=new Ks;#t;#s=null;#i=!1;#n;#o;#r=!1;static{this._timer=null}#a=null;constructor(){if(!ei._creatingInstance)throw new Error("请使用 YSYTAgentSdk.getInstance() 获取实例");clearInterval(this.#s),this.#s=setInterval(async()=>{const A=await this.#V();he.updateRttObject(A)},2e3),Ps.requestMediaPermissions(),this.#n=le.subscribeKey("answerDevice",async A=>{1===A?(await this.initWebRtc(),Ve.stateObject.state===exports.AgentStatus.UNREGISTERED&&await this.#e._changeState({data:{...Ve.stateBeforeChange,state_name:Ve.stateBeforeChange.state===exports.AgentStatus.IDLE?"空闲":"忙碌"}})):await this.destroyRtc()}),this.#o=le.subscribeKey("isNextState",async A=>{if(A){await this.#e._agentLogin(xs);1===le.get("answerDevice")&&await this.#A.reconnect();let A="";const e=new URL(Gs).host;A=Gs.includes("https")?`wss://${e}`:`ws://${e}`;const{agent_no:t}=Ve.agentInfo;$s.getInstance({url:`${A}/ccs-ws/api/v1/ws/call/${t}?Authorization=`,sipClient:this.#A}),Ve.stateObject.state===exports.AgentStatus.OFFLINE&&setTimeout(()=>{this.#e._changeState({data:{...this.#a,state_name:this.#a.state===exports.AgentStatus.BUSY&&"整理"===this.#a.state_name?"忙碌":this.#a.state_name},success:()=>{le.updateDisplayText(""),ae.emit(exports.CallSipCallEventEnum.AGENT_STATE,this.#a)}})},10)}else this.#a=Ve.stateObject,$s.__internalClose(),le.updateDisplayText("离线")}),this.on(exports.EventName.KICK_OFF,()=>{this.destroy()}),window.addEventListener("online",this.#c),window.addEventListener("offline",this.#l)}#c=()=>{le.updateIsNextState(!0)};#l=()=>{le.updateIsNextState(!1)};async#h(){const A=le.get("isNextState");try{await Ns(),A||le.updateIsNextState(!0)}catch(e){A&&le.updateIsNextState(!1)}}#g(){ei._timer||(ei._timer=setInterval(()=>this.#h(),3e3))}static get instance(){return this._instance}static async destroyInstance(){this._instance&&(await this._instance.destroy(),this._instance=null)}static getInstance(A){if(!this._instance){if(!A)throw new Error("首次调用必须传入配置参数");const{url:e,appKey:t,appSecret:s,agentNo:i}=A;Gs=e||"https://aicc-api.yescloudy.com",Fs=t,Ys=s,xs=i,ei._creatingInstance=!0,this._instance=new ei,delete ei._creatingInstance,window.addEventListener("beforeunload",()=>{this._instance?.destroy()})}return this._instance}getInit(){return this.#r}async initWebRtc(){if(this.#A)return;const A=Ve.agentInfo.sip_account_list.find(A=>1===A.device_type);if(!A)throw new Error(JSON.stringify({code:1,msg:"未找到 sip_account_list"}));{const e=A.sip_register_addr;this.#A=new ge({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#q),await this.#A.start()}}async init({actionNodeParams:A,enableBrowserAlert:e,logBuiltinEnabled:t,browserAlertTime:s,initialState:i,initDevice:n}){try{const{viewHtmlElement:o,rttHTML:r}=A||{};Ve.logBuiltinEnabled=t||!1,Ve.browserAlertTime=s||5e3,await this.#e._agentLogin(xs);const{agent_no:a,current_answer_device:V,current_state:c,out_display_number:l,out_display_select_switch:h}=Ve.agentInfo;(i||c)===exports.AgentStatus.IDLE?(le.updateActionConfigs(ft),Ve.stateObject={state:i||c,state_name:"空闲"},Ve.stateBeforeChange=Ve.stateObject):(i||c)===exports.AgentStatus.BUSY&&(le.updateActionConfigs(Bt),Ve.stateObject={state:c,state_name:"忙碌"},Ve.stateBeforeChange=Ve.stateObject),1===h?le.updateSelectOutNumber(l):le.updateSelectOutNumber("");let g="";const q=new URL(Gs).host;g=Gs.includes("https")?`wss://${q}`:`ws://${q}`,le.updateAnswerDevice(n||V),1===(n||V)&&await this.initWebRtc(),setTimeout(()=>{this.#e._changeState({data:Ve.stateObject}),this.#e.changeDevice({data:{device:n||V}})},500),$s.getInstance({url:`${g}/ccs-ws/api/v1/ws/call/${a}?Authorization=`,sipClient:this.#A}),this.#t=new Ai(this.#A),A&&o&&(this.#i=!0,new Ws({container:o,rttHTML:r,statusParams:{state:exports.AgentStatus.IDLE,statusName:"空闲"}},this,this.#t)),Ve.enableBrowserAlert=e,e&&Ps.requestPermission(),ae.emit(exports.EventName.AGENT_INIT_STATUS,!0),this.#r=!0,clearInterval(ei._timer),ei._timer=null,this.#g()}catch(A){this.#i&&Hs("初始化失败"),ae.emit(exports.EventName.AGENT_INIT_STATUS,!1),this.#r=!1}}#q=A=>{const{type:e,data:t}=A;ae.emit(e,t)};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}async destroyRtc(){await(this.#A?.destroy()),this.#A=null}async destroy(){ei._instance&&(await this.destroyRtc(),clearInterval(this.#s),$s.__internalClose(),ae.emit(exports.EventName.DESTROY),this.offAll(),this.#n?.(),this.#o?.(),this.#i=!1,ei._instance=null,le.reset(),le.updateSelectOutNumber(""),clearInterval(ei._timer),ei._timer=null)}async#V(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){const A=A=>(...e)=>{if(!this.#i)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{answerCall:A(()=>this.#t.answerCall()),makeCall:A=>this.#t.makeCall(A),previewMakeCall:(A,e)=>this.#t.previewCall(A,e),cancelCall:A(()=>this.#t.cancelCall()),hangup:A(()=>this.#t.hangup()),sendDTMF:A(A=>this.#t.sendDTMF(A)),holdCall:A(()=>this.#t.holdCall()),unholdCall:A(()=>this.#t.unholdCall()),consultCall:A(async A=>{try{await this.#t.consultCall(A)}catch(A){throw console.warn(A),A}}),consultRetrieve:A(()=>this.#t.consultRetrieve()),consultTransfer:A(()=>this.#t.consultTransfer()),mute:A(()=>this.#t.mute()),unmute:A(()=>this.#t.unmute()),satisfactionEvaluation:A(()=>this.#t.satisfactionEvaluation()),startConference:A(()=>this.#t.startConference()),transferAgent:A(A=>this.#t.transferAgent(A)),transferOutline:A(A=>this.#t.transferOutline(A)),earSpeakStart:A(A=>this.#e.earCall(A)),earSpeakStop:A(A=>this.#e.stopEarCall(A)),forceInsert:A(A=>this.#e.forceInsert(A)),forceDisconnect:A(A=>this.#e.forceDisconnect(A))}}get agent_api(){const A=A=>(...e)=>{if(!this.#i)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{changeDevice:A(A=>this.#e.changeDevice(A)),changeState:A(A=>this.#e.changeState(A)),getIdleAgentList:A(A=>this.#e.getIdleAgentList(A)),getAgentState:A(A=>this.#e.getAgentState(A)),setAgentExplicit:A(A=>this.#e.setAgentExplicit(A)),checkAgentLogin:A=>this.#e.checkAgentLogin(A),getCallRecord:A=>this.#e.getCallRecord(A),agentLogout:async(A,e)=>{try{await this.#e.logout(A),await this.destroy(),e?.({code:0,msg:""})}catch(A){}},listenAgentCall:A=>this.#e.listenCall(A)}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t,out_display_data:s,out_display_select_switch:i,current_state:n}=Ve.agentInfo,{stateObject:o}=Ve,r={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,init_state:n,default_device:le.get("answerDevice"),out_display_data:s,out_display_select_switch:i,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:r[Number(A)]})),stateObject:o}}async getRealTimeCustomerInfo(){return le.get("customerObject")}setBrowserAlert(A){if("boolean"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));Ve.logBuiltinEnabled=A||!1}setBrowserAlertTime(A){if("number"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));Ve.browserAlertTime=A||3e3}}ei=ti,exports.default=ti;
914
+ `;mt(s,this.rttHTML)}}class Ps{static requestPermission(){"Notification"in window&&"default"===Notification.permission&&Notification.requestPermission()}static async requestMediaPermissions(){try{const A=await navigator.mediaDevices.enumerateDevices();if(A.some(A=>"audioinput"===A.kind&&""!==A.label))return null;return await navigator.mediaDevices.getUserMedia({audio:!0})}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t,s){if("Notification"in window&&"granted"===Notification.permission){const i=new Notification(A,{body:e,tag:`xy-global-notification${(new Date).getTime()}`,renotify:!0});i.onclick=()=>{window.focus(),i.close(),t?.()},setTimeout(()=>i.close(),1e3*(s||3))}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}const zs=console.log,Xs=(...A)=>{Ve.logBuiltinEnabled&&zs(...A)};let _s=null;class $s{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Ks,this.sipClient=null,this.pendingMessages=new Map,this.initWebSocket()}static getInstance({url:A,sipClient:e}){if(!_s){if(!A)throw new Error("WebSocket 尚未初始化");_s=new $s(A),_s.sipClient=e}return _s}stateIdleChange(){const{state:A}=Ve.stateObject;A!==exports.AgentStatus.IDLE&&(Ve.stateBeforeChange,this.apiClient._changeState({data:{...Ve.stateBeforeChange,state_name:Ve.stateBeforeChange.state===exports.AgentStatus.IDLE?"空闲":"忙碌"}}))}inCallAutoAnswer(){const{soft_device_auto_answer:A,auto_answer_time:e}=Ve.agentInfo,t=1===A,s=le.get("direction");if(t&&s===exports.DirectionEnum.INCOMING){const A=Number(e)||0;A>0&&(Ve.autoAnswerTimer=setTimeout(()=>{this.sipClient?.answerCall(),Ve.autoAnswerTimer=null},1e3*A))}}async getCustomerInfo(A){try{await this.apiClient._getInCallCrmDetail({data:{phone:A},success:A=>{le.updateCustomerInfo(A.data||{phone:A.data.phone,is_vip:0,customer_name:"未知客户",city:"未知",province:"未知",contact_count:0,in_contact_count:0,trace_id:A.data.trace_id,contact_count_month:0,in_contact_count_month:0})}})}catch(A){}}putAgentState(A,e){if(!A)return;if(5===e)return void this.stateIdleChange();Ve.sessionId="";const{post_call_process_time:t}=Ve.agentInfo,s=t||0;if(Ve.autoStateTimer&&(clearTimeout(Ve.autoStateTimer),Ve.autoStateTimer=null),le.updateCustomerInfo(void 0),s>0){const{state:A}=Ve.stateObject;if(A===exports.AgentStatus.IDLE)return;this.apiClient._changeState({data:{state:exports.AgentStatus.BUSY,state_name:"整理"}}),Ve.autoStateTimer=setTimeout(()=>{Ve.autoStateTimer=null,this.stateIdleChange()},1e3*s)}else this.stateIdleChange()}stateBusyChange(){Ve.sessionId="",clearTimeout(Ve.autoStateTimer),le.updateCustomerInfo(void 0),this.apiClient._changeState({data:{state:exports.AgentStatus.BUSY,state_name:"忙碌"}})}initWebSocket(){if(1===this.ws?.readyState)return;const A=Ds(Fs,Ys);this.ws=new WebSocket(this.url+A),this.ws.onopen=()=>{const A=(new Date).getTime();this.sendMessage({type:0,msg_id:A}),this.pendingMessages.set(A,performance.now()),this.startHeartbeat(),this.manualClose=!1},this.ws.onmessage=async A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:n,msg_id:o}=e;if(0===t&&o){const A=this.pendingMessages.get(o),e=performance.now()-A;Ve.latency=parseFloat(e.toFixed(2)),this.pendingMessages.delete(o)}if(0!==t&&Xs("%cWebSocket 收到消息:","color: blue; font-weight: bold;",e),t!==exports.WebsocketTypeEnum.OUT_CALL&&t!==exports.WebsocketTypeEnum.PREVIEW_OUT_CALL||(0!==i?(le.reset(),ae.emit(exports.CallSipCallEventEnum.OUT_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n),le.updateActionConfigs(ft),setTimeout(()=>{le.updateCustomerInfo(void 0)},500),this.stateIdleChange()):0===i&&(ae.emit(exports.CallSipCallEventEnum.OUT_SUCCESS),clearTimeout(Ve.autoStateTimer))),t===exports.WebsocketTypeEnum.AGENT_STATE){const{state:A,state_name:e}=s;Ve.stateObject={state:A,state_name:e},"振铃中"===e&&le.updateDisplayText(exports.DisplayTextEnum.AGENT_RINGING),A===exports.AgentStatus.UNREGISTERED&&le.updateActionConfigs(wt),A===exports.AgentStatus.IDLE&&Ve.stateObject.state===exports.AgentStatus.UNREGISTERED&&le.updateActionConfigs(ft),ae.emit(exports.CallSipCallEventEnum.AGENT_STATE,{state:A,state_name:e})}if(t===exports.WebsocketTypeEnum.OUT_CALL_INCOMING_CALL){try{await this.getCustomerInfo(s.trace_id||s.customer_phone)}catch(A){console.error(A)}s.preview_task_id?ae.emit(exports.CallSipCallEventEnum.PREVIEW_OUT_INCOMING_CALL,{customer_phone:s.customer_phone,session_id:s.session_id,preview_task_id:s.preview_task_id,trace_id:s.trace_id}):ae.emit(exports.CallSipCallEventEnum.OUT_INCOMING_CALL,{customer_phone:s.customer_phone,session_id:s.session_id,trace_id:s.trace_id}),Ve.sessionId=s.session_id,le.updateActionConfigs(St)}if(t===exports.WebsocketTypeEnum.OUT_CALL_END)if(le.updateDisplayText(""),1===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.OUT_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)le.reset(),ae.emit(exports.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),this.putAgentState(!0),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no){le.get("isCalling")&&(le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(Qt))}else if(3===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.TRANSFER_END,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no){ae.emit(exports.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),ae.emit(exports.EventName.FAIL_NOTIFICATION,"转接失败");const A=le.get("direction");A===exports.DirectionEnum.OUTGOING?le.updateActionConfigs(Qt):A===exports.DirectionEnum.INCOMING&&le.updateActionConfigs(Ut)}else 5===s.device_type&&s.agent_no===Ve.agentInfo.agent_no&&(this.putAgentState(!0,5),Ve.monitoredAgentNo="",Ve.earSpeakAgent="",le.reset(),ae.emit(exports.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft));if(t===exports.WebsocketTypeEnum.OUT_CALL_RINGING&&1===s.type&&(ae.emit(exports.CallSipCallEventEnum.OUT_RINGING,{session_id:Ve.sessionId,type:s.type}),le.updateDisplayText(exports.DisplayTextEnum.RINGING)),t===exports.WebsocketTypeEnum.OUT_CALL_ANSWER&&(clearTimeout(Ve.autoStateTimer),le.updateIsCalling(!0),ae.emit(exports.CallSipCallEventEnum.OUT_OFF_ANSWER,{session_id:Ve.sessionId}),le.updateOutCallIsAnswer(!0),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(Qt)),t===exports.WebsocketTypeEnum.CONSULT_RINGING&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_RINGING,{session_id:s.session_id}),le.updateDisplayText(exports.DisplayTextEnum.AGENT_RINGING),le.updateActionConfigs([]),clearTimeout(Ve.autoStateTimer)),t===exports.WebsocketTypeEnum.CONSULT_ANSWER&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_OFF_HOOK,{session_id:s.session_id}),le.updateConsultIsAnswer(!0),le.updateDisplayText(exports.DisplayTextEnum.CONSULTING),le.updateActionConfigs(Tt)),t===exports.WebsocketTypeEnum.CONSULT_FAIL&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_FAILED,{custom_reason:s.custom_reason}),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(Qt)),t===exports.WebsocketTypeEnum.CONSULT_CALL_IN&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_INCOMING,{agent_no:s.agent_no,agent_mane:s.agent_name,session_id:s.session_id}),Ve.sessionId=s.session_id,le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.CONSULT),le.updateDisplayText(exports.DisplayTextEnum.CONSULT_CALL_IN),le.updateActionConfigs(Rt),Ve.enableBrowserAlert&&Ps.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{agent_mane:s.agent_name,agent_no:s.agent_no})},Ve.browserAlertTime)),t===exports.WebsocketTypeEnum.CONSULT_CALL_IN_SUCCESS&&(ae.emit(exports.CallSipCallEventEnum.CONSULT_CALL_IN_SUCCESS,{session_id:s.session_id}),le.updateConsultIsAnswer(!0),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(yt)),t===exports.WebsocketTypeEnum.CONSULT_RETURN_CALL_SUCCESS&&("success"===s.status?(le.updateConsultIsAnswer(!1),ae.emit(exports.CallSipCallEventEnum.CONSULT_RETURN_CALL_SUCCESS),le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP),le.updateActionConfigs(Qt)):ae.emit(exports.EventName.FAIL_NOTIFICATION,"媒体失败")),t===exports.WebsocketTypeEnum.MUTE&&(0===i?(le.updateIsMuted(!0),ae.emit(exports.CallSipCallEventEnum.MUTE_SUCCESS),le.updateDisplayText(exports.DisplayTextEnum.MUTING)):(ae.emit(exports.CallSipCallEventEnum.MUTE_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.UNMUTE&&(0===i?(le.updateIsMuted(!1),ae.emit(exports.CallSipCallEventEnum.UNMUTE_SUCCESS),le.updateDisplayText(exports.DisplayTextEnum.CALLING)):(ae.emit(exports.CallSipCallEventEnum.UNMUTE_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CALL_HOLD&&(0===i?(le.updateIsHold(!0),le.updateDisplayText(exports.DisplayTextEnum.HOLDING),ae.emit(exports.CallSipCallEventEnum.HOLD_SUCCESS)):(ae.emit(exports.CallSipCallEventEnum.HOLD_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CALL_UNHOLD&&(0===i?(le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateIsHold(!1),ae.emit(exports.CallSipCallEventEnum.UNHOLD_SUCCESS)):(ae.emit(exports.CallSipCallEventEnum.UNHOLD_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CONSULT_TRANSFER&&(0===i?ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_SUCCESS):(ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CONSULT_TRANSFER_FAILED&&ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,s.status),t===exports.WebsocketTypeEnum.CONSULT_TRANSFER_OFF_HOOK&&(le.updateDirection(exports.DirectionEnum.INCOMING),le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.CONSULT_TRANSFER_OFF_HOOK),le.updateActionConfigs(Ut),le.updateIncomingIsAnswer(!0),le.updateConsultIsAnswer(!1)),t===exports.WebsocketTypeEnum.INCOMING_CALL){clearTimeout(Ve.autoStateTimer),Ve.sessionId=s.session_id;try{await this.getCustomerInfo(s.trace_id||s.customer_phone)}catch(A){console.error(A)}le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.INCOMING),this.inCallAutoAnswer(),le.updateDisplayText(exports.DisplayTextEnum.INCOMING_CALL),1===s.direction&&ae.emit(exports.CallSipCallEventEnum.INCOMING_CALL,{customer_phone:s.customer_phone,trace_id:s.trace_id,session_id:s.session_id}),3===s.direction&&(ae.emit(exports.CallSipCallEventEnum.PREDICT_INCOMING_CALL,{customer_phone:s.customer_phone,trace_id:s.trace_id,session_id:s.session_id}),this.sipClient?.answerCall()),le.updateActionConfigs(Rt),Ve.enableBrowserAlert&&Ps.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})},Ve.browserAlertTime)}if(t===exports.WebsocketTypeEnum.INCOMING_CALL_OFF_HOOK&&(le.updateIncomingIsAnswer(!0),ae.emit(exports.CallSipCallEventEnum.INCOMING_CALL_OFF_HOOK,{session_id:Ve.sessionId}),le.updateActionConfigs(Ut),le.updateDisplayText(exports.DisplayTextEnum.CALLING)),t===exports.WebsocketTypeEnum.INCOMING_CALL_END)if(le.updateDisplayText(""),1===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.INCOMING_CALL_END,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)le.reset(),ae.emit(exports.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),this.putAgentState(!0),le.updateActionConfigs(ft);else if(2===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no)le.updateDisplayText(exports.DisplayTextEnum.CALLING),ae.emit(exports.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(Qt);else if(3===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no===Ve.agentInfo.agent_no)this.putAgentState(!0),le.reset(),ae.emit(exports.CallSipCallEventEnum.TRANSFER_END,{session_id:s.session_id}),le.updateActionConfigs(ft);else if(4===s.device_type&&s.agent_no!==Ve.agentInfo.agent_no){ae.emit(exports.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),ae.emit(exports.EventName.FAIL_NOTIFICATION,"转接失败");const A=le.get("direction");A===exports.DirectionEnum.OUTGOING?le.updateActionConfigs(Qt):A===exports.DirectionEnum.INCOMING&&le.updateActionConfigs(Ut)}else 5===s.device_type&&s.agent_no===Ve.agentInfo.agent_no&&(this.putAgentState(!0,5),Ve.monitoredAgentNo="",Ve.earSpeakAgent="",le.reset(),ae.emit(exports.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:s.session_id}),le.updateActionConfigs(ft));if(t===exports.WebsocketTypeEnum.SATISFACTION_EVALUATION&&(0===i?ae.emit(exports.CallSipCallEventEnum.SATISFACTION_EVALUATION_SUCCESS):(ae.emit(exports.CallSipCallEventEnum.SATISFACTION_EVALUATION_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n))),t===exports.WebsocketTypeEnum.CONSULT_THREE_WAY&&(0!==i?(ae.emit(exports.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,n),ae.emit(exports.EventName.FAIL_NOTIFICATION,n)):0===i&&le.updateIsMeeting(!0)),t===exports.WebsocketTypeEnum.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(le.updateDirection(exports.DirectionEnum.MEETING),le.updateDisplayText(exports.DisplayTextEnum.MEETING),le.updateActionConfigs(Dt),ae.emit(exports.CallSipCallEventEnum.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(exports.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),le.updateIsMeeting(!1))),t===exports.WebsocketTypeEnum.TRANSFER_INCOMING_CALL&&(clearTimeout(Ve.autoStateTimer),s.agent_no===Ve.agentInfo.agent_no?(le.updateDisplayText(exports.DisplayTextEnum.TRANSFERRING),ae.emit(exports.CallSipCallEventEnum.TRANSFER_PROGRESS),le.updateActionConfigs([]),le.updateTransferIsAnswer(!0)):(Ve.sessionId=s.session_id,ae.emit(exports.CallSipCallEventEnum.TRANSFER_INCOMING_CALL,{agent_no:s.agent_no,agent_name:s.agent_name,session_id:s.session_id}),le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.TRANSFER),le.updateDisplayText(exports.DisplayTextEnum.TRANSFER_INCOMING_CALL),le.updateActionConfigs(Rt),Ve.enableBrowserAlert&&Ps.show("📞 转接来电",`坐席 [${s.agent_no}] 正在转接...`,()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{agent_no:s.agent_no})},Ve.browserAlertTime))),t===exports.WebsocketTypeEnum.TRANSFER_OFF_HOOK&&(ae.emit(exports.CallSipCallEventEnum.TRANSFER_OFF_HOOK,{session_id:Ve.sessionId}),le.updateTransferIsAnswer(!1),le.updateDisplayText(exports.DisplayTextEnum.CALLING),le.updateActionConfigs(Ut)),t===exports.WebsocketTypeEnum.TRANSFER_FAILED&&"failed"===s.status){ae.emit(exports.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),ae.emit(exports.EventName.FAIL_NOTIFICATION,"转接失败");const A=le.get("direction");A===exports.DirectionEnum.OUTGOING?le.updateActionConfigs(Qt):A===exports.DirectionEnum.INCOMING&&le.updateActionConfigs(Ut)}t===exports.WebsocketTypeEnum.KICK_OFFLINE&&ae.emit(exports.EventName.KICK_OFF),t===exports.WebsocketTypeEnum.CONTINUOUS_NOT_ANSWER&&(ae.emit(exports.EventName.FAIL_NOTIFICATION,`已连续 ${s.miss_count} 次未接, 设置忙碌`),this.stateBusyChange()),t===exports.WebsocketTypeEnum.SIGN_OUT&&ae.emit(exports.EventName.SIGN_OUT),t===exports.WebsocketTypeEnum.SIGN_IN_SWITCH_DEVICE&&ae.emit(exports.EventName.SIGN_IN_SWITCH_DEVICE,s),t===exports.WebsocketTypeEnum.LISTEN_INCOMING_CALL&&(clearTimeout(Ve.autoStateTimer),Ve.sessionId=s.session_id,le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.INCOMING),this.inCallAutoAnswer(),le.updateDisplayText(exports.DisplayTextEnum.LISTENING),le.updateActionConfigs(Rt),ae.emit(exports.CallSipCallEventEnum.LISTEN_INCOMING_CALL,{session_id:s.session_id}),Ve.enableBrowserAlert&&Ps.show("📞 监听来电","正在来电...",()=>{ae.emit(exports.EventName.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})},Ve.browserAlertTime)),t===exports.WebsocketTypeEnum.LISTEN_INCOMING_CALL_OFF_HOOK&&(Ve.monitoredAgentNo=s.monitored_agent_no,Ve.earSpeakAgent="",le.updateIncomingIsAnswer(!0),ae.emit(exports.CallSipCallEventEnum.LISTEN_INCOMING_CALL_OFF_HOOK,{session_id:Ve.sessionId,monitored_agent_no:s.monitored_agent_no}),le.updateActionConfigs(kt),le.updateDisplayText(exports.DisplayTextEnum.CALLING)),t===exports.WebsocketTypeEnum.LISTEN_CALL_FAILED&&"failed"===s.status&&(ae.emit(exports.CallSipCallEventEnum.LISTEN_CALL_FAILED),Ve.monitoredAgentNo=""),t===exports.WebsocketTypeEnum.EAR_SPEECH&&("success"===s.status?(s.monitored_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(Gt),ae.emit(exports.CallSipCallEventEnum.EAR_SPEECH_BE_SUCCESS)),s.monitor_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(Ft),ae.emit(exports.CallSipCallEventEnum.EAR_SPEECH_SUCCESS,{monitored_agent_no:s.monitored_agent_no,monitor_agent_no:s.monitor_agent_no}),Ve.earSpeakAgent=s.monitored_agent_no)):ae.emit(exports.CallSipCallEventEnum.EAR_SPEECH_FAILED)),t===exports.WebsocketTypeEnum.STOP_EAR_SPEECH&&("success"===s.status?(s.monitored_agent_no===Ve.agentInfo.agent_no&&le.updateActionConfigs(Ut),s.monitor_agent_no===Ve.agentInfo.agent_no&&le.updateActionConfigs(kt),Ve.earSpeakAgent="",ae.emit(exports.CallSipCallEventEnum.STOP_EAR_SPEECH_SUCCESS)):ae.emit(exports.CallSipCallEventEnum.STOP_EAR_SPEECH_FAILED)),t===exports.WebsocketTypeEnum.CALL_FORCE_INSERT&&("success"===s.status?(s.monitored_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(xt),ae.emit(exports.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS,{monitored_agent_no:s.monitored_agent_no,monitor_agent_no:s.monitor_agent_no})),s.monitor_agent_no===Ve.agentInfo.agent_no&&(le.updateActionConfigs(Yt),ae.emit(exports.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS_LISTENER,{monitored_agent_no:s.monitored_agent_no,monitor_agent_no:s.monitor_agent_no}))):ae.emit(exports.CallSipCallEventEnum.CALL_FORCE_INSERT_FAILED))},this.ws.onclose=()=>{this.stopHeartbeat(),this.manualClose||setTimeout(()=>this.initWebSocket(),this.reconnectDelay)},this.ws.onerror=()=>{this.ws?.close()}}startHeartbeat(){const A=new Blob(["\n let timer;\n self.onmessage = function (e) {\n if (e.data === 'start') {\n timer = setInterval(() => {\n self.postMessage('heartbeat');\n }, 5000);\n } else if (e.data === 'stop') {\n clearInterval(timer);\n }\n };\n "],{type:"application/javascript"}),e=URL.createObjectURL(A);this.heartbeatWorker=new Worker(e),this.heartbeatWorker.onmessage=()=>{const A=(new Date).getTime();this.sendMessage({type:0,msg_id:A}),this.pendingMessages.set(A,performance.now())},this.heartbeatWorker.postMessage("start")}stopHeartbeat(){this.heartbeatWorker&&(this.heartbeatWorker.postMessage("stop"),this.heartbeatWorker.terminate(),this.heartbeatWorker=null)}sendMessage(A){this.ws?.readyState===WebSocket.OPEN?(this.ws.send(JSON.stringify(A)),0!==A.type&&Xs("%cWebSocket 发送消息:","color: green; font-weight: bold;",A)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}reconnect(){this.initWebSocket()}static __internalClose(){_s&&(_s.close(),_s=null)}static __internalSend(A){if(!_s)throw new Error("WebSocket 尚未初始化");_s.sendMessage(A)}}class Ai{constructor(A){this.sipClient=null,this.sipClient=A}roleMute(){const A=le.get("isCalling"),e=Ve.sessionId;if(!A)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));if(!e)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}))}holdCall(){this.roleMute();const A=le.get("isHold"),{sessionId:e}=Ve;if(!e)return;if(!le.get("actionConfigs").includes("hold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿保持"}));if(A)throw new Error(JSON.stringify({code:1,msg:"当前已处于保持状态"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CALL_HOLD,data:{session_id:e}})}unholdCall(){this.roleMute();const{isHold:A}=le.getState(),{sessionId:e}=Ve;if(!le.get("actionConfigs").includes("unhold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取消保持"}));if(e){if(!A)throw new Error(JSON.stringify({code:1,msg:"当前未处于保持状态"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CALL_UNHOLD,data:{session_id:e}})}}sendDTMF(A){if(1!==le.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));if(!le.get("actionConfigs").includes("dtmf"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿发送按键"}));const{isCalling:e}=le.getState();if(!e)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));this.sipClient.sendDTMF(A)}cancelCall(){if(!le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const A=Ve.sessionId;ae.emit(exports.CallSipCallEventEnum.REJECT,{session_id:A}),$s.__internalSend({type:exports.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:A}})}async consultCall(A){this.roleMute();const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=le.getState(),n=Ve.sessionId;if(!le.get("actionConfigs").includes("consult"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询"}));if(s)throw new Error(JSON.stringify({code:1,msg:"当前正在咨询"}));if(!(e||t||i))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));if(!n)throw new Error(JSON.stringify({code:1,msg:"sessionId不存在"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_REQUEST,data:{session_id:n,consultation_agent_no:A}})}async answerCall(){if(1!==le.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));await this.sipClient.answerCall()}makeCall(A){if("string"!=typeof A||""===A.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));const e={};(A=>{if(!A||"string"!=typeof A)return!1;const e=A.replace(/\s+/g,"");return e.length%4==0&&/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)})(A)?e.trace_id=A:e.customer_phone=A;const t=le.get("isCalling"),s=le.get("selectOutNumber")||"";if(t)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.OUTGOING),$s.__internalSend({type:exports.WebsocketTypeEnum.OUT_CALL,data:{...e,caller:s.replace(/[\s\r\n]+/g,"")}})}previewCall(A,e){const t={};Rs(A)?t.customer_phone=A:t.trace_id=A;const s=le.get("isCalling"),i=le.get("selectOutNumber")||"";if(s)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));if("string"!=typeof A||""===A.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));le.updateIsCalling(!0),le.updateDirection(exports.DirectionEnum.OUTGOING),$s.__internalSend({type:exports.WebsocketTypeEnum.PREVIEW_OUT_CALL,data:{...t,caller:i,preview_task_id:e}})}async hangup(){if(!le.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const A=Ve.sessionId;$s.__internalSend({type:exports.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:A}})}mute(){this.roleMute();const A=le.get("actionConfigs"),e=le.get("isMuted"),t=Ve.sessionId;if(e)throw new Error(JSON.stringify({code:1,msg:"当前未处于静音状态"}));if(!A.includes("mute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:exports.WebsocketTypeEnum.MUTE,data:{session_id:t}})}unmute(){this.roleMute();const A=le.get("actionConfigs"),e=le.get("isMuted"),t=Ve.sessionId;if(!e)throw new Error(JSON.stringify({code:1,msg:"当前未处于未静音状态"}));if(!A.includes("unmute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:exports.WebsocketTypeEnum.UNMUTE,data:{session_id:t}})}consultTransfer(){this.roleMute();const A=le.get("consultIsAnswer"),e=Ve.sessionId;if(!le.get("actionConfigs").includes("consult_transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询转移"}));if(!A)throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_TRANSFER,data:{session_id:e}})}satisfactionEvaluation(){this.roleMute();const A=Ve.sessionId;if(!le.get("actionConfigs").includes("satisfaction"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用满意度评价"}));$s.__internalSend({type:exports.WebsocketTypeEnum.SATISFACTION_EVALUATION,data:{session_id:A}})}startConference(){this.roleMute();if(!le.get("actionConfigs").includes("conference"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用三方会议"}));const A=Ve.sessionId;if(!le.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_THREE_WAY,data:{session_id:A}})}consultRetrieve(){this.roleMute();if(!le.get("actionConfigs").includes("consult_retrieve"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取回通话"}));const A=Ve.sessionId;if(!le.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:exports.WebsocketTypeEnum.CONSULT_RETURN_CALL,data:{session_id:A}})}async transferAgent(A){this.roleMute();if(!le.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));const{transferIsAnswer:e}=le.getState(),t=Ve.sessionId;if(e)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:exports.WebsocketTypeEnum.TRANSFER,data:{session_id:t,transfer_type:0,transfer_dest:A}})}async transferOutline(A){this.roleMute();if(!le.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));if(!A)throw new Error(JSON.stringify({code:1,msg:"号码不能为空"}));if(!/^\d+$/.test(A))throw new Error(JSON.stringify({code:1,msg:"号码格式错误"}));const{transferIsAnswer:e}=le.getState(),t=Ve.sessionId;if(e)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));if(e)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:exports.WebsocketTypeEnum.TRANSFER,data:{session_id:t,transfer_type:2,transfer_dest:A}})}}var ei;class ti{static{this._instance=null}#A=null;#e=new Ks;#t;#s=null;#i=!1;#n;#o;#r=!1;static{this._timer=null}#a=null;constructor(){if(!ei._creatingInstance)throw new Error("请使用 YSYTAgentSdk.getInstance() 获取实例");clearInterval(this.#s),this.#s=setInterval(async()=>{const A=await this.#V();he.updateRttObject(A)},2e3),Ps.requestMediaPermissions(),this.#n=le.subscribeKey("answerDevice",async A=>{1===A?(await this.initWebRtc(),Ve.stateObject.state===exports.AgentStatus.UNREGISTERED&&await this.#e._changeState({data:{...Ve.stateBeforeChange,state_name:Ve.stateBeforeChange.state===exports.AgentStatus.IDLE?"空闲":"忙碌"}})):await this.destroyRtc()}),this.#o=le.subscribeKey("isNextState",async A=>{if(A){await this.#e._agentLogin(xs);1===le.get("answerDevice")&&await this.#A.reconnect();let A="";const e=new URL(Gs).host;A=Gs.includes("https")?`wss://${e}`:`ws://${e}`;const{agent_no:t}=Ve.agentInfo;$s.getInstance({url:`${A}/ccs-ws/api/v1/ws/call/${t}?Authorization=`,sipClient:this.#A}),Ve.stateObject.state===exports.AgentStatus.OFFLINE&&setTimeout(()=>{this.#e._changeState({data:{...this.#a,state_name:this.#a.state===exports.AgentStatus.BUSY&&"整理"===this.#a.state_name?"忙碌":this.#a.state_name},success:()=>{le.updateDisplayText(""),ae.emit(exports.CallSipCallEventEnum.AGENT_STATE,this.#a)}})},10)}else this.#a=Ve.stateObject,$s.__internalClose(),le.updateDisplayText("离线")}),this.on(exports.EventName.KICK_OFF,()=>{this.destroy()}),window.addEventListener("online",this.#c),window.addEventListener("offline",this.#l)}#c=()=>{le.updateIsNextState(!0)};#l=()=>{le.updateIsNextState(!1)};async#h(){const A=le.get("isNextState");try{await Ns(),A||le.updateIsNextState(!0)}catch(e){A&&le.updateIsNextState(!1)}}#g(){ei._timer||(ei._timer=setInterval(()=>this.#h(),3e3))}static get instance(){return this._instance}static async destroyInstance(){this._instance&&(await this._instance.destroy(),this._instance=null)}static getInstance(A){if(!this._instance){if(!A)throw new Error("首次调用必须传入配置参数");const{url:e,appKey:t,appSecret:s,agentNo:i}=A;Gs=e||"https://aicc-api.yescloudy.com",Fs=t,Ys=s,xs=i,ei._creatingInstance=!0,this._instance=new ei,delete ei._creatingInstance,window.addEventListener("beforeunload",()=>{this._instance?.destroy()})}return this._instance}getInit(){return this.#r}async initWebRtc(){if(this.#A)return;const A=Ve.agentInfo.sip_account_list.find(A=>1===A.device_type);if(!A)throw new Error(JSON.stringify({code:1,msg:"未找到 sip_account_list"}));{const e=A.sip_register_addr;this.#A=new ge({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#q),await this.#A.start()}}async init({actionNodeParams:A,enableBrowserAlert:e,logBuiltinEnabled:t,browserAlertTime:s,initialState:i,initDevice:n}){try{const{viewHtmlElement:o,rttHTML:r}=A||{};Ve.logBuiltinEnabled=t||!1,Ve.browserAlertTime=s||5e3,await this.#e._agentLogin(xs);const{agent_no:a,current_answer_device:V,current_state:c,out_display_number:l,out_display_select_switch:h}=Ve.agentInfo;(i||c)===exports.AgentStatus.IDLE?(le.updateActionConfigs(ft),Ve.stateObject={state:i||c,state_name:"空闲"},Ve.stateBeforeChange=Ve.stateObject):(i||c)===exports.AgentStatus.BUSY&&(le.updateActionConfigs(Bt),Ve.stateObject={state:c,state_name:"忙碌"},Ve.stateBeforeChange=Ve.stateObject),1===h?le.updateSelectOutNumber(l):le.updateSelectOutNumber("");let g="";const q=new URL(Gs).host;g=Gs.includes("https")?`wss://${q}`:`ws://${q}`,le.updateAnswerDevice(n||V),1===(n||V)&&await this.initWebRtc(),setTimeout(()=>{this.#e._changeState({data:Ve.stateObject}),this.#e.changeDevice({data:{device:n||V}})},500),$s.getInstance({url:`${g}/ccs-ws/api/v1/ws/call/${a}?Authorization=`,sipClient:this.#A}),this.#t=new Ai(this.#A),A&&o&&(this.#i=!0,new Ws({container:o,rttHTML:r,statusParams:{state:exports.AgentStatus.IDLE,statusName:"空闲"}},this,this.#t)),Ve.enableBrowserAlert=e,e&&Ps.requestPermission(),ae.emit(exports.EventName.AGENT_INIT_STATUS,!0),this.#r=!0,clearInterval(ei._timer),ei._timer=null,this.#g()}catch(A){this.#i&&Hs("初始化失败"),ae.emit(exports.EventName.AGENT_INIT_STATUS,!1),this.#r=!1}}#q=A=>{const{type:e,data:t}=A;ae.emit(e,t)};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}async destroyRtc(){await(this.#A?.destroy()),this.#A=null}async destroy(){ei._instance&&(await this.destroyRtc(),clearInterval(this.#s),$s.__internalClose(),ae.emit(exports.EventName.DESTROY),this.offAll(),this.#n?.(),this.#o?.(),this.#i=!1,ei._instance=null,le.reset(),le.updateSelectOutNumber(""),clearInterval(ei._timer),ei._timer=null)}async#V(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){const A=A=>(...e)=>{if(!this.#i)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{answerCall:A(()=>this.#t.answerCall()),makeCall:A=>this.#t.makeCall(A),previewMakeCall:(A,e)=>this.#t.previewCall(A,e),cancelCall:A(()=>this.#t.cancelCall()),hangup:A(()=>this.#t.hangup()),sendDTMF:A(A=>this.#t.sendDTMF(A)),holdCall:A(()=>this.#t.holdCall()),unholdCall:A(()=>this.#t.unholdCall()),consultCall:A(async A=>{try{await this.#t.consultCall(A)}catch(A){throw console.warn(A),A}}),consultRetrieve:A(()=>this.#t.consultRetrieve()),consultTransfer:A(()=>this.#t.consultTransfer()),mute:A(()=>this.#t.mute()),unmute:A(()=>this.#t.unmute()),satisfactionEvaluation:A(()=>this.#t.satisfactionEvaluation()),startConference:A(()=>this.#t.startConference()),transferAgent:A(A=>this.#t.transferAgent(A)),transferOutline:A(A=>this.#t.transferOutline(A)),earSpeakStart:A(A=>this.#e.earCall(A)),earSpeakStop:A(A=>this.#e.stopEarCall(A)),forceInsert:A(A=>this.#e.forceInsert(A)),forceDisconnect:A(A=>this.#e.forceDisconnect(A))}}get agent_api(){const A=A=>(...e)=>{if(!this.#i)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{changeDevice:A(A=>this.#e.changeDevice(A)),changeState:A(A=>this.#e.changeState(A)),getIdleAgentList:A(A=>this.#e.getIdleAgentList(A)),getAgentState:A(A=>this.#e.getAgentState(A)),setAgentExplicit:A(A=>this.#e.setAgentExplicit(A)),checkAgentLogin:A=>this.#e.checkAgentLogin(A),getCallRecord:A=>this.#e.getCallRecord(A),agentLogout:async(A,e)=>{try{await this.#e.logout(A),await this.destroy(),e?.({code:0,msg:""})}catch(A){}},listenAgentCall:A=>this.#e.listenCall(A)}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t,out_display_data:s,out_display_select_switch:i,current_state:n}=Ve.agentInfo,{stateObject:o}=Ve,r={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,init_state:n,default_device:le.get("answerDevice"),out_display_data:s,out_display_select_switch:i,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:r[Number(A)]})),stateObject:o}}async getRealTimeCustomerInfo(){return le.get("customerObject")}setBrowserAlert(A){if("boolean"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));Ve.logBuiltinEnabled=A||!1}setBrowserAlertTime(A){if("number"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));Ve.browserAlertTime=A||3e3}}ei=ti,exports.default=ti;