ysyt-agent-sdk 1.1.26 → 1.1.28
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.
|
@@ -524,7 +524,7 @@ const Nt=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
|
-
!function(A){!function(){var s="input is invalid type",i="object"==typeof window,n=i?window:{};n.JS_MD5_NO_WINDOW&&(i=!1);var o=!i&&"object"==typeof self,r=!n.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;r?n=Qs:o&&(n=self);var a,V=!n.JS_MD5_NO_COMMON_JS&&A.exports,c=!n.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),h=[128,32768,8388608,-2147483648],g=[0,8,16,24],q=["hex","array","digest","buffer","arrayBuffer","base64"],d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),u=[];if(c){var p=new ArrayBuffer(68);a=new Uint8Array(p),u=new Uint32Array(p)}var m=Array.isArray;!n.JS_MD5_NO_NODE_JS&&m||(m=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var C=ArrayBuffer.isView;!c||!n.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&C||(C=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var E=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(s);if(c&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!m(A)&&!C(A))throw new Error(s);return[A,!1]},I=function(A){return function(e){return new f(!0).update(e)[A]()}},M=function(A){var i,o=e,r=t.Buffer;i=r.from&&!n.JS_MD5_NO_BUFFER_FROM?r.from:function(A){return new r(A)};return function(e){if("string"==typeof e)return o.createHash("md5").update(e,"utf8").digest("hex");if(null==e)throw new Error(s);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),m(e)||C(e)||e.constructor===r?o.createHash("md5").update(i(e)).digest("hex"):A(e)}},w=function(A){return function(e,t){return new B(e,!0).update(t)[A]()}};function f(A){if(A)u[0]=u[16]=u[1]=u[2]=u[3]=u[4]=u[5]=u[6]=u[7]=u[8]=u[9]=u[10]=u[11]=u[12]=u[13]=u[14]=u[15]=0,this.blocks=u,this.buffer8=a;else if(c){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 B(A,e){var t,s=E(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 f(!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}f.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}f.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=E(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(c)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<<g[3&s++]:t<2048?(r[s>>>2]|=(192|t>>>6)<<g[3&s++],r[s>>>2]|=(128|63&t)<<g[3&s++]):t<55296||t>=57344?(r[s>>>2]|=(224|t>>>12)<<g[3&s++],r[s>>>2]|=(128|t>>>6&63)<<g[3&s++],r[s>>>2]|=(128|63&t)<<g[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++n)),r[s>>>2]|=(240|t>>>18)<<g[3&s++],r[s>>>2]|=(128|t>>>12&63)<<g[3&s++],r[s>>>2]|=(128|t>>>6&63)<<g[3&s++],r[s>>>2]|=(128|63&t)<<g[3&s++]);else if(c)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]<<g[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},f.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=h[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()}},f.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)},f.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return l[A>>>4&15]+l[15&A]+l[A>>>12&15]+l[A>>>8&15]+l[A>>>20&15]+l[A>>>16&15]+l[A>>>28&15]+l[A>>>24&15]+l[e>>>4&15]+l[15&e]+l[e>>>12&15]+l[e>>>8&15]+l[e>>>20&15]+l[e>>>16&15]+l[e>>>28&15]+l[e>>>24&15]+l[t>>>4&15]+l[15&t]+l[t>>>12&15]+l[t>>>8&15]+l[t>>>20&15]+l[t>>>16&15]+l[t>>>28&15]+l[t>>>24&15]+l[s>>>4&15]+l[15&s]+l[s>>>12&15]+l[s>>>8&15]+l[s>>>20&15]+l[s>>>16&15]+l[s>>>28&15]+l[s>>>24&15]},f.prototype.toString=f.prototype.hex,f.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]},f.prototype.array=f.prototype.digest,f.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},f.prototype.buffer=f.prototype.arrayBuffer,f.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+=d[A>>>2]+d[63&(A<<4|e>>>4)]+d[63&(e<<2|t>>>6)]+d[63&t];return A=i[n],s+=d[A>>>2]+d[A<<4&63]+"=="},B.prototype=new f,B.prototype.finalize=function(){if(f.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();f.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),f.prototype.finalize.call(this)}};var S=function(){var A=I("hex");r&&(A=M(A)),A.create=function(){return new f},A.update=function(e){return A.create().update(e)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=I(t)}return A}();S.md5=S,S.md5.hmac=function(){var A=w("hex");A.create=function(A){return new B(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=w(t)}return A}(),V?A.exports=S:n.md5=S}()}(Ts);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="",vs="";function Zs(){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 Os(A,e){const t=Zs(),s="api/"+A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const Ns=A=>Os(`${ks}/state/change`,A),xs=()=>async function(A,e){const t=Zs(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}("/heartbeat",{});class Ks{constructor(){this.roleData={agentInfo:()=>{if(!ce.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}=ce.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}=ce.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(e){try{const A=await(t={agent_no:e},Os(`${ks}/agent/login`,t));ce.agentInfo=A.data}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}var t}async _changeState(e){try{ce.autoStateTimer&&(clearTimeout(ce.autoStateTimer),ce.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:n}=t,{agent_no:o}=ce.agentInfo;await Ns({agent_no:o,state_name:n,state:i}),i===A.AgentStatus.IDLE?he.updateActionConfigs(Bt):i===A.AgentStatus.BUSY&&he.updateActionConfigs(St),ce.stateObject={state:i,state_name:n},s?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async _getInCallCrmDetail(e){try{const{phone:A}=e.data,t={};Rs(A)?t.phone=A:t.trace_id=A;const s=await(A=>Os(`${Us}/crm/popups`,A))({...t});e.success?.(s)}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async changeDevice(e){try{if(he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;1===i&&he.updateAnswerDevice(i),this.roleData.changeDevice(i);const{agent_no:n}=ce.agentInfo;await(A=>Os(`${ks}/device/change`,A))({agent_no:n,answer_device:i}),he.updateAnswerDevice(i);const o=he.get("actionConfigs");he.updateActionConfigs(o),2===i&&ce.stateObject.state===A.AgentStatus.UNREGISTERED&&await this._changeState({data:{...ce.stateBeforeChange,state_name:ce.stateBeforeChange.state===A.AgentStatus.IDLE?"空闲":"忙碌"}}),s?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async changeState(e){try{if(he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));ce.autoStateTimer&&(clearTimeout(ce.autoStateTimer),ce.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:n}=t;this.roleData.changeState(i,n);const{agent_no:o}=ce.agentInfo;await Ns({agent_no:o,state_name:n,state:i}),(ce.stateObject.state===A.AgentStatus.IDLE||ce.stateObject.state===A.AgentStatus.BUSY&&"整理"!==n)&&(ce.stateBeforeChange=ce.stateObject),i===A.AgentStatus.IDLE?he.updateActionConfigs(Bt):i===A.AgentStatus.BUSY&&he.updateActionConfigs(St),ce.stateObject={state:i,state_name:n},s?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async getIdleAgentList(e){const{agent_no:t}=ce.agentInfo;try{this.roleData.agentInfo();const A=await(A=>Os(`${ks}/agent/free`,A))({agent_no:t});e.success?.(A)}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async getAgentState(e){try{const A=await Os(`${Us}/agent/statecfg/list`,{}),t=(A.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();e.success?.({...A,data:t})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async setAgentExplicit(e){try{this.roleData.agentInfo(),this.roleData.requestInfo(e),this.roleData.setAgentExplicit(e.data.number);const{agent_id:A}=ce.agentInfo;await(A=>Os(`${Us}/agent/update`,A))({agent_id:A,out_display_number:e.data.number}),he.updateSelectOutNumber(e.data.number),e.success?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async checkAgentLogin(e){try{this.roleData.requestInfo(e);const{agent_no:A}=e.data;if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "agent_no" is required'}));const t=await(A=>Os(`${ks}/agent/islogin`,A))({agent_no:A});e.success?.(t)}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async getCallRecord(e){try{this.roleData.agentInfo();const{success:A}=e,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}=ce.agentInfo,r=await(A=>Os(`${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;A?.({code:a,msg:V,data:c})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async logout(e){this.roleData.agentInfo();try{const{agent_no:A}=ce.agentInfo,{data:t,success:s}=e;await(A=>Os(`${ks}/agent/logout`,A))({...t,agent_no:A}),s?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async listenCall(e){try{const{agent_no:A}=ce.agentInfo,{data:t,success:s}=e;if(this.roleData.agentInfo(),this.roleData.requestInfo(e),!t.monitored_agent_no)throw new Error(JSON.stringify({code:1,msg:'Parameter "monitored_agent_no" is required'}));await(A=>Os(`${ks}/call/monitor`,A))({...t,monitor_agent_no:A}),ce.monitoredAgentNo=t.monitored_agent_no,s?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async earCall(e){try{const{agentInfo:A,monitoredAgentNo:t}=ce,{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Os(`${ks}/call/whisper`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async stopEarCall(e){try{const{agentInfo:A,earSpeakAgent:t}=ce;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前没有正在耳语的坐席"}));const{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;await(A=>Os(`${ks}/call/stopwhisper`,A))({monitor_agent_no:s,monitored_agent_no:t}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async forceInsert(e){try{const{agentInfo:A,monitoredAgentNo:t}=ce,{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Os(`${ks}/call/bargein`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async forceDisconnect(e){try{const{agentInfo:A,monitoredAgentNo:t}=ce,{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Os(`${ks}/call/intercept`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}}let bs=class extends It{constructor(){super(...arguments),this.type="info",this.content="",this.duration=3e3}static{this.styles=Ee`
|
|
527
|
+
!function(A){!function(){var s="input is invalid type",i="object"==typeof window,n=i?window:{};n.JS_MD5_NO_WINDOW&&(i=!1);var o=!i&&"object"==typeof self,r=!n.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;r?n=Qs:o&&(n=self);var a,V=!n.JS_MD5_NO_COMMON_JS&&A.exports,c=!n.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),h=[128,32768,8388608,-2147483648],g=[0,8,16,24],q=["hex","array","digest","buffer","arrayBuffer","base64"],d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),u=[];if(c){var p=new ArrayBuffer(68);a=new Uint8Array(p),u=new Uint32Array(p)}var m=Array.isArray;!n.JS_MD5_NO_NODE_JS&&m||(m=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var C=ArrayBuffer.isView;!c||!n.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&C||(C=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var E=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(s);if(c&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!m(A)&&!C(A))throw new Error(s);return[A,!1]},I=function(A){return function(e){return new f(!0).update(e)[A]()}},M=function(A){var i,o=e,r=t.Buffer;i=r.from&&!n.JS_MD5_NO_BUFFER_FROM?r.from:function(A){return new r(A)};return function(e){if("string"==typeof e)return o.createHash("md5").update(e,"utf8").digest("hex");if(null==e)throw new Error(s);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),m(e)||C(e)||e.constructor===r?o.createHash("md5").update(i(e)).digest("hex"):A(e)}},w=function(A){return function(e,t){return new B(e,!0).update(t)[A]()}};function f(A){if(A)u[0]=u[16]=u[1]=u[2]=u[3]=u[4]=u[5]=u[6]=u[7]=u[8]=u[9]=u[10]=u[11]=u[12]=u[13]=u[14]=u[15]=0,this.blocks=u,this.buffer8=a;else if(c){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 B(A,e){var t,s=E(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 f(!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}f.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}f.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=E(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(c)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<<g[3&s++]:t<2048?(r[s>>>2]|=(192|t>>>6)<<g[3&s++],r[s>>>2]|=(128|63&t)<<g[3&s++]):t<55296||t>=57344?(r[s>>>2]|=(224|t>>>12)<<g[3&s++],r[s>>>2]|=(128|t>>>6&63)<<g[3&s++],r[s>>>2]|=(128|63&t)<<g[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++n)),r[s>>>2]|=(240|t>>>18)<<g[3&s++],r[s>>>2]|=(128|t>>>12&63)<<g[3&s++],r[s>>>2]|=(128|t>>>6&63)<<g[3&s++],r[s>>>2]|=(128|63&t)<<g[3&s++]);else if(c)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]<<g[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},f.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=h[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()}},f.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)},f.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return l[A>>>4&15]+l[15&A]+l[A>>>12&15]+l[A>>>8&15]+l[A>>>20&15]+l[A>>>16&15]+l[A>>>28&15]+l[A>>>24&15]+l[e>>>4&15]+l[15&e]+l[e>>>12&15]+l[e>>>8&15]+l[e>>>20&15]+l[e>>>16&15]+l[e>>>28&15]+l[e>>>24&15]+l[t>>>4&15]+l[15&t]+l[t>>>12&15]+l[t>>>8&15]+l[t>>>20&15]+l[t>>>16&15]+l[t>>>28&15]+l[t>>>24&15]+l[s>>>4&15]+l[15&s]+l[s>>>12&15]+l[s>>>8&15]+l[s>>>20&15]+l[s>>>16&15]+l[s>>>28&15]+l[s>>>24&15]},f.prototype.toString=f.prototype.hex,f.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]},f.prototype.array=f.prototype.digest,f.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},f.prototype.buffer=f.prototype.arrayBuffer,f.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+=d[A>>>2]+d[63&(A<<4|e>>>4)]+d[63&(e<<2|t>>>6)]+d[63&t];return A=i[n],s+=d[A>>>2]+d[A<<4&63]+"=="},B.prototype=new f,B.prototype.finalize=function(){if(f.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();f.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),f.prototype.finalize.call(this)}};var S=function(){var A=I("hex");r&&(A=M(A)),A.create=function(){return new f},A.update=function(e){return A.create().update(e)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=I(t)}return A}();S.md5=S,S.md5.hmac=function(){var A=w("hex");A.create=function(A){return new B(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=w(t)}return A}(),V?A.exports=S:n.md5=S}()}(Ts);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="",vs="";function Zs(){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 Os(A,e){const t=Zs(),s="api/"+A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const Ns=A=>Os(`${ks}/state/change`,A),xs=()=>async function(A,e){const t=Zs(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}("/heartbeat",{});class Ks{constructor(){this.roleData={agentInfo:()=>{if(!ce.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}=ce.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}=ce.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(e){try{const A=await(t={agent_no:e},Os(`${ks}/agent/login`,t));ce.agentInfo=A.data}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}var t}async _changeState(e){try{ce.autoStateTimer&&(clearTimeout(ce.autoStateTimer),ce.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:n}=t,{agent_no:o}=ce.agentInfo;await Ns({agent_no:o,state_name:n,state:i}),i===A.AgentStatus.IDLE?he.updateActionConfigs(Bt):i===A.AgentStatus.BUSY&&he.updateActionConfigs(St),ce.stateObject={state:i,state_name:n},s?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async _getInCallCrmDetail(e){try{const{phone:A}=e.data,t={};Rs(A)?t.phone=A:t.trace_id=A;const s=await(A=>Os(`${Us}/crm/popups`,A))({...t});e.success?.(s)}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async changeDevice(e){try{if(he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;1===i&&he.updateAnswerDevice(i),this.roleData.changeDevice(i);const{agent_no:n}=ce.agentInfo;await(A=>Os(`${ks}/device/change`,A))({agent_no:n,answer_device:i}),he.updateAnswerDevice(i);const o=he.get("actionConfigs");he.updateActionConfigs(o),2===i&&ce.stateObject.state===A.AgentStatus.UNREGISTERED&&await this._changeState({data:{...ce.stateBeforeChange,state_name:ce.stateBeforeChange.state===A.AgentStatus.IDLE?"空闲":"忙碌"}}),s?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async changeState(e){try{if(he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前正在通话中,请勿切换设备"}));ce.autoStateTimer&&(clearTimeout(ce.autoStateTimer),ce.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:n}=t;this.roleData.changeState(i,n);const{agent_no:o}=ce.agentInfo;await Ns({agent_no:o,state_name:n,state:i}),(ce.stateObject.state===A.AgentStatus.IDLE||ce.stateObject.state===A.AgentStatus.BUSY&&"整理"!==n)&&(ce.stateBeforeChange=ce.stateObject),i===A.AgentStatus.IDLE?he.updateActionConfigs(Bt):i===A.AgentStatus.BUSY&&he.updateActionConfigs(St),ce.stateObject={state:i,state_name:n},s?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async getIdleAgentList(e){const{agent_no:t}=ce.agentInfo;try{this.roleData.agentInfo();const A=await(A=>Os(`${ks}/agent/free`,A))({agent_no:t});e.success?.(A)}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async getAgentState(e){try{const A=await Os(`${Us}/agent/statecfg/list`,{}),t=(A.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();e.success?.({...A,data:t})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async setAgentExplicit(e){try{this.roleData.agentInfo(),this.roleData.requestInfo(e),this.roleData.setAgentExplicit(e.data.number);const{agent_id:A}=ce.agentInfo;await(A=>Os(`${Us}/agent/update`,A))({agent_id:A,out_display_number:e.data.number}),he.updateSelectOutNumber(e.data.number),e.success?.({code:0,msg:"请求成功"})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async checkAgentLogin(e){try{this.roleData.requestInfo(e);const{agent_no:A}=e.data;if(!A)throw new Error(JSON.stringify({code:1,msg:'Parameter "agent_no" is required'}));const t=await(A=>Os(`${ks}/agent/islogin`,A))({agent_no:A});e.success?.(t)}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async getCallRecord(e){try{this.roleData.agentInfo();const{success:A}=e,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}=ce.agentInfo,r=await(A=>Os(`${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;A?.({code:a,msg:V,data:c})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async logout(e){this.roleData.agentInfo();try{const{agent_no:A}=ce.agentInfo,{data:t,success:s}=e;await(A=>Os(`${ks}/agent/logout`,A))({...t,agent_no:A}),s?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async listenCall(e){try{const{agent_no:A}=ce.agentInfo,{data:t,success:s}=e;if(this.roleData.agentInfo(),this.roleData.requestInfo(e),!t.monitored_agent_no)throw new Error(JSON.stringify({code:1,msg:'Parameter "monitored_agent_no" is required'}));await(A=>Os(`${ks}/call/monitor`,A))({...t,monitor_agent_no:A}),ce.monitoredAgentNo=t.monitored_agent_no,s?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async earCall(e){try{const{agentInfo:A,monitoredAgentNo:t}=ce,{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Os(`${ks}/call/whisper`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async stopEarCall(e){try{const{agentInfo:A,earSpeakAgent:t}=ce;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前没有正在耳语的坐席"}));const{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;await(A=>Os(`${ks}/call/stopwhisper`,A))({monitor_agent_no:s,monitored_agent_no:t}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async forceInsert(e){try{const{agentInfo:A,monitoredAgentNo:t}=ce,{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Os(`${ks}/call/bargein`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}async forceDisconnect(e){try{const{agentInfo:A,monitoredAgentNo:t}=ce,{agent_no:s}=A;this.roleData.agentInfo();const{success:i}=e;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未有监听坐席"}));await(A=>Os(`${ks}/call/intercept`,A))({monitored_agent_no:t,monitor_agent_no:s}),i?.({code:0,msg:""})}catch(e){throw Ve.emit(A.EventName.FAIL_NOTIFICATION,JSON.parse(e.message).msg),e}}}let bs=class extends It{constructor(){super(...arguments),this.type="info",this.content="",this.duration=3e3}static{this.styles=Ee`
|
|
528
528
|
:host {
|
|
529
529
|
display: block;
|
|
530
530
|
margin-top: 10px;
|
|
@@ -911,4 +911,4 @@ const Nt=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
|
|
|
911
911
|
`:""}
|
|
912
912
|
</div>
|
|
913
913
|
</my-popover>
|
|
914
|
-
`;Ct(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)=>{ce.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:e}=ce.stateObject;e!==A.AgentStatus.IDLE&&(ce.stateBeforeChange,this.apiClient._changeState({data:{...ce.stateBeforeChange,state_name:ce.stateBeforeChange.state===A.AgentStatus.IDLE?"空闲":"忙碌"}}))}inCallAutoAnswer(){const{soft_device_auto_answer:e,auto_answer_time:t}=ce.agentInfo,s=1===e,i=he.get("direction");if(s&&i===A.DirectionEnum.INCOMING){const A=Number(t)||0;A>0&&(ce.autoAnswerTimer=setTimeout(()=>{this.sipClient?.answerCall(),ce.autoAnswerTimer=null},1e3*A))}}async getCustomerInfo(A){try{await this.apiClient._getInCallCrmDetail({data:{phone:A},success:A=>{he.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(e,t){if(!e)return;if(5===t)return void this.stateIdleChange();ce.sessionId="";const{post_call_process_time:s}=ce.agentInfo,i=s||0;if(ce.autoStateTimer&&(clearTimeout(ce.autoStateTimer),ce.autoStateTimer=null),he.updateCustomerInfo(void 0),i>0){const{state:e}=ce.stateObject;if(e===A.AgentStatus.IDLE)return;this.apiClient._changeState({data:{state:A.AgentStatus.BUSY,state_name:"整理"}}),ce.autoStateTimer=setTimeout(()=>{ce.autoStateTimer=null,this.stateIdleChange()},1e3*i)}else this.stateIdleChange()}stateBusyChange(){ce.sessionId="",clearTimeout(ce.autoStateTimer),he.updateCustomerInfo(void 0),this.apiClient._changeState({data:{state:A.AgentStatus.BUSY,state_name:"忙碌"}})}initWebSocket(){if(1===this.ws?.readyState)return;const e=Ds(Fs,Ys);this.ws=new WebSocket(this.url+e),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 e=>{const t=JSON.parse(e.data),{type:s,data:i,code:n,msg:o,msg_id:r}=t;if(0===s&&r){const A=this.pendingMessages.get(r),e=performance.now()-A;ce.latency=parseFloat(e.toFixed(2)),this.pendingMessages.delete(r)}if(0!==s&&Xs("%cWebSocket 收到消息:","color: blue; font-weight: bold;",t),s!==A.WebsocketTypeEnum.OUT_CALL&&s!==A.WebsocketTypeEnum.PREVIEW_OUT_CALL||(0!==n?(he.reset(),Ve.emit(A.CallSipCallEventEnum.OUT_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o),he.updateActionConfigs(Bt),setTimeout(()=>{he.updateCustomerInfo(void 0)},500),this.stateIdleChange()):0===n&&(Ve.emit(A.CallSipCallEventEnum.OUT_SUCCESS),clearTimeout(ce.autoStateTimer))),s===A.WebsocketTypeEnum.AGENT_STATE){const{state:e,state_name:t}=i;ce.stateObject={state:e,state_name:t},"振铃中"===t&&he.updateDisplayText(A.DisplayTextEnum.AGENT_RINGING),e===A.AgentStatus.UNREGISTERED&&he.updateActionConfigs(ft),e===A.AgentStatus.IDLE&&ce.stateObject.state===A.AgentStatus.UNREGISTERED&&he.updateActionConfigs(Bt),Ve.emit(A.CallSipCallEventEnum.AGENT_STATE,{state:e,state_name:t})}if(s===A.WebsocketTypeEnum.OUT_CALL_INCOMING_CALL){try{await this.getCustomerInfo(i.trace_id||i.customer_phone)}catch(A){console.error(A)}i.preview_task_id?Ve.emit(A.CallSipCallEventEnum.PREVIEW_OUT_INCOMING_CALL,{customer_phone:i.customer_phone,session_id:i.session_id,preview_task_id:i.preview_task_id,trace_id:i.trace_id}):Ve.emit(A.CallSipCallEventEnum.OUT_INCOMING_CALL,{customer_phone:i.customer_phone,session_id:i.session_id,trace_id:i.trace_id}),ce.sessionId=i.session_id,he.updateActionConfigs(Qt)}if(s===A.WebsocketTypeEnum.OUT_CALL_END)if(he.updateDisplayText(""),1===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.OUT_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no===ce.agentInfo.agent_no)he.reset(),Ve.emit(A.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),this.putAgentState(!0),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no!==ce.agentInfo.agent_no){he.get("isCalling")&&(he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Tt))}else if(3===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.TRANSFER_END,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no!==ce.agentInfo.agent_no){Ve.emit(A.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),Ve.emit(A.EventName.FAIL_NOTIFICATION,"转接失败");const e=he.get("direction");e===A.DirectionEnum.OUTGOING?he.updateActionConfigs(Tt):e===A.DirectionEnum.INCOMING&&he.updateActionConfigs(kt)}else 5===i.device_type&&i.agent_no===ce.agentInfo.agent_no&&(this.putAgentState(!0,5),ce.monitoredAgentNo="",ce.earSpeakAgent="",he.reset(),Ve.emit(A.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt));if(s===A.WebsocketTypeEnum.OUT_CALL_RINGING&&1===i.type&&(Ve.emit(A.CallSipCallEventEnum.OUT_RINGING,{session_id:ce.sessionId,type:i.type}),he.updateDisplayText(A.DisplayTextEnum.RINGING)),s===A.WebsocketTypeEnum.OUT_CALL_ANSWER&&(clearTimeout(ce.autoStateTimer),he.updateIsCalling(!0),Ve.emit(A.CallSipCallEventEnum.OUT_OFF_ANSWER,{session_id:ce.sessionId}),he.updateOutCallIsAnswer(!0),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(Tt)),s===A.WebsocketTypeEnum.CONSULT_RINGING&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_RINGING,{session_id:i.session_id}),he.updateDisplayText(A.DisplayTextEnum.AGENT_RINGING),he.updateActionConfigs([]),clearTimeout(ce.autoStateTimer)),s===A.WebsocketTypeEnum.CONSULT_ANSWER&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_OFF_HOOK,{session_id:i.session_id}),he.updateConsultIsAnswer(!0),he.updateDisplayText(A.DisplayTextEnum.CONSULTING),he.updateActionConfigs(yt)),s===A.WebsocketTypeEnum.CONSULT_FAIL&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_FAILED,{custom_reason:i.custom_reason}),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(Tt)),s===A.WebsocketTypeEnum.CONSULT_CALL_IN&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_INCOMING,{agent_no:i.agent_no,agent_mane:i.agent_name,session_id:i.session_id}),ce.sessionId=i.session_id,he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.CONSULT),he.updateDisplayText(A.DisplayTextEnum.CONSULT_CALL_IN),he.updateActionConfigs(Ut),ce.enableBrowserAlert&&Ps.show("📞 咨询来电",`坐席 [${i.agent_name}] 正在咨询...`,()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{agent_mane:i.agent_name,agent_no:i.agent_no})},ce.browserAlertTime)),s===A.WebsocketTypeEnum.CONSULT_CALL_IN_SUCCESS&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_CALL_IN_SUCCESS,{session_id:i.session_id}),he.updateConsultIsAnswer(!0),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(Dt)),s===A.WebsocketTypeEnum.CONSULT_RETURN_CALL_SUCCESS&&("success"===i.status?(he.updateConsultIsAnswer(!1),Ve.emit(A.CallSipCallEventEnum.CONSULT_RETURN_CALL_SUCCESS),he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP),he.updateActionConfigs(Tt)):Ve.emit(A.EventName.FAIL_NOTIFICATION,"媒体失败")),s===A.WebsocketTypeEnum.MUTE&&(0===n?(he.updateIsMuted(!0),Ve.emit(A.CallSipCallEventEnum.MUTE_SUCCESS),he.updateDisplayText(A.DisplayTextEnum.MUTING)):(Ve.emit(A.CallSipCallEventEnum.MUTE_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.UNMUTE&&(0===n?(he.updateIsMuted(!1),Ve.emit(A.CallSipCallEventEnum.UNMUTE_SUCCESS),he.updateDisplayText(A.DisplayTextEnum.CALLING)):(Ve.emit(A.CallSipCallEventEnum.UNMUTE_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CALL_HOLD&&(0===n?(he.updateIsHold(!0),he.updateDisplayText(A.DisplayTextEnum.HOLDING),Ve.emit(A.CallSipCallEventEnum.HOLD_SUCCESS)):(Ve.emit(A.CallSipCallEventEnum.HOLD_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CALL_UNHOLD&&(0===n?(he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateIsHold(!1),Ve.emit(A.CallSipCallEventEnum.UNHOLD_SUCCESS)):(Ve.emit(A.CallSipCallEventEnum.UNHOLD_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CONSULT_TRANSFER&&(0===n?Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_SUCCESS):(Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CONSULT_TRANSFER_FAILED&&Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,i.status),s===A.WebsocketTypeEnum.CONSULT_TRANSFER_OFF_HOOK&&(he.updateDirection(A.DirectionEnum.INCOMING),he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_OFF_HOOK),he.updateActionConfigs(kt),he.updateIncomingIsAnswer(!0),he.updateConsultIsAnswer(!1)),s===A.WebsocketTypeEnum.INCOMING_CALL){clearTimeout(ce.autoStateTimer),ce.sessionId=i.session_id;try{await this.getCustomerInfo(i.trace_id||i.customer_phone)}catch(A){console.error(A)}he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.INCOMING),this.inCallAutoAnswer(),he.updateDisplayText(A.DisplayTextEnum.INCOMING_CALL),1===i.direction&&Ve.emit(A.CallSipCallEventEnum.INCOMING_CALL,{customer_phone:i.customer_phone,trace_id:i.trace_id,session_id:i.session_id}),3===i.direction&&(Ve.emit(A.CallSipCallEventEnum.PREDICT_INCOMING_CALL,{customer_phone:i.customer_phone,trace_id:i.trace_id,session_id:i.session_id}),this.sipClient?.answerCall()),he.updateActionConfigs(Ut),ce.enableBrowserAlert&&Ps.show("📞 客户来电",`客户 [${i.customer_phone}] 正在呼入...`,()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{customer_phone:i.customer_phone})},ce.browserAlertTime)}if(s===A.WebsocketTypeEnum.INCOMING_CALL_OFF_HOOK&&(he.updateIncomingIsAnswer(!0),Ve.emit(A.CallSipCallEventEnum.INCOMING_CALL_OFF_HOOK,{session_id:ce.sessionId}),he.updateActionConfigs(kt),he.updateDisplayText(A.DisplayTextEnum.CALLING)),s===A.WebsocketTypeEnum.INCOMING_CALL_END)if(he.updateDisplayText(""),1===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.INCOMING_CALL_END,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no===ce.agentInfo.agent_no)he.reset(),Ve.emit(A.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),this.putAgentState(!0),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no!==ce.agentInfo.agent_no)he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Tt);else if(3===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.TRANSFER_END,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no!==ce.agentInfo.agent_no){Ve.emit(A.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),Ve.emit(A.EventName.FAIL_NOTIFICATION,"转接失败");const e=he.get("direction");e===A.DirectionEnum.OUTGOING?he.updateActionConfigs(Tt):e===A.DirectionEnum.INCOMING&&he.updateActionConfigs(kt)}else 5===i.device_type&&i.agent_no===ce.agentInfo.agent_no&&(this.putAgentState(!0,5),ce.monitoredAgentNo="",ce.earSpeakAgent="",he.reset(),Ve.emit(A.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt));if(s===A.WebsocketTypeEnum.SATISFACTION_EVALUATION&&(0===n?Ve.emit(A.CallSipCallEventEnum.SATISFACTION_EVALUATION_SUCCESS):(Ve.emit(A.CallSipCallEventEnum.SATISFACTION_EVALUATION_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CONSULT_THREE_WAY&&(0!==n?(Ve.emit(A.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o)):0===n&&he.updateIsMeeting(!0)),s===A.WebsocketTypeEnum.CONSULT_THREE_WAY_RESULT&&("success"===i.status?(he.updateDirection(A.DirectionEnum.MEETING),he.updateDisplayText(A.DisplayTextEnum.MEETING),he.updateActionConfigs(Rt),Ve.emit(A.CallSipCallEventEnum.CONSULT_THREE_WAY_SUCCESS)):(Ve.emit(A.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,{conf_name:i.conf_name}),he.updateIsMeeting(!1))),s===A.WebsocketTypeEnum.TRANSFER_INCOMING_CALL&&(clearTimeout(ce.autoStateTimer),i.agent_no===ce.agentInfo.agent_no?(he.updateDisplayText(A.DisplayTextEnum.TRANSFERRING),Ve.emit(A.CallSipCallEventEnum.TRANSFER_PROGRESS),he.updateActionConfigs([]),he.updateTransferIsAnswer(!0)):(ce.sessionId=i.session_id,Ve.emit(A.CallSipCallEventEnum.TRANSFER_INCOMING_CALL,{agent_no:i.agent_no,agent_name:i.agent_name,session_id:i.session_id}),he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.TRANSFER),he.updateDisplayText(A.DisplayTextEnum.TRANSFER_INCOMING_CALL),he.updateActionConfigs(Ut),ce.enableBrowserAlert&&Ps.show("📞 转接来电",`坐席 [${i.agent_no}] 正在转接...`,()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{agent_no:i.agent_no})},ce.browserAlertTime))),s===A.WebsocketTypeEnum.TRANSFER_OFF_HOOK&&(Ve.emit(A.CallSipCallEventEnum.TRANSFER_OFF_HOOK,{session_id:ce.sessionId}),he.updateTransferIsAnswer(!1),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(kt)),s===A.WebsocketTypeEnum.TRANSFER_FAILED&&"failed"===i.status){Ve.emit(A.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),Ve.emit(A.EventName.FAIL_NOTIFICATION,"转接失败");const e=he.get("direction");e===A.DirectionEnum.OUTGOING?he.updateActionConfigs(Tt):e===A.DirectionEnum.INCOMING&&he.updateActionConfigs(kt)}s===A.WebsocketTypeEnum.KICK_OFFLINE&&Ve.emit(A.EventName.KICK_OFF),s===A.WebsocketTypeEnum.CONTINUOUS_NOT_ANSWER&&(Ve.emit(A.EventName.FAIL_NOTIFICATION,`已连续 ${i.miss_count} 次未接, 设置忙碌`),this.stateBusyChange()),s===A.WebsocketTypeEnum.SIGN_OUT&&Ve.emit(A.EventName.SIGN_OUT),s===A.WebsocketTypeEnum.SIGN_IN_SWITCH_DEVICE&&Ve.emit(A.EventName.SIGN_IN_SWITCH_DEVICE,i),s===A.WebsocketTypeEnum.LISTEN_INCOMING_CALL&&(clearTimeout(ce.autoStateTimer),ce.sessionId=i.session_id,he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.INCOMING),this.inCallAutoAnswer(),he.updateDisplayText(A.DisplayTextEnum.LISTENING),he.updateActionConfigs(Ut),Ve.emit(A.CallSipCallEventEnum.LISTEN_INCOMING_CALL,{session_id:i.session_id}),ce.enableBrowserAlert&&Ps.show("📞 监听来电","正在来电...",()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{customer_phone:i.customer_phone})},ce.browserAlertTime)),s===A.WebsocketTypeEnum.LISTEN_INCOMING_CALL_OFF_HOOK&&(ce.monitoredAgentNo=i.monitored_agent_no,ce.earSpeakAgent="",he.updateIncomingIsAnswer(!0),Ve.emit(A.CallSipCallEventEnum.LISTEN_INCOMING_CALL_OFF_HOOK,{session_id:ce.sessionId,monitored_agent_no:i.monitored_agent_no}),he.updateActionConfigs(Gt),he.updateDisplayText(A.DisplayTextEnum.CALLING)),s===A.WebsocketTypeEnum.LISTEN_CALL_FAILED&&"failed"===i.status&&(Ve.emit(A.CallSipCallEventEnum.LISTEN_CALL_FAILED),ce.monitoredAgentNo=""),s===A.WebsocketTypeEnum.EAR_SPEECH&&("success"===i.status?(i.monitored_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(Ft),Ve.emit(A.CallSipCallEventEnum.EAR_SPEECH_BE_SUCCESS)),i.monitor_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(Yt),Ve.emit(A.CallSipCallEventEnum.EAR_SPEECH_SUCCESS,{monitored_agent_no:i.monitored_agent_no,monitor_agent_no:i.monitor_agent_no}),ce.earSpeakAgent=i.monitored_agent_no)):Ve.emit(A.CallSipCallEventEnum.EAR_SPEECH_FAILED)),s===A.WebsocketTypeEnum.STOP_EAR_SPEECH&&("success"===i.status?(i.monitored_agent_no===ce.agentInfo.agent_no&&he.updateActionConfigs(kt),i.monitor_agent_no===ce.agentInfo.agent_no&&he.updateActionConfigs(Gt),ce.earSpeakAgent="",Ve.emit(A.CallSipCallEventEnum.STOP_EAR_SPEECH_SUCCESS)):Ve.emit(A.CallSipCallEventEnum.STOP_EAR_SPEECH_FAILED)),s===A.WebsocketTypeEnum.CALL_FORCE_INSERT&&("success"===i.status?(i.monitored_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(Zt),Ve.emit(A.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS,{monitored_agent_no:i.monitored_agent_no,monitor_agent_no:i.monitor_agent_no})),i.monitor_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(vt),Ve.emit(A.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS_LISTENER,{monitored_agent_no:i.monitored_agent_no,monitor_agent_no:i.monitor_agent_no}))):Ve.emit(A.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=he.get("isCalling"),e=ce.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 e=he.get("isHold"),{sessionId:t}=ce;if(!t)return;if(!he.get("actionConfigs").includes("hold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿保持"}));if(e)throw new Error(JSON.stringify({code:1,msg:"当前已处于保持状态"}));$s.__internalSend({type:A.WebsocketTypeEnum.CALL_HOLD,data:{session_id:t}})}unholdCall(){this.roleMute();const{isHold:e}=he.getState(),{sessionId:t}=ce;if(!he.get("actionConfigs").includes("unhold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取消保持"}));if(t){if(!e)throw new Error(JSON.stringify({code:1,msg:"当前未处于保持状态"}));$s.__internalSend({type:A.WebsocketTypeEnum.CALL_UNHOLD,data:{session_id:t}})}}sendDTMF(A){if(1!==he.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));if(!he.get("actionConfigs").includes("dtmf"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿发送按键"}));const{isCalling:e}=he.getState();if(!e)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));this.sipClient.sendDTMF(A)}cancelCall(){if(!he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const e=ce.sessionId;Ve.emit(A.CallSipCallEventEnum.REJECT,{session_id:e}),$s.__internalSend({type:A.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:e}})}async consultCall(e){this.roleMute();const{isCalling:t,outCallIsAnswer:s,consultIsAnswer:i,incomingIsAnswer:n}=he.getState(),o=ce.sessionId;if(!he.get("actionConfigs").includes("consult"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询"}));if(i)throw new Error(JSON.stringify({code:1,msg:"当前正在咨询"}));if(!(t||s||n))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));if(!o)throw new Error(JSON.stringify({code:1,msg:"sessionId不存在"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_REQUEST,data:{session_id:o,consultation_agent_no:e}})}async answerCall(){if(1!==he.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));await this.sipClient.answerCall()}makeCall(e){const t={};Rs(e)?t.customer_phone=e:t.trace_id=e;const s=he.get("isCalling"),i=he.get("selectOutNumber")||"";if(s)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));if("string"!=typeof e||""===e.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.OUTGOING),$s.__internalSend({type:A.WebsocketTypeEnum.OUT_CALL,data:{...t,caller:i}})}previewCall(e,t){const s={};Rs(e)?s.customer_phone=e:s.trace_id=e;const i=he.get("isCalling"),n=he.get("selectOutNumber")||"";if(i)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));if("string"!=typeof e||""===e.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.OUTGOING),$s.__internalSend({type:A.WebsocketTypeEnum.PREVIEW_OUT_CALL,data:{...s,caller:n,preview_task_id:t}})}async hangup(){if(!he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const e=ce.sessionId;$s.__internalSend({type:A.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:e}})}mute(){this.roleMute();const e=he.get("actionConfigs"),t=he.get("isMuted"),s=ce.sessionId;if(t)throw new Error(JSON.stringify({code:1,msg:"当前未处于静音状态"}));if(!e.includes("mute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:A.WebsocketTypeEnum.MUTE,data:{session_id:s}})}unmute(){this.roleMute();const e=he.get("actionConfigs"),t=he.get("isMuted"),s=ce.sessionId;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未处于未静音状态"}));if(!e.includes("unmute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:A.WebsocketTypeEnum.UNMUTE,data:{session_id:s}})}consultTransfer(){this.roleMute();const e=he.get("consultIsAnswer"),t=ce.sessionId;if(!he.get("actionConfigs").includes("consult_transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询转移"}));if(!e)throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_TRANSFER,data:{session_id:t}})}satisfactionEvaluation(){this.roleMute();const e=ce.sessionId;if(!he.get("actionConfigs").includes("satisfaction"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用满意度评价"}));$s.__internalSend({type:A.WebsocketTypeEnum.SATISFACTION_EVALUATION,data:{session_id:e}})}startConference(){this.roleMute();if(!he.get("actionConfigs").includes("conference"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用三方会议"}));const e=ce.sessionId;if(!he.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_THREE_WAY,data:{session_id:e}})}consultRetrieve(){this.roleMute();if(!he.get("actionConfigs").includes("consult_retrieve"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取回通话"}));const e=ce.sessionId;if(!he.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_RETURN_CALL,data:{session_id:e}})}async transferAgent(e){this.roleMute();if(!he.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));const{transferIsAnswer:t}=he.getState(),s=ce.sessionId;if(t)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:A.WebsocketTypeEnum.TRANSFER,data:{session_id:s,transfer_type:0,transfer_dest:e}})}async transferOutline(e){this.roleMute();if(!he.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));if(!e)throw new Error(JSON.stringify({code:1,msg:"号码不能为空"}));if(!/^\d+$/.test(e))throw new Error(JSON.stringify({code:1,msg:"号码格式错误"}));const{transferIsAnswer:t}=he.getState(),s=ce.sessionId;if(t)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));if(t)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:A.WebsocketTypeEnum.TRANSFER,data:{session_id:s,transfer_type:2,transfer_dest:e}})}}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();ge.updateRttObject(A)},2e3),Ps.requestMediaPermissions(),this.#n=he.subscribeKey("answerDevice",async e=>{1===e?(await this.initWebRtc(),ce.stateObject.state===A.AgentStatus.UNREGISTERED&&await this.#e._changeState({data:{...ce.stateBeforeChange,state_name:ce.stateBeforeChange.state===A.AgentStatus.IDLE?"空闲":"忙碌"}})):await this.destroyRtc()}),this.#o=he.subscribeKey("isNextState",async e=>{if(e){await this.#e._agentLogin(vs);1===he.get("answerDevice")&&await this.#A.reconnect();let e="";const t=new URL(Gs).host;e=Gs.includes("https")?`wss://${t}`:`ws://${t}`;const{agent_no:s}=ce.agentInfo;$s.getInstance({url:`${e}/ccs-ws/api/v1/ws/call/${s}?Authorization=`,sipClient:this.#A}),ce.stateObject.state===A.AgentStatus.OFFLINE&&setTimeout(()=>{this.#e._changeState({data:{...this.#a,state_name:this.#a.state===A.AgentStatus.BUSY&&"整理"===this.#a.state_name?"忙碌":this.#a.state_name},success:()=>{he.updateDisplayText(""),Ve.emit(A.CallSipCallEventEnum.AGENT_STATE,this.#a)}})},10)}else this.#a=ce.stateObject,$s.__internalClose(),he.updateDisplayText("离线")}),this.on(A.EventName.KICK_OFF,()=>{this.destroy()}),window.addEventListener("online",this.#c),window.addEventListener("offline",this.#l)}#c=()=>{he.updateIsNextState(!0)};#l=()=>{he.updateIsNextState(!1)};async#h(){const A=he.get("isNextState");try{await xs(),A||he.updateIsNextState(!0)}catch(e){A&&he.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,vs=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=ce.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 qe({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:e,enableBrowserAlert:t,logBuiltinEnabled:s,browserAlertTime:i,initialState:n,initDevice:o}){try{const{viewHtmlElement:r,rttHTML:a}=e||{};ce.logBuiltinEnabled=s||!1,ce.browserAlertTime=i||5e3,await this.#e._agentLogin(vs);const{agent_no:V,current_answer_device:c,current_state:l,out_display_number:h,out_display_select_switch:g}=ce.agentInfo;(n||l)===A.AgentStatus.IDLE?(he.updateActionConfigs(Bt),ce.stateObject={state:n||l,state_name:"空闲"},ce.stateBeforeChange=ce.stateObject):(n||l)===A.AgentStatus.BUSY&&(he.updateActionConfigs(St),ce.stateObject={state:l,state_name:"忙碌"},ce.stateBeforeChange=ce.stateObject),1===g?he.updateSelectOutNumber(h):he.updateSelectOutNumber("");let q="";const d=new URL(Gs).host;q=Gs.includes("https")?`wss://${d}`:`ws://${d}`,he.updateAnswerDevice(o||c),1===(o||c)&&await this.initWebRtc(),setTimeout(()=>{this.#e._changeState({data:ce.stateObject}),this.#e.changeDevice({data:{device:o||c}})},500),$s.getInstance({url:`${q}/ccs-ws/api/v1/ws/call/${V}?Authorization=`,sipClient:this.#A}),this.#t=new Ai(this.#A),e&&r&&(this.#i=!0,new Ws({container:r,rttHTML:a,statusParams:{state:A.AgentStatus.IDLE,statusName:"空闲"}},this,this.#t)),ce.enableBrowserAlert=t,t&&Ps.requestPermission(),Ve.emit(A.EventName.AGENT_INIT_STATUS,!0),this.#r=!0,clearInterval(ei._timer),ei._timer=null,this.#g()}catch(e){this.#i&&Hs("初始化失败"),Ve.emit(A.EventName.AGENT_INIT_STATUS,!1),this.#r=!1}}#q=A=>{const{type:e,data:t}=A;Ve.emit(e,t)};on(A,e){return Ve.on(A,e),this}off(A,e){Ve.off(A,e)}offAll(){Ve.clearAllListeners()}async destroyRtc(){await(this.#A?.destroy()),this.#A=null}async destroy(){ei._instance&&(await this.destroyRtc(),clearInterval(this.#s),$s.__internalClose(),Ve.emit(A.EventName.DESTROY),this.offAll(),this.#n?.(),this.#o?.(),this.#i=!1,ei._instance=null,he.reset(),he.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}=ce.agentInfo,{stateObject:o}=ce,r={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,init_state:n,default_device:he.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 he.get("customerObject")}setBrowserAlert(A){if("boolean"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));ce.logBuiltinEnabled=A||!1}setBrowserAlertTime(A){if("number"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));ce.browserAlertTime=A||3e3}}ei=ti,A.default=ti,Object.defineProperty(A,"__esModule",{value:!0})});
|
|
914
|
+
`;Ct(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)=>{ce.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:e}=ce.stateObject;e!==A.AgentStatus.IDLE&&(ce.stateBeforeChange,this.apiClient._changeState({data:{...ce.stateBeforeChange,state_name:ce.stateBeforeChange.state===A.AgentStatus.IDLE?"空闲":"忙碌"}}))}inCallAutoAnswer(){const{soft_device_auto_answer:e,auto_answer_time:t}=ce.agentInfo,s=1===e,i=he.get("direction");if(s&&i===A.DirectionEnum.INCOMING){const A=Number(t)||0;A>0&&(ce.autoAnswerTimer=setTimeout(()=>{this.sipClient?.answerCall(),ce.autoAnswerTimer=null},1e3*A))}}async getCustomerInfo(A){try{await this.apiClient._getInCallCrmDetail({data:{phone:A},success:A=>{he.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(e,t){if(!e)return;if(5===t)return void this.stateIdleChange();ce.sessionId="";const{post_call_process_time:s}=ce.agentInfo,i=s||0;if(ce.autoStateTimer&&(clearTimeout(ce.autoStateTimer),ce.autoStateTimer=null),he.updateCustomerInfo(void 0),i>0){const{state:e}=ce.stateObject;if(e===A.AgentStatus.IDLE)return;this.apiClient._changeState({data:{state:A.AgentStatus.BUSY,state_name:"整理"}}),ce.autoStateTimer=setTimeout(()=>{ce.autoStateTimer=null,this.stateIdleChange()},1e3*i)}else this.stateIdleChange()}stateBusyChange(){ce.sessionId="",clearTimeout(ce.autoStateTimer),he.updateCustomerInfo(void 0),this.apiClient._changeState({data:{state:A.AgentStatus.BUSY,state_name:"忙碌"}})}initWebSocket(){if(1===this.ws?.readyState)return;const e=Ds(Fs,Ys);this.ws=new WebSocket(this.url+e),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 e=>{const t=JSON.parse(e.data),{type:s,data:i,code:n,msg:o,msg_id:r}=t;if(0===s&&r){const A=this.pendingMessages.get(r),e=performance.now()-A;ce.latency=parseFloat(e.toFixed(2)),this.pendingMessages.delete(r)}if(0!==s&&Xs("%cWebSocket 收到消息:","color: blue; font-weight: bold;",t),s!==A.WebsocketTypeEnum.OUT_CALL&&s!==A.WebsocketTypeEnum.PREVIEW_OUT_CALL||(0!==n?(he.reset(),Ve.emit(A.CallSipCallEventEnum.OUT_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o),he.updateActionConfigs(Bt),setTimeout(()=>{he.updateCustomerInfo(void 0)},500),this.stateIdleChange()):0===n&&(Ve.emit(A.CallSipCallEventEnum.OUT_SUCCESS),clearTimeout(ce.autoStateTimer))),s===A.WebsocketTypeEnum.AGENT_STATE){const{state:e,state_name:t}=i;ce.stateObject={state:e,state_name:t},"振铃中"===t&&he.updateDisplayText(A.DisplayTextEnum.AGENT_RINGING),e===A.AgentStatus.UNREGISTERED&&he.updateActionConfigs(ft),e===A.AgentStatus.IDLE&&ce.stateObject.state===A.AgentStatus.UNREGISTERED&&he.updateActionConfigs(Bt),Ve.emit(A.CallSipCallEventEnum.AGENT_STATE,{state:e,state_name:t})}if(s===A.WebsocketTypeEnum.OUT_CALL_INCOMING_CALL){try{await this.getCustomerInfo(i.trace_id||i.customer_phone)}catch(A){console.error(A)}i.preview_task_id?Ve.emit(A.CallSipCallEventEnum.PREVIEW_OUT_INCOMING_CALL,{customer_phone:i.customer_phone,session_id:i.session_id,preview_task_id:i.preview_task_id,trace_id:i.trace_id}):Ve.emit(A.CallSipCallEventEnum.OUT_INCOMING_CALL,{customer_phone:i.customer_phone,session_id:i.session_id,trace_id:i.trace_id}),ce.sessionId=i.session_id,he.updateActionConfigs(Qt)}if(s===A.WebsocketTypeEnum.OUT_CALL_END)if(he.updateDisplayText(""),1===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.OUT_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no===ce.agentInfo.agent_no)he.reset(),Ve.emit(A.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),this.putAgentState(!0),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no!==ce.agentInfo.agent_no){he.get("isCalling")&&(he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Tt))}else if(3===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.TRANSFER_END,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no!==ce.agentInfo.agent_no){Ve.emit(A.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),Ve.emit(A.EventName.FAIL_NOTIFICATION,"转接失败");const e=he.get("direction");e===A.DirectionEnum.OUTGOING?he.updateActionConfigs(Tt):e===A.DirectionEnum.INCOMING&&he.updateActionConfigs(kt)}else 5===i.device_type&&i.agent_no===ce.agentInfo.agent_no&&(this.putAgentState(!0,5),ce.monitoredAgentNo="",ce.earSpeakAgent="",he.reset(),Ve.emit(A.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt));if(s===A.WebsocketTypeEnum.OUT_CALL_RINGING&&1===i.type&&(Ve.emit(A.CallSipCallEventEnum.OUT_RINGING,{session_id:ce.sessionId,type:i.type}),he.updateDisplayText(A.DisplayTextEnum.RINGING)),s===A.WebsocketTypeEnum.OUT_CALL_ANSWER&&(clearTimeout(ce.autoStateTimer),he.updateIsCalling(!0),Ve.emit(A.CallSipCallEventEnum.OUT_OFF_ANSWER,{session_id:ce.sessionId}),he.updateOutCallIsAnswer(!0),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(Tt)),s===A.WebsocketTypeEnum.CONSULT_RINGING&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_RINGING,{session_id:i.session_id}),he.updateDisplayText(A.DisplayTextEnum.AGENT_RINGING),he.updateActionConfigs([]),clearTimeout(ce.autoStateTimer)),s===A.WebsocketTypeEnum.CONSULT_ANSWER&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_OFF_HOOK,{session_id:i.session_id}),he.updateConsultIsAnswer(!0),he.updateDisplayText(A.DisplayTextEnum.CONSULTING),he.updateActionConfigs(yt)),s===A.WebsocketTypeEnum.CONSULT_FAIL&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_FAILED,{custom_reason:i.custom_reason}),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(Tt)),s===A.WebsocketTypeEnum.CONSULT_CALL_IN&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_INCOMING,{agent_no:i.agent_no,agent_mane:i.agent_name,session_id:i.session_id}),ce.sessionId=i.session_id,he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.CONSULT),he.updateDisplayText(A.DisplayTextEnum.CONSULT_CALL_IN),he.updateActionConfigs(Ut),ce.enableBrowserAlert&&Ps.show("📞 咨询来电",`坐席 [${i.agent_name}] 正在咨询...`,()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{agent_mane:i.agent_name,agent_no:i.agent_no})},ce.browserAlertTime)),s===A.WebsocketTypeEnum.CONSULT_CALL_IN_SUCCESS&&(Ve.emit(A.CallSipCallEventEnum.CONSULT_CALL_IN_SUCCESS,{session_id:i.session_id}),he.updateConsultIsAnswer(!0),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(Dt)),s===A.WebsocketTypeEnum.CONSULT_RETURN_CALL_SUCCESS&&("success"===i.status?(he.updateConsultIsAnswer(!1),Ve.emit(A.CallSipCallEventEnum.CONSULT_RETURN_CALL_SUCCESS),he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP),he.updateActionConfigs(Tt)):Ve.emit(A.EventName.FAIL_NOTIFICATION,"媒体失败")),s===A.WebsocketTypeEnum.MUTE&&(0===n?(he.updateIsMuted(!0),Ve.emit(A.CallSipCallEventEnum.MUTE_SUCCESS),he.updateDisplayText(A.DisplayTextEnum.MUTING)):(Ve.emit(A.CallSipCallEventEnum.MUTE_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.UNMUTE&&(0===n?(he.updateIsMuted(!1),Ve.emit(A.CallSipCallEventEnum.UNMUTE_SUCCESS),he.updateDisplayText(A.DisplayTextEnum.CALLING)):(Ve.emit(A.CallSipCallEventEnum.UNMUTE_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CALL_HOLD&&(0===n?(he.updateIsHold(!0),he.updateDisplayText(A.DisplayTextEnum.HOLDING),Ve.emit(A.CallSipCallEventEnum.HOLD_SUCCESS)):(Ve.emit(A.CallSipCallEventEnum.HOLD_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CALL_UNHOLD&&(0===n?(he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateIsHold(!1),Ve.emit(A.CallSipCallEventEnum.UNHOLD_SUCCESS)):(Ve.emit(A.CallSipCallEventEnum.UNHOLD_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CONSULT_TRANSFER&&(0===n?Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_SUCCESS):(Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CONSULT_TRANSFER_FAILED&&Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_FAILED,i.status),s===A.WebsocketTypeEnum.CONSULT_TRANSFER_OFF_HOOK&&(he.updateDirection(A.DirectionEnum.INCOMING),he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.CONSULT_TRANSFER_OFF_HOOK),he.updateActionConfigs(kt),he.updateIncomingIsAnswer(!0),he.updateConsultIsAnswer(!1)),s===A.WebsocketTypeEnum.INCOMING_CALL){clearTimeout(ce.autoStateTimer),ce.sessionId=i.session_id;try{await this.getCustomerInfo(i.trace_id||i.customer_phone)}catch(A){console.error(A)}he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.INCOMING),this.inCallAutoAnswer(),he.updateDisplayText(A.DisplayTextEnum.INCOMING_CALL),1===i.direction&&Ve.emit(A.CallSipCallEventEnum.INCOMING_CALL,{customer_phone:i.customer_phone,trace_id:i.trace_id,session_id:i.session_id}),3===i.direction&&(Ve.emit(A.CallSipCallEventEnum.PREDICT_INCOMING_CALL,{customer_phone:i.customer_phone,trace_id:i.trace_id,session_id:i.session_id}),this.sipClient?.answerCall()),he.updateActionConfigs(Ut),ce.enableBrowserAlert&&Ps.show("📞 客户来电",`客户 [${i.customer_phone}] 正在呼入...`,()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{customer_phone:i.customer_phone})},ce.browserAlertTime)}if(s===A.WebsocketTypeEnum.INCOMING_CALL_OFF_HOOK&&(he.updateIncomingIsAnswer(!0),Ve.emit(A.CallSipCallEventEnum.INCOMING_CALL_OFF_HOOK,{session_id:ce.sessionId}),he.updateActionConfigs(kt),he.updateDisplayText(A.DisplayTextEnum.CALLING)),s===A.WebsocketTypeEnum.INCOMING_CALL_END)if(he.updateDisplayText(""),1===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.INCOMING_CALL_END,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no===ce.agentInfo.agent_no)he.reset(),Ve.emit(A.CallSipCallEventEnum.OUR_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),this.putAgentState(!0),he.updateActionConfigs(Bt);else if(2===i.device_type&&i.agent_no!==ce.agentInfo.agent_no)he.updateDisplayText(A.DisplayTextEnum.CALLING),Ve.emit(A.CallSipCallEventEnum.OTHER_SIDE_CONSULT_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Tt);else if(3===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.THREE_WAY_OUR_SIDE_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no===ce.agentInfo.agent_no)this.putAgentState(!0),he.reset(),Ve.emit(A.CallSipCallEventEnum.TRANSFER_END,{session_id:i.session_id}),he.updateActionConfigs(Bt);else if(4===i.device_type&&i.agent_no!==ce.agentInfo.agent_no){Ve.emit(A.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),Ve.emit(A.EventName.FAIL_NOTIFICATION,"转接失败");const e=he.get("direction");e===A.DirectionEnum.OUTGOING?he.updateActionConfigs(Tt):e===A.DirectionEnum.INCOMING&&he.updateActionConfigs(kt)}else 5===i.device_type&&i.agent_no===ce.agentInfo.agent_no&&(this.putAgentState(!0,5),ce.monitoredAgentNo="",ce.earSpeakAgent="",he.reset(),Ve.emit(A.CallSipCallEventEnum.LISTEN_HANGUP,{session_id:i.session_id}),he.updateActionConfigs(Bt));if(s===A.WebsocketTypeEnum.SATISFACTION_EVALUATION&&(0===n?Ve.emit(A.CallSipCallEventEnum.SATISFACTION_EVALUATION_SUCCESS):(Ve.emit(A.CallSipCallEventEnum.SATISFACTION_EVALUATION_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o))),s===A.WebsocketTypeEnum.CONSULT_THREE_WAY&&(0!==n?(Ve.emit(A.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,o),Ve.emit(A.EventName.FAIL_NOTIFICATION,o)):0===n&&he.updateIsMeeting(!0)),s===A.WebsocketTypeEnum.CONSULT_THREE_WAY_RESULT&&("success"===i.status?(he.updateDirection(A.DirectionEnum.MEETING),he.updateDisplayText(A.DisplayTextEnum.MEETING),he.updateActionConfigs(Rt),Ve.emit(A.CallSipCallEventEnum.CONSULT_THREE_WAY_SUCCESS)):(Ve.emit(A.CallSipCallEventEnum.CONSULT_THREE_WAY_FAILED,{conf_name:i.conf_name}),he.updateIsMeeting(!1))),s===A.WebsocketTypeEnum.TRANSFER_INCOMING_CALL&&(clearTimeout(ce.autoStateTimer),i.agent_no===ce.agentInfo.agent_no?(he.updateDisplayText(A.DisplayTextEnum.TRANSFERRING),Ve.emit(A.CallSipCallEventEnum.TRANSFER_PROGRESS),he.updateActionConfigs([]),he.updateTransferIsAnswer(!0)):(ce.sessionId=i.session_id,Ve.emit(A.CallSipCallEventEnum.TRANSFER_INCOMING_CALL,{agent_no:i.agent_no,agent_name:i.agent_name,session_id:i.session_id}),he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.TRANSFER),he.updateDisplayText(A.DisplayTextEnum.TRANSFER_INCOMING_CALL),he.updateActionConfigs(Ut),ce.enableBrowserAlert&&Ps.show("📞 转接来电",`坐席 [${i.agent_no}] 正在转接...`,()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{agent_no:i.agent_no})},ce.browserAlertTime))),s===A.WebsocketTypeEnum.TRANSFER_OFF_HOOK&&(Ve.emit(A.CallSipCallEventEnum.TRANSFER_OFF_HOOK,{session_id:ce.sessionId}),he.updateTransferIsAnswer(!1),he.updateDisplayText(A.DisplayTextEnum.CALLING),he.updateActionConfigs(kt)),s===A.WebsocketTypeEnum.TRANSFER_FAILED&&"failed"===i.status){Ve.emit(A.CallSipCallEventEnum.TRANSFER_FAILED,"未知原因"),Ve.emit(A.EventName.FAIL_NOTIFICATION,"转接失败");const e=he.get("direction");e===A.DirectionEnum.OUTGOING?he.updateActionConfigs(Tt):e===A.DirectionEnum.INCOMING&&he.updateActionConfigs(kt)}s===A.WebsocketTypeEnum.KICK_OFFLINE&&Ve.emit(A.EventName.KICK_OFF),s===A.WebsocketTypeEnum.CONTINUOUS_NOT_ANSWER&&(Ve.emit(A.EventName.FAIL_NOTIFICATION,`已连续 ${i.miss_count} 次未接, 设置忙碌`),this.stateBusyChange()),s===A.WebsocketTypeEnum.SIGN_OUT&&Ve.emit(A.EventName.SIGN_OUT),s===A.WebsocketTypeEnum.SIGN_IN_SWITCH_DEVICE&&Ve.emit(A.EventName.SIGN_IN_SWITCH_DEVICE,i),s===A.WebsocketTypeEnum.LISTEN_INCOMING_CALL&&(clearTimeout(ce.autoStateTimer),ce.sessionId=i.session_id,he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.INCOMING),this.inCallAutoAnswer(),he.updateDisplayText(A.DisplayTextEnum.LISTENING),he.updateActionConfigs(Ut),Ve.emit(A.CallSipCallEventEnum.LISTEN_INCOMING_CALL,{session_id:i.session_id}),ce.enableBrowserAlert&&Ps.show("📞 监听来电","正在来电...",()=>{Ve.emit(A.EventName.NOTIFICATION_CLICK,{customer_phone:i.customer_phone})},ce.browserAlertTime)),s===A.WebsocketTypeEnum.LISTEN_INCOMING_CALL_OFF_HOOK&&(ce.monitoredAgentNo=i.monitored_agent_no,ce.earSpeakAgent="",he.updateIncomingIsAnswer(!0),Ve.emit(A.CallSipCallEventEnum.LISTEN_INCOMING_CALL_OFF_HOOK,{session_id:ce.sessionId,monitored_agent_no:i.monitored_agent_no}),he.updateActionConfigs(Gt),he.updateDisplayText(A.DisplayTextEnum.CALLING)),s===A.WebsocketTypeEnum.LISTEN_CALL_FAILED&&"failed"===i.status&&(Ve.emit(A.CallSipCallEventEnum.LISTEN_CALL_FAILED),ce.monitoredAgentNo=""),s===A.WebsocketTypeEnum.EAR_SPEECH&&("success"===i.status?(i.monitored_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(Ft),Ve.emit(A.CallSipCallEventEnum.EAR_SPEECH_BE_SUCCESS)),i.monitor_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(Yt),Ve.emit(A.CallSipCallEventEnum.EAR_SPEECH_SUCCESS,{monitored_agent_no:i.monitored_agent_no,monitor_agent_no:i.monitor_agent_no}),ce.earSpeakAgent=i.monitored_agent_no)):Ve.emit(A.CallSipCallEventEnum.EAR_SPEECH_FAILED)),s===A.WebsocketTypeEnum.STOP_EAR_SPEECH&&("success"===i.status?(i.monitored_agent_no===ce.agentInfo.agent_no&&he.updateActionConfigs(kt),i.monitor_agent_no===ce.agentInfo.agent_no&&he.updateActionConfigs(Gt),ce.earSpeakAgent="",Ve.emit(A.CallSipCallEventEnum.STOP_EAR_SPEECH_SUCCESS)):Ve.emit(A.CallSipCallEventEnum.STOP_EAR_SPEECH_FAILED)),s===A.WebsocketTypeEnum.CALL_FORCE_INSERT&&("success"===i.status?(i.monitored_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(Zt),Ve.emit(A.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS,{monitored_agent_no:i.monitored_agent_no,monitor_agent_no:i.monitor_agent_no})),i.monitor_agent_no===ce.agentInfo.agent_no&&(he.updateActionConfigs(vt),Ve.emit(A.CallSipCallEventEnum.CALL_FORCE_INSERT_SUCCESS_LISTENER,{monitored_agent_no:i.monitored_agent_no,monitor_agent_no:i.monitor_agent_no}))):Ve.emit(A.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=he.get("isCalling"),e=ce.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 e=he.get("isHold"),{sessionId:t}=ce;if(!t)return;if(!he.get("actionConfigs").includes("hold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿保持"}));if(e)throw new Error(JSON.stringify({code:1,msg:"当前已处于保持状态"}));$s.__internalSend({type:A.WebsocketTypeEnum.CALL_HOLD,data:{session_id:t}})}unholdCall(){this.roleMute();const{isHold:e}=he.getState(),{sessionId:t}=ce;if(!he.get("actionConfigs").includes("unhold"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取消保持"}));if(t){if(!e)throw new Error(JSON.stringify({code:1,msg:"当前未处于保持状态"}));$s.__internalSend({type:A.WebsocketTypeEnum.CALL_UNHOLD,data:{session_id:t}})}}sendDTMF(A){if(1!==he.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));if(!he.get("actionConfigs").includes("dtmf"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿发送按键"}));const{isCalling:e}=he.getState();if(!e)throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));this.sipClient.sendDTMF(A)}cancelCall(){if(!he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const e=ce.sessionId;Ve.emit(A.CallSipCallEventEnum.REJECT,{session_id:e}),$s.__internalSend({type:A.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:e}})}async consultCall(e){this.roleMute();const{isCalling:t,outCallIsAnswer:s,consultIsAnswer:i,incomingIsAnswer:n}=he.getState(),o=ce.sessionId;if(!he.get("actionConfigs").includes("consult"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询"}));if(i)throw new Error(JSON.stringify({code:1,msg:"当前正在咨询"}));if(!(t||s||n))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));if(!o)throw new Error(JSON.stringify({code:1,msg:"sessionId不存在"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_REQUEST,data:{session_id:o,consultation_agent_no:e}})}async answerCall(){if(1!==he.get("answerDevice"))throw new Error(JSON.stringify({code:1,msg:"当前设备不支持此功能"}));await this.sipClient.answerCall()}makeCall(e){if("string"!=typeof e||""===e.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));const t={};(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)})(e)?t.trace_id=e:t.customer_phone=e.replace(/[\s\r\n-]+/g,"");const s=he.get("isCalling"),i=he.get("selectOutNumber")||"";if(s)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.OUTGOING),$s.__internalSend({type:A.WebsocketTypeEnum.OUT_CALL,data:{...t,caller:i.replace(/[\s\r\n-]+/g,"")}})}previewCall(e,t){const s={};Rs(e)?s.customer_phone=e:s.trace_id=e;const i=he.get("isCalling"),n=he.get("selectOutNumber")||"";if(i)throw new Error(JSON.stringify({code:1,msg:"正在呼叫中,请勿重复点击"}));if("string"!=typeof e||""===e.trim())throw new Error(JSON.stringify({code:1,msg:"外呼号码非法"}));he.updateIsCalling(!0),he.updateDirection(A.DirectionEnum.OUTGOING),$s.__internalSend({type:A.WebsocketTypeEnum.PREVIEW_OUT_CALL,data:{...s,caller:n,preview_task_id:t}})}async hangup(){if(!he.get("isCalling"))throw new Error(JSON.stringify({code:1,msg:"当前没有通话"}));const e=ce.sessionId;$s.__internalSend({type:A.WebsocketTypeEnum.AGENT_HANGUP,data:{session_id:e}})}mute(){this.roleMute();const e=he.get("actionConfigs"),t=he.get("isMuted"),s=ce.sessionId;if(t)throw new Error(JSON.stringify({code:1,msg:"当前未处于静音状态"}));if(!e.includes("mute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:A.WebsocketTypeEnum.MUTE,data:{session_id:s}})}unmute(){this.roleMute();const e=he.get("actionConfigs"),t=he.get("isMuted"),s=ce.sessionId;if(!t)throw new Error(JSON.stringify({code:1,msg:"当前未处于未静音状态"}));if(!e.includes("unmute"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用静音"}));$s.__internalSend({type:A.WebsocketTypeEnum.UNMUTE,data:{session_id:s}})}consultTransfer(){this.roleMute();const e=he.get("consultIsAnswer"),t=ce.sessionId;if(!he.get("actionConfigs").includes("consult_transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用咨询转移"}));if(!e)throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_TRANSFER,data:{session_id:t}})}satisfactionEvaluation(){this.roleMute();const e=ce.sessionId;if(!he.get("actionConfigs").includes("satisfaction"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用满意度评价"}));$s.__internalSend({type:A.WebsocketTypeEnum.SATISFACTION_EVALUATION,data:{session_id:e}})}startConference(){this.roleMute();if(!he.get("actionConfigs").includes("conference"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿调用三方会议"}));const e=ce.sessionId;if(!he.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_THREE_WAY,data:{session_id:e}})}consultRetrieve(){this.roleMute();if(!he.get("actionConfigs").includes("consult_retrieve"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿取回通话"}));const e=ce.sessionId;if(!he.get("consultIsAnswer"))throw new Error(JSON.stringify({code:1,msg:"当前未处于咨询中"}));$s.__internalSend({type:A.WebsocketTypeEnum.CONSULT_RETURN_CALL,data:{session_id:e}})}async transferAgent(e){this.roleMute();if(!he.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));const{transferIsAnswer:t}=he.getState(),s=ce.sessionId;if(t)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:A.WebsocketTypeEnum.TRANSFER,data:{session_id:s,transfer_type:0,transfer_dest:e}})}async transferOutline(e){this.roleMute();if(!he.get("actionConfigs").includes("transfer"))throw new Error(JSON.stringify({code:1,msg:"当前状态请勿转接"}));if(!e)throw new Error(JSON.stringify({code:1,msg:"号码不能为空"}));if(!/^\d+$/.test(e))throw new Error(JSON.stringify({code:1,msg:"号码格式错误"}));const{transferIsAnswer:t}=he.getState(),s=ce.sessionId;if(t)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));if(t)throw new Error(JSON.stringify({code:1,msg:"当前正在转接"}));$s.__internalSend({type:A.WebsocketTypeEnum.TRANSFER,data:{session_id:s,transfer_type:2,transfer_dest:e}})}}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();ge.updateRttObject(A)},2e3),Ps.requestMediaPermissions(),this.#n=he.subscribeKey("answerDevice",async e=>{1===e?(await this.initWebRtc(),ce.stateObject.state===A.AgentStatus.UNREGISTERED&&await this.#e._changeState({data:{...ce.stateBeforeChange,state_name:ce.stateBeforeChange.state===A.AgentStatus.IDLE?"空闲":"忙碌"}})):await this.destroyRtc()}),this.#o=he.subscribeKey("isNextState",async e=>{if(e){await this.#e._agentLogin(vs);1===he.get("answerDevice")&&await this.#A.reconnect();let e="";const t=new URL(Gs).host;e=Gs.includes("https")?`wss://${t}`:`ws://${t}`;const{agent_no:s}=ce.agentInfo;$s.getInstance({url:`${e}/ccs-ws/api/v1/ws/call/${s}?Authorization=`,sipClient:this.#A}),ce.stateObject.state===A.AgentStatus.OFFLINE&&setTimeout(()=>{this.#e._changeState({data:{...this.#a,state_name:this.#a.state===A.AgentStatus.BUSY&&"整理"===this.#a.state_name?"忙碌":this.#a.state_name},success:()=>{he.updateDisplayText(""),Ve.emit(A.CallSipCallEventEnum.AGENT_STATE,this.#a)}})},10)}else this.#a=ce.stateObject,$s.__internalClose(),he.updateDisplayText("离线")}),this.on(A.EventName.KICK_OFF,()=>{this.destroy()}),window.addEventListener("online",this.#c),window.addEventListener("offline",this.#l)}#c=()=>{he.updateIsNextState(!0)};#l=()=>{he.updateIsNextState(!1)};async#h(){const A=he.get("isNextState");try{await xs(),A||he.updateIsNextState(!0)}catch(e){A&&he.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,vs=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=ce.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 qe({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:e,enableBrowserAlert:t,logBuiltinEnabled:s,browserAlertTime:i,initialState:n,initDevice:o}){try{const{viewHtmlElement:r,rttHTML:a}=e||{};ce.logBuiltinEnabled=s||!1,ce.browserAlertTime=i||5e3,await this.#e._agentLogin(vs);const{agent_no:V,current_answer_device:c,current_state:l,out_display_number:h,out_display_select_switch:g}=ce.agentInfo;(n||l)===A.AgentStatus.IDLE?(he.updateActionConfigs(Bt),ce.stateObject={state:n||l,state_name:"空闲"},ce.stateBeforeChange=ce.stateObject):(n||l)===A.AgentStatus.BUSY&&(he.updateActionConfigs(St),ce.stateObject={state:l,state_name:"忙碌"},ce.stateBeforeChange=ce.stateObject),1===g?he.updateSelectOutNumber(h):he.updateSelectOutNumber("");let q="";const d=new URL(Gs).host;q=Gs.includes("https")?`wss://${d}`:`ws://${d}`,he.updateAnswerDevice(o||c),1===(o||c)&&await this.initWebRtc(),setTimeout(()=>{this.#e._changeState({data:ce.stateObject}),this.#e.changeDevice({data:{device:o||c}})},500),$s.getInstance({url:`${q}/ccs-ws/api/v1/ws/call/${V}?Authorization=`,sipClient:this.#A}),this.#t=new Ai(this.#A),e&&r&&(this.#i=!0,new Ws({container:r,rttHTML:a,statusParams:{state:A.AgentStatus.IDLE,statusName:"空闲"}},this,this.#t)),ce.enableBrowserAlert=t,t&&Ps.requestPermission(),Ve.emit(A.EventName.AGENT_INIT_STATUS,!0),this.#r=!0,clearInterval(ei._timer),ei._timer=null,this.#g()}catch(e){this.#i&&Hs("初始化失败"),Ve.emit(A.EventName.AGENT_INIT_STATUS,!1),this.#r=!1}}#q=A=>{const{type:e,data:t}=A;Ve.emit(e,t)};on(A,e){return Ve.on(A,e),this}off(A,e){Ve.off(A,e)}offAll(){Ve.clearAllListeners()}async destroyRtc(){await(this.#A?.destroy()),this.#A=null}async destroy(){ei._instance&&(await this.destroyRtc(),clearInterval(this.#s),$s.__internalClose(),Ve.emit(A.EventName.DESTROY),this.offAll(),this.#n?.(),this.#o?.(),this.#i=!1,ei._instance=null,he.reset(),he.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}=ce.agentInfo,{stateObject:o}=ce,r={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,init_state:n,default_device:he.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 he.get("customerObject")}setBrowserAlert(A){if("boolean"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));ce.logBuiltinEnabled=A||!1}setBrowserAlertTime(A){if("number"!=typeof A)throw new Error(JSON.stringify({code:1,msg:"参数类型错误"}));ce.browserAlertTime=A||3e3}}ei=ti,A.default=ti,Object.defineProperty(A,"__esModule",{value:!0})});
|