ysyt-agent-sdk 1.0.37 → 1.0.38

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.
@@ -122,6 +122,8 @@ export interface AgentDataType {
122
122
  value: number;
123
123
  label: string;
124
124
  }[];
125
+ init_state: AgentObjectType['init_state'];
126
+ default_device: AgentObjectType['default_device'];
125
127
  stateObject: {
126
128
  state: AgentStatus;
127
129
  state_name: string;
@@ -581,7 +581,7 @@ const as=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
581
581
  <div class="popup ${this.open?"":"hidden"}">
582
582
  <slot name="content"></slot>
583
583
  </div>
584
- `}};ns([ls()],Gs.prototype,"open",void 0),Gs=ns([as("my-icon-popup")],Gs);class Ys{constructor(){this.roleData={agentInfo:()=>{if(!St.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:A=>{if(!A.data)throw new Error("请传入参数")},changeDevice:A=>{if(!A)throw new Error('Parameter "device" is required');const{answer_devices:e}=St.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error("当前设备不支持")},changeState:(A,e)=>{if(!A)throw new Error('Parameter "state" is required');if(!e)throw new Error('Parameter "state_name" is required');if(2===A&&"通话中"===e)throw new Error("当前状态不支持");if(![1,2].includes(A))throw new Error("当前状态不支持")}}}async _agentLogin(A){try{const t=await(e={agent_no:A},Bs(`${Es}/agent/login`,e));St.agentInfo=t.data}catch(A){throw console.log(A),new Error("登录失败")}var e}async changeDevice(A){try{if(Dt.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;this.roleData.changeDevice(s);const{agent_no:i}=St.agentInfo;await(A=>Bs(`${Es}/device/change`,A))({agent_no:i,answer_device:s}),Dt.updateAnswerDevice(s);const r=Dt.get("actionConfigs");Dt.updateActionConfigs(r),t?.({code:0,msg:"请求成功"})}catch(A){throw console.log(A),new Error("切换设备失败")}}async changeState(A){try{St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:r}=St.agentInfo;await(A=>Bs(`${Es}/state/change`,A))({agent_no:r,state_name:i,state:s}),s===Ae.IDLE?Dt.updateActionConfigs(mt):s===Ae.BUSY&&Dt.updateActionConfigs(Ct),St.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){console.log(A)}}async getIdleAgentList(A){const{agent_no:e}=St.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Bs(`${Es}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){console.log(A)}}async getAgentState(A){try{const e=await Bs(`${Cs}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).map(A=>({state:A.state,state_name:A.state_name})).reverse();A.success?.({...e,data:t})}catch(A){console.log(A)}}}class Fs{constructor({container:A,rttHTML:e,statusParams:t},s){this.VoiceSDKInstance=s,this.apiClient=new Ys,this.isOpenSelect=!1,this.statusParams={state:Ae.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=A=>{this.rttHTML&&this.renderRtt(A.rttObject)},this.handleCallInfoChange=A=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const A=document.querySelector(".ysyt-select");A.style.height="0px",setTimeout(()=>{A.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=A=>{A.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const e=document.querySelector(".ysyt-select");this.isOpenSelect?(e.style.height=e.scrollHeight+"px",e.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async A=>{const{state:e,statusName:t}=A;await this.apiClient.changeState({data:{state:e,state_name:t},success:()=>{this.statusParams=A;const e=document.getElementById("my-timer");e?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async A=>{try{await this.apiClient.changeDevice({data:{device:A},success:({code:e})=>{0===e&&(1!==A&&this.VoiceSDKInstance.destroyRtc(),us("切换成功"),this.default_device=A,this.render())}})}catch(A){console.log(A),ps(A.message),this.render()}},this.ruleCall=async A=>{if(A)try{await this.VoiceSDKInstance.call_api.makeCall(A)}catch(A){console.error(A)}},this.onCall=()=>{const A=document.querySelector("my-input");this.ruleCall(A.value)},this.renderCallPopover=()=>ze`
584
+ `}};ns([ls()],Gs.prototype,"open",void 0),Gs=ns([as("my-icon-popup")],Gs);class Ys{constructor(){this.roleData={agentInfo:()=>{if(!St.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:A=>{if(!A.data)throw new Error("请传入参数")},changeDevice:A=>{if(!A)throw new Error('Parameter "device" is required');const{answer_devices:e}=St.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error("当前设备不支持")},changeState:(A,e)=>{if(!A)throw new Error('Parameter "state" is required');if(!e)throw new Error('Parameter "state_name" is required');if(2===A&&"通话中"===e)throw new Error("当前状态不支持");if(![1,2].includes(A))throw new Error("当前状态不支持")}}}async _agentLogin(A){try{const t=await(e={agent_no:A},Bs(`${Es}/agent/login`,e));St.agentInfo=t.data}catch(A){throw console.log(A),new Error("登录失败")}var e}async changeDevice(A){try{if(Dt.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;this.roleData.changeDevice(s);const{agent_no:i}=St.agentInfo;await(A=>Bs(`${Es}/device/change`,A))({agent_no:i,answer_device:s}),Dt.updateAnswerDevice(s);const r=Dt.get("actionConfigs");Dt.updateActionConfigs(r),t?.({code:0,msg:"请求成功"})}catch(A){throw console.log(A),new Error("切换设备失败")}}async changeState(A){try{St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:r}=St.agentInfo;await(A=>Bs(`${Es}/state/change`,A))({agent_no:r,state_name:i,state:s}),s===Ae.IDLE?Dt.updateActionConfigs(mt):s===Ae.BUSY&&Dt.updateActionConfigs(Ct),St.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){console.log(A)}}async getIdleAgentList(A){const{agent_no:e}=St.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Bs(`${Es}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){console.log(A)}}async getAgentState(A){try{const e=await Bs(`${Cs}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).filter(A=>"通话中"!==A.state_name).map(A=>({state:A.state,state_name:A.state_name})).reverse();console.log(t),A.success?.({...e,data:t})}catch(A){console.log(A)}}}class Fs{constructor({container:A,rttHTML:e,statusParams:t},s){this.VoiceSDKInstance=s,this.apiClient=new Ys,this.isOpenSelect=!1,this.statusParams={state:Ae.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=A=>{this.rttHTML&&this.renderRtt(A.rttObject)},this.handleCallInfoChange=A=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const A=document.querySelector(".ysyt-select");A.style.height="0px",setTimeout(()=>{A.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=A=>{A.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const e=document.querySelector(".ysyt-select");this.isOpenSelect?(e.style.height=e.scrollHeight+"px",e.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async A=>{const{state:e,statusName:t}=A;await this.apiClient.changeState({data:{state:e,state_name:t},success:()=>{this.statusParams=A;const e=document.getElementById("my-timer");e?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async A=>{try{await this.apiClient.changeDevice({data:{device:A},success:({code:e})=>{0===e&&(1!==A&&this.VoiceSDKInstance.destroyRtc(),us("切换成功"),this.default_device=A,this.render())}})}catch(A){console.log(A),ps(A.message),this.render()}},this.ruleCall=async A=>{if(A)try{await this.VoiceSDKInstance.call_api.makeCall(A)}catch(A){console.error(A)}},this.onCall=()=>{const A=document.querySelector("my-input");this.ruleCall(A.value)},this.renderCallPopover=()=>ze`
585
585
  <my-icon-popup>
586
586
  <div slot="icon">
587
587
  <i class="ysyt icon-boda my-icon"></i>
@@ -821,4 +821,4 @@ const as=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
821
821
  `:""}
822
822
  </div>
823
823
  </my-popover>
824
- `;qt(s,this.rttHTML)}}const Zs=new class{constructor(){this.events={}}on(A,e){this.events[A]=this.events[A]||[],this.events[A].push(e)}off(A,e){this.events[A]=(this.events[A]||[]).filter(A=>A!==e)}emit(A,...e){(this.events[A]||[]).forEach(A=>A(...e))}};class vs{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 console.log("已授权麦克风权限"),null;const e=await navigator.mediaDevices.getUserMedia({audio:!0});return console.log("获取音频权限成功"),e}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t){if("Notification"in window&&"granted"===Notification.permission){const s=new Notification(A,{body:e,tag:"xy-global-notification",renotify:!0});s.onclick=()=>{window.focus(),s.close(),t?.()},setTimeout(()=>s.close(),5e3)}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}let xs=null;class Ks{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Ys,this.initWebSocket()}static getInstance(A){if(!xs){if(!A)throw new Error("WebSocket 尚未初始化");xs=new Ks(A)}return xs}stateIdleChange(){const{state:A}=St.stateObject;A!==Ae.IDLE&&this.apiClient.changeState({data:{state:Ae.IDLE,state_name:"空闲"}})}putAgentState(){St.sessionId="";const{post_call_process_time:A}=St.agentInfo,e=A||0;St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),e>0?St.autoStateTimer=setTimeout(()=>{St.autoStateTimer=null,this.stateIdleChange()},e):this.stateIdleChange()}initWebSocket(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.sendMessage({type:0}),this.startHeartbeat()},this.ws.onmessage=A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:r}=e;if(0!==t&&console.warn(t),t===ie.OUT_CALL&&(0!==i?(ae.emit(se.OUT_FAILED,r),this.stateIdleChange()):0===i&&ae.emit(se.OUT_SUCCESS)),t===ie.AGENT_STATE){const{state:A,state_name:e}=s;St.stateObject={state:A,state_name:e},"振铃中"===e&&Dt.updateDisplayText(oe.AGENT_RINGING),ae.emit(se.AGENT_STATE,{state:A,state_name:e})}t===ie.OUT_CALL_INCOMING_CALL&&(ae.emit(se.OUT_INCOMING_CALL),St.sessionId=s.session_id,Dt.updateActionConfigs(Et)),t===ie.OUT_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.OUT_HANGUP,s),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.OUT_CALL_RINGING&&(ae.emit(se.OUT_RINGING,s),Dt.updateDisplayText(oe.RINGING)),t===ie.OUT_CALL_ANSWER&&(ae.emit(se.OUT_OFF_ANSWER,s),Dt.updateOutCallIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_RINGING&&(ae.emit(se.CONSULT_RINGING),Dt.updateDisplayText(oe.AGENT_RINGING),Dt.updateActionConfigs([])),t===ie.CONSULT_ANSWER&&(ae.emit(se.CONSULT_OFF_HOOK,s),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CONSULTING),Dt.updateActionConfigs(Mt)),t===ie.CONSULT_FAIL&&(ae.emit(se.CONSULT_FAILED,{custom_reason:s.custom_reason}),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_CALL_IN&&(ae.emit(se.CONSULT_INCOMING,s),Dt.updateIsCalling(!0),Dt.updateDirection(ee.CONSULT),Dt.updateDisplayText(oe.CONSULT_CALL_IN),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{agent_mane:s.agent_name})})),t===ie.CONSULT_CALL_IN_SUCCESS&&(St.sessionId=s.session_id,ae.emit(se.CONSULT_CALL_IN_SUCCESS),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(wt)),t===ie.CONSULT_RETURN_CALL_SUCCESS&&(ae.emit(se.CONSULT_RETURN_CALL_SUCCESS),Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)),t===ie.MUTE&&(0===i?(Dt.updateIsMuted(!0),ae.emit(se.MUTE_SUCCESS)):ae.emit(se.MUTE_FAILED,r)),t===ie.UNMUTE&&(0===i?(Dt.updateIsMuted(!1),ae.emit(se.UNMUTE_SUCCESS)):ae.emit(se.UNMUTE_FAILED,r)),t===ie.CONSULT_TRANSFER&&(0===i?ae.emit(se.CONSULT_TRANSFER_SUCCESS):ae.emit(se.CONSULT_TRANSFER_FAILED,r)),t===ie.CONSULT_TRANSFER_FAILED&&ae.emit(se.CONSULT_TRANSFER_FAILED,s.status),t===ie.CONSULT_TRANSFER_OFF_HOOK&&(Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.CALLING),ae.emit(se.CONSULT_TRANSFER_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateIncomingIsAnswer(!0),Dt.updateConsultIsAnswer(!1)),t===ie.INCOMING_CALL&&(St.sessionId=s.session_id,Dt.updateIsCalling(!0),Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.INCOMING_CALL),ae.emit(se.INCOMING_CALL,{customer_phone:s.customer_phone}),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})})),t===ie.INCOMING_CALL_OFF_HOOK&&(Dt.updateIncomingIsAnswer(!0),ae.emit(se.INCOMING_CALL_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateDisplayText(oe.CALLING)),t===ie.INCOMING_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.INCOMING_CALL_END),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.SATISFACTION_EVALUATION&&(0===i?ae.emit(se.SATISFACTION_EVALUATION_SUCCESS):ae.emit(se.SATISFACTION_EVALUATION_FAILED,r)),t===ie.CONSULT_THREE_WAY&&(0!==i?ae.emit(se.CONSULT_THREE_WAY_FAILED,r):0===i&&Dt.updateIsMeeting(!0)),t===ie.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(Dt.updateDirection(ee.MEETING),Dt.updateDisplayText(oe.MEETING),Dt.updateActionConfigs(Bt),ae.emit(se.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(se.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),Dt.updateIsMeeting(!1))),0!==t&&Zs.emit("ws-message",e)},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 }, 14000);\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=()=>{this.sendMessage({type:0})},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)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}static __internalClose(){xs&&(xs.close(),xs=null)}static __internalSend(A){if(!xs)throw new Error("WebSocket 尚未初始化");xs.sendMessage(A)}}module.exports=class{#A=null;#e=new Ys;#t=null;#s=!1;#i;constructor(){clearInterval(this.#t),this.#t=setInterval(async()=>{const A=await this.#r();Qs.updateRttObject(A)},2e3),vs.requestMediaPermissions(),window.addEventListener("beforeunload",()=>{this.destroy()}),this.#i=Dt.subscribeKey("answerDevice",A=>{1===A&&this.initWebRtc()})}async initWebRtc(){const A=St.agentInfo.sip_account_list.find(A=>1===A.device_type);if(A){const e=A.sip_register_addr;this.#A=new fs({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#o),await this.#A.start()}}async init({actionNodeParams:A,url:e,appKey:t,appSecret:s,agentNo:i,enableBrowserAlert:r}){try{const{viewHtmlElement:o,rttHTML:n}=A||{},a=e||"https://aicc.yescloudy.com";Is=a,Ms=t,ws=s;const V=os(t,s);await this.#e._agentLogin(i);const{agent_no:c,current_answer_device:h,init_state:l}=St.agentInfo;l===Ae.IDLE?(Dt.updateActionConfigs(mt),St.stateObject={state:l,state_name:"空闲"}):l===Ae.BUSY&&(Dt.updateActionConfigs(Ct),St.stateObject={state:l,state_name:"忙碌"});let q="";const g=new URL(a).host;q=a.includes("https")?`wss://${g}`:`ws://${g}`,Ks.getInstance(`${q}/ccs-ws/api/v1/ws/call/${c}?Authorization=${V}`),Dt.updateAnswerDevice(h),1===h&&await this.initWebRtc(),A&&o&&(this.#s=!0,new Fs({container:o,rttHTML:n,statusParams:{state:Ae.IDLE,statusName:"空闲"}},this)),St.enableBrowserAlert=r,r&&vs.requestPermission()}catch(A){this.#s&&ps("初始化失败"),console.log(A)}}#o=A=>{const{type:e,data:t}=A;ae.emit(e,t)};#n=A=>{};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}#a(){const A=Dt.get("isCalling"),e=St.sessionId;if(!A)throw new Error("当前没有通话");if(!e)throw new Error("当前没有通话")}#V(){this.#a();const A=Dt.get("isHold"),{sessionId:e}=St;if(e){if(A)throw new Error("当前已处于保持状态");Ks.__internalSend({type:ie.CALL_HOLD,data:{session_id:e}}),Dt.updateDisplayText(oe.HOLD),Dt.updateIsHold(!0)}}#c(){this.#a();const{isHold:A}=Dt.getState(),{sessionId:e}=St;if(e){if(!A)throw new Error("当前未处于保持状态");Ks.__internalSend({type:ie.CALL_UNHOLD,data:{session_id:e}}),Dt.updateDisplayText(""),Dt.updateIsHold(!1)}}#h(A){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:e}=Dt.getState();if(!e)throw new Error("当前没有通话");this.#A.sendDTMF(A)}#l(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A,direction:e,outCallIsAnswer:t}=Dt.getState();if(!A)throw new Error("当前没有通话");t||(e===ee.INCOMING?this.#q():e===ee.OUTGOING&&this.#g())}async#d(A){if(this.#a(),!this.#A)throw new Error("请先初始化SDK");const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=Dt.getState(),r=St.sessionId;if(s)throw new Error("当前正在咨询");if(!(e||t||i))throw new Error("当前没有通话");if(!r)throw new Error("sessionId不存在");Ks.__internalSend({type:ie.CONSULT_REQUEST,data:{session_id:r,consultation_agent_no:A}})}async#u(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");await this.#A.answerCall()}async#q(){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A}=Dt.getState();if(!A)throw new Error("当前没有通话");await this.#A.rejectInCall()}async#p(A){if(!this.#A)throw new Error("请先初始化SDK");if(Dt.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");Dt.updateIsCalling(!0),Dt.updateDirection(ee.OUTGOING),Ks.__internalSend({type:ie.OUT_CALL,data:{customer_phone:A}})}async#g(){const{isCalling:A}=Dt.getState();if(!this.#A)throw new Error("请先初始化SDK");if(!A)throw new Error("当前没有通话");await this.#A.rejectOutCall()}async#m(){if(!this.#A)throw new Error("请先初始化SDK");if(!Dt.get("isCalling"))throw new Error("当前没有通话");await this.#A.hangup()}#C(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(e)throw new Error("当前未处于静音状态");if(!A.includes("mute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.MUTE,data:{session_id:t}})}#E(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(!e)throw new Error("当前未处于未静音状态");if(!A.includes("unmute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.UNMUTE,data:{session_id:t}})}#I(){this.#a();const A=Dt.get("consultIsAnswer"),e=St.sessionId;if(!Dt.get("actionConfigs").includes("consult_transfer"))throw new Error("当前状态请勿调用咨询转移");if(!A)throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_TRANSFER,data:{session_id:e}})}#M(){this.#a();const A=St.sessionId;if(!Dt.get("actionConfigs").includes("satisfaction"))throw new Error("当前状态请勿调用满意度评价");Ks.__internalSend({type:ie.SATISFACTION_EVALUATION,data:{session_id:A}})}#w(){this.#a();if(!Dt.get("actionConfigs").includes("conference"))throw new Error("当前状态请勿调用三方会议");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_THREE_WAY,data:{session_id:A}})}#B(){this.#a();if(!Dt.get("actionConfigs").includes("consult_retrieve"))throw new Error("当前状态请勿取回通话");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_RETURN_CALL,data:{session_id:A}})}async destroyRtc(){await(this.#A?.destroy())}destroy(){this.destroyRtc(),clearInterval(this.#t),Zs.off("ws-message",this.#n),Ks.__internalClose(),this.offAll(),this.#i?.(),this.#A=null,this.#e=null,this.#s=!1}async#r(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){return this.#s?{answerCall:this.#u.bind(this),makeCall:this.#p.bind(this),cancelCall:this.#l.bind(this),hangup:this.#m.bind(this),sendDTMF:this.#h.bind(this),holdCall:this.#V.bind(this),unholdCall:this.#c.bind(this),consultCall:async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}},consultRetrieve:this.#B.bind(this),consultTransfer:this.#I.bind(this),mute:this.#C.bind(this),unmute:this.#E.bind(this),satisfactionEvaluation:this.#M.bind(this),startConference:this.#w.bind(this)}:{}}get agent_api(){return this.#s?{changeDevice:this.#e.changeDevice.bind(this.#e),changeState:this.#e.changeState.bind(this.#e),getIdleAgentList:A=>this.#e.getIdleAgentList(A),getAgentState:A=>this.#e.getAgentState(A)}:{}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t}=St.agentInfo,{stateObject:s}=St,i={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:i[Number(A)]})),stateObject:s}}};
824
+ `;qt(s,this.rttHTML)}}const Zs=new class{constructor(){this.events={}}on(A,e){this.events[A]=this.events[A]||[],this.events[A].push(e)}off(A,e){this.events[A]=(this.events[A]||[]).filter(A=>A!==e)}emit(A,...e){(this.events[A]||[]).forEach(A=>A(...e))}};class vs{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 console.log("已授权麦克风权限"),null;const e=await navigator.mediaDevices.getUserMedia({audio:!0});return console.log("获取音频权限成功"),e}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t){if("Notification"in window&&"granted"===Notification.permission){const s=new Notification(A,{body:e,tag:"xy-global-notification",renotify:!0});s.onclick=()=>{window.focus(),s.close(),t?.()},setTimeout(()=>s.close(),5e3)}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}let xs=null;class Ks{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Ys,this.initWebSocket()}static getInstance(A){if(!xs){if(!A)throw new Error("WebSocket 尚未初始化");xs=new Ks(A)}return xs}stateIdleChange(){const{state:A}=St.stateObject;A!==Ae.IDLE&&this.apiClient.changeState({data:{state:Ae.IDLE,state_name:"空闲"}})}putAgentState(){St.sessionId="";const{post_call_process_time:A}=St.agentInfo,e=A||0;St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),e>0?St.autoStateTimer=setTimeout(()=>{St.autoStateTimer=null,this.stateIdleChange()},e):this.stateIdleChange()}initWebSocket(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.sendMessage({type:0}),this.startHeartbeat()},this.ws.onmessage=A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:r}=e;if(0!==t&&console.warn(t),t===ie.OUT_CALL&&(0!==i?(ae.emit(se.OUT_FAILED,r),this.stateIdleChange()):0===i&&ae.emit(se.OUT_SUCCESS)),t===ie.AGENT_STATE){const{state:A,state_name:e}=s;St.stateObject={state:A,state_name:e},"振铃中"===e&&Dt.updateDisplayText(oe.AGENT_RINGING),ae.emit(se.AGENT_STATE,{state:A,state_name:e})}t===ie.OUT_CALL_INCOMING_CALL&&(ae.emit(se.OUT_INCOMING_CALL),St.sessionId=s.session_id,Dt.updateActionConfigs(Et)),t===ie.OUT_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.OUT_HANGUP,s),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.OUT_CALL_RINGING&&(ae.emit(se.OUT_RINGING,s),Dt.updateDisplayText(oe.RINGING)),t===ie.OUT_CALL_ANSWER&&(ae.emit(se.OUT_OFF_ANSWER,s),Dt.updateOutCallIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_RINGING&&(ae.emit(se.CONSULT_RINGING),Dt.updateDisplayText(oe.AGENT_RINGING),Dt.updateActionConfigs([])),t===ie.CONSULT_ANSWER&&(ae.emit(se.CONSULT_OFF_HOOK,s),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CONSULTING),Dt.updateActionConfigs(Mt)),t===ie.CONSULT_FAIL&&(ae.emit(se.CONSULT_FAILED,{custom_reason:s.custom_reason}),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_CALL_IN&&(ae.emit(se.CONSULT_INCOMING,s),Dt.updateIsCalling(!0),Dt.updateDirection(ee.CONSULT),Dt.updateDisplayText(oe.CONSULT_CALL_IN),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{agent_mane:s.agent_name})})),t===ie.CONSULT_CALL_IN_SUCCESS&&(St.sessionId=s.session_id,ae.emit(se.CONSULT_CALL_IN_SUCCESS),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(wt)),t===ie.CONSULT_RETURN_CALL_SUCCESS&&(ae.emit(se.CONSULT_RETURN_CALL_SUCCESS),Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)),t===ie.MUTE&&(0===i?(Dt.updateIsMuted(!0),ae.emit(se.MUTE_SUCCESS)):ae.emit(se.MUTE_FAILED,r)),t===ie.UNMUTE&&(0===i?(Dt.updateIsMuted(!1),ae.emit(se.UNMUTE_SUCCESS)):ae.emit(se.UNMUTE_FAILED,r)),t===ie.CONSULT_TRANSFER&&(0===i?ae.emit(se.CONSULT_TRANSFER_SUCCESS):ae.emit(se.CONSULT_TRANSFER_FAILED,r)),t===ie.CONSULT_TRANSFER_FAILED&&ae.emit(se.CONSULT_TRANSFER_FAILED,s.status),t===ie.CONSULT_TRANSFER_OFF_HOOK&&(Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.CALLING),ae.emit(se.CONSULT_TRANSFER_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateIncomingIsAnswer(!0),Dt.updateConsultIsAnswer(!1)),t===ie.INCOMING_CALL&&(St.sessionId=s.session_id,Dt.updateIsCalling(!0),Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.INCOMING_CALL),ae.emit(se.INCOMING_CALL,{customer_phone:s.customer_phone}),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})})),t===ie.INCOMING_CALL_OFF_HOOK&&(Dt.updateIncomingIsAnswer(!0),ae.emit(se.INCOMING_CALL_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateDisplayText(oe.CALLING)),t===ie.INCOMING_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.INCOMING_CALL_END),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.SATISFACTION_EVALUATION&&(0===i?ae.emit(se.SATISFACTION_EVALUATION_SUCCESS):ae.emit(se.SATISFACTION_EVALUATION_FAILED,r)),t===ie.CONSULT_THREE_WAY&&(0!==i?ae.emit(se.CONSULT_THREE_WAY_FAILED,r):0===i&&Dt.updateIsMeeting(!0)),t===ie.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(Dt.updateDirection(ee.MEETING),Dt.updateDisplayText(oe.MEETING),Dt.updateActionConfigs(Bt),ae.emit(se.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(se.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),Dt.updateIsMeeting(!1))),0!==t&&Zs.emit("ws-message",e)},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 }, 14000);\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=()=>{this.sendMessage({type:0})},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)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}static __internalClose(){xs&&(xs.close(),xs=null)}static __internalSend(A){if(!xs)throw new Error("WebSocket 尚未初始化");xs.sendMessage(A)}}module.exports=class{#A=null;#e=new Ys;#t=null;#s=!1;#i;constructor(){clearInterval(this.#t),this.#t=setInterval(async()=>{const A=await this.#r();Qs.updateRttObject(A)},2e3),vs.requestMediaPermissions(),window.addEventListener("beforeunload",()=>{this.destroy()}),this.#i=Dt.subscribeKey("answerDevice",A=>{1===A&&this.initWebRtc()})}async initWebRtc(){const A=St.agentInfo.sip_account_list.find(A=>1===A.device_type);if(A){const e=A.sip_register_addr;this.#A=new fs({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#o),await this.#A.start()}}async init({actionNodeParams:A,url:e,appKey:t,appSecret:s,agentNo:i,enableBrowserAlert:r}){try{const{viewHtmlElement:o,rttHTML:n}=A||{},a=e||"https://aicc.yescloudy.com";Is=a,Ms=t,ws=s;const V=os(t,s);await this.#e._agentLogin(i);const{agent_no:c,current_answer_device:h,init_state:l}=St.agentInfo;l===Ae.IDLE?(Dt.updateActionConfigs(mt),St.stateObject={state:l,state_name:"空闲"}):l===Ae.BUSY&&(Dt.updateActionConfigs(Ct),St.stateObject={state:l,state_name:"忙碌"});let q="";const g=new URL(a).host;q=a.includes("https")?`wss://${g}`:`ws://${g}`,Ks.getInstance(`${q}/ccs-ws/api/v1/ws/call/${c}?Authorization=${V}`),Dt.updateAnswerDevice(h),1===h&&await this.initWebRtc(),A&&o&&(this.#s=!0,new Fs({container:o,rttHTML:n,statusParams:{state:Ae.IDLE,statusName:"空闲"}},this)),St.enableBrowserAlert=r,r&&vs.requestPermission()}catch(A){this.#s&&ps("初始化失败"),console.log(A)}}#o=A=>{const{type:e,data:t}=A;ae.emit(e,t)};#n=A=>{};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}#a(){const A=Dt.get("isCalling"),e=St.sessionId;if(!A)throw new Error("当前没有通话");if(!e)throw new Error("当前没有通话")}#V(){this.#a();const A=Dt.get("isHold"),{sessionId:e}=St;if(e){if(A)throw new Error("当前已处于保持状态");Ks.__internalSend({type:ie.CALL_HOLD,data:{session_id:e}}),Dt.updateDisplayText(oe.HOLD),Dt.updateIsHold(!0)}}#c(){this.#a();const{isHold:A}=Dt.getState(),{sessionId:e}=St;if(e){if(!A)throw new Error("当前未处于保持状态");Ks.__internalSend({type:ie.CALL_UNHOLD,data:{session_id:e}}),Dt.updateDisplayText(""),Dt.updateIsHold(!1)}}#h(A){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:e}=Dt.getState();if(!e)throw new Error("当前没有通话");this.#A.sendDTMF(A)}#l(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A,direction:e,outCallIsAnswer:t}=Dt.getState();if(!A)throw new Error("当前没有通话");t||(e===ee.INCOMING?this.#q():e===ee.OUTGOING&&this.#g())}async#d(A){if(this.#a(),!this.#A)throw new Error("请先初始化SDK");const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=Dt.getState(),r=St.sessionId;if(s)throw new Error("当前正在咨询");if(!(e||t||i))throw new Error("当前没有通话");if(!r)throw new Error("sessionId不存在");Ks.__internalSend({type:ie.CONSULT_REQUEST,data:{session_id:r,consultation_agent_no:A}})}async#u(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");await this.#A.answerCall()}async#q(){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A}=Dt.getState();if(!A)throw new Error("当前没有通话");await this.#A.rejectInCall()}async#p(A){if(!this.#A)throw new Error("请先初始化SDK");if(Dt.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");Dt.updateIsCalling(!0),Dt.updateDirection(ee.OUTGOING),Ks.__internalSend({type:ie.OUT_CALL,data:{customer_phone:A}})}async#g(){const{isCalling:A}=Dt.getState();if(!this.#A)throw new Error("请先初始化SDK");if(!A)throw new Error("当前没有通话");await this.#A.rejectOutCall()}async#m(){if(!this.#A)throw new Error("请先初始化SDK");if(!Dt.get("isCalling"))throw new Error("当前没有通话");await this.#A.hangup()}#C(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(e)throw new Error("当前未处于静音状态");if(!A.includes("mute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.MUTE,data:{session_id:t}})}#E(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(!e)throw new Error("当前未处于未静音状态");if(!A.includes("unmute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.UNMUTE,data:{session_id:t}})}#I(){this.#a();const A=Dt.get("consultIsAnswer"),e=St.sessionId;if(!Dt.get("actionConfigs").includes("consult_transfer"))throw new Error("当前状态请勿调用咨询转移");if(!A)throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_TRANSFER,data:{session_id:e}})}#M(){this.#a();const A=St.sessionId;if(!Dt.get("actionConfigs").includes("satisfaction"))throw new Error("当前状态请勿调用满意度评价");Ks.__internalSend({type:ie.SATISFACTION_EVALUATION,data:{session_id:A}})}#w(){this.#a();if(!Dt.get("actionConfigs").includes("conference"))throw new Error("当前状态请勿调用三方会议");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_THREE_WAY,data:{session_id:A}})}#B(){this.#a();if(!Dt.get("actionConfigs").includes("consult_retrieve"))throw new Error("当前状态请勿取回通话");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_RETURN_CALL,data:{session_id:A}})}async destroyRtc(){await(this.#A?.destroy())}destroy(){this.destroyRtc(),clearInterval(this.#t),Zs.off("ws-message",this.#n),Ks.__internalClose(),this.offAll(),this.#i?.(),this.#A=null,this.#e=null,this.#s=!1}async#r(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){return this.#s?{answerCall:this.#u.bind(this),makeCall:this.#p.bind(this),cancelCall:this.#l.bind(this),hangup:this.#m.bind(this),sendDTMF:this.#h.bind(this),holdCall:this.#V.bind(this),unholdCall:this.#c.bind(this),consultCall:async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}},consultRetrieve:this.#B.bind(this),consultTransfer:this.#I.bind(this),mute:this.#C.bind(this),unmute:this.#E.bind(this),satisfactionEvaluation:this.#M.bind(this),startConference:this.#w.bind(this)}:{}}get agent_api(){return this.#s?{changeDevice:this.#e.changeDevice.bind(this.#e),changeState:this.#e.changeState.bind(this.#e),getIdleAgentList:A=>this.#e.getIdleAgentList(A),getAgentState:A=>this.#e.getAgentState(A)}:{}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t,init_state:s,default_device:i}=St.agentInfo,{stateObject:r}=St,o={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,init_state:s,default_device:i,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:o[Number(A)]})),stateObject:r}}};
@@ -581,7 +581,7 @@ const Vs=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
581
581
  <div class="popup ${this.open?"":"hidden"}">
582
582
  <slot name="content"></slot>
583
583
  </div>
584
- `}};as([qs()],Ys.prototype,"open",void 0),Ys=as([Vs("my-icon-popup")],Ys);class Fs{constructor(){this.roleData={agentInfo:()=>{if(!St.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:A=>{if(!A.data)throw new Error("请传入参数")},changeDevice:A=>{if(!A)throw new Error('Parameter "device" is required');const{answer_devices:e}=St.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error("当前设备不支持")},changeState:(A,e)=>{if(!A)throw new Error('Parameter "state" is required');if(!e)throw new Error('Parameter "state_name" is required');if(2===A&&"通话中"===e)throw new Error("当前状态不支持");if(![1,2].includes(A))throw new Error("当前状态不支持")}}}async _agentLogin(A){try{const t=await(e={agent_no:A},Qs(`${Is}/agent/login`,e));St.agentInfo=t.data}catch(A){throw console.log(A),new Error("登录失败")}var e}async changeDevice(A){try{if(Dt.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;this.roleData.changeDevice(s);const{agent_no:i}=St.agentInfo;await(A=>Qs(`${Is}/device/change`,A))({agent_no:i,answer_device:s}),Dt.updateAnswerDevice(s);const r=Dt.get("actionConfigs");Dt.updateActionConfigs(r),t?.({code:0,msg:"请求成功"})}catch(A){throw console.log(A),new Error("切换设备失败")}}async changeState(A){try{St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:r}=St.agentInfo;await(A=>Qs(`${Is}/state/change`,A))({agent_no:r,state_name:i,state:s}),s===Ae.IDLE?Dt.updateActionConfigs(mt):s===Ae.BUSY&&Dt.updateActionConfigs(Ct),St.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){console.log(A)}}async getIdleAgentList(A){const{agent_no:e}=St.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Qs(`${Is}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){console.log(A)}}async getAgentState(A){try{const e=await Qs(`${Es}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).map(A=>({state:A.state,state_name:A.state_name})).reverse();A.success?.({...e,data:t})}catch(A){console.log(A)}}}class Zs{constructor({container:A,rttHTML:e,statusParams:t},s){this.VoiceSDKInstance=s,this.apiClient=new Fs,this.isOpenSelect=!1,this.statusParams={state:Ae.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=A=>{this.rttHTML&&this.renderRtt(A.rttObject)},this.handleCallInfoChange=A=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const A=document.querySelector(".ysyt-select");A.style.height="0px",setTimeout(()=>{A.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=A=>{A.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const e=document.querySelector(".ysyt-select");this.isOpenSelect?(e.style.height=e.scrollHeight+"px",e.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async A=>{const{state:e,statusName:t}=A;await this.apiClient.changeState({data:{state:e,state_name:t},success:()=>{this.statusParams=A;const e=document.getElementById("my-timer");e?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async A=>{try{await this.apiClient.changeDevice({data:{device:A},success:({code:e})=>{0===e&&(1!==A&&this.VoiceSDKInstance.destroyRtc(),ps("切换成功"),this.default_device=A,this.render())}})}catch(A){console.log(A),ms(A.message),this.render()}},this.ruleCall=async A=>{if(A)try{await this.VoiceSDKInstance.call_api.makeCall(A)}catch(A){console.error(A)}},this.onCall=()=>{const A=document.querySelector("my-input");this.ruleCall(A.value)},this.renderCallPopover=()=>ze`
584
+ `}};as([qs()],Ys.prototype,"open",void 0),Ys=as([Vs("my-icon-popup")],Ys);class Fs{constructor(){this.roleData={agentInfo:()=>{if(!St.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:A=>{if(!A.data)throw new Error("请传入参数")},changeDevice:A=>{if(!A)throw new Error('Parameter "device" is required');const{answer_devices:e}=St.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error("当前设备不支持")},changeState:(A,e)=>{if(!A)throw new Error('Parameter "state" is required');if(!e)throw new Error('Parameter "state_name" is required');if(2===A&&"通话中"===e)throw new Error("当前状态不支持");if(![1,2].includes(A))throw new Error("当前状态不支持")}}}async _agentLogin(A){try{const t=await(e={agent_no:A},Qs(`${Is}/agent/login`,e));St.agentInfo=t.data}catch(A){throw console.log(A),new Error("登录失败")}var e}async changeDevice(A){try{if(Dt.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;this.roleData.changeDevice(s);const{agent_no:i}=St.agentInfo;await(A=>Qs(`${Is}/device/change`,A))({agent_no:i,answer_device:s}),Dt.updateAnswerDevice(s);const r=Dt.get("actionConfigs");Dt.updateActionConfigs(r),t?.({code:0,msg:"请求成功"})}catch(A){throw console.log(A),new Error("切换设备失败")}}async changeState(A){try{St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:r}=St.agentInfo;await(A=>Qs(`${Is}/state/change`,A))({agent_no:r,state_name:i,state:s}),s===Ae.IDLE?Dt.updateActionConfigs(mt):s===Ae.BUSY&&Dt.updateActionConfigs(Ct),St.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){console.log(A)}}async getIdleAgentList(A){const{agent_no:e}=St.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Qs(`${Is}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){console.log(A)}}async getAgentState(A){try{const e=await Qs(`${Es}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).filter(A=>"通话中"!==A.state_name).map(A=>({state:A.state,state_name:A.state_name})).reverse();console.log(t),A.success?.({...e,data:t})}catch(A){console.log(A)}}}class Zs{constructor({container:A,rttHTML:e,statusParams:t},s){this.VoiceSDKInstance=s,this.apiClient=new Fs,this.isOpenSelect=!1,this.statusParams={state:Ae.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=A=>{this.rttHTML&&this.renderRtt(A.rttObject)},this.handleCallInfoChange=A=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const A=document.querySelector(".ysyt-select");A.style.height="0px",setTimeout(()=>{A.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=A=>{A.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const e=document.querySelector(".ysyt-select");this.isOpenSelect?(e.style.height=e.scrollHeight+"px",e.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async A=>{const{state:e,statusName:t}=A;await this.apiClient.changeState({data:{state:e,state_name:t},success:()=>{this.statusParams=A;const e=document.getElementById("my-timer");e?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async A=>{try{await this.apiClient.changeDevice({data:{device:A},success:({code:e})=>{0===e&&(1!==A&&this.VoiceSDKInstance.destroyRtc(),ps("切换成功"),this.default_device=A,this.render())}})}catch(A){console.log(A),ms(A.message),this.render()}},this.ruleCall=async A=>{if(A)try{await this.VoiceSDKInstance.call_api.makeCall(A)}catch(A){console.error(A)}},this.onCall=()=>{const A=document.querySelector("my-input");this.ruleCall(A.value)},this.renderCallPopover=()=>ze`
585
585
  <my-icon-popup>
586
586
  <div slot="icon">
587
587
  <i class="ysyt icon-boda my-icon"></i>
@@ -821,4 +821,4 @@ const Vs=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
821
821
  `:""}
822
822
  </div>
823
823
  </my-popover>
824
- `;qt(s,this.rttHTML)}}const vs=new class{constructor(){this.events={}}on(A,e){this.events[A]=this.events[A]||[],this.events[A].push(e)}off(A,e){this.events[A]=(this.events[A]||[]).filter(A=>A!==e)}emit(A,...e){(this.events[A]||[]).forEach(A=>A(...e))}};class xs{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 console.log("已授权麦克风权限"),null;const e=await navigator.mediaDevices.getUserMedia({audio:!0});return console.log("获取音频权限成功"),e}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t){if("Notification"in window&&"granted"===Notification.permission){const s=new Notification(A,{body:e,tag:"xy-global-notification",renotify:!0});s.onclick=()=>{window.focus(),s.close(),t?.()},setTimeout(()=>s.close(),5e3)}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}let Ks=null;class Os{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Fs,this.initWebSocket()}static getInstance(A){if(!Ks){if(!A)throw new Error("WebSocket 尚未初始化");Ks=new Os(A)}return Ks}stateIdleChange(){const{state:A}=St.stateObject;A!==Ae.IDLE&&this.apiClient.changeState({data:{state:Ae.IDLE,state_name:"空闲"}})}putAgentState(){St.sessionId="";const{post_call_process_time:A}=St.agentInfo,e=A||0;St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),e>0?St.autoStateTimer=setTimeout(()=>{St.autoStateTimer=null,this.stateIdleChange()},e):this.stateIdleChange()}initWebSocket(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.sendMessage({type:0}),this.startHeartbeat()},this.ws.onmessage=A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:r}=e;if(0!==t&&console.warn(t),t===ie.OUT_CALL&&(0!==i?(ae.emit(se.OUT_FAILED,r),this.stateIdleChange()):0===i&&ae.emit(se.OUT_SUCCESS)),t===ie.AGENT_STATE){const{state:A,state_name:e}=s;St.stateObject={state:A,state_name:e},"振铃中"===e&&Dt.updateDisplayText(oe.AGENT_RINGING),ae.emit(se.AGENT_STATE,{state:A,state_name:e})}t===ie.OUT_CALL_INCOMING_CALL&&(ae.emit(se.OUT_INCOMING_CALL),St.sessionId=s.session_id,Dt.updateActionConfigs(Et)),t===ie.OUT_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.OUT_HANGUP,s),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.OUT_CALL_RINGING&&(ae.emit(se.OUT_RINGING,s),Dt.updateDisplayText(oe.RINGING)),t===ie.OUT_CALL_ANSWER&&(ae.emit(se.OUT_OFF_ANSWER,s),Dt.updateOutCallIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_RINGING&&(ae.emit(se.CONSULT_RINGING),Dt.updateDisplayText(oe.AGENT_RINGING),Dt.updateActionConfigs([])),t===ie.CONSULT_ANSWER&&(ae.emit(se.CONSULT_OFF_HOOK,s),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CONSULTING),Dt.updateActionConfigs(Mt)),t===ie.CONSULT_FAIL&&(ae.emit(se.CONSULT_FAILED,{custom_reason:s.custom_reason}),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_CALL_IN&&(ae.emit(se.CONSULT_INCOMING,s),Dt.updateIsCalling(!0),Dt.updateDirection(ee.CONSULT),Dt.updateDisplayText(oe.CONSULT_CALL_IN),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&xs.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{agent_mane:s.agent_name})})),t===ie.CONSULT_CALL_IN_SUCCESS&&(St.sessionId=s.session_id,ae.emit(se.CONSULT_CALL_IN_SUCCESS),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(wt)),t===ie.CONSULT_RETURN_CALL_SUCCESS&&(ae.emit(se.CONSULT_RETURN_CALL_SUCCESS),Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)),t===ie.MUTE&&(0===i?(Dt.updateIsMuted(!0),ae.emit(se.MUTE_SUCCESS)):ae.emit(se.MUTE_FAILED,r)),t===ie.UNMUTE&&(0===i?(Dt.updateIsMuted(!1),ae.emit(se.UNMUTE_SUCCESS)):ae.emit(se.UNMUTE_FAILED,r)),t===ie.CONSULT_TRANSFER&&(0===i?ae.emit(se.CONSULT_TRANSFER_SUCCESS):ae.emit(se.CONSULT_TRANSFER_FAILED,r)),t===ie.CONSULT_TRANSFER_FAILED&&ae.emit(se.CONSULT_TRANSFER_FAILED,s.status),t===ie.CONSULT_TRANSFER_OFF_HOOK&&(Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.CALLING),ae.emit(se.CONSULT_TRANSFER_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateIncomingIsAnswer(!0),Dt.updateConsultIsAnswer(!1)),t===ie.INCOMING_CALL&&(St.sessionId=s.session_id,Dt.updateIsCalling(!0),Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.INCOMING_CALL),ae.emit(se.INCOMING_CALL,{customer_phone:s.customer_phone}),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&xs.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})})),t===ie.INCOMING_CALL_OFF_HOOK&&(Dt.updateIncomingIsAnswer(!0),ae.emit(se.INCOMING_CALL_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateDisplayText(oe.CALLING)),t===ie.INCOMING_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.INCOMING_CALL_END),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.SATISFACTION_EVALUATION&&(0===i?ae.emit(se.SATISFACTION_EVALUATION_SUCCESS):ae.emit(se.SATISFACTION_EVALUATION_FAILED,r)),t===ie.CONSULT_THREE_WAY&&(0!==i?ae.emit(se.CONSULT_THREE_WAY_FAILED,r):0===i&&Dt.updateIsMeeting(!0)),t===ie.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(Dt.updateDirection(ee.MEETING),Dt.updateDisplayText(oe.MEETING),Dt.updateActionConfigs(Bt),ae.emit(se.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(se.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),Dt.updateIsMeeting(!1))),0!==t&&vs.emit("ws-message",e)},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 }, 14000);\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=()=>{this.sendMessage({type:0})},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)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}static __internalClose(){Ks&&(Ks.close(),Ks=null)}static __internalSend(A){if(!Ks)throw new Error("WebSocket 尚未初始化");Ks.sendMessage(A)}}class bs{#A=null;#e=new Fs;#t=null;#s=!1;#i;constructor(){clearInterval(this.#t),this.#t=setInterval(async()=>{const A=await this.#r();fs.updateRttObject(A)},2e3),xs.requestMediaPermissions(),window.addEventListener("beforeunload",()=>{this.destroy()}),this.#i=Dt.subscribeKey("answerDevice",A=>{1===A&&this.initWebRtc()})}async initWebRtc(){const A=St.agentInfo.sip_account_list.find(A=>1===A.device_type);if(A){const e=A.sip_register_addr;this.#A=new Ss({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#o),await this.#A.start()}}async init({actionNodeParams:A,url:e,appKey:t,appSecret:s,agentNo:i,enableBrowserAlert:r}){try{const{viewHtmlElement:o,rttHTML:n}=A||{},a=e||"https://aicc.yescloudy.com";Ms=a,ws=t,Bs=s;const V=ns(t,s);await this.#e._agentLogin(i);const{agent_no:c,current_answer_device:h,init_state:l}=St.agentInfo;l===Ae.IDLE?(Dt.updateActionConfigs(mt),St.stateObject={state:l,state_name:"空闲"}):l===Ae.BUSY&&(Dt.updateActionConfigs(Ct),St.stateObject={state:l,state_name:"忙碌"});let q="";const g=new URL(a).host;q=a.includes("https")?`wss://${g}`:`ws://${g}`,Os.getInstance(`${q}/ccs-ws/api/v1/ws/call/${c}?Authorization=${V}`),Dt.updateAnswerDevice(h),1===h&&await this.initWebRtc(),A&&o&&(this.#s=!0,new Zs({container:o,rttHTML:n,statusParams:{state:Ae.IDLE,statusName:"空闲"}},this)),St.enableBrowserAlert=r,r&&xs.requestPermission()}catch(A){this.#s&&ms("初始化失败"),console.log(A)}}#o=A=>{const{type:e,data:t}=A;ae.emit(e,t)};#n=A=>{};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}#a(){const A=Dt.get("isCalling"),e=St.sessionId;if(!A)throw new Error("当前没有通话");if(!e)throw new Error("当前没有通话")}#V(){this.#a();const A=Dt.get("isHold"),{sessionId:e}=St;if(e){if(A)throw new Error("当前已处于保持状态");Os.__internalSend({type:ie.CALL_HOLD,data:{session_id:e}}),Dt.updateDisplayText(oe.HOLD),Dt.updateIsHold(!0)}}#c(){this.#a();const{isHold:A}=Dt.getState(),{sessionId:e}=St;if(e){if(!A)throw new Error("当前未处于保持状态");Os.__internalSend({type:ie.CALL_UNHOLD,data:{session_id:e}}),Dt.updateDisplayText(""),Dt.updateIsHold(!1)}}#h(A){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:e}=Dt.getState();if(!e)throw new Error("当前没有通话");this.#A.sendDTMF(A)}#l(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A,direction:e,outCallIsAnswer:t}=Dt.getState();if(!A)throw new Error("当前没有通话");t||(e===ee.INCOMING?this.#q():e===ee.OUTGOING&&this.#g())}async#d(A){if(this.#a(),!this.#A)throw new Error("请先初始化SDK");const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=Dt.getState(),r=St.sessionId;if(s)throw new Error("当前正在咨询");if(!(e||t||i))throw new Error("当前没有通话");if(!r)throw new Error("sessionId不存在");Os.__internalSend({type:ie.CONSULT_REQUEST,data:{session_id:r,consultation_agent_no:A}})}async#u(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");await this.#A.answerCall()}async#q(){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A}=Dt.getState();if(!A)throw new Error("当前没有通话");await this.#A.rejectInCall()}async#p(A){if(!this.#A)throw new Error("请先初始化SDK");if(Dt.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");Dt.updateIsCalling(!0),Dt.updateDirection(ee.OUTGOING),Os.__internalSend({type:ie.OUT_CALL,data:{customer_phone:A}})}async#g(){const{isCalling:A}=Dt.getState();if(!this.#A)throw new Error("请先初始化SDK");if(!A)throw new Error("当前没有通话");await this.#A.rejectOutCall()}async#m(){if(!this.#A)throw new Error("请先初始化SDK");if(!Dt.get("isCalling"))throw new Error("当前没有通话");await this.#A.hangup()}#C(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(e)throw new Error("当前未处于静音状态");if(!A.includes("mute"))throw new Error("当前状态请勿调用静音");Os.__internalSend({type:ie.MUTE,data:{session_id:t}})}#E(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(!e)throw new Error("当前未处于未静音状态");if(!A.includes("unmute"))throw new Error("当前状态请勿调用静音");Os.__internalSend({type:ie.UNMUTE,data:{session_id:t}})}#I(){this.#a();const A=Dt.get("consultIsAnswer"),e=St.sessionId;if(!Dt.get("actionConfigs").includes("consult_transfer"))throw new Error("当前状态请勿调用咨询转移");if(!A)throw new Error("当前未处于咨询中");Os.__internalSend({type:ie.CONSULT_TRANSFER,data:{session_id:e}})}#M(){this.#a();const A=St.sessionId;if(!Dt.get("actionConfigs").includes("satisfaction"))throw new Error("当前状态请勿调用满意度评价");Os.__internalSend({type:ie.SATISFACTION_EVALUATION,data:{session_id:A}})}#w(){this.#a();if(!Dt.get("actionConfigs").includes("conference"))throw new Error("当前状态请勿调用三方会议");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Os.__internalSend({type:ie.CONSULT_THREE_WAY,data:{session_id:A}})}#B(){this.#a();if(!Dt.get("actionConfigs").includes("consult_retrieve"))throw new Error("当前状态请勿取回通话");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Os.__internalSend({type:ie.CONSULT_RETURN_CALL,data:{session_id:A}})}async destroyRtc(){await(this.#A?.destroy())}destroy(){this.destroyRtc(),clearInterval(this.#t),vs.off("ws-message",this.#n),Os.__internalClose(),this.offAll(),this.#i?.(),this.#A=null,this.#e=null,this.#s=!1}async#r(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){return this.#s?{answerCall:this.#u.bind(this),makeCall:this.#p.bind(this),cancelCall:this.#l.bind(this),hangup:this.#m.bind(this),sendDTMF:this.#h.bind(this),holdCall:this.#V.bind(this),unholdCall:this.#c.bind(this),consultCall:async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}},consultRetrieve:this.#B.bind(this),consultTransfer:this.#I.bind(this),mute:this.#C.bind(this),unmute:this.#E.bind(this),satisfactionEvaluation:this.#M.bind(this),startConference:this.#w.bind(this)}:{}}get agent_api(){return this.#s?{changeDevice:this.#e.changeDevice.bind(this.#e),changeState:this.#e.changeState.bind(this.#e),getIdleAgentList:A=>this.#e.getIdleAgentList(A),getAgentState:A=>this.#e.getAgentState(A)}:{}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t}=St.agentInfo,{stateObject:s}=St,i={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:i[Number(A)]})),stateObject:s}}}export{bs as default};
824
+ `;qt(s,this.rttHTML)}}const vs=new class{constructor(){this.events={}}on(A,e){this.events[A]=this.events[A]||[],this.events[A].push(e)}off(A,e){this.events[A]=(this.events[A]||[]).filter(A=>A!==e)}emit(A,...e){(this.events[A]||[]).forEach(A=>A(...e))}};class xs{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 console.log("已授权麦克风权限"),null;const e=await navigator.mediaDevices.getUserMedia({audio:!0});return console.log("获取音频权限成功"),e}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t){if("Notification"in window&&"granted"===Notification.permission){const s=new Notification(A,{body:e,tag:"xy-global-notification",renotify:!0});s.onclick=()=>{window.focus(),s.close(),t?.()},setTimeout(()=>s.close(),5e3)}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}let Ks=null;class Os{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Fs,this.initWebSocket()}static getInstance(A){if(!Ks){if(!A)throw new Error("WebSocket 尚未初始化");Ks=new Os(A)}return Ks}stateIdleChange(){const{state:A}=St.stateObject;A!==Ae.IDLE&&this.apiClient.changeState({data:{state:Ae.IDLE,state_name:"空闲"}})}putAgentState(){St.sessionId="";const{post_call_process_time:A}=St.agentInfo,e=A||0;St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),e>0?St.autoStateTimer=setTimeout(()=>{St.autoStateTimer=null,this.stateIdleChange()},e):this.stateIdleChange()}initWebSocket(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.sendMessage({type:0}),this.startHeartbeat()},this.ws.onmessage=A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:r}=e;if(0!==t&&console.warn(t),t===ie.OUT_CALL&&(0!==i?(ae.emit(se.OUT_FAILED,r),this.stateIdleChange()):0===i&&ae.emit(se.OUT_SUCCESS)),t===ie.AGENT_STATE){const{state:A,state_name:e}=s;St.stateObject={state:A,state_name:e},"振铃中"===e&&Dt.updateDisplayText(oe.AGENT_RINGING),ae.emit(se.AGENT_STATE,{state:A,state_name:e})}t===ie.OUT_CALL_INCOMING_CALL&&(ae.emit(se.OUT_INCOMING_CALL),St.sessionId=s.session_id,Dt.updateActionConfigs(Et)),t===ie.OUT_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.OUT_HANGUP,s),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.OUT_CALL_RINGING&&(ae.emit(se.OUT_RINGING,s),Dt.updateDisplayText(oe.RINGING)),t===ie.OUT_CALL_ANSWER&&(ae.emit(se.OUT_OFF_ANSWER,s),Dt.updateOutCallIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_RINGING&&(ae.emit(se.CONSULT_RINGING),Dt.updateDisplayText(oe.AGENT_RINGING),Dt.updateActionConfigs([])),t===ie.CONSULT_ANSWER&&(ae.emit(se.CONSULT_OFF_HOOK,s),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CONSULTING),Dt.updateActionConfigs(Mt)),t===ie.CONSULT_FAIL&&(ae.emit(se.CONSULT_FAILED,{custom_reason:s.custom_reason}),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_CALL_IN&&(ae.emit(se.CONSULT_INCOMING,s),Dt.updateIsCalling(!0),Dt.updateDirection(ee.CONSULT),Dt.updateDisplayText(oe.CONSULT_CALL_IN),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&xs.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{agent_mane:s.agent_name})})),t===ie.CONSULT_CALL_IN_SUCCESS&&(St.sessionId=s.session_id,ae.emit(se.CONSULT_CALL_IN_SUCCESS),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(wt)),t===ie.CONSULT_RETURN_CALL_SUCCESS&&(ae.emit(se.CONSULT_RETURN_CALL_SUCCESS),Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)),t===ie.MUTE&&(0===i?(Dt.updateIsMuted(!0),ae.emit(se.MUTE_SUCCESS)):ae.emit(se.MUTE_FAILED,r)),t===ie.UNMUTE&&(0===i?(Dt.updateIsMuted(!1),ae.emit(se.UNMUTE_SUCCESS)):ae.emit(se.UNMUTE_FAILED,r)),t===ie.CONSULT_TRANSFER&&(0===i?ae.emit(se.CONSULT_TRANSFER_SUCCESS):ae.emit(se.CONSULT_TRANSFER_FAILED,r)),t===ie.CONSULT_TRANSFER_FAILED&&ae.emit(se.CONSULT_TRANSFER_FAILED,s.status),t===ie.CONSULT_TRANSFER_OFF_HOOK&&(Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.CALLING),ae.emit(se.CONSULT_TRANSFER_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateIncomingIsAnswer(!0),Dt.updateConsultIsAnswer(!1)),t===ie.INCOMING_CALL&&(St.sessionId=s.session_id,Dt.updateIsCalling(!0),Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.INCOMING_CALL),ae.emit(se.INCOMING_CALL,{customer_phone:s.customer_phone}),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&xs.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})})),t===ie.INCOMING_CALL_OFF_HOOK&&(Dt.updateIncomingIsAnswer(!0),ae.emit(se.INCOMING_CALL_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateDisplayText(oe.CALLING)),t===ie.INCOMING_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.INCOMING_CALL_END),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.SATISFACTION_EVALUATION&&(0===i?ae.emit(se.SATISFACTION_EVALUATION_SUCCESS):ae.emit(se.SATISFACTION_EVALUATION_FAILED,r)),t===ie.CONSULT_THREE_WAY&&(0!==i?ae.emit(se.CONSULT_THREE_WAY_FAILED,r):0===i&&Dt.updateIsMeeting(!0)),t===ie.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(Dt.updateDirection(ee.MEETING),Dt.updateDisplayText(oe.MEETING),Dt.updateActionConfigs(Bt),ae.emit(se.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(se.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),Dt.updateIsMeeting(!1))),0!==t&&vs.emit("ws-message",e)},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 }, 14000);\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=()=>{this.sendMessage({type:0})},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)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}static __internalClose(){Ks&&(Ks.close(),Ks=null)}static __internalSend(A){if(!Ks)throw new Error("WebSocket 尚未初始化");Ks.sendMessage(A)}}class bs{#A=null;#e=new Fs;#t=null;#s=!1;#i;constructor(){clearInterval(this.#t),this.#t=setInterval(async()=>{const A=await this.#r();fs.updateRttObject(A)},2e3),xs.requestMediaPermissions(),window.addEventListener("beforeunload",()=>{this.destroy()}),this.#i=Dt.subscribeKey("answerDevice",A=>{1===A&&this.initWebRtc()})}async initWebRtc(){const A=St.agentInfo.sip_account_list.find(A=>1===A.device_type);if(A){const e=A.sip_register_addr;this.#A=new Ss({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#o),await this.#A.start()}}async init({actionNodeParams:A,url:e,appKey:t,appSecret:s,agentNo:i,enableBrowserAlert:r}){try{const{viewHtmlElement:o,rttHTML:n}=A||{},a=e||"https://aicc.yescloudy.com";Ms=a,ws=t,Bs=s;const V=ns(t,s);await this.#e._agentLogin(i);const{agent_no:c,current_answer_device:h,init_state:l}=St.agentInfo;l===Ae.IDLE?(Dt.updateActionConfigs(mt),St.stateObject={state:l,state_name:"空闲"}):l===Ae.BUSY&&(Dt.updateActionConfigs(Ct),St.stateObject={state:l,state_name:"忙碌"});let q="";const g=new URL(a).host;q=a.includes("https")?`wss://${g}`:`ws://${g}`,Os.getInstance(`${q}/ccs-ws/api/v1/ws/call/${c}?Authorization=${V}`),Dt.updateAnswerDevice(h),1===h&&await this.initWebRtc(),A&&o&&(this.#s=!0,new Zs({container:o,rttHTML:n,statusParams:{state:Ae.IDLE,statusName:"空闲"}},this)),St.enableBrowserAlert=r,r&&xs.requestPermission()}catch(A){this.#s&&ms("初始化失败"),console.log(A)}}#o=A=>{const{type:e,data:t}=A;ae.emit(e,t)};#n=A=>{};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}#a(){const A=Dt.get("isCalling"),e=St.sessionId;if(!A)throw new Error("当前没有通话");if(!e)throw new Error("当前没有通话")}#V(){this.#a();const A=Dt.get("isHold"),{sessionId:e}=St;if(e){if(A)throw new Error("当前已处于保持状态");Os.__internalSend({type:ie.CALL_HOLD,data:{session_id:e}}),Dt.updateDisplayText(oe.HOLD),Dt.updateIsHold(!0)}}#c(){this.#a();const{isHold:A}=Dt.getState(),{sessionId:e}=St;if(e){if(!A)throw new Error("当前未处于保持状态");Os.__internalSend({type:ie.CALL_UNHOLD,data:{session_id:e}}),Dt.updateDisplayText(""),Dt.updateIsHold(!1)}}#h(A){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:e}=Dt.getState();if(!e)throw new Error("当前没有通话");this.#A.sendDTMF(A)}#l(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A,direction:e,outCallIsAnswer:t}=Dt.getState();if(!A)throw new Error("当前没有通话");t||(e===ee.INCOMING?this.#q():e===ee.OUTGOING&&this.#g())}async#d(A){if(this.#a(),!this.#A)throw new Error("请先初始化SDK");const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=Dt.getState(),r=St.sessionId;if(s)throw new Error("当前正在咨询");if(!(e||t||i))throw new Error("当前没有通话");if(!r)throw new Error("sessionId不存在");Os.__internalSend({type:ie.CONSULT_REQUEST,data:{session_id:r,consultation_agent_no:A}})}async#u(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");await this.#A.answerCall()}async#q(){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A}=Dt.getState();if(!A)throw new Error("当前没有通话");await this.#A.rejectInCall()}async#p(A){if(!this.#A)throw new Error("请先初始化SDK");if(Dt.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");Dt.updateIsCalling(!0),Dt.updateDirection(ee.OUTGOING),Os.__internalSend({type:ie.OUT_CALL,data:{customer_phone:A}})}async#g(){const{isCalling:A}=Dt.getState();if(!this.#A)throw new Error("请先初始化SDK");if(!A)throw new Error("当前没有通话");await this.#A.rejectOutCall()}async#m(){if(!this.#A)throw new Error("请先初始化SDK");if(!Dt.get("isCalling"))throw new Error("当前没有通话");await this.#A.hangup()}#C(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(e)throw new Error("当前未处于静音状态");if(!A.includes("mute"))throw new Error("当前状态请勿调用静音");Os.__internalSend({type:ie.MUTE,data:{session_id:t}})}#E(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(!e)throw new Error("当前未处于未静音状态");if(!A.includes("unmute"))throw new Error("当前状态请勿调用静音");Os.__internalSend({type:ie.UNMUTE,data:{session_id:t}})}#I(){this.#a();const A=Dt.get("consultIsAnswer"),e=St.sessionId;if(!Dt.get("actionConfigs").includes("consult_transfer"))throw new Error("当前状态请勿调用咨询转移");if(!A)throw new Error("当前未处于咨询中");Os.__internalSend({type:ie.CONSULT_TRANSFER,data:{session_id:e}})}#M(){this.#a();const A=St.sessionId;if(!Dt.get("actionConfigs").includes("satisfaction"))throw new Error("当前状态请勿调用满意度评价");Os.__internalSend({type:ie.SATISFACTION_EVALUATION,data:{session_id:A}})}#w(){this.#a();if(!Dt.get("actionConfigs").includes("conference"))throw new Error("当前状态请勿调用三方会议");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Os.__internalSend({type:ie.CONSULT_THREE_WAY,data:{session_id:A}})}#B(){this.#a();if(!Dt.get("actionConfigs").includes("consult_retrieve"))throw new Error("当前状态请勿取回通话");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Os.__internalSend({type:ie.CONSULT_RETURN_CALL,data:{session_id:A}})}async destroyRtc(){await(this.#A?.destroy())}destroy(){this.destroyRtc(),clearInterval(this.#t),vs.off("ws-message",this.#n),Os.__internalClose(),this.offAll(),this.#i?.(),this.#A=null,this.#e=null,this.#s=!1}async#r(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){return this.#s?{answerCall:this.#u.bind(this),makeCall:this.#p.bind(this),cancelCall:this.#l.bind(this),hangup:this.#m.bind(this),sendDTMF:this.#h.bind(this),holdCall:this.#V.bind(this),unholdCall:this.#c.bind(this),consultCall:async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}},consultRetrieve:this.#B.bind(this),consultTransfer:this.#I.bind(this),mute:this.#C.bind(this),unmute:this.#E.bind(this),satisfactionEvaluation:this.#M.bind(this),startConference:this.#w.bind(this)}:{}}get agent_api(){return this.#s?{changeDevice:this.#e.changeDevice.bind(this.#e),changeState:this.#e.changeState.bind(this.#e),getIdleAgentList:A=>this.#e.getIdleAgentList(A),getAgentState:A=>this.#e.getAgentState(A)}:{}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t,init_state:s,default_device:i}=St.agentInfo,{stateObject:r}=St,o={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,init_state:s,default_device:i,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:o[Number(A)]})),stateObject:r}}}export{bs as default};
@@ -581,7 +581,7 @@ const as=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
581
581
  <div class="popup ${this.open?"":"hidden"}">
582
582
  <slot name="content"></slot>
583
583
  </div>
584
- `}};ns([ls()],Gs.prototype,"open",void 0),Gs=ns([as("my-icon-popup")],Gs);class Ys{constructor(){this.roleData={agentInfo:()=>{if(!St.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:A=>{if(!A.data)throw new Error("请传入参数")},changeDevice:A=>{if(!A)throw new Error('Parameter "device" is required');const{answer_devices:e}=St.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error("当前设备不支持")},changeState:(A,e)=>{if(!A)throw new Error('Parameter "state" is required');if(!e)throw new Error('Parameter "state_name" is required');if(2===A&&"通话中"===e)throw new Error("当前状态不支持");if(![1,2].includes(A))throw new Error("当前状态不支持")}}}async _agentLogin(A){try{const t=await(e={agent_no:A},Bs(`${Es}/agent/login`,e));St.agentInfo=t.data}catch(A){throw console.log(A),new Error("登录失败")}var e}async changeDevice(A){try{if(Dt.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;this.roleData.changeDevice(s);const{agent_no:i}=St.agentInfo;await(A=>Bs(`${Es}/device/change`,A))({agent_no:i,answer_device:s}),Dt.updateAnswerDevice(s);const r=Dt.get("actionConfigs");Dt.updateActionConfigs(r),t?.({code:0,msg:"请求成功"})}catch(A){throw console.log(A),new Error("切换设备失败")}}async changeState(A){try{St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:r}=St.agentInfo;await(A=>Bs(`${Es}/state/change`,A))({agent_no:r,state_name:i,state:s}),s===Ae.IDLE?Dt.updateActionConfigs(mt):s===Ae.BUSY&&Dt.updateActionConfigs(Ct),St.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){console.log(A)}}async getIdleAgentList(A){const{agent_no:e}=St.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Bs(`${Es}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){console.log(A)}}async getAgentState(A){try{const e=await Bs(`${Cs}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).map(A=>({state:A.state,state_name:A.state_name})).reverse();A.success?.({...e,data:t})}catch(A){console.log(A)}}}class Fs{constructor({container:A,rttHTML:e,statusParams:t},s){this.VoiceSDKInstance=s,this.apiClient=new Ys,this.isOpenSelect=!1,this.statusParams={state:Ae.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=A=>{this.rttHTML&&this.renderRtt(A.rttObject)},this.handleCallInfoChange=A=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const A=document.querySelector(".ysyt-select");A.style.height="0px",setTimeout(()=>{A.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=A=>{A.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const e=document.querySelector(".ysyt-select");this.isOpenSelect?(e.style.height=e.scrollHeight+"px",e.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async A=>{const{state:e,statusName:t}=A;await this.apiClient.changeState({data:{state:e,state_name:t},success:()=>{this.statusParams=A;const e=document.getElementById("my-timer");e?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async A=>{try{await this.apiClient.changeDevice({data:{device:A},success:({code:e})=>{0===e&&(1!==A&&this.VoiceSDKInstance.destroyRtc(),us("切换成功"),this.default_device=A,this.render())}})}catch(A){console.log(A),ps(A.message),this.render()}},this.ruleCall=async A=>{if(A)try{await this.VoiceSDKInstance.call_api.makeCall(A)}catch(A){console.error(A)}},this.onCall=()=>{const A=document.querySelector("my-input");this.ruleCall(A.value)},this.renderCallPopover=()=>ze`
584
+ `}};ns([ls()],Gs.prototype,"open",void 0),Gs=ns([as("my-icon-popup")],Gs);class Ys{constructor(){this.roleData={agentInfo:()=>{if(!St.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:A=>{if(!A.data)throw new Error("请传入参数")},changeDevice:A=>{if(!A)throw new Error('Parameter "device" is required');const{answer_devices:e}=St.agentInfo;if(!e.split(",").map(A=>Number(A)).includes(A))throw new Error("当前设备不支持")},changeState:(A,e)=>{if(!A)throw new Error('Parameter "state" is required');if(!e)throw new Error('Parameter "state_name" is required');if(2===A&&"通话中"===e)throw new Error("当前状态不支持");if(![1,2].includes(A))throw new Error("当前状态不支持")}}}async _agentLogin(A){try{const t=await(e={agent_no:A},Bs(`${Es}/agent/login`,e));St.agentInfo=t.data}catch(A){throw console.log(A),new Error("登录失败")}var e}async changeDevice(A){try{if(Dt.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{device:s}=e;this.roleData.changeDevice(s);const{agent_no:i}=St.agentInfo;await(A=>Bs(`${Es}/device/change`,A))({agent_no:i,answer_device:s}),Dt.updateAnswerDevice(s);const r=Dt.get("actionConfigs");Dt.updateActionConfigs(r),t?.({code:0,msg:"请求成功"})}catch(A){throw console.log(A),new Error("切换设备失败")}}async changeState(A){try{St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(A);const{data:e,success:t}=A,{state:s,state_name:i}=e;this.roleData.changeState(s,i);const{agent_no:r}=St.agentInfo;await(A=>Bs(`${Es}/state/change`,A))({agent_no:r,state_name:i,state:s}),s===Ae.IDLE?Dt.updateActionConfigs(mt):s===Ae.BUSY&&Dt.updateActionConfigs(Ct),St.stateObject={state:s,state_name:i},t?.({code:0,msg:"请求成功"})}catch(A){console.log(A)}}async getIdleAgentList(A){const{agent_no:e}=St.agentInfo;try{this.roleData.agentInfo();const t=await(A=>Bs(`${Es}/agent/free`,A))({agent_no:e});A.success?.(t)}catch(A){console.log(A)}}async getAgentState(A){try{const e=await Bs(`${Cs}/agent/statecfg/list`,{}),t=(e.data||[]).filter(A=>0===A.enable).filter(A=>0!==A.state&&3!==A.state).filter(A=>"通话中"!==A.state_name).map(A=>({state:A.state,state_name:A.state_name})).reverse();console.log(t),A.success?.({...e,data:t})}catch(A){console.log(A)}}}class Fs{constructor({container:A,rttHTML:e,statusParams:t},s){this.VoiceSDKInstance=s,this.apiClient=new Ys,this.isOpenSelect=!1,this.statusParams={state:Ae.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=A=>{this.rttHTML&&this.renderRtt(A.rttObject)},this.handleCallInfoChange=A=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const A=document.querySelector(".ysyt-select");A.style.height="0px",setTimeout(()=>{A.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=A=>{A.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const e=document.querySelector(".ysyt-select");this.isOpenSelect?(e.style.height=e.scrollHeight+"px",e.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async A=>{const{state:e,statusName:t}=A;await this.apiClient.changeState({data:{state:e,state_name:t},success:()=>{this.statusParams=A;const e=document.getElementById("my-timer");e?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async A=>{try{await this.apiClient.changeDevice({data:{device:A},success:({code:e})=>{0===e&&(1!==A&&this.VoiceSDKInstance.destroyRtc(),us("切换成功"),this.default_device=A,this.render())}})}catch(A){console.log(A),ps(A.message),this.render()}},this.ruleCall=async A=>{if(A)try{await this.VoiceSDKInstance.call_api.makeCall(A)}catch(A){console.error(A)}},this.onCall=()=>{const A=document.querySelector("my-input");this.ruleCall(A.value)},this.renderCallPopover=()=>ze`
585
585
  <my-icon-popup>
586
586
  <div slot="icon">
587
587
  <i class="ysyt icon-boda my-icon"></i>
@@ -821,4 +821,4 @@ const as=A=>(e,t)=>{void 0!==t?t.addInitializer(()=>{customElements.define(A,e)}
821
821
  `:""}
822
822
  </div>
823
823
  </my-popover>
824
- `;qt(s,this.rttHTML)}}const Zs=new class{constructor(){this.events={}}on(A,e){this.events[A]=this.events[A]||[],this.events[A].push(e)}off(A,e){this.events[A]=(this.events[A]||[]).filter(A=>A!==e)}emit(A,...e){(this.events[A]||[]).forEach(A=>A(...e))}};class vs{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 console.log("已授权麦克风权限"),null;const e=await navigator.mediaDevices.getUserMedia({audio:!0});return console.log("获取音频权限成功"),e}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t){if("Notification"in window&&"granted"===Notification.permission){const s=new Notification(A,{body:e,tag:"xy-global-notification",renotify:!0});s.onclick=()=>{window.focus(),s.close(),t?.()},setTimeout(()=>s.close(),5e3)}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}let xs=null;class Ks{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Ys,this.initWebSocket()}static getInstance(A){if(!xs){if(!A)throw new Error("WebSocket 尚未初始化");xs=new Ks(A)}return xs}stateIdleChange(){const{state:A}=St.stateObject;A!==Ae.IDLE&&this.apiClient.changeState({data:{state:Ae.IDLE,state_name:"空闲"}})}putAgentState(){St.sessionId="";const{post_call_process_time:A}=St.agentInfo,e=A||0;St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),e>0?St.autoStateTimer=setTimeout(()=>{St.autoStateTimer=null,this.stateIdleChange()},e):this.stateIdleChange()}initWebSocket(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.sendMessage({type:0}),this.startHeartbeat()},this.ws.onmessage=A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:r}=e;if(0!==t&&console.warn(t),t===ie.OUT_CALL&&(0!==i?(ae.emit(se.OUT_FAILED,r),this.stateIdleChange()):0===i&&ae.emit(se.OUT_SUCCESS)),t===ie.AGENT_STATE){const{state:A,state_name:e}=s;St.stateObject={state:A,state_name:e},"振铃中"===e&&Dt.updateDisplayText(oe.AGENT_RINGING),ae.emit(se.AGENT_STATE,{state:A,state_name:e})}t===ie.OUT_CALL_INCOMING_CALL&&(ae.emit(se.OUT_INCOMING_CALL),St.sessionId=s.session_id,Dt.updateActionConfigs(Et)),t===ie.OUT_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.OUT_HANGUP,s),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.OUT_CALL_RINGING&&(ae.emit(se.OUT_RINGING,s),Dt.updateDisplayText(oe.RINGING)),t===ie.OUT_CALL_ANSWER&&(ae.emit(se.OUT_OFF_ANSWER,s),Dt.updateOutCallIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_RINGING&&(ae.emit(se.CONSULT_RINGING),Dt.updateDisplayText(oe.AGENT_RINGING),Dt.updateActionConfigs([])),t===ie.CONSULT_ANSWER&&(ae.emit(se.CONSULT_OFF_HOOK,s),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CONSULTING),Dt.updateActionConfigs(Mt)),t===ie.CONSULT_FAIL&&(ae.emit(se.CONSULT_FAILED,{custom_reason:s.custom_reason}),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_CALL_IN&&(ae.emit(se.CONSULT_INCOMING,s),Dt.updateIsCalling(!0),Dt.updateDirection(ee.CONSULT),Dt.updateDisplayText(oe.CONSULT_CALL_IN),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{agent_mane:s.agent_name})})),t===ie.CONSULT_CALL_IN_SUCCESS&&(St.sessionId=s.session_id,ae.emit(se.CONSULT_CALL_IN_SUCCESS),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(wt)),t===ie.CONSULT_RETURN_CALL_SUCCESS&&(ae.emit(se.CONSULT_RETURN_CALL_SUCCESS),Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)),t===ie.MUTE&&(0===i?(Dt.updateIsMuted(!0),ae.emit(se.MUTE_SUCCESS)):ae.emit(se.MUTE_FAILED,r)),t===ie.UNMUTE&&(0===i?(Dt.updateIsMuted(!1),ae.emit(se.UNMUTE_SUCCESS)):ae.emit(se.UNMUTE_FAILED,r)),t===ie.CONSULT_TRANSFER&&(0===i?ae.emit(se.CONSULT_TRANSFER_SUCCESS):ae.emit(se.CONSULT_TRANSFER_FAILED,r)),t===ie.CONSULT_TRANSFER_FAILED&&ae.emit(se.CONSULT_TRANSFER_FAILED,s.status),t===ie.CONSULT_TRANSFER_OFF_HOOK&&(Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.CALLING),ae.emit(se.CONSULT_TRANSFER_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateIncomingIsAnswer(!0),Dt.updateConsultIsAnswer(!1)),t===ie.INCOMING_CALL&&(St.sessionId=s.session_id,Dt.updateIsCalling(!0),Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.INCOMING_CALL),ae.emit(se.INCOMING_CALL,{customer_phone:s.customer_phone}),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})})),t===ie.INCOMING_CALL_OFF_HOOK&&(Dt.updateIncomingIsAnswer(!0),ae.emit(se.INCOMING_CALL_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateDisplayText(oe.CALLING)),t===ie.INCOMING_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.INCOMING_CALL_END),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.SATISFACTION_EVALUATION&&(0===i?ae.emit(se.SATISFACTION_EVALUATION_SUCCESS):ae.emit(se.SATISFACTION_EVALUATION_FAILED,r)),t===ie.CONSULT_THREE_WAY&&(0!==i?ae.emit(se.CONSULT_THREE_WAY_FAILED,r):0===i&&Dt.updateIsMeeting(!0)),t===ie.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(Dt.updateDirection(ee.MEETING),Dt.updateDisplayText(oe.MEETING),Dt.updateActionConfigs(Bt),ae.emit(se.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(se.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),Dt.updateIsMeeting(!1))),0!==t&&Zs.emit("ws-message",e)},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 }, 14000);\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=()=>{this.sendMessage({type:0})},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)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}static __internalClose(){xs&&(xs.close(),xs=null)}static __internalSend(A){if(!xs)throw new Error("WebSocket 尚未初始化");xs.sendMessage(A)}}return class{#A=null;#e=new Ys;#t=null;#s=!1;#i;constructor(){clearInterval(this.#t),this.#t=setInterval(async()=>{const A=await this.#r();Qs.updateRttObject(A)},2e3),vs.requestMediaPermissions(),window.addEventListener("beforeunload",()=>{this.destroy()}),this.#i=Dt.subscribeKey("answerDevice",A=>{1===A&&this.initWebRtc()})}async initWebRtc(){const A=St.agentInfo.sip_account_list.find(A=>1===A.device_type);if(A){const e=A.sip_register_addr;this.#A=new fs({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#o),await this.#A.start()}}async init({actionNodeParams:A,url:e,appKey:t,appSecret:s,agentNo:i,enableBrowserAlert:r}){try{const{viewHtmlElement:o,rttHTML:n}=A||{},a=e||"https://aicc.yescloudy.com";Is=a,Ms=t,ws=s;const V=os(t,s);await this.#e._agentLogin(i);const{agent_no:c,current_answer_device:h,init_state:l}=St.agentInfo;l===Ae.IDLE?(Dt.updateActionConfigs(mt),St.stateObject={state:l,state_name:"空闲"}):l===Ae.BUSY&&(Dt.updateActionConfigs(Ct),St.stateObject={state:l,state_name:"忙碌"});let q="";const g=new URL(a).host;q=a.includes("https")?`wss://${g}`:`ws://${g}`,Ks.getInstance(`${q}/ccs-ws/api/v1/ws/call/${c}?Authorization=${V}`),Dt.updateAnswerDevice(h),1===h&&await this.initWebRtc(),A&&o&&(this.#s=!0,new Fs({container:o,rttHTML:n,statusParams:{state:Ae.IDLE,statusName:"空闲"}},this)),St.enableBrowserAlert=r,r&&vs.requestPermission()}catch(A){this.#s&&ps("初始化失败"),console.log(A)}}#o=A=>{const{type:e,data:t}=A;ae.emit(e,t)};#n=A=>{};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}#a(){const A=Dt.get("isCalling"),e=St.sessionId;if(!A)throw new Error("当前没有通话");if(!e)throw new Error("当前没有通话")}#V(){this.#a();const A=Dt.get("isHold"),{sessionId:e}=St;if(e){if(A)throw new Error("当前已处于保持状态");Ks.__internalSend({type:ie.CALL_HOLD,data:{session_id:e}}),Dt.updateDisplayText(oe.HOLD),Dt.updateIsHold(!0)}}#c(){this.#a();const{isHold:A}=Dt.getState(),{sessionId:e}=St;if(e){if(!A)throw new Error("当前未处于保持状态");Ks.__internalSend({type:ie.CALL_UNHOLD,data:{session_id:e}}),Dt.updateDisplayText(""),Dt.updateIsHold(!1)}}#h(A){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:e}=Dt.getState();if(!e)throw new Error("当前没有通话");this.#A.sendDTMF(A)}#l(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A,direction:e,outCallIsAnswer:t}=Dt.getState();if(!A)throw new Error("当前没有通话");t||(e===ee.INCOMING?this.#q():e===ee.OUTGOING&&this.#g())}async#d(A){if(this.#a(),!this.#A)throw new Error("请先初始化SDK");const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=Dt.getState(),r=St.sessionId;if(s)throw new Error("当前正在咨询");if(!(e||t||i))throw new Error("当前没有通话");if(!r)throw new Error("sessionId不存在");Ks.__internalSend({type:ie.CONSULT_REQUEST,data:{session_id:r,consultation_agent_no:A}})}async#u(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");await this.#A.answerCall()}async#q(){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A}=Dt.getState();if(!A)throw new Error("当前没有通话");await this.#A.rejectInCall()}async#p(A){if(!this.#A)throw new Error("请先初始化SDK");if(Dt.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");Dt.updateIsCalling(!0),Dt.updateDirection(ee.OUTGOING),Ks.__internalSend({type:ie.OUT_CALL,data:{customer_phone:A}})}async#g(){const{isCalling:A}=Dt.getState();if(!this.#A)throw new Error("请先初始化SDK");if(!A)throw new Error("当前没有通话");await this.#A.rejectOutCall()}async#m(){if(!this.#A)throw new Error("请先初始化SDK");if(!Dt.get("isCalling"))throw new Error("当前没有通话");await this.#A.hangup()}#C(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(e)throw new Error("当前未处于静音状态");if(!A.includes("mute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.MUTE,data:{session_id:t}})}#E(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(!e)throw new Error("当前未处于未静音状态");if(!A.includes("unmute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.UNMUTE,data:{session_id:t}})}#I(){this.#a();const A=Dt.get("consultIsAnswer"),e=St.sessionId;if(!Dt.get("actionConfigs").includes("consult_transfer"))throw new Error("当前状态请勿调用咨询转移");if(!A)throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_TRANSFER,data:{session_id:e}})}#M(){this.#a();const A=St.sessionId;if(!Dt.get("actionConfigs").includes("satisfaction"))throw new Error("当前状态请勿调用满意度评价");Ks.__internalSend({type:ie.SATISFACTION_EVALUATION,data:{session_id:A}})}#w(){this.#a();if(!Dt.get("actionConfigs").includes("conference"))throw new Error("当前状态请勿调用三方会议");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_THREE_WAY,data:{session_id:A}})}#B(){this.#a();if(!Dt.get("actionConfigs").includes("consult_retrieve"))throw new Error("当前状态请勿取回通话");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_RETURN_CALL,data:{session_id:A}})}async destroyRtc(){await(this.#A?.destroy())}destroy(){this.destroyRtc(),clearInterval(this.#t),Zs.off("ws-message",this.#n),Ks.__internalClose(),this.offAll(),this.#i?.(),this.#A=null,this.#e=null,this.#s=!1}async#r(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){return this.#s?{answerCall:this.#u.bind(this),makeCall:this.#p.bind(this),cancelCall:this.#l.bind(this),hangup:this.#m.bind(this),sendDTMF:this.#h.bind(this),holdCall:this.#V.bind(this),unholdCall:this.#c.bind(this),consultCall:async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}},consultRetrieve:this.#B.bind(this),consultTransfer:this.#I.bind(this),mute:this.#C.bind(this),unmute:this.#E.bind(this),satisfactionEvaluation:this.#M.bind(this),startConference:this.#w.bind(this)}:{}}get agent_api(){return this.#s?{changeDevice:this.#e.changeDevice.bind(this.#e),changeState:this.#e.changeState.bind(this.#e),getIdleAgentList:A=>this.#e.getIdleAgentList(A),getAgentState:A=>this.#e.getAgentState(A)}:{}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t}=St.agentInfo,{stateObject:s}=St,i={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:i[Number(A)]})),stateObject:s}}}});
824
+ `;qt(s,this.rttHTML)}}const Zs=new class{constructor(){this.events={}}on(A,e){this.events[A]=this.events[A]||[],this.events[A].push(e)}off(A,e){this.events[A]=(this.events[A]||[]).filter(A=>A!==e)}emit(A,...e){(this.events[A]||[]).forEach(A=>A(...e))}};class vs{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 console.log("已授权麦克风权限"),null;const e=await navigator.mediaDevices.getUserMedia({audio:!0});return console.log("获取音频权限成功"),e}catch(A){return console.warn("获取音频权限失败:",A),null}}static show(A,e,t){if("Notification"in window&&"granted"===Notification.permission){const s=new Notification(A,{body:e,tag:"xy-global-notification",renotify:!0});s.onclick=()=>{window.focus(),s.close(),t?.()},setTimeout(()=>s.close(),5e3)}}static async checkMediaPermissions(){try{return(await navigator.mediaDevices.enumerateDevices()).some(A=>"audioinput"===A.kind&&""!==A.label)}catch(A){return console.warn("无法检查设备权限:",A),!1}}}let xs=null;class Ks{constructor(A){this.url=A,this.ws=null,this.heartbeatWorker=null,this.reconnectDelay=3e3,this.manualClose=!1,this.apiClient=new Ys,this.initWebSocket()}static getInstance(A){if(!xs){if(!A)throw new Error("WebSocket 尚未初始化");xs=new Ks(A)}return xs}stateIdleChange(){const{state:A}=St.stateObject;A!==Ae.IDLE&&this.apiClient.changeState({data:{state:Ae.IDLE,state_name:"空闲"}})}putAgentState(){St.sessionId="";const{post_call_process_time:A}=St.agentInfo,e=A||0;St.autoStateTimer&&(clearTimeout(St.autoStateTimer),St.autoStateTimer=null),e>0?St.autoStateTimer=setTimeout(()=>{St.autoStateTimer=null,this.stateIdleChange()},e):this.stateIdleChange()}initWebSocket(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.sendMessage({type:0}),this.startHeartbeat()},this.ws.onmessage=A=>{const e=JSON.parse(A.data),{type:t,data:s,code:i,msg:r}=e;if(0!==t&&console.warn(t),t===ie.OUT_CALL&&(0!==i?(ae.emit(se.OUT_FAILED,r),this.stateIdleChange()):0===i&&ae.emit(se.OUT_SUCCESS)),t===ie.AGENT_STATE){const{state:A,state_name:e}=s;St.stateObject={state:A,state_name:e},"振铃中"===e&&Dt.updateDisplayText(oe.AGENT_RINGING),ae.emit(se.AGENT_STATE,{state:A,state_name:e})}t===ie.OUT_CALL_INCOMING_CALL&&(ae.emit(se.OUT_INCOMING_CALL),St.sessionId=s.session_id,Dt.updateActionConfigs(Et)),t===ie.OUT_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.OUT_HANGUP,s),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.OUT_CALL_RINGING&&(ae.emit(se.OUT_RINGING,s),Dt.updateDisplayText(oe.RINGING)),t===ie.OUT_CALL_ANSWER&&(ae.emit(se.OUT_OFF_ANSWER,s),Dt.updateOutCallIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_RINGING&&(ae.emit(se.CONSULT_RINGING),Dt.updateDisplayText(oe.AGENT_RINGING),Dt.updateActionConfigs([])),t===ie.CONSULT_ANSWER&&(ae.emit(se.CONSULT_OFF_HOOK,s),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CONSULTING),Dt.updateActionConfigs(Mt)),t===ie.CONSULT_FAIL&&(ae.emit(se.CONSULT_FAILED,{custom_reason:s.custom_reason}),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(It)),t===ie.CONSULT_CALL_IN&&(ae.emit(se.CONSULT_INCOMING,s),Dt.updateIsCalling(!0),Dt.updateDirection(ee.CONSULT),Dt.updateDisplayText(oe.CONSULT_CALL_IN),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 咨询来电",`坐席 [${s.agent_name}] 正在咨询...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{agent_mane:s.agent_name})})),t===ie.CONSULT_CALL_IN_SUCCESS&&(St.sessionId=s.session_id,ae.emit(se.CONSULT_CALL_IN_SUCCESS),Dt.updateConsultIsAnswer(!0),Dt.updateDisplayText(oe.CALLING),Dt.updateActionConfigs(wt)),t===ie.CONSULT_RETURN_CALL_SUCCESS&&(ae.emit(se.CONSULT_RETURN_CALL_SUCCESS),Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)),t===ie.MUTE&&(0===i?(Dt.updateIsMuted(!0),ae.emit(se.MUTE_SUCCESS)):ae.emit(se.MUTE_FAILED,r)),t===ie.UNMUTE&&(0===i?(Dt.updateIsMuted(!1),ae.emit(se.UNMUTE_SUCCESS)):ae.emit(se.UNMUTE_FAILED,r)),t===ie.CONSULT_TRANSFER&&(0===i?ae.emit(se.CONSULT_TRANSFER_SUCCESS):ae.emit(se.CONSULT_TRANSFER_FAILED,r)),t===ie.CONSULT_TRANSFER_FAILED&&ae.emit(se.CONSULT_TRANSFER_FAILED,s.status),t===ie.CONSULT_TRANSFER_OFF_HOOK&&(Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.CALLING),ae.emit(se.CONSULT_TRANSFER_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateIncomingIsAnswer(!0),Dt.updateConsultIsAnswer(!1)),t===ie.INCOMING_CALL&&(St.sessionId=s.session_id,Dt.updateIsCalling(!0),Dt.updateDirection(ee.INCOMING),Dt.updateDisplayText(oe.INCOMING_CALL),ae.emit(se.INCOMING_CALL,{customer_phone:s.customer_phone}),Dt.updateActionConfigs(Qt),St.enableBrowserAlert&&vs.show("📞 客户来电",`客户 [${s.customer_phone}] 正在呼入...`,()=>{ae.emit(re.NOTIFICATION_CLICK,{customer_phone:s.customer_phone})})),t===ie.INCOMING_CALL_OFF_HOOK&&(Dt.updateIncomingIsAnswer(!0),ae.emit(se.INCOMING_CALL_OFF_HOOK),Dt.updateActionConfigs(ft),Dt.updateDisplayText(oe.CALLING)),t===ie.INCOMING_CALL_END&&(1===s.device_type&&s.agent_no===St.agentInfo.agent_no?(this.putAgentState(),Dt.reset(),ae.emit(se.INCOMING_CALL_END),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no===St.agentInfo.agent_no?(Dt.reset(),ae.emit(se.OUR_SIDE_CONSULT_HANGUP,s),this.putAgentState(),Dt.updateActionConfigs(mt)):2===s.device_type&&s.agent_no!==St.agentInfo.agent_no?(Dt.updateDisplayText(oe.CALLING),ae.emit(se.OTHER_SIDE_CONSULT_HANGUP,s),Dt.updateActionConfigs(It)):3===s.device_type&&s.agent_no===St.agentInfo.agent_no&&(this.putAgentState(),Dt.reset(),ae.emit(se.THREE_WAY_OUR_SIDE_HANGUP),Dt.updateActionConfigs(mt))),t===ie.SATISFACTION_EVALUATION&&(0===i?ae.emit(se.SATISFACTION_EVALUATION_SUCCESS):ae.emit(se.SATISFACTION_EVALUATION_FAILED,r)),t===ie.CONSULT_THREE_WAY&&(0!==i?ae.emit(se.CONSULT_THREE_WAY_FAILED,r):0===i&&Dt.updateIsMeeting(!0)),t===ie.CONSULT_THREE_WAY_RESULT&&("success"===s.status?(Dt.updateDirection(ee.MEETING),Dt.updateDisplayText(oe.MEETING),Dt.updateActionConfigs(Bt),ae.emit(se.CONSULT_THREE_WAY_SUCCESS)):(ae.emit(se.CONSULT_THREE_WAY_FAILED,{conf_name:s.conf_name}),Dt.updateIsMeeting(!1))),0!==t&&Zs.emit("ws-message",e)},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 }, 14000);\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=()=>{this.sendMessage({type:0})},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)):console.warn("WebSocket 未连接,消息未发送")}close(){this.manualClose=!0,this.stopHeartbeat(),this.ws?.close()}static __internalClose(){xs&&(xs.close(),xs=null)}static __internalSend(A){if(!xs)throw new Error("WebSocket 尚未初始化");xs.sendMessage(A)}}return class{#A=null;#e=new Ys;#t=null;#s=!1;#i;constructor(){clearInterval(this.#t),this.#t=setInterval(async()=>{const A=await this.#r();Qs.updateRttObject(A)},2e3),vs.requestMediaPermissions(),window.addEventListener("beforeunload",()=>{this.destroy()}),this.#i=Dt.subscribeKey("answerDevice",A=>{1===A&&this.initWebRtc()})}async initWebRtc(){const A=St.agentInfo.sip_account_list.find(A=>1===A.device_type);if(A){const e=A.sip_register_addr;this.#A=new fs({server:e.split(":")[0],user:A.sip_account,password:A.sip_password,webSocket:`wss://${e}`,callTimeout:3e4},this.#o),await this.#A.start()}}async init({actionNodeParams:A,url:e,appKey:t,appSecret:s,agentNo:i,enableBrowserAlert:r}){try{const{viewHtmlElement:o,rttHTML:n}=A||{},a=e||"https://aicc.yescloudy.com";Is=a,Ms=t,ws=s;const V=os(t,s);await this.#e._agentLogin(i);const{agent_no:c,current_answer_device:h,init_state:l}=St.agentInfo;l===Ae.IDLE?(Dt.updateActionConfigs(mt),St.stateObject={state:l,state_name:"空闲"}):l===Ae.BUSY&&(Dt.updateActionConfigs(Ct),St.stateObject={state:l,state_name:"忙碌"});let q="";const g=new URL(a).host;q=a.includes("https")?`wss://${g}`:`ws://${g}`,Ks.getInstance(`${q}/ccs-ws/api/v1/ws/call/${c}?Authorization=${V}`),Dt.updateAnswerDevice(h),1===h&&await this.initWebRtc(),A&&o&&(this.#s=!0,new Fs({container:o,rttHTML:n,statusParams:{state:Ae.IDLE,statusName:"空闲"}},this)),St.enableBrowserAlert=r,r&&vs.requestPermission()}catch(A){this.#s&&ps("初始化失败"),console.log(A)}}#o=A=>{const{type:e,data:t}=A;ae.emit(e,t)};#n=A=>{};on(A,e){return ae.on(A,e),this}off(A,e){ae.off(A,e)}offAll(){ae.clearAllListeners()}#a(){const A=Dt.get("isCalling"),e=St.sessionId;if(!A)throw new Error("当前没有通话");if(!e)throw new Error("当前没有通话")}#V(){this.#a();const A=Dt.get("isHold"),{sessionId:e}=St;if(e){if(A)throw new Error("当前已处于保持状态");Ks.__internalSend({type:ie.CALL_HOLD,data:{session_id:e}}),Dt.updateDisplayText(oe.HOLD),Dt.updateIsHold(!0)}}#c(){this.#a();const{isHold:A}=Dt.getState(),{sessionId:e}=St;if(e){if(!A)throw new Error("当前未处于保持状态");Ks.__internalSend({type:ie.CALL_UNHOLD,data:{session_id:e}}),Dt.updateDisplayText(""),Dt.updateIsHold(!1)}}#h(A){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:e}=Dt.getState();if(!e)throw new Error("当前没有通话");this.#A.sendDTMF(A)}#l(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A,direction:e,outCallIsAnswer:t}=Dt.getState();if(!A)throw new Error("当前没有通话");t||(e===ee.INCOMING?this.#q():e===ee.OUTGOING&&this.#g())}async#d(A){if(this.#a(),!this.#A)throw new Error("请先初始化SDK");const{isCalling:e,outCallIsAnswer:t,consultIsAnswer:s,incomingIsAnswer:i}=Dt.getState(),r=St.sessionId;if(s)throw new Error("当前正在咨询");if(!(e||t||i))throw new Error("当前没有通话");if(!r)throw new Error("sessionId不存在");Ks.__internalSend({type:ie.CONSULT_REQUEST,data:{session_id:r,consultation_agent_no:A}})}async#u(){if(1!==Dt.get("answerDevice"))throw new Error("当前设备不支持此功能");if(!this.#A)throw new Error("请先初始化SDK");await this.#A.answerCall()}async#q(){if(!this.#A)throw new Error("请先初始化SDK");const{isCalling:A}=Dt.getState();if(!A)throw new Error("当前没有通话");await this.#A.rejectInCall()}async#p(A){if(!this.#A)throw new Error("请先初始化SDK");if(Dt.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");Dt.updateIsCalling(!0),Dt.updateDirection(ee.OUTGOING),Ks.__internalSend({type:ie.OUT_CALL,data:{customer_phone:A}})}async#g(){const{isCalling:A}=Dt.getState();if(!this.#A)throw new Error("请先初始化SDK");if(!A)throw new Error("当前没有通话");await this.#A.rejectOutCall()}async#m(){if(!this.#A)throw new Error("请先初始化SDK");if(!Dt.get("isCalling"))throw new Error("当前没有通话");await this.#A.hangup()}#C(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(e)throw new Error("当前未处于静音状态");if(!A.includes("mute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.MUTE,data:{session_id:t}})}#E(){this.#a();const A=Dt.get("actionConfigs"),e=Dt.get("isMuted"),t=St.sessionId;if(!e)throw new Error("当前未处于未静音状态");if(!A.includes("unmute"))throw new Error("当前状态请勿调用静音");Ks.__internalSend({type:ie.UNMUTE,data:{session_id:t}})}#I(){this.#a();const A=Dt.get("consultIsAnswer"),e=St.sessionId;if(!Dt.get("actionConfigs").includes("consult_transfer"))throw new Error("当前状态请勿调用咨询转移");if(!A)throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_TRANSFER,data:{session_id:e}})}#M(){this.#a();const A=St.sessionId;if(!Dt.get("actionConfigs").includes("satisfaction"))throw new Error("当前状态请勿调用满意度评价");Ks.__internalSend({type:ie.SATISFACTION_EVALUATION,data:{session_id:A}})}#w(){this.#a();if(!Dt.get("actionConfigs").includes("conference"))throw new Error("当前状态请勿调用三方会议");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_THREE_WAY,data:{session_id:A}})}#B(){this.#a();if(!Dt.get("actionConfigs").includes("consult_retrieve"))throw new Error("当前状态请勿取回通话");const A=St.sessionId;if(!Dt.get("consultIsAnswer"))throw new Error("当前未处于咨询中");Ks.__internalSend({type:ie.CONSULT_RETURN_CALL,data:{session_id:A}})}async destroyRtc(){await(this.#A?.destroy())}destroy(){this.destroyRtc(),clearInterval(this.#t),Zs.off("ws-message",this.#n),Ks.__internalClose(),this.offAll(),this.#i?.(),this.#A=null,this.#e=null,this.#s=!1}async#r(){return this.#A?this.#A.getNetworkStats():{}}get call_api(){return this.#s?{answerCall:this.#u.bind(this),makeCall:this.#p.bind(this),cancelCall:this.#l.bind(this),hangup:this.#m.bind(this),sendDTMF:this.#h.bind(this),holdCall:this.#V.bind(this),unholdCall:this.#c.bind(this),consultCall:async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}},consultRetrieve:this.#B.bind(this),consultTransfer:this.#I.bind(this),mute:this.#C.bind(this),unmute:this.#E.bind(this),satisfactionEvaluation:this.#M.bind(this),startConference:this.#w.bind(this)}:{}}get agent_api(){return this.#s?{changeDevice:this.#e.changeDevice.bind(this.#e),changeState:this.#e.changeState.bind(this.#e),getIdleAgentList:A=>this.#e.getIdleAgentList(A),getAgentState:A=>this.#e.getAgentState(A)}:{}}getAgentData(){const{agent_no:A,agent_name:e,answer_devices:t,init_state:s,default_device:i}=St.agentInfo,{stateObject:r}=St,o={1:"软电话",2:"手机模式",3:"SIP话机"};return{agent_no:A,agent_name:e,init_state:s,default_device:i,answer_devices:(t||"").split(",").map(A=>({value:Number(A),label:o[Number(A)]})),stateObject:r}}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ysyt-agent-sdk",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "main": "dist/ysyt-agent-sdk.cjs.js",
5
5
  "module": "dist/ysyt-agent-sdk.esm.js",
6
6
  "types": "dist/src/index.d.ts",