ysyt-agent-sdk 1.0.38 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentDataType, AgentItemType, AgentStateDataType, InitInfoType, RequestBodyType } from '@/types';
|
|
1
|
+
import { AgentDataType, AgentItemType, AgentStateDataType, DeviceType, InitInfoType, RequestBodyType, StateType } from '@/types';
|
|
2
2
|
import { Events } from '@/store/event-center';
|
|
3
3
|
export type * from './types';
|
|
4
4
|
declare class YSYTAgentSdk {
|
|
@@ -21,44 +21,29 @@ declare class YSYTAgentSdk {
|
|
|
21
21
|
destroyRtc(): Promise<void>;
|
|
22
22
|
destroy(): void;
|
|
23
23
|
get call_api(): {
|
|
24
|
-
answerCall
|
|
25
|
-
makeCall
|
|
26
|
-
cancelCall
|
|
27
|
-
hangup
|
|
28
|
-
sendDTMF
|
|
29
|
-
holdCall
|
|
30
|
-
unholdCall
|
|
31
|
-
consultCall?: undefined;
|
|
32
|
-
consultRetrieve?: undefined;
|
|
33
|
-
consultTransfer?: undefined;
|
|
34
|
-
mute?: undefined;
|
|
35
|
-
unmute?: undefined;
|
|
36
|
-
satisfactionEvaluation?: undefined;
|
|
37
|
-
startConference?: undefined;
|
|
38
|
-
} | {
|
|
39
|
-
answerCall: any;
|
|
40
|
-
makeCall: any;
|
|
41
|
-
cancelCall: any;
|
|
42
|
-
hangup: any;
|
|
43
|
-
sendDTMF: any;
|
|
44
|
-
holdCall: any;
|
|
45
|
-
unholdCall: any;
|
|
24
|
+
answerCall: () => Promise<void>;
|
|
25
|
+
makeCall: (number: string) => Promise<void>;
|
|
26
|
+
cancelCall: () => void;
|
|
27
|
+
hangup: () => Promise<void>;
|
|
28
|
+
sendDTMF: (tone: string) => void;
|
|
29
|
+
holdCall: () => void;
|
|
30
|
+
unholdCall: () => void;
|
|
46
31
|
consultCall: (agent_no: string) => Promise<void>;
|
|
47
|
-
consultRetrieve:
|
|
48
|
-
consultTransfer:
|
|
49
|
-
mute:
|
|
50
|
-
unmute:
|
|
51
|
-
satisfactionEvaluation:
|
|
52
|
-
startConference:
|
|
32
|
+
consultRetrieve: () => void;
|
|
33
|
+
consultTransfer: () => void;
|
|
34
|
+
mute: () => void;
|
|
35
|
+
unmute: () => void;
|
|
36
|
+
satisfactionEvaluation: () => void;
|
|
37
|
+
startConference: () => void;
|
|
53
38
|
};
|
|
54
39
|
get agent_api(): {
|
|
55
|
-
changeDevice
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
changeDevice: (params: RequestBodyType<{
|
|
41
|
+
device: DeviceType;
|
|
42
|
+
}>) => Promise<void>;
|
|
43
|
+
changeState: (params: RequestBodyType<{
|
|
44
|
+
state: StateType;
|
|
45
|
+
state_name: string;
|
|
46
|
+
}>) => Promise<void>;
|
|
62
47
|
getIdleAgentList: (params: RequestBodyType<unknown, AgentItemType[]>) => Promise<void>;
|
|
63
48
|
getAgentState: (params: RequestBodyType<unknown, AgentStateDataType>) => Promise<void>;
|
|
64
49
|
};
|
|
@@ -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,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}}};
|
|
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(){const A=A=>(...e)=>{if(this.#s)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{answerCall:A(()=>this.#u()),makeCall:A(A=>this.#p(A)),cancelCall:A(()=>this.#l()),hangup:A(()=>this.#m()),sendDTMF:A(A=>this.#h(A)),holdCall:A(()=>this.#V()),unholdCall:A(()=>this.#c()),consultCall:A(async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}}),consultRetrieve:A(()=>this.#B()),consultTransfer:A(()=>this.#I()),mute:A(()=>this.#C()),unmute:A(()=>this.#E()),satisfactionEvaluation:A(()=>this.#M()),startConference:A(()=>this.#w())}}get agent_api(){const A=A=>(...e)=>{if(this.#s)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{changeDevice:A(A=>this.#e.changeDevice(A)),changeState:A(A=>this.#e.changeState(A)),getIdleAgentList:A(A=>this.#e.getIdleAgentList(A)),getAgentState:A(A=>this.#e.getAgentState(A))}}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}}};
|
|
@@ -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,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};
|
|
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(){const A=A=>(...e)=>{if(this.#s)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{answerCall:A(()=>this.#u()),makeCall:A(A=>this.#p(A)),cancelCall:A(()=>this.#l()),hangup:A(()=>this.#m()),sendDTMF:A(A=>this.#h(A)),holdCall:A(()=>this.#V()),unholdCall:A(()=>this.#c()),consultCall:A(async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}}),consultRetrieve:A(()=>this.#B()),consultTransfer:A(()=>this.#I()),mute:A(()=>this.#C()),unmute:A(()=>this.#E()),satisfactionEvaluation:A(()=>this.#M()),startConference:A(()=>this.#w())}}get agent_api(){const A=A=>(...e)=>{if(this.#s)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{changeDevice:A(A=>this.#e.changeDevice(A)),changeState:A(A=>this.#e.changeState(A)),getIdleAgentList:A(A=>this.#e.getIdleAgentList(A)),getAgentState:A(A=>this.#e.getAgentState(A))}}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};
|
|
@@ -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,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}}}});
|
|
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(){const A=A=>(...e)=>{if(this.#s)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{answerCall:A(()=>this.#u()),makeCall:A(A=>this.#p(A)),cancelCall:A(()=>this.#l()),hangup:A(()=>this.#m()),sendDTMF:A(A=>this.#h(A)),holdCall:A(()=>this.#V()),unholdCall:A(()=>this.#c()),consultCall:A(async A=>{try{await this.#d(A)}catch(A){throw console.warn(A),A}}),consultRetrieve:A(()=>this.#B()),consultTransfer:A(()=>this.#I()),mute:A(()=>this.#C()),unmute:A(()=>this.#E()),satisfactionEvaluation:A(()=>this.#M()),startConference:A(()=>this.#w())}}get agent_api(){const A=A=>(...e)=>{if(this.#s)return A.apply(this,e);console.warn("当前未使用个人开发模式")};return{changeDevice:A(A=>this.#e.changeDevice(A)),changeState:A(A=>this.#e.changeState(A)),getIdleAgentList:A(A=>this.#e.getIdleAgentList(A)),getAgentState:A(A=>this.#e.getAgentState(A))}}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}}}});
|