ysyt-agent-sdk 1.0.25 → 1.0.26
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.
|
@@ -3,26 +3,20 @@ export declare class MySelect extends LitElement {
|
|
|
3
3
|
placeholder: string;
|
|
4
4
|
value: string | null;
|
|
5
5
|
width: string | null;
|
|
6
|
-
/** 是否展开菜单 */
|
|
7
6
|
private open;
|
|
8
|
-
/** 控制菜单动画显示 */
|
|
9
7
|
private animating;
|
|
10
|
-
/** 选中内容的克隆节点 */
|
|
11
8
|
private selectedContent;
|
|
12
9
|
static styles: import("lit").CSSResult;
|
|
13
10
|
connectedCallback(): void;
|
|
14
11
|
disconnectedCallback(): void;
|
|
15
|
-
handleOutsideClick
|
|
16
|
-
toggleDropdown
|
|
17
|
-
openDropdown
|
|
18
|
-
closeDropdown
|
|
19
|
-
handleOptionClick
|
|
20
|
-
/** 组件属性变化时,更新选中内容 */
|
|
12
|
+
private handleOutsideClick;
|
|
13
|
+
private toggleDropdown;
|
|
14
|
+
private openDropdown;
|
|
15
|
+
private closeDropdown;
|
|
16
|
+
private handleOptionClick;
|
|
21
17
|
updated(changedProps: Map<string, unknown>): void;
|
|
22
|
-
/** 根据当前 value 找对应选项内容 clone */
|
|
23
18
|
private updateSelectedContent;
|
|
24
|
-
/** 渲染选中内容,如果没有则渲染 placeholder */
|
|
25
19
|
private renderSelectedLabel;
|
|
26
|
-
renderSelectOptions
|
|
20
|
+
private renderSelectOptions;
|
|
27
21
|
render(): TemplateResult<1>;
|
|
28
22
|
}
|
|
@@ -25,6 +25,7 @@ export declare class PhoneView {
|
|
|
25
25
|
private consultShow;
|
|
26
26
|
private modalRoot;
|
|
27
27
|
private agentStateData;
|
|
28
|
+
private default_device;
|
|
28
29
|
constructor({ container, rttHTML, statusParams }: Props, VoiceSDKInstance: YSYTAgentSdk);
|
|
29
30
|
private eventHandle;
|
|
30
31
|
private handleNetworkInfoChange;
|
|
@@ -114,7 +114,7 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
114
114
|
border: 1px solid #595959;
|
|
115
115
|
color: #595959;
|
|
116
116
|
}
|
|
117
|
-
`}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.remove()},this.duration+300)}render(){return Jt`<div>${this.content}</div>`}};oi([di({type:String})],ui.prototype,"type",void 0),oi([di({type:String})],ui.prototype,"content",void 0),oi([di({type:Number})],ui.prototype,"duration",void 0),ui=oi([ai("my-message")],ui);const pi=(e,t,s=3e3)=>{let i=document.querySelector("#message-container");i||(i=document.createElement("div"),i.id="message-container",Object.assign(i.style,{position:"fixed",top:"14px",left:"50%",transform:"translateX(-50%)",zIndex:"9999"}),document.body.appendChild(i));const r=document.createElement("my-message");r.setAttribute("type",e),r.setAttribute("content",t),r.setAttribute("duration",String(s)),r.style.setProperty("--fade-delay",s/1e3+"s"),i.appendChild(r)},fi=(e,t=3e3)=>pi("success",e,t),mi=(e,t=3e3)=>pi("error",e,t),vi=(e,t=3e3)=>pi("warning",e,t),wi="/v1/aicc/bmserver",yi="/v1/aicc/ccs";let bi="",Ti="",Si="";async function Ci(e,t){const s=function(){const e=ni(Ti,Si);return ti.create({prefixUrl:`${bi}/api`,timeout:!1,headers:{Authorization:e},hooks:{afterResponse:[async(e,t,s)=>{const i=await s.clone().json();if(0!==i.code)throw mi(i.msg),new Error(JSON.stringify(i)||"请求失败");return s.json=async()=>i,s}]}})}(),i=e.replace(/^\/+/,"");return s.post(i,{json:t}).json()}const Ei=new class extends Qe{updateRttObject(e){this.setState({rttObject:e})}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class Ai{constructor(e,t){this.config=e,this.eventCallback=t,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleMessage=e=>{},this.handleNetworkInfoChange=e=>{if(e.rttObject?.rtt){0===(e.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Ei.subscribe(this.handleNetworkInfoChange)}async start(){const e=Xe.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!e)throw new Error("无效的SIP配置");const t={uri:e,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:0},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:!1};this.userAgent=new Xe(t),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case ee.Connecting:t=st.WEB_RTC_CONNECTING;break;case ee.Connected:t=st.WEB_RTC_CONNECTED,this.reconnectAttempts=0,_s.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case ee.Disconnecting:t=st.WEB_RTC_DISCONNECTING;break;case ee.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=st.WEB_RTC_DISCONNECTED;const e=Rs.get("answerDevice");if(!_s.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const e=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${e}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},e)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.transport.stateChange.addListener(e=>{}),this.userAgent.delegate={onInvite:e=>{this.handleIncomingCall(e)}})}async register(){if(this.userAgent){this.registerer=new ne(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case X.Initial:t="initial";break;case X.Registered:t=st.WEB_RTC_REGISTERED;break;case X.Unregistered:t=st.WEB_RTC_UNREGISTERED;break;case X.Terminated:t=st.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:st.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(e){const t=e.sessionDescriptionHandler;if(t){const e=t.peerConnection;if(!e)return;const s=new MediaStream;e.getReceivers().forEach(e=>{e.track&&"audio"===e.track.kind&&s.addTrack(e.track)});let i=document.getElementById("sip-remote-audio");i||(i=document.createElement("audio"),i.id="sip-remote-audio",i.autoplay=!0,i.style.display="none",document.body.appendChild(i)),i.srcObject=s,i.play().catch(e=>{console.error("音频播放失败,需要用户交互触发",e)})}}handleSessionState(e,t,s){e.stateChange.addListener(t=>{switch(t){case K.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=e,this.attachRemoteAudio(e);break;case K.Terminating:break;case K.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case K.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=_s.agentInfo,i=Rs.get("direction"),r=1===t;if(i===tt.OUTGOING)this.answerCall();else if(r&&i===tt.INCOMING){const e=Number(s)||0;e>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},e):this.answerCall()}}async makeCall(e){if(Rs.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");if(!this.userAgent)throw Rs.updateIsCalling(!1),Rs.updateDirection(null),new Error("SIP客户端未初始化");Rs.updateIsCalling(!0),Rs.updateDirection(tt.OUTGOING);const t=Xe.makeURI(`sip:${e}@${this.config.server}`);if(!t)throw new Error("无效的被叫号码");const s=new Z(this.userAgent,t);this.handleSessionState(s,!0,e);try{this.activeSession=s,await s.invite(),this.config.callTimeout&&(this.callTimeoutTimer=setTimeout(()=>{s.state!==K.Established&&(this.hangup(),this.eventCallback?.({type:"error",data:{message:"呼叫超时未接通"}}))},this.config.callTimeout))}catch(e){this.eventCallback?.({type:"error",data:{message:"呼叫失败",detail:e}}),Rs.updateIsCalling(!1),Rs.updateDirection(null)}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{console.log((new Date).toLocaleString()),await this.incomingInvitation.accept(),console.log((new Date).toLocaleString()),this.activeSession=this.incomingInvitation,this.incomingInvitation=null}catch(e){this.eventCallback?.({type:st.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,Rs.updateDirection(null),Rs.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(e){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:e}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:st.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession){clearTimeout(this.callTimeoutTimer);const e=this.activeSession;if(!e)return;const t=e.state;try{t===K.Established?await e.bye():t===K.Establishing&&(e instanceof Z?await e.cancel():e instanceof J&&await e.reject()),clearTimeout(this.callTimeoutTimer)}catch(e){console.error("挂断失败",e)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof J&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await
|
|
117
|
+
`}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.remove()},this.duration+300)}render(){return Jt`<div>${this.content}</div>`}};oi([di({type:String})],ui.prototype,"type",void 0),oi([di({type:String})],ui.prototype,"content",void 0),oi([di({type:Number})],ui.prototype,"duration",void 0),ui=oi([ai("my-message")],ui);const pi=(e,t,s=3e3)=>{let i=document.querySelector("#message-container");i||(i=document.createElement("div"),i.id="message-container",Object.assign(i.style,{position:"fixed",top:"14px",left:"50%",transform:"translateX(-50%)",zIndex:"9999"}),document.body.appendChild(i));const r=document.createElement("my-message");r.setAttribute("type",e),r.setAttribute("content",t),r.setAttribute("duration",String(s)),r.style.setProperty("--fade-delay",s/1e3+"s"),i.appendChild(r)},fi=(e,t=3e3)=>pi("success",e,t),mi=(e,t=3e3)=>pi("error",e,t),vi=(e,t=3e3)=>pi("warning",e,t),wi="/v1/aicc/bmserver",yi="/v1/aicc/ccs";let bi="",Ti="",Si="";async function Ci(e,t){const s=function(){const e=ni(Ti,Si);return ti.create({prefixUrl:`${bi}/api`,timeout:!1,headers:{Authorization:e},hooks:{afterResponse:[async(e,t,s)=>{const i=await s.clone().json();if(0!==i.code)throw mi(i.msg),new Error(JSON.stringify(i)||"请求失败");return s.json=async()=>i,s}]}})}(),i=e.replace(/^\/+/,"");return s.post(i,{json:t}).json()}const Ei=new class extends Qe{updateRttObject(e){this.setState({rttObject:e})}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class Ai{constructor(e,t){this.config=e,this.eventCallback=t,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleMessage=e=>{},this.handleNetworkInfoChange=e=>{if(e.rttObject?.rtt){0===(e.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Ei.subscribe(this.handleNetworkInfoChange)}async start(){const e=Xe.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!e)throw new Error("无效的SIP配置");const t={uri:e,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:0},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:!1};this.userAgent=new Xe(t),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case ee.Connecting:t=st.WEB_RTC_CONNECTING;break;case ee.Connected:t=st.WEB_RTC_CONNECTED,this.reconnectAttempts=0,_s.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case ee.Disconnecting:t=st.WEB_RTC_DISCONNECTING;break;case ee.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=st.WEB_RTC_DISCONNECTED;const e=Rs.get("answerDevice");if(!_s.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const e=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${e}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},e)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.transport.stateChange.addListener(e=>{}),this.userAgent.delegate={onInvite:e=>{this.handleIncomingCall(e)}})}async register(){if(this.userAgent){this.registerer=new ne(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case X.Initial:t="initial";break;case X.Registered:t=st.WEB_RTC_REGISTERED;break;case X.Unregistered:t=st.WEB_RTC_UNREGISTERED;break;case X.Terminated:t=st.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:st.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(e){const t=e.sessionDescriptionHandler;if(t){const e=t.peerConnection;if(!e)return;const s=new MediaStream;e.getReceivers().forEach(e=>{e.track&&"audio"===e.track.kind&&s.addTrack(e.track)});let i=document.getElementById("sip-remote-audio");i||(i=document.createElement("audio"),i.id="sip-remote-audio",i.autoplay=!0,i.style.display="none",document.body.appendChild(i)),i.srcObject=s,i.play().catch(e=>{console.error("音频播放失败,需要用户交互触发",e)})}}handleSessionState(e,t,s){e.stateChange.addListener(t=>{switch(t){case K.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=e,this.attachRemoteAudio(e);break;case K.Terminating:break;case K.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case K.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=_s.agentInfo,i=Rs.get("direction"),r=1===t;if(i===tt.OUTGOING)this.answerCall();else if(r&&i===tt.INCOMING){const e=Number(s)||0;e>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},e):this.answerCall()}}async makeCall(e){if(Rs.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");if(!this.userAgent)throw Rs.updateIsCalling(!1),Rs.updateDirection(null),new Error("SIP客户端未初始化");Rs.updateIsCalling(!0),Rs.updateDirection(tt.OUTGOING);const t=Xe.makeURI(`sip:${e}@${this.config.server}`);if(!t)throw new Error("无效的被叫号码");const s=new Z(this.userAgent,t);this.handleSessionState(s,!0,e);try{this.activeSession=s,await s.invite(),this.config.callTimeout&&(this.callTimeoutTimer=setTimeout(()=>{s.state!==K.Established&&(this.hangup(),this.eventCallback?.({type:"error",data:{message:"呼叫超时未接通"}}))},this.config.callTimeout))}catch(e){this.eventCallback?.({type:"error",data:{message:"呼叫失败",detail:e}}),Rs.updateIsCalling(!1),Rs.updateDirection(null)}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{console.log((new Date).toLocaleString()),await this.incomingInvitation.accept(),console.log((new Date).toLocaleString()),this.activeSession=this.incomingInvitation,this.incomingInvitation=null}catch(e){this.eventCallback?.({type:st.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,Rs.updateDirection(null),Rs.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(e){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:e}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:st.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession){clearTimeout(this.callTimeoutTimer);const e=this.activeSession;if(!e)return;const t=e.state;try{t===K.Established?await e.bye():t===K.Establishing&&(e instanceof Z?await e.cancel():e instanceof J&&await e.reject()),clearTimeout(this.callTimeoutTimer)}catch(e){console.error("挂断失败",e)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof J&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(e){console.warn("注销失败",e)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!_s.isRtcReconnecting){_s.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),console.log("重连成功"),this.isOffline=!1}catch(e){console.error("重连失败",e)}finally{_s.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const e=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!e)return null;const t=await e.getStats(),s={};return t.forEach(e=>{"candidate-pair"===e.type&&"succeeded"===e.state&&null!=e.currentRoundTripTime&&(s.rtt=+(1e3*e.currentRoundTripTime).toFixed(2)),"inbound-rtp"===e.type&&"audio"===e.kind&&(s.jitter=+(1e3*e.jitter).toFixed(2),s.packetsLost=e.packetsLost,s.packetsReceived=e.packetsReceived,e.bytesReceived&&e.timestamp&&(s.recvBitrate=+(e.bytesReceived/1024).toFixed(2))),"outbound-rtp"===e.type&&"audio"===e.kind&&(s.packetsSent=e.packetsSent,e.bytesSent&&e.timestamp&&(s.sendBitrate=+(e.bytesSent/1024).toFixed(2))),"codec"===e.type&&e.mimeType&&(s.codec=e.mimeType)}),{...s,rtt:s?.rtt||40}}try{const e=Date.now();await Ci(`${wi}/config/ping`,{});const t=Date.now();return{rtt:t-e||1}}catch(e){console.log(e)}}}let _i=class extends fs{static{this.styles=pt`
|
|
118
118
|
.timer-text {
|
|
119
119
|
width: 70px;
|
|
120
120
|
font-size: 14px;
|
|
@@ -358,11 +358,9 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
358
358
|
align-items: center;
|
|
359
359
|
justify-content: center;
|
|
360
360
|
}
|
|
361
|
-
|
|
362
361
|
.select-box.open {
|
|
363
362
|
border-bottom-color: #4096ff;
|
|
364
363
|
}
|
|
365
|
-
|
|
366
364
|
.dropdown {
|
|
367
365
|
position: absolute;
|
|
368
366
|
top: 100%;
|
|
@@ -370,7 +368,6 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
370
368
|
right: 0;
|
|
371
369
|
background: white;
|
|
372
370
|
width: 120px;
|
|
373
|
-
//border: 1px solid #ddd;
|
|
374
371
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
|
375
372
|
border-radius: 4px;
|
|
376
373
|
margin-top: 4px;
|
|
@@ -385,27 +382,22 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
385
382
|
max-height: 200px;
|
|
386
383
|
overflow: auto;
|
|
387
384
|
}
|
|
388
|
-
|
|
389
385
|
.dropdown.show {
|
|
390
386
|
opacity: 1;
|
|
391
387
|
transform: scaleY(1);
|
|
392
388
|
pointer-events: auto;
|
|
393
389
|
}
|
|
394
|
-
|
|
395
390
|
.option {
|
|
396
391
|
padding: 8px 12px;
|
|
397
392
|
cursor: pointer;
|
|
398
393
|
}
|
|
399
|
-
|
|
400
394
|
.option:hover {
|
|
401
395
|
background-color: #f5f5f5;
|
|
402
396
|
}
|
|
403
|
-
|
|
404
397
|
.option[selected] {
|
|
405
398
|
background-color: #e6f4ff;
|
|
406
399
|
color: #1677ff;
|
|
407
400
|
}
|
|
408
|
-
|
|
409
401
|
.selected-label {
|
|
410
402
|
display: inline-flex;
|
|
411
403
|
align-items: center;
|
|
@@ -413,7 +405,10 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
413
405
|
color: #4096ff;
|
|
414
406
|
font-size: 14px;
|
|
415
407
|
}
|
|
416
|
-
|
|
408
|
+
.placeholder {
|
|
409
|
+
color: #999;
|
|
410
|
+
}
|
|
411
|
+
`}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.handleOutsideClick)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("click",this.handleOutsideClick)}toggleDropdown(){this.open?this.closeDropdown():this.openDropdown()}openDropdown(){this.open=!0,requestAnimationFrame(()=>this.animating=!0)}closeDropdown(){this.animating=!1,setTimeout(()=>this.open=!1,200)}handleOptionClick(e,t){const s=t.getAttribute("value");s&&s!==this.value&&(this.dispatchEvent(new CustomEvent("change",{detail:{value:s}})),this.closeDropdown())}updated(e){e.has("value")&&this.updateSelectedContent()}updateSelectedContent(){const e=Array.from(this.children).find(e=>"SELECT-OPTION"===e.tagName&&e.getAttribute("value")===this.value);this.selectedContent=e?e.cloneNode(!0):null}renderSelectedLabel(){return this.selectedContent?Jt`<span class="selected-label">${this.selectedContent}</span>`:Jt`<span class="placeholder">${this.placeholder}</span>`}renderSelectOptions(){return Array.from(this.children).filter(e=>"SELECT-OPTION"===e.tagName).map(e=>{const t=e.getAttribute("value")===this.value;return Jt`
|
|
417
412
|
<div class="option" ?selected=${t} @click=${t=>this.handleOptionClick(t,e)}>
|
|
418
413
|
${e.cloneNode(!0)}
|
|
419
414
|
</div>
|
|
@@ -421,7 +416,6 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
421
416
|
<div style="width: ${this.width};" class="select-box ${this.open?"open":""}" @click=${this.toggleDropdown}>
|
|
422
417
|
${this.renderSelectedLabel()}
|
|
423
418
|
</div>
|
|
424
|
-
|
|
425
419
|
${this.open?Jt`<div class="dropdown ${this.animating?"show":""}">${this.renderSelectOptions()}</div>`:Xt}
|
|
426
420
|
`}};oi([di({type:String})],Di.prototype,"placeholder",void 0),oi([di({type:String})],Di.prototype,"value",void 0),oi([di({type:String})],Di.prototype,"width",void 0),oi([li()],Di.prototype,"open",void 0),oi([li()],Di.prototype,"animating",void 0),oi([li()],Di.prototype,"selectedContent",void 0),Di=oi([ai("my-select")],Di);let xi=class extends fs{constructor(){super(...arguments),this.isDialerVisible=!1,this.inputValue="",this.keys=["1","2","3","4","5","6","7","8","9","*","0","#"],this.handleDocumentClick=e=>{(e.composedPath?.()||[]).includes(this)||(this.isDialerVisible=!1)},this.handleValueSize=()=>this.inputValue.length<10?26:this.inputValue.length>=10&&this.inputValue.length<20?24:this.inputValue.length>=21&&this.inputValue.length<25?18:this.inputValue.length>25?14:16}static{this.styles=pt`
|
|
427
421
|
.key-body {
|
|
@@ -587,7 +581,7 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
587
581
|
<div class="popup ${this.open?"":"hidden"}">
|
|
588
582
|
<slot name="content"></slot>
|
|
589
583
|
</div>
|
|
590
|
-
`}};oi([li()],Ni.prototype,"open",void 0),Ni=oi([ai("my-icon-popup")],Ni);class Hi{constructor(){this.roleData={agentInfo:()=>{if(!_s.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:e=>{if(!e.data)throw new Error("请传入参数")},changeDevice:e=>{if(!e)throw new Error('Parameter "device" is required');const{answer_devices:t}=_s.agentInfo;if(!t.split(",").map(e=>Number(e)).includes(e))throw new Error("当前设备不支持")},changeState:(e,t)=>{if(!e)throw new Error('Parameter "state" is required');if(!t)throw new Error('Parameter "state_name" is required');if(2===e&&"通话中"===t)throw new Error("当前状态不支持");if(![1,2].includes(e))throw new Error("当前状态不支持")}}}async _agentLogin(e){try{const s=await(t={agent_no:e},Ci(`${yi}/agent/login`,t));_s.agentInfo=s.data}catch(e){throw console.log(e),new Error("登录失败")}var t}async changeDevice(e){try{this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;this.roleData.changeDevice(i);const{agent_no:r}=_s.agentInfo;await(e=>Ci(`${yi}/device/change`,e))({agent_no:r,answer_device:i}),Rs.updateAnswerDevice(i);const n=Rs.get("actionConfigs");Rs.updateActionConfigs(n),s?.({code:0,msg:"请求成功"})}catch(e){throw console.log(e),new Error("切换设备失败")}}async changeState(e){try{_s.autoStateTimer&&(clearTimeout(_s.autoStateTimer),_s.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:r}=t;this.roleData.changeState(i,r);const{agent_no:n}=_s.agentInfo;await(e=>Ci(`${yi}/state/change`,e))({agent_no:n,state_name:r,state:i}),i===et.IDLE?Rs.updateActionConfigs(ws):i===et.BUSY&&Rs.updateActionConfigs(ys),_s.stateObject={state:i,state_name:r},s?.({code:0,msg:"请求成功"})}catch(e){console.log(e)}}async getIdleAgentList(e){const{agent_no:t}=_s.agentInfo;try{this.roleData.agentInfo();const s=await(e=>Ci(`${yi}/agent/free`,e))({agent_no:t});e.success?.(s)}catch(e){console.log(e)}}async getAgentState(e){try{const t=await Ci(`${wi}/agent/statecfg/list`,{}),s=(t.data||[]).filter(e=>0===e.enable).filter(e=>0!==e.state&&3!==e.state).map(e=>({state:e.state,state_name:e.state_name})).reverse();e.success?.({...t,data:s})}catch(e){console.log(e)}}}class Pi{constructor({container:e,rttHTML:t,statusParams:s},i){this.VoiceSDKInstance=i,this.apiClient=new Hi,this.isOpenSelect=!1,this.statusParams={state:et.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.handleNetworkInfoChange=e=>{this.rttHTML&&this.renderRtt(e.rttObject)},this.handleCallInfoChange=e=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const e=document.querySelector(".ysyt-select");e.style.height="0px",setTimeout(()=>{e.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=e=>{e.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const t=document.querySelector(".ysyt-select");this.isOpenSelect?(t.style.height=t.scrollHeight+"px",t.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async e=>{const{state:t,statusName:s}=e;await this.apiClient.changeState({data:{state:t,state_name:s},success:()=>{this.statusParams=e;const t=document.getElementById("my-timer");t?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async e=>{await this.apiClient.changeDevice({data:{device:e},success:({code:t})=>{0===t&&(1!==e&&this.VoiceSDKInstance.destroyRtc(),fi("切换成功"),this.render())}})},this.ruleCall=async e=>{if(e)try{await this.VoiceSDKInstance.call_api.makeCall(e)}catch(e){console.error(e)}},this.onCall=()=>{const e=document.querySelector("my-input");this.ruleCall(e.value)},this.renderCallPopover=()=>Jt`
|
|
584
|
+
`}};oi([li()],Ni.prototype,"open",void 0),Ni=oi([ai("my-icon-popup")],Ni);class Hi{constructor(){this.roleData={agentInfo:()=>{if(!_s.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:e=>{if(!e.data)throw new Error("请传入参数")},changeDevice:e=>{if(!e)throw new Error('Parameter "device" is required');const{answer_devices:t}=_s.agentInfo;if(!t.split(",").map(e=>Number(e)).includes(e))throw new Error("当前设备不支持")},changeState:(e,t)=>{if(!e)throw new Error('Parameter "state" is required');if(!t)throw new Error('Parameter "state_name" is required');if(2===e&&"通话中"===t)throw new Error("当前状态不支持");if(![1,2].includes(e))throw new Error("当前状态不支持")}}}async _agentLogin(e){try{const s=await(t={agent_no:e},Ci(`${yi}/agent/login`,t));_s.agentInfo=s.data}catch(e){throw console.log(e),new Error("登录失败")}var t}async changeDevice(e){try{if(Rs.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;this.roleData.changeDevice(i);const{agent_no:r}=_s.agentInfo;await(e=>Ci(`${yi}/device/change`,e))({agent_no:r,answer_device:i}),Rs.updateAnswerDevice(i);const n=Rs.get("actionConfigs");Rs.updateActionConfigs(n),s?.({code:0,msg:"请求成功"})}catch(e){throw console.log(e),new Error("切换设备失败")}}async changeState(e){try{_s.autoStateTimer&&(clearTimeout(_s.autoStateTimer),_s.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:r}=t;this.roleData.changeState(i,r);const{agent_no:n}=_s.agentInfo;await(e=>Ci(`${yi}/state/change`,e))({agent_no:n,state_name:r,state:i}),i===et.IDLE?Rs.updateActionConfigs(ws):i===et.BUSY&&Rs.updateActionConfigs(ys),_s.stateObject={state:i,state_name:r},s?.({code:0,msg:"请求成功"})}catch(e){console.log(e)}}async getIdleAgentList(e){const{agent_no:t}=_s.agentInfo;try{this.roleData.agentInfo();const s=await(e=>Ci(`${yi}/agent/free`,e))({agent_no:t});e.success?.(s)}catch(e){console.log(e)}}async getAgentState(e){try{const t=await Ci(`${wi}/agent/statecfg/list`,{}),s=(t.data||[]).filter(e=>0===e.enable).filter(e=>0!==e.state&&3!==e.state).map(e=>({state:e.state,state_name:e.state_name})).reverse();e.success?.({...t,data:s})}catch(e){console.log(e)}}}class Pi{constructor({container:e,rttHTML:t,statusParams:s},i){this.VoiceSDKInstance=i,this.apiClient=new Hi,this.isOpenSelect=!1,this.statusParams={state:et.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=e=>{this.rttHTML&&this.renderRtt(e.rttObject)},this.handleCallInfoChange=e=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const e=document.querySelector(".ysyt-select");e.style.height="0px",setTimeout(()=>{e.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=e=>{e.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const t=document.querySelector(".ysyt-select");this.isOpenSelect?(t.style.height=t.scrollHeight+"px",t.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async e=>{const{state:t,statusName:s}=e;await this.apiClient.changeState({data:{state:t,state_name:s},success:()=>{this.statusParams=e;const t=document.getElementById("my-timer");t?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async e=>{try{await this.apiClient.changeDevice({data:{device:e},success:({code:t})=>{0===t&&(1!==e&&this.VoiceSDKInstance.destroyRtc(),fi("切换成功"),this.default_device=e,this.render())}})}catch(e){console.log(e),mi(e.message),this.render()}},this.ruleCall=async e=>{if(e)try{await this.VoiceSDKInstance.call_api.makeCall(e)}catch(e){console.error(e)}},this.onCall=()=>{const e=document.querySelector("my-input");this.ruleCall(e.value)},this.renderCallPopover=()=>Jt`
|
|
591
585
|
<my-icon-popup>
|
|
592
586
|
<div slot="icon">
|
|
593
587
|
<i class="ysyt icon-boda my-icon"></i>
|
|
@@ -671,7 +665,7 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
671
665
|
<my-tooltip content="拒接" color="#F5212D" @click="${()=>this.VoiceSDKInstance.call_api.cancelCall()}">
|
|
672
666
|
<i class="ysyt icon-quxiao my-icon" style="color: #F5212D"></i>
|
|
673
667
|
</my-tooltip>
|
|
674
|
-
`,this.container=e,this.statusParams=s,this.rttHTML=t;const{init_state:r}=_s.agentInfo;1===r?this.statusParams={state:et.IDLE,statusName:"空闲"}:2===r&&(this.statusParams={state:et.BUSY,statusName:"忙碌"}),Rs.subscribe(this.handleCallInfoChange),Ei.subscribe(this.handleNetworkInfoChange);const
|
|
668
|
+
`,this.container=e,this.statusParams=s,this.rttHTML=t;const{init_state:r,default_device:n}=_s.agentInfo;this.default_device=n,1===r?this.statusParams={state:et.IDLE,statusName:"空闲"}:2===r&&(this.statusParams={state:et.BUSY,statusName:"忙碌"}),Rs.subscribe(this.handleCallInfoChange),Ei.subscribe(this.handleNetworkInfoChange);const o=()=>{this.hiddenSelect()};document.removeEventListener("click",o),document.addEventListener("click",o),this.eventHandle(),this.getAgentStateList()}eventHandle(){ct.on(it.AGENT_STATE,e=>{this.statusParams={state:e.state,statusName:e.state_name},this.render()}),ct.on(it.CONSULT_FAILED,()=>{mi("咨询失败")}),ct.on(it.OUT_FAILED,e=>{mi(`外呼失败: ${e}`)})}async getAgentStateList(){try{await this.VoiceSDKInstance.agent_api.getAgentState({success:({data:e,code:t})=>{0===t?(this.agentStateData=e,this.render()):mi("获取状态列表失败")}})}catch(e){console.log(e)}}onKeyPress(e){console.log("外部收到按键:",e.detail.key)}async renderConsultModalToBody(){try{await this.VoiceSDKInstance.agent_api.getIdleAgentList({success:e=>{const{data:t}=e,s=t||[];if(0===s.length&&(this.consultShow=!1,vi("没有空闲坐席")),!this.consultShow)return void(this.modalRoot&&(document.body.removeChild(this.modalRoot),this.modalRoot=null));this.modalRoot||(this.modalRoot=document.createElement("div"),document.body.appendChild(this.modalRoot));const i=Jt`
|
|
675
669
|
<my-modal-wrapper
|
|
676
670
|
.visible=${!0}
|
|
677
671
|
.showFooter=${!1}
|
|
@@ -692,16 +686,16 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
692
686
|
</div>`}
|
|
693
687
|
</div>
|
|
694
688
|
</my-modal-wrapper>
|
|
695
|
-
`;us(i,this.modalRoot)}})}catch(e){mi(e)}}getActionConfigs(){const{show_satisfaction:e}=_s.agentInfo,t=Rs.get("isHold"),s=Rs.get("isMuted"),i=Rs.get("actionConfigs").filter(i=>(0!==e||"satisfaction"!==i)&&(!(!t&&"unhold"===i)&&((!t||"hold"!==i)&&((!s||"mute"!==i)&&!(!s&&"unmute"===i)))));return[{render:this.renderCallPopover,type:"call_number"},{render:this.renderAnswer,type:"answer"},{render:this.renderReject,type:"reject"},{render:this.renderHangup,type:"hangup"},{render:this.renderDialer,type:"dtmf"},{render:this.renderUnhold,type:"unhold"},{render:this.renderHold,type:"hold"},{render:this.renderMute,type:"mute"},{render:this.renderUnmute,type:"unmute"},{render:this.renderSatisfaction,type:"satisfaction"},{render:this.renderConsult,type:"consult"},{render:this.renderTransfer,type:"transfer"},{render:this.renderConsultTransfer,type:"consult_transfer"}].filter(({type:e})=>i.includes(e))}async render(){const{displayText:e}=Rs.getState(),{
|
|
689
|
+
`;us(i,this.modalRoot)}})}catch(e){mi(e)}}getActionConfigs(){const{show_satisfaction:e}=_s.agentInfo,t=Rs.get("isHold"),s=Rs.get("isMuted"),i=Rs.get("actionConfigs").filter(i=>(0!==e||"satisfaction"!==i)&&(!(!t&&"unhold"===i)&&((!t||"hold"!==i)&&((!s||"mute"!==i)&&!(!s&&"unmute"===i)))));return[{render:this.renderCallPopover,type:"call_number"},{render:this.renderAnswer,type:"answer"},{render:this.renderReject,type:"reject"},{render:this.renderHangup,type:"hangup"},{render:this.renderDialer,type:"dtmf"},{render:this.renderUnhold,type:"unhold"},{render:this.renderHold,type:"hold"},{render:this.renderMute,type:"mute"},{render:this.renderUnmute,type:"unmute"},{render:this.renderSatisfaction,type:"satisfaction"},{render:this.renderConsult,type:"consult"},{render:this.renderTransfer,type:"transfer"},{render:this.renderConsultTransfer,type:"consult_transfer"}].filter(({type:e})=>i.includes(e))}async render(){const{displayText:e}=Rs.getState(),{answer_devices:t}=_s.agentInfo;console.log(t);const s=(t||"").split(","),i=this.getActionConfigs(),r={...vs},{statusColor:n}=r,o=document.querySelector("head");if(o){const e=Jt`
|
|
696
690
|
<style>
|
|
697
691
|
.ysyt-phone-body {
|
|
698
|
-
background: ${
|
|
692
|
+
background: ${n[this.statusParams.state]};
|
|
699
693
|
}
|
|
700
694
|
.ysyt-action-body {
|
|
701
|
-
border-bottom: 1px solid ${
|
|
695
|
+
border-bottom: 1px solid ${n[this.statusParams.state]};
|
|
702
696
|
}
|
|
703
697
|
</style>
|
|
704
|
-
`;us(e,
|
|
698
|
+
`;us(e,o)}const a=Jt`
|
|
705
699
|
<i class="ysyt icon-shang select-icon" style="${this.isOpenSelect?"display: block;":"display: none;"}"></i>
|
|
706
700
|
<div
|
|
707
701
|
class="ysyt-select"
|
|
@@ -718,30 +712,30 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
718
712
|
`)}
|
|
719
713
|
</div>
|
|
720
714
|
</div>
|
|
721
|
-
`,
|
|
715
|
+
`,c=Jt`
|
|
722
716
|
<div id="ysyt-body">
|
|
723
717
|
<div id="ysyt-devices-body">
|
|
724
718
|
<my-select
|
|
725
719
|
width="100px"
|
|
726
|
-
value="${String(
|
|
720
|
+
value="${String(this.default_device)}"
|
|
727
721
|
placeholder=""
|
|
728
722
|
@change=${e=>this.onChangeDevices(Number(e.detail.value))}
|
|
729
723
|
>
|
|
730
|
-
${
|
|
724
|
+
${s.includes("1")?Jt`
|
|
731
725
|
<select-option value="1">
|
|
732
726
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
733
727
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAjhJREFUaEPtmM1WwjAQhWeAF0I34kZ5MuDJqBtxo7wQEE9CkzNNk8yktIl4YKOHRvPl9s5PBuEOP3iHzPCALvXWxEq/HBfvGmp2AfPz8/m0LQXp78NCa1gEtQF1hbUfVLirBZ6EXh3neweL0CjAnVZaodpoeIW4/lqemtKKB6E76rawFM48V2oPCM1heV7/CWircMoCr9+LrVa8hk16SufArH7mqoZNboKuZZMetLXG4enMZhatsl1fMij/F7RUuZwYGCvLRJWWQDtPA4DUTmOARwORg6bApdNeD1qaEWy6Kw2s31QwQxigRLWr4eNO3xPyGJfGLDRnoTH8G/of8d5DqX0MijvUVLCuwwxtwPmae14FWm/K+bZW3xENRKtUCsweqkZ7muwvODBJCzuFVdimiAu6GvmaheZKdY3KyELToIz5Nxe8d1lGaPCCH9KLsgia9s2xsk3BU8HprzOeb2/60pZADC0Bp2tMagqMGULBawJ+pt6k8FnQUhu4rNOmDg1vBG3BYorSv0upngXd8XdESZvi9AHpjMSlPmbs4I8vQiOKbOgccP8Alxk00uFOqkYMgh4CPqTIxFrkwdAlwCeBdj0KmflJ0xanfKphu0lpunEnY2QWi+BFJDG9Gg3a2cXLtznBZ+G5tnhUaH9TqqDUNvSNxcYSk0B34Iny5vvWOnaNfhP6d5PTydrU/XNS6F6h8Q8QMnNgHu4vKwLtb2qrJf3eKi4pPlWguXTHPX9AcwqN9fwulf4FD/s5TOGFiLYAAAAASUVORK5CYII="}" width="16" alt="" /><span style="font-size: 14px">软电话</span>
|
|
734
728
|
</div>
|
|
735
729
|
</select-option>
|
|
736
730
|
`:""}
|
|
737
|
-
${
|
|
731
|
+
${s.includes("2")?Jt`
|
|
738
732
|
<select-option value="2">
|
|
739
733
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
740
734
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAWtJREFUaEPtWdFNAzEMdW6Ewgo3BzBOYYi2Q0DHKcxxK0BHaNA7cIVEVD0n8Uck31dVOfbLyzvn9JxkwCcNiFmqQd8fl8eWDX9u5/fa9WbQm9dlnyZ5yFmaQF8BZzmcX+a9ZQMm0HfH5QSwKcnKUr7Ih6XYv9gkO/yHfF/b+YnNRYMGw4IiFczcAlOTlwf9tmQUPz/P9BqWOZwgYlm2aQAbgO7Msm5KZccSQoFGp7hkOUF7SeTAMsjGZZEd3hUX0CyI2jgX0GC6uWMUdqQt1AX0kJoO0H9k4to9gulgutCS9HIJeYQ8Qh7cV0j0aeUpukdBMSGPkMeNRhLyCHmEPIibdujLJcyawgm7+R7T9GPz9nx8bTHSgNQpAev2u1wuYBWuKWt+q+fMxruBtnjIVqN8tZEN3jdl9a5MjzgJAHA9RvzWuUvrC6kzHHYKsNa2Fr0ybl1Ysnh/rWPX6VYHnF1SmJnuUrUxyZCgvwFf6/M9kuThSwAAAABJRU5ErkJggg=="}" width="16" alt="" /><span style="font-size: 14px">手机模式</span>
|
|
741
735
|
</div>
|
|
742
736
|
</select-option>
|
|
743
737
|
`:""}
|
|
744
|
-
${
|
|
738
|
+
${s.includes("3")?Jt`
|
|
745
739
|
<select-option value="3">
|
|
746
740
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
747
741
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAq5JREFUaEPtmWFywiAQhcEr6Als79F6LdsZdab1WsZ7tJ7AXiF0lmYzC9mFDUGrM/qrmrB8PB7LQq25w4+9Q2bzgL7WrD2UvhmlF8/vr865jXXueD7tt1PAIBZtf/76aPA7PKPf4Xf6Pn2WtMdiud46YzZ9R9Y2P9+fqxLw+dPbwTgXQNvZbIUw8+XaGRJ/0LcxkDV2IJwIHTSytuk7LADnAGDgCOFns20P8NvPae+ZuEFiGxaadtIHpqqPBPcqEsh4plLQg/6tbVhoqZNYfY1VKBC1AwUfBf03+PDDBQg6KFCcTjUoB/Hoos7ag9gT2g+hESphgbGKUygUAKcds4TK0x1TEbTvqEBxaANtMSOhXZJKg4edO5rZrMFMUwxdCk4zgyZ70BkhsxR5WmEPyeOphUbboBXqQTM5M7eZ4ELjVPHKdikviEM3kkSeVilNO5GUE5Xudqx4kANoZpHDO8Hi7GZcD41bbmYT4Tah3KzUeM7viEqL5GxRA5CLIdYe/a5IiprBtHczorFRzQHI0AqL9DvdyFpk6gDkKo9YRMoKuS1/KpzUXl1PSxbIVXCXAM+eEft0JVjgPzJIFjooLYU8rAWvdXTLQsc1hmgTcpzi1kDNo5sKmhY58LdYY0RnSqydnbUv9Lg25ejm+9culKAm1tbaUfAaR7dR0HGxTk/O3MC9HUDh7mOt3QVXBgX1uFia5pQvKf6lmKWx1PaQKruc4pcQoQg6ziipxZmDHsRSlATF0AOPJ+41aoNPgu7BndtgGpPqlLHgqTiToREm3jxK4TWVYzVozuddTvWXhjeptJhdME/DzRK5u4gHEd9CpQZaVekYRLothTQZvEuugDW2uih04Hdafwhe0R7brgIdWAf+G9C2weV6yjbc+K4OrVmQuXce0DmFaj2/S6V/Ae/pt8oTAp/jAAAAAElFTkSuQmCC"}" width="16" alt="" /><span style="font-size: 14px">SIP话机</span>
|
|
@@ -761,14 +755,14 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
761
755
|
<span>${t}</span>
|
|
762
756
|
`:void 0)(this.statusParams)}
|
|
763
757
|
<i class="ysyt icon-xia"></i>
|
|
764
|
-
${
|
|
758
|
+
${a}
|
|
765
759
|
`}
|
|
766
760
|
</div>
|
|
767
761
|
<timer-component id="my-timer"></timer-component>
|
|
768
762
|
</div>
|
|
769
|
-
<div class="ysyt-action-body">${
|
|
763
|
+
<div class="ysyt-action-body">${i.map(e=>e.render())}</div>
|
|
770
764
|
</div>
|
|
771
|
-
`;us(
|
|
765
|
+
`;us(c,this.container)}async renderRtt(e){const{outCallIsAnswer:t}=Rs.getState(),s=e?.rtt||500,i=Jt`
|
|
772
766
|
<my-popover triggerType="hover">
|
|
773
767
|
<div slot="trigger" id="wifi-body">
|
|
774
768
|
${s>=250?Jt`<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAlVJREFUaEPtmGFuwyAMhU2PtU1qOVmbk5FKW4+1TCawkcQYG2i3aM2fqirBn83zc1IDO7zMDpnhCf2oU+teaefcKYW31o69k6mGTuDOAWoBmwGNCVwBYKxNSAUdQDWQkiIPuMhae5EsxjUi6ARWUk1pbGrdIIFnoZWwqXbx+NPrqJAQLmXhSWghLELGo1U1m3MuSiFKLXc6JPwGOmyY28yD1jYQRSZIYAP+DV2obnfYdQIF+EV8Dx2AHVGJu8Mq4X3VDSMHUSe3WAV3L8eF0BNxs9XoNpwU2mF0CdwSv6fDxIeRWFrkyYEjNMoi+q9YDkKHyRUT41wlCRBxhqhptCDRWC24S41aRDIMcT2jaCKGZsXESr6aQmM1NRNUBK8Z46mE1tWMumX9W+DHxUkYA7eMcbH+maFCnVxx3xI05SzFTTXCZnok62BZ6MxmYt11AM/G4qCxidIpqfJuDXSm0fWVTgz+pBk0E7wFx/gMn4fRwLv4KTC+EXExxZbHVW6ClwuAOQJMjMWZEWC6GriJ31ByMZug56pOZx6WDD20wFdDT/DqKmDTDKrBq6BnOVDTESXgZ5Z/owGIus5Jx4wGPqy2aWuhV/6NsGbgGm6Wkk9iMVAM3NQM6huwKj+V1jfX6pSqJFIFrT1Oaj1WXmOF6R6/Bt2S+N2gWypZSqg7NOEsVbrlwLtC560QuoL3hqYeZWfnrrC2u4zxdNPgw9R/J2HZwda6xRr+f1d6OXQ2B/t3NU2D1z1fPMw9thrHBpS/AJT8Of7eVdPSoK3rntCtFZTev8tKfwHUBxjzil9I5gAAAABJRU5ErkJggg=="}" alt="" />`:""}
|
|
@@ -114,7 +114,7 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
114
114
|
border: 1px solid #595959;
|
|
115
115
|
color: #595959;
|
|
116
116
|
}
|
|
117
|
-
`}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.remove()},this.duration+300)}render(){return Jt`<div>${this.content}</div>`}};ai([li({type:String})],pi.prototype,"type",void 0),ai([li({type:String})],pi.prototype,"content",void 0),ai([li({type:Number})],pi.prototype,"duration",void 0),pi=ai([ci("my-message")],pi);const fi=(e,t,s=3e3)=>{let i=document.querySelector("#message-container");i||(i=document.createElement("div"),i.id="message-container",Object.assign(i.style,{position:"fixed",top:"14px",left:"50%",transform:"translateX(-50%)",zIndex:"9999"}),document.body.appendChild(i));const r=document.createElement("my-message");r.setAttribute("type",e),r.setAttribute("content",t),r.setAttribute("duration",String(s)),r.style.setProperty("--fade-delay",s/1e3+"s"),i.appendChild(r)},mi=(e,t=3e3)=>fi("success",e,t),vi=(e,t=3e3)=>fi("error",e,t),wi=(e,t=3e3)=>fi("warning",e,t),yi="/v1/aicc/bmserver",bi="/v1/aicc/ccs";let Ti="",Si="",Ci="";async function Ei(e,t){const s=function(){const e=oi(Si,Ci);return si.create({prefixUrl:`${Ti}/api`,timeout:!1,headers:{Authorization:e},hooks:{afterResponse:[async(e,t,s)=>{const i=await s.clone().json();if(0!==i.code)throw vi(i.msg),new Error(JSON.stringify(i)||"请求失败");return s.json=async()=>i,s}]}})}(),i=e.replace(/^\/+/,"");return s.post(i,{json:t}).json()}const Ai=new class extends Qe{updateRttObject(e){this.setState({rttObject:e})}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _i{constructor(e,t){this.config=e,this.eventCallback=t,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleMessage=e=>{},this.handleNetworkInfoChange=e=>{if(e.rttObject?.rtt){0===(e.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Ai.subscribe(this.handleNetworkInfoChange)}async start(){const e=Xe.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!e)throw new Error("无效的SIP配置");const t={uri:e,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:0},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:!1};this.userAgent=new Xe(t),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case ee.Connecting:t=st.WEB_RTC_CONNECTING;break;case ee.Connected:t=st.WEB_RTC_CONNECTED,this.reconnectAttempts=0,_s.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case ee.Disconnecting:t=st.WEB_RTC_DISCONNECTING;break;case ee.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=st.WEB_RTC_DISCONNECTED;const e=Rs.get("answerDevice");if(!_s.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const e=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${e}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},e)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.transport.stateChange.addListener(e=>{}),this.userAgent.delegate={onInvite:e=>{this.handleIncomingCall(e)}})}async register(){if(this.userAgent){this.registerer=new ne(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case X.Initial:t="initial";break;case X.Registered:t=st.WEB_RTC_REGISTERED;break;case X.Unregistered:t=st.WEB_RTC_UNREGISTERED;break;case X.Terminated:t=st.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:st.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(e){const t=e.sessionDescriptionHandler;if(t){const e=t.peerConnection;if(!e)return;const s=new MediaStream;e.getReceivers().forEach(e=>{e.track&&"audio"===e.track.kind&&s.addTrack(e.track)});let i=document.getElementById("sip-remote-audio");i||(i=document.createElement("audio"),i.id="sip-remote-audio",i.autoplay=!0,i.style.display="none",document.body.appendChild(i)),i.srcObject=s,i.play().catch(e=>{console.error("音频播放失败,需要用户交互触发",e)})}}handleSessionState(e,t,s){e.stateChange.addListener(t=>{switch(t){case K.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=e,this.attachRemoteAudio(e);break;case K.Terminating:break;case K.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case K.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=_s.agentInfo,i=Rs.get("direction"),r=1===t;if(i===tt.OUTGOING)this.answerCall();else if(r&&i===tt.INCOMING){const e=Number(s)||0;e>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},e):this.answerCall()}}async makeCall(e){if(Rs.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");if(!this.userAgent)throw Rs.updateIsCalling(!1),Rs.updateDirection(null),new Error("SIP客户端未初始化");Rs.updateIsCalling(!0),Rs.updateDirection(tt.OUTGOING);const t=Xe.makeURI(`sip:${e}@${this.config.server}`);if(!t)throw new Error("无效的被叫号码");const s=new Z(this.userAgent,t);this.handleSessionState(s,!0,e);try{this.activeSession=s,await s.invite(),this.config.callTimeout&&(this.callTimeoutTimer=setTimeout(()=>{s.state!==K.Established&&(this.hangup(),this.eventCallback?.({type:"error",data:{message:"呼叫超时未接通"}}))},this.config.callTimeout))}catch(e){this.eventCallback?.({type:"error",data:{message:"呼叫失败",detail:e}}),Rs.updateIsCalling(!1),Rs.updateDirection(null)}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{console.log((new Date).toLocaleString()),await this.incomingInvitation.accept(),console.log((new Date).toLocaleString()),this.activeSession=this.incomingInvitation,this.incomingInvitation=null}catch(e){this.eventCallback?.({type:st.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,Rs.updateDirection(null),Rs.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(e){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:e}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:st.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession){clearTimeout(this.callTimeoutTimer);const e=this.activeSession;if(!e)return;const t=e.state;try{t===K.Established?await e.bye():t===K.Establishing&&(e instanceof Z?await e.cancel():e instanceof J&&await e.reject()),clearTimeout(this.callTimeoutTimer)}catch(e){console.error("挂断失败",e)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof J&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await
|
|
117
|
+
`}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.remove()},this.duration+300)}render(){return Jt`<div>${this.content}</div>`}};ai([li({type:String})],pi.prototype,"type",void 0),ai([li({type:String})],pi.prototype,"content",void 0),ai([li({type:Number})],pi.prototype,"duration",void 0),pi=ai([ci("my-message")],pi);const fi=(e,t,s=3e3)=>{let i=document.querySelector("#message-container");i||(i=document.createElement("div"),i.id="message-container",Object.assign(i.style,{position:"fixed",top:"14px",left:"50%",transform:"translateX(-50%)",zIndex:"9999"}),document.body.appendChild(i));const r=document.createElement("my-message");r.setAttribute("type",e),r.setAttribute("content",t),r.setAttribute("duration",String(s)),r.style.setProperty("--fade-delay",s/1e3+"s"),i.appendChild(r)},mi=(e,t=3e3)=>fi("success",e,t),vi=(e,t=3e3)=>fi("error",e,t),wi=(e,t=3e3)=>fi("warning",e,t),yi="/v1/aicc/bmserver",bi="/v1/aicc/ccs";let Ti="",Si="",Ci="";async function Ei(e,t){const s=function(){const e=oi(Si,Ci);return si.create({prefixUrl:`${Ti}/api`,timeout:!1,headers:{Authorization:e},hooks:{afterResponse:[async(e,t,s)=>{const i=await s.clone().json();if(0!==i.code)throw vi(i.msg),new Error(JSON.stringify(i)||"请求失败");return s.json=async()=>i,s}]}})}(),i=e.replace(/^\/+/,"");return s.post(i,{json:t}).json()}const Ai=new class extends Qe{updateRttObject(e){this.setState({rttObject:e})}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _i{constructor(e,t){this.config=e,this.eventCallback=t,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleMessage=e=>{},this.handleNetworkInfoChange=e=>{if(e.rttObject?.rtt){0===(e.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Ai.subscribe(this.handleNetworkInfoChange)}async start(){const e=Xe.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!e)throw new Error("无效的SIP配置");const t={uri:e,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:0},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:!1};this.userAgent=new Xe(t),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case ee.Connecting:t=st.WEB_RTC_CONNECTING;break;case ee.Connected:t=st.WEB_RTC_CONNECTED,this.reconnectAttempts=0,_s.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case ee.Disconnecting:t=st.WEB_RTC_DISCONNECTING;break;case ee.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=st.WEB_RTC_DISCONNECTED;const e=Rs.get("answerDevice");if(!_s.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const e=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${e}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},e)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.transport.stateChange.addListener(e=>{}),this.userAgent.delegate={onInvite:e=>{this.handleIncomingCall(e)}})}async register(){if(this.userAgent){this.registerer=new ne(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case X.Initial:t="initial";break;case X.Registered:t=st.WEB_RTC_REGISTERED;break;case X.Unregistered:t=st.WEB_RTC_UNREGISTERED;break;case X.Terminated:t=st.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:st.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(e){const t=e.sessionDescriptionHandler;if(t){const e=t.peerConnection;if(!e)return;const s=new MediaStream;e.getReceivers().forEach(e=>{e.track&&"audio"===e.track.kind&&s.addTrack(e.track)});let i=document.getElementById("sip-remote-audio");i||(i=document.createElement("audio"),i.id="sip-remote-audio",i.autoplay=!0,i.style.display="none",document.body.appendChild(i)),i.srcObject=s,i.play().catch(e=>{console.error("音频播放失败,需要用户交互触发",e)})}}handleSessionState(e,t,s){e.stateChange.addListener(t=>{switch(t){case K.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=e,this.attachRemoteAudio(e);break;case K.Terminating:break;case K.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case K.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=_s.agentInfo,i=Rs.get("direction"),r=1===t;if(i===tt.OUTGOING)this.answerCall();else if(r&&i===tt.INCOMING){const e=Number(s)||0;e>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},e):this.answerCall()}}async makeCall(e){if(Rs.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");if(!this.userAgent)throw Rs.updateIsCalling(!1),Rs.updateDirection(null),new Error("SIP客户端未初始化");Rs.updateIsCalling(!0),Rs.updateDirection(tt.OUTGOING);const t=Xe.makeURI(`sip:${e}@${this.config.server}`);if(!t)throw new Error("无效的被叫号码");const s=new Z(this.userAgent,t);this.handleSessionState(s,!0,e);try{this.activeSession=s,await s.invite(),this.config.callTimeout&&(this.callTimeoutTimer=setTimeout(()=>{s.state!==K.Established&&(this.hangup(),this.eventCallback?.({type:"error",data:{message:"呼叫超时未接通"}}))},this.config.callTimeout))}catch(e){this.eventCallback?.({type:"error",data:{message:"呼叫失败",detail:e}}),Rs.updateIsCalling(!1),Rs.updateDirection(null)}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{console.log((new Date).toLocaleString()),await this.incomingInvitation.accept(),console.log((new Date).toLocaleString()),this.activeSession=this.incomingInvitation,this.incomingInvitation=null}catch(e){this.eventCallback?.({type:st.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,Rs.updateDirection(null),Rs.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(e){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:e}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:st.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession){clearTimeout(this.callTimeoutTimer);const e=this.activeSession;if(!e)return;const t=e.state;try{t===K.Established?await e.bye():t===K.Establishing&&(e instanceof Z?await e.cancel():e instanceof J&&await e.reject()),clearTimeout(this.callTimeoutTimer)}catch(e){console.error("挂断失败",e)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof J&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(e){console.warn("注销失败",e)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!_s.isRtcReconnecting){_s.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),console.log("重连成功"),this.isOffline=!1}catch(e){console.error("重连失败",e)}finally{_s.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const e=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!e)return null;const t=await e.getStats(),s={};return t.forEach(e=>{"candidate-pair"===e.type&&"succeeded"===e.state&&null!=e.currentRoundTripTime&&(s.rtt=+(1e3*e.currentRoundTripTime).toFixed(2)),"inbound-rtp"===e.type&&"audio"===e.kind&&(s.jitter=+(1e3*e.jitter).toFixed(2),s.packetsLost=e.packetsLost,s.packetsReceived=e.packetsReceived,e.bytesReceived&&e.timestamp&&(s.recvBitrate=+(e.bytesReceived/1024).toFixed(2))),"outbound-rtp"===e.type&&"audio"===e.kind&&(s.packetsSent=e.packetsSent,e.bytesSent&&e.timestamp&&(s.sendBitrate=+(e.bytesSent/1024).toFixed(2))),"codec"===e.type&&e.mimeType&&(s.codec=e.mimeType)}),{...s,rtt:s?.rtt||40}}try{const e=Date.now();await Ei(`${yi}/config/ping`,{});const t=Date.now();return{rtt:t-e||1}}catch(e){console.log(e)}}}let Ii=class extends fs{static{this.styles=pt`
|
|
118
118
|
.timer-text {
|
|
119
119
|
width: 70px;
|
|
120
120
|
font-size: 14px;
|
|
@@ -358,11 +358,9 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
358
358
|
align-items: center;
|
|
359
359
|
justify-content: center;
|
|
360
360
|
}
|
|
361
|
-
|
|
362
361
|
.select-box.open {
|
|
363
362
|
border-bottom-color: #4096ff;
|
|
364
363
|
}
|
|
365
|
-
|
|
366
364
|
.dropdown {
|
|
367
365
|
position: absolute;
|
|
368
366
|
top: 100%;
|
|
@@ -370,7 +368,6 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
370
368
|
right: 0;
|
|
371
369
|
background: white;
|
|
372
370
|
width: 120px;
|
|
373
|
-
//border: 1px solid #ddd;
|
|
374
371
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
|
375
372
|
border-radius: 4px;
|
|
376
373
|
margin-top: 4px;
|
|
@@ -385,27 +382,22 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
385
382
|
max-height: 200px;
|
|
386
383
|
overflow: auto;
|
|
387
384
|
}
|
|
388
|
-
|
|
389
385
|
.dropdown.show {
|
|
390
386
|
opacity: 1;
|
|
391
387
|
transform: scaleY(1);
|
|
392
388
|
pointer-events: auto;
|
|
393
389
|
}
|
|
394
|
-
|
|
395
390
|
.option {
|
|
396
391
|
padding: 8px 12px;
|
|
397
392
|
cursor: pointer;
|
|
398
393
|
}
|
|
399
|
-
|
|
400
394
|
.option:hover {
|
|
401
395
|
background-color: #f5f5f5;
|
|
402
396
|
}
|
|
403
|
-
|
|
404
397
|
.option[selected] {
|
|
405
398
|
background-color: #e6f4ff;
|
|
406
399
|
color: #1677ff;
|
|
407
400
|
}
|
|
408
|
-
|
|
409
401
|
.selected-label {
|
|
410
402
|
display: inline-flex;
|
|
411
403
|
align-items: center;
|
|
@@ -413,7 +405,10 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
413
405
|
color: #4096ff;
|
|
414
406
|
font-size: 14px;
|
|
415
407
|
}
|
|
416
|
-
|
|
408
|
+
.placeholder {
|
|
409
|
+
color: #999;
|
|
410
|
+
}
|
|
411
|
+
`}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.handleOutsideClick)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("click",this.handleOutsideClick)}toggleDropdown(){this.open?this.closeDropdown():this.openDropdown()}openDropdown(){this.open=!0,requestAnimationFrame(()=>this.animating=!0)}closeDropdown(){this.animating=!1,setTimeout(()=>this.open=!1,200)}handleOptionClick(e,t){const s=t.getAttribute("value");s&&s!==this.value&&(this.dispatchEvent(new CustomEvent("change",{detail:{value:s}})),this.closeDropdown())}updated(e){e.has("value")&&this.updateSelectedContent()}updateSelectedContent(){const e=Array.from(this.children).find(e=>"SELECT-OPTION"===e.tagName&&e.getAttribute("value")===this.value);this.selectedContent=e?e.cloneNode(!0):null}renderSelectedLabel(){return this.selectedContent?Jt`<span class="selected-label">${this.selectedContent}</span>`:Jt`<span class="placeholder">${this.placeholder}</span>`}renderSelectOptions(){return Array.from(this.children).filter(e=>"SELECT-OPTION"===e.tagName).map(e=>{const t=e.getAttribute("value")===this.value;return Jt`
|
|
417
412
|
<div class="option" ?selected=${t} @click=${t=>this.handleOptionClick(t,e)}>
|
|
418
413
|
${e.cloneNode(!0)}
|
|
419
414
|
</div>
|
|
@@ -421,7 +416,6 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
421
416
|
<div style="width: ${this.width};" class="select-box ${this.open?"open":""}" @click=${this.toggleDropdown}>
|
|
422
417
|
${this.renderSelectedLabel()}
|
|
423
418
|
</div>
|
|
424
|
-
|
|
425
419
|
${this.open?Jt`<div class="dropdown ${this.animating?"show":""}">${this.renderSelectOptions()}</div>`:Xt}
|
|
426
420
|
`}};ai([li({type:String})],xi.prototype,"placeholder",void 0),ai([li({type:String})],xi.prototype,"value",void 0),ai([li({type:String})],xi.prototype,"width",void 0),ai([gi()],xi.prototype,"open",void 0),ai([gi()],xi.prototype,"animating",void 0),ai([gi()],xi.prototype,"selectedContent",void 0),xi=ai([ci("my-select")],xi);let ki=class extends fs{constructor(){super(...arguments),this.isDialerVisible=!1,this.inputValue="",this.keys=["1","2","3","4","5","6","7","8","9","*","0","#"],this.handleDocumentClick=e=>{(e.composedPath?.()||[]).includes(this)||(this.isDialerVisible=!1)},this.handleValueSize=()=>this.inputValue.length<10?26:this.inputValue.length>=10&&this.inputValue.length<20?24:this.inputValue.length>=21&&this.inputValue.length<25?18:this.inputValue.length>25?14:16}static{this.styles=pt`
|
|
427
421
|
.key-body {
|
|
@@ -587,7 +581,7 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
587
581
|
<div class="popup ${this.open?"":"hidden"}">
|
|
588
582
|
<slot name="content"></slot>
|
|
589
583
|
</div>
|
|
590
|
-
`}};ai([gi()],Hi.prototype,"open",void 0),Hi=ai([ci("my-icon-popup")],Hi);class Pi{constructor(){this.roleData={agentInfo:()=>{if(!_s.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:e=>{if(!e.data)throw new Error("请传入参数")},changeDevice:e=>{if(!e)throw new Error('Parameter "device" is required');const{answer_devices:t}=_s.agentInfo;if(!t.split(",").map(e=>Number(e)).includes(e))throw new Error("当前设备不支持")},changeState:(e,t)=>{if(!e)throw new Error('Parameter "state" is required');if(!t)throw new Error('Parameter "state_name" is required');if(2===e&&"通话中"===t)throw new Error("当前状态不支持");if(![1,2].includes(e))throw new Error("当前状态不支持")}}}async _agentLogin(e){try{const s=await(t={agent_no:e},Ei(`${bi}/agent/login`,t));_s.agentInfo=s.data}catch(e){throw console.log(e),new Error("登录失败")}var t}async changeDevice(e){try{this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;this.roleData.changeDevice(i);const{agent_no:r}=_s.agentInfo;await(e=>Ei(`${bi}/device/change`,e))({agent_no:r,answer_device:i}),Rs.updateAnswerDevice(i);const n=Rs.get("actionConfigs");Rs.updateActionConfigs(n),s?.({code:0,msg:"请求成功"})}catch(e){throw console.log(e),new Error("切换设备失败")}}async changeState(e){try{_s.autoStateTimer&&(clearTimeout(_s.autoStateTimer),_s.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:r}=t;this.roleData.changeState(i,r);const{agent_no:n}=_s.agentInfo;await(e=>Ei(`${bi}/state/change`,e))({agent_no:n,state_name:r,state:i}),i===et.IDLE?Rs.updateActionConfigs(ws):i===et.BUSY&&Rs.updateActionConfigs(ys),_s.stateObject={state:i,state_name:r},s?.({code:0,msg:"请求成功"})}catch(e){console.log(e)}}async getIdleAgentList(e){const{agent_no:t}=_s.agentInfo;try{this.roleData.agentInfo();const s=await(e=>Ei(`${bi}/agent/free`,e))({agent_no:t});e.success?.(s)}catch(e){console.log(e)}}async getAgentState(e){try{const t=await Ei(`${yi}/agent/statecfg/list`,{}),s=(t.data||[]).filter(e=>0===e.enable).filter(e=>0!==e.state&&3!==e.state).map(e=>({state:e.state,state_name:e.state_name})).reverse();e.success?.({...t,data:s})}catch(e){console.log(e)}}}class Oi{constructor({container:e,rttHTML:t,statusParams:s},i){this.VoiceSDKInstance=i,this.apiClient=new Pi,this.isOpenSelect=!1,this.statusParams={state:et.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.handleNetworkInfoChange=e=>{this.rttHTML&&this.renderRtt(e.rttObject)},this.handleCallInfoChange=e=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const e=document.querySelector(".ysyt-select");e.style.height="0px",setTimeout(()=>{e.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=e=>{e.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const t=document.querySelector(".ysyt-select");this.isOpenSelect?(t.style.height=t.scrollHeight+"px",t.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async e=>{const{state:t,statusName:s}=e;await this.apiClient.changeState({data:{state:t,state_name:s},success:()=>{this.statusParams=e;const t=document.getElementById("my-timer");t?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async e=>{await this.apiClient.changeDevice({data:{device:e},success:({code:t})=>{0===t&&(1!==e&&this.VoiceSDKInstance.destroyRtc(),mi("切换成功"),this.render())}})},this.ruleCall=async e=>{if(e)try{await this.VoiceSDKInstance.call_api.makeCall(e)}catch(e){console.error(e)}},this.onCall=()=>{const e=document.querySelector("my-input");this.ruleCall(e.value)},this.renderCallPopover=()=>Jt`
|
|
584
|
+
`}};ai([gi()],Hi.prototype,"open",void 0),Hi=ai([ci("my-icon-popup")],Hi);class Pi{constructor(){this.roleData={agentInfo:()=>{if(!_s.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:e=>{if(!e.data)throw new Error("请传入参数")},changeDevice:e=>{if(!e)throw new Error('Parameter "device" is required');const{answer_devices:t}=_s.agentInfo;if(!t.split(",").map(e=>Number(e)).includes(e))throw new Error("当前设备不支持")},changeState:(e,t)=>{if(!e)throw new Error('Parameter "state" is required');if(!t)throw new Error('Parameter "state_name" is required');if(2===e&&"通话中"===t)throw new Error("当前状态不支持");if(![1,2].includes(e))throw new Error("当前状态不支持")}}}async _agentLogin(e){try{const s=await(t={agent_no:e},Ei(`${bi}/agent/login`,t));_s.agentInfo=s.data}catch(e){throw console.log(e),new Error("登录失败")}var t}async changeDevice(e){try{if(Rs.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;this.roleData.changeDevice(i);const{agent_no:r}=_s.agentInfo;await(e=>Ei(`${bi}/device/change`,e))({agent_no:r,answer_device:i}),Rs.updateAnswerDevice(i);const n=Rs.get("actionConfigs");Rs.updateActionConfigs(n),s?.({code:0,msg:"请求成功"})}catch(e){throw console.log(e),new Error("切换设备失败")}}async changeState(e){try{_s.autoStateTimer&&(clearTimeout(_s.autoStateTimer),_s.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:r}=t;this.roleData.changeState(i,r);const{agent_no:n}=_s.agentInfo;await(e=>Ei(`${bi}/state/change`,e))({agent_no:n,state_name:r,state:i}),i===et.IDLE?Rs.updateActionConfigs(ws):i===et.BUSY&&Rs.updateActionConfigs(ys),_s.stateObject={state:i,state_name:r},s?.({code:0,msg:"请求成功"})}catch(e){console.log(e)}}async getIdleAgentList(e){const{agent_no:t}=_s.agentInfo;try{this.roleData.agentInfo();const s=await(e=>Ei(`${bi}/agent/free`,e))({agent_no:t});e.success?.(s)}catch(e){console.log(e)}}async getAgentState(e){try{const t=await Ei(`${yi}/agent/statecfg/list`,{}),s=(t.data||[]).filter(e=>0===e.enable).filter(e=>0!==e.state&&3!==e.state).map(e=>({state:e.state,state_name:e.state_name})).reverse();e.success?.({...t,data:s})}catch(e){console.log(e)}}}class Oi{constructor({container:e,rttHTML:t,statusParams:s},i){this.VoiceSDKInstance=i,this.apiClient=new Pi,this.isOpenSelect=!1,this.statusParams={state:et.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=e=>{this.rttHTML&&this.renderRtt(e.rttObject)},this.handleCallInfoChange=e=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const e=document.querySelector(".ysyt-select");e.style.height="0px",setTimeout(()=>{e.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=e=>{e.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const t=document.querySelector(".ysyt-select");this.isOpenSelect?(t.style.height=t.scrollHeight+"px",t.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async e=>{const{state:t,statusName:s}=e;await this.apiClient.changeState({data:{state:t,state_name:s},success:()=>{this.statusParams=e;const t=document.getElementById("my-timer");t?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async e=>{try{await this.apiClient.changeDevice({data:{device:e},success:({code:t})=>{0===t&&(1!==e&&this.VoiceSDKInstance.destroyRtc(),mi("切换成功"),this.default_device=e,this.render())}})}catch(e){console.log(e),vi(e.message),this.render()}},this.ruleCall=async e=>{if(e)try{await this.VoiceSDKInstance.call_api.makeCall(e)}catch(e){console.error(e)}},this.onCall=()=>{const e=document.querySelector("my-input");this.ruleCall(e.value)},this.renderCallPopover=()=>Jt`
|
|
591
585
|
<my-icon-popup>
|
|
592
586
|
<div slot="icon">
|
|
593
587
|
<i class="ysyt icon-boda my-icon"></i>
|
|
@@ -671,7 +665,7 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
671
665
|
<my-tooltip content="拒接" color="#F5212D" @click="${()=>this.VoiceSDKInstance.call_api.cancelCall()}">
|
|
672
666
|
<i class="ysyt icon-quxiao my-icon" style="color: #F5212D"></i>
|
|
673
667
|
</my-tooltip>
|
|
674
|
-
`,this.container=e,this.statusParams=s,this.rttHTML=t;const{init_state:r}=_s.agentInfo;1===r?this.statusParams={state:et.IDLE,statusName:"空闲"}:2===r&&(this.statusParams={state:et.BUSY,statusName:"忙碌"}),Rs.subscribe(this.handleCallInfoChange),Ai.subscribe(this.handleNetworkInfoChange);const
|
|
668
|
+
`,this.container=e,this.statusParams=s,this.rttHTML=t;const{init_state:r,default_device:n}=_s.agentInfo;this.default_device=n,1===r?this.statusParams={state:et.IDLE,statusName:"空闲"}:2===r&&(this.statusParams={state:et.BUSY,statusName:"忙碌"}),Rs.subscribe(this.handleCallInfoChange),Ai.subscribe(this.handleNetworkInfoChange);const o=()=>{this.hiddenSelect()};document.removeEventListener("click",o),document.addEventListener("click",o),this.eventHandle(),this.getAgentStateList()}eventHandle(){ct.on(it.AGENT_STATE,e=>{this.statusParams={state:e.state,statusName:e.state_name},this.render()}),ct.on(it.CONSULT_FAILED,()=>{vi("咨询失败")}),ct.on(it.OUT_FAILED,e=>{vi(`外呼失败: ${e}`)})}async getAgentStateList(){try{await this.VoiceSDKInstance.agent_api.getAgentState({success:({data:e,code:t})=>{0===t?(this.agentStateData=e,this.render()):vi("获取状态列表失败")}})}catch(e){console.log(e)}}onKeyPress(e){console.log("外部收到按键:",e.detail.key)}async renderConsultModalToBody(){try{await this.VoiceSDKInstance.agent_api.getIdleAgentList({success:e=>{const{data:t}=e,s=t||[];if(0===s.length&&(this.consultShow=!1,wi("没有空闲坐席")),!this.consultShow)return void(this.modalRoot&&(document.body.removeChild(this.modalRoot),this.modalRoot=null));this.modalRoot||(this.modalRoot=document.createElement("div"),document.body.appendChild(this.modalRoot));const i=Jt`
|
|
675
669
|
<my-modal-wrapper
|
|
676
670
|
.visible=${!0}
|
|
677
671
|
.showFooter=${!1}
|
|
@@ -692,16 +686,16 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
692
686
|
</div>`}
|
|
693
687
|
</div>
|
|
694
688
|
</my-modal-wrapper>
|
|
695
|
-
`;us(i,this.modalRoot)}})}catch(e){vi(e)}}getActionConfigs(){const{show_satisfaction:e}=_s.agentInfo,t=Rs.get("isHold"),s=Rs.get("isMuted"),i=Rs.get("actionConfigs").filter(i=>(0!==e||"satisfaction"!==i)&&(!(!t&&"unhold"===i)&&((!t||"hold"!==i)&&((!s||"mute"!==i)&&!(!s&&"unmute"===i)))));return[{render:this.renderCallPopover,type:"call_number"},{render:this.renderAnswer,type:"answer"},{render:this.renderReject,type:"reject"},{render:this.renderHangup,type:"hangup"},{render:this.renderDialer,type:"dtmf"},{render:this.renderUnhold,type:"unhold"},{render:this.renderHold,type:"hold"},{render:this.renderMute,type:"mute"},{render:this.renderUnmute,type:"unmute"},{render:this.renderSatisfaction,type:"satisfaction"},{render:this.renderConsult,type:"consult"},{render:this.renderTransfer,type:"transfer"},{render:this.renderConsultTransfer,type:"consult_transfer"}].filter(({type:e})=>i.includes(e))}async render(){const{displayText:e}=Rs.getState(),{
|
|
689
|
+
`;us(i,this.modalRoot)}})}catch(e){vi(e)}}getActionConfigs(){const{show_satisfaction:e}=_s.agentInfo,t=Rs.get("isHold"),s=Rs.get("isMuted"),i=Rs.get("actionConfigs").filter(i=>(0!==e||"satisfaction"!==i)&&(!(!t&&"unhold"===i)&&((!t||"hold"!==i)&&((!s||"mute"!==i)&&!(!s&&"unmute"===i)))));return[{render:this.renderCallPopover,type:"call_number"},{render:this.renderAnswer,type:"answer"},{render:this.renderReject,type:"reject"},{render:this.renderHangup,type:"hangup"},{render:this.renderDialer,type:"dtmf"},{render:this.renderUnhold,type:"unhold"},{render:this.renderHold,type:"hold"},{render:this.renderMute,type:"mute"},{render:this.renderUnmute,type:"unmute"},{render:this.renderSatisfaction,type:"satisfaction"},{render:this.renderConsult,type:"consult"},{render:this.renderTransfer,type:"transfer"},{render:this.renderConsultTransfer,type:"consult_transfer"}].filter(({type:e})=>i.includes(e))}async render(){const{displayText:e}=Rs.getState(),{answer_devices:t}=_s.agentInfo;console.log(t);const s=(t||"").split(","),i=this.getActionConfigs(),r={...vs},{statusColor:n}=r,o=document.querySelector("head");if(o){const e=Jt`
|
|
696
690
|
<style>
|
|
697
691
|
.ysyt-phone-body {
|
|
698
|
-
background: ${
|
|
692
|
+
background: ${n[this.statusParams.state]};
|
|
699
693
|
}
|
|
700
694
|
.ysyt-action-body {
|
|
701
|
-
border-bottom: 1px solid ${
|
|
695
|
+
border-bottom: 1px solid ${n[this.statusParams.state]};
|
|
702
696
|
}
|
|
703
697
|
</style>
|
|
704
|
-
`;us(e,
|
|
698
|
+
`;us(e,o)}const a=Jt`
|
|
705
699
|
<i class="ysyt icon-shang select-icon" style="${this.isOpenSelect?"display: block;":"display: none;"}"></i>
|
|
706
700
|
<div
|
|
707
701
|
class="ysyt-select"
|
|
@@ -718,30 +712,30 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
718
712
|
`)}
|
|
719
713
|
</div>
|
|
720
714
|
</div>
|
|
721
|
-
`,
|
|
715
|
+
`,c=Jt`
|
|
722
716
|
<div id="ysyt-body">
|
|
723
717
|
<div id="ysyt-devices-body">
|
|
724
718
|
<my-select
|
|
725
719
|
width="100px"
|
|
726
|
-
value="${String(
|
|
720
|
+
value="${String(this.default_device)}"
|
|
727
721
|
placeholder=""
|
|
728
722
|
@change=${e=>this.onChangeDevices(Number(e.detail.value))}
|
|
729
723
|
>
|
|
730
|
-
${
|
|
724
|
+
${s.includes("1")?Jt`
|
|
731
725
|
<select-option value="1">
|
|
732
726
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
733
727
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAjhJREFUaEPtmM1WwjAQhWeAF0I34kZ5MuDJqBtxo7wQEE9CkzNNk8yktIl4YKOHRvPl9s5PBuEOP3iHzPCALvXWxEq/HBfvGmp2AfPz8/m0LQXp78NCa1gEtQF1hbUfVLirBZ6EXh3neweL0CjAnVZaodpoeIW4/lqemtKKB6E76rawFM48V2oPCM1heV7/CWircMoCr9+LrVa8hk16SufArH7mqoZNboKuZZMetLXG4enMZhatsl1fMij/F7RUuZwYGCvLRJWWQDtPA4DUTmOARwORg6bApdNeD1qaEWy6Kw2s31QwQxigRLWr4eNO3xPyGJfGLDRnoTH8G/of8d5DqX0MijvUVLCuwwxtwPmae14FWm/K+bZW3xENRKtUCsweqkZ7muwvODBJCzuFVdimiAu6GvmaheZKdY3KyELToIz5Nxe8d1lGaPCCH9KLsgia9s2xsk3BU8HprzOeb2/60pZADC0Bp2tMagqMGULBawJ+pt6k8FnQUhu4rNOmDg1vBG3BYorSv0upngXd8XdESZvi9AHpjMSlPmbs4I8vQiOKbOgccP8Alxk00uFOqkYMgh4CPqTIxFrkwdAlwCeBdj0KmflJ0xanfKphu0lpunEnY2QWi+BFJDG9Gg3a2cXLtznBZ+G5tnhUaH9TqqDUNvSNxcYSk0B34Iny5vvWOnaNfhP6d5PTydrU/XNS6F6h8Q8QMnNgHu4vKwLtb2qrJf3eKi4pPlWguXTHPX9AcwqN9fwulf4FD/s5TOGFiLYAAAAASUVORK5CYII="}" width="16" alt="" /><span style="font-size: 14px">软电话</span>
|
|
734
728
|
</div>
|
|
735
729
|
</select-option>
|
|
736
730
|
`:""}
|
|
737
|
-
${
|
|
731
|
+
${s.includes("2")?Jt`
|
|
738
732
|
<select-option value="2">
|
|
739
733
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
740
734
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAWtJREFUaEPtWdFNAzEMdW6Ewgo3BzBOYYi2Q0DHKcxxK0BHaNA7cIVEVD0n8Uck31dVOfbLyzvn9JxkwCcNiFmqQd8fl8eWDX9u5/fa9WbQm9dlnyZ5yFmaQF8BZzmcX+a9ZQMm0HfH5QSwKcnKUr7Ih6XYv9gkO/yHfF/b+YnNRYMGw4IiFczcAlOTlwf9tmQUPz/P9BqWOZwgYlm2aQAbgO7Msm5KZccSQoFGp7hkOUF7SeTAMsjGZZEd3hUX0CyI2jgX0GC6uWMUdqQt1AX0kJoO0H9k4to9gulgutCS9HIJeYQ8Qh7cV0j0aeUpukdBMSGPkMeNRhLyCHmEPIibdujLJcyawgm7+R7T9GPz9nx8bTHSgNQpAev2u1wuYBWuKWt+q+fMxruBtnjIVqN8tZEN3jdl9a5MjzgJAHA9RvzWuUvrC6kzHHYKsNa2Fr0ybl1Ysnh/rWPX6VYHnF1SmJnuUrUxyZCgvwFf6/M9kuThSwAAAABJRU5ErkJggg=="}" width="16" alt="" /><span style="font-size: 14px">手机模式</span>
|
|
741
735
|
</div>
|
|
742
736
|
</select-option>
|
|
743
737
|
`:""}
|
|
744
|
-
${
|
|
738
|
+
${s.includes("3")?Jt`
|
|
745
739
|
<select-option value="3">
|
|
746
740
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
747
741
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAq5JREFUaEPtmWFywiAQhcEr6Als79F6LdsZdab1WsZ7tJ7AXiF0lmYzC9mFDUGrM/qrmrB8PB7LQq25w4+9Q2bzgL7WrD2UvhmlF8/vr865jXXueD7tt1PAIBZtf/76aPA7PKPf4Xf6Pn2WtMdiud46YzZ9R9Y2P9+fqxLw+dPbwTgXQNvZbIUw8+XaGRJ/0LcxkDV2IJwIHTSytuk7LADnAGDgCOFns20P8NvPae+ZuEFiGxaadtIHpqqPBPcqEsh4plLQg/6tbVhoqZNYfY1VKBC1AwUfBf03+PDDBQg6KFCcTjUoB/Hoos7ag9gT2g+hESphgbGKUygUAKcds4TK0x1TEbTvqEBxaANtMSOhXZJKg4edO5rZrMFMUwxdCk4zgyZ70BkhsxR5WmEPyeOphUbboBXqQTM5M7eZ4ELjVPHKdikviEM3kkSeVilNO5GUE5Xudqx4kANoZpHDO8Hi7GZcD41bbmYT4Tah3KzUeM7viEqL5GxRA5CLIdYe/a5IiprBtHczorFRzQHI0AqL9DvdyFpk6gDkKo9YRMoKuS1/KpzUXl1PSxbIVXCXAM+eEft0JVjgPzJIFjooLYU8rAWvdXTLQsc1hmgTcpzi1kDNo5sKmhY58LdYY0RnSqydnbUv9Lg25ejm+9culKAm1tbaUfAaR7dR0HGxTk/O3MC9HUDh7mOt3QVXBgX1uFia5pQvKf6lmKWx1PaQKruc4pcQoQg6ziipxZmDHsRSlATF0AOPJ+41aoNPgu7BndtgGpPqlLHgqTiToREm3jxK4TWVYzVozuddTvWXhjeptJhdME/DzRK5u4gHEd9CpQZaVekYRLothTQZvEuugDW2uih04Hdafwhe0R7brgIdWAf+G9C2weV6yjbc+K4OrVmQuXce0DmFaj2/S6V/Ae/pt8oTAp/jAAAAAElFTkSuQmCC"}" width="16" alt="" /><span style="font-size: 14px">SIP话机</span>
|
|
@@ -761,14 +755,14 @@ const ci=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
761
755
|
<span>${t}</span>
|
|
762
756
|
`:void 0)(this.statusParams)}
|
|
763
757
|
<i class="ysyt icon-xia"></i>
|
|
764
|
-
${
|
|
758
|
+
${a}
|
|
765
759
|
`}
|
|
766
760
|
</div>
|
|
767
761
|
<timer-component id="my-timer"></timer-component>
|
|
768
762
|
</div>
|
|
769
|
-
<div class="ysyt-action-body">${
|
|
763
|
+
<div class="ysyt-action-body">${i.map(e=>e.render())}</div>
|
|
770
764
|
</div>
|
|
771
|
-
`;us(
|
|
765
|
+
`;us(c,this.container)}async renderRtt(e){const{outCallIsAnswer:t}=Rs.getState(),s=e?.rtt||500,i=Jt`
|
|
772
766
|
<my-popover triggerType="hover">
|
|
773
767
|
<div slot="trigger" id="wifi-body">
|
|
774
768
|
${s>=250?Jt`<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAlVJREFUaEPtmGFuwyAMhU2PtU1qOVmbk5FKW4+1TCawkcQYG2i3aM2fqirBn83zc1IDO7zMDpnhCf2oU+teaefcKYW31o69k6mGTuDOAWoBmwGNCVwBYKxNSAUdQDWQkiIPuMhae5EsxjUi6ARWUk1pbGrdIIFnoZWwqXbx+NPrqJAQLmXhSWghLELGo1U1m3MuSiFKLXc6JPwGOmyY28yD1jYQRSZIYAP+DV2obnfYdQIF+EV8Dx2AHVGJu8Mq4X3VDSMHUSe3WAV3L8eF0BNxs9XoNpwU2mF0CdwSv6fDxIeRWFrkyYEjNMoi+q9YDkKHyRUT41wlCRBxhqhptCDRWC24S41aRDIMcT2jaCKGZsXESr6aQmM1NRNUBK8Z46mE1tWMumX9W+DHxUkYA7eMcbH+maFCnVxx3xI05SzFTTXCZnok62BZ6MxmYt11AM/G4qCxidIpqfJuDXSm0fWVTgz+pBk0E7wFx/gMn4fRwLv4KTC+EXExxZbHVW6ClwuAOQJMjMWZEWC6GriJ31ByMZug56pOZx6WDD20wFdDT/DqKmDTDKrBq6BnOVDTESXgZ5Z/owGIus5Jx4wGPqy2aWuhV/6NsGbgGm6Wkk9iMVAM3NQM6huwKj+V1jfX6pSqJFIFrT1Oaj1WXmOF6R6/Bt2S+N2gWypZSqg7NOEsVbrlwLtC560QuoL3hqYeZWfnrrC2u4zxdNPgw9R/J2HZwda6xRr+f1d6OXQ2B/t3NU2D1z1fPMw9thrHBpS/AJT8Of7eVdPSoK3rntCtFZTev8tKfwHUBxjzil9I5gAAAABJRU5ErkJggg=="}" alt="" />`:""}
|
|
@@ -114,7 +114,7 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
114
114
|
border: 1px solid #595959;
|
|
115
115
|
color: #595959;
|
|
116
116
|
}
|
|
117
|
-
`}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.remove()},this.duration+300)}render(){return Jt`<div>${this.content}</div>`}};oi([di({type:String})],gi.prototype,"type",void 0),oi([di({type:String})],gi.prototype,"content",void 0),oi([di({type:Number})],gi.prototype,"duration",void 0),gi=oi([ai("my-message")],gi);const pi=(e,t,s=3e3)=>{let i=document.querySelector("#message-container");i||(i=document.createElement("div"),i.id="message-container",Object.assign(i.style,{position:"fixed",top:"14px",left:"50%",transform:"translateX(-50%)",zIndex:"9999"}),document.body.appendChild(i));const r=document.createElement("my-message");r.setAttribute("type",e),r.setAttribute("content",t),r.setAttribute("duration",String(s)),r.style.setProperty("--fade-delay",s/1e3+"s"),i.appendChild(r)},fi=(e,t=3e3)=>pi("success",e,t),mi=(e,t=3e3)=>pi("error",e,t),vi=(e,t=3e3)=>pi("warning",e,t),wi="/v1/aicc/bmserver",yi="/v1/aicc/ccs";let bi="",Ti="",Si="";async function Ci(e,t){const s=function(){const e=ni(Ti,Si);return ti.create({prefixUrl:`${bi}/api`,timeout:!1,headers:{Authorization:e},hooks:{afterResponse:[async(e,t,s)=>{const i=await s.clone().json();if(0!==i.code)throw mi(i.msg),new Error(JSON.stringify(i)||"请求失败");return s.json=async()=>i,s}]}})}(),i=e.replace(/^\/+/,"");return s.post(i,{json:t}).json()}const Ei=new class extends Qe{updateRttObject(e){this.setState({rttObject:e})}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class Ai{constructor(e,t){this.config=e,this.eventCallback=t,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleMessage=e=>{},this.handleNetworkInfoChange=e=>{if(e.rttObject?.rtt){0===(e.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Ei.subscribe(this.handleNetworkInfoChange)}async start(){const e=Xe.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!e)throw new Error("无效的SIP配置");const t={uri:e,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:0},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:!1};this.userAgent=new Xe(t),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case ee.Connecting:t=st.WEB_RTC_CONNECTING;break;case ee.Connected:t=st.WEB_RTC_CONNECTED,this.reconnectAttempts=0,_s.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case ee.Disconnecting:t=st.WEB_RTC_DISCONNECTING;break;case ee.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=st.WEB_RTC_DISCONNECTED;const e=Rs.get("answerDevice");if(!_s.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const e=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${e}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},e)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.transport.stateChange.addListener(e=>{}),this.userAgent.delegate={onInvite:e=>{this.handleIncomingCall(e)}})}async register(){if(this.userAgent){this.registerer=new ne(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case X.Initial:t="initial";break;case X.Registered:t=st.WEB_RTC_REGISTERED;break;case X.Unregistered:t=st.WEB_RTC_UNREGISTERED;break;case X.Terminated:t=st.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:st.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(e){const t=e.sessionDescriptionHandler;if(t){const e=t.peerConnection;if(!e)return;const s=new MediaStream;e.getReceivers().forEach(e=>{e.track&&"audio"===e.track.kind&&s.addTrack(e.track)});let i=document.getElementById("sip-remote-audio");i||(i=document.createElement("audio"),i.id="sip-remote-audio",i.autoplay=!0,i.style.display="none",document.body.appendChild(i)),i.srcObject=s,i.play().catch(e=>{console.error("音频播放失败,需要用户交互触发",e)})}}handleSessionState(e,t,s){e.stateChange.addListener(t=>{switch(t){case K.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=e,this.attachRemoteAudio(e);break;case K.Terminating:break;case K.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case K.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=_s.agentInfo,i=Rs.get("direction"),r=1===t;if(i===tt.OUTGOING)this.answerCall();else if(r&&i===tt.INCOMING){const e=Number(s)||0;e>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},e):this.answerCall()}}async makeCall(e){if(Rs.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");if(!this.userAgent)throw Rs.updateIsCalling(!1),Rs.updateDirection(null),new Error("SIP客户端未初始化");Rs.updateIsCalling(!0),Rs.updateDirection(tt.OUTGOING);const t=Xe.makeURI(`sip:${e}@${this.config.server}`);if(!t)throw new Error("无效的被叫号码");const s=new Z(this.userAgent,t);this.handleSessionState(s,!0,e);try{this.activeSession=s,await s.invite(),this.config.callTimeout&&(this.callTimeoutTimer=setTimeout(()=>{s.state!==K.Established&&(this.hangup(),this.eventCallback?.({type:"error",data:{message:"呼叫超时未接通"}}))},this.config.callTimeout))}catch(e){this.eventCallback?.({type:"error",data:{message:"呼叫失败",detail:e}}),Rs.updateIsCalling(!1),Rs.updateDirection(null)}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{console.log((new Date).toLocaleString()),await this.incomingInvitation.accept(),console.log((new Date).toLocaleString()),this.activeSession=this.incomingInvitation,this.incomingInvitation=null}catch(e){this.eventCallback?.({type:st.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,Rs.updateDirection(null),Rs.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(e){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:e}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:st.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession){clearTimeout(this.callTimeoutTimer);const e=this.activeSession;if(!e)return;const t=e.state;try{t===K.Established?await e.bye():t===K.Establishing&&(e instanceof Z?await e.cancel():e instanceof J&&await e.reject()),clearTimeout(this.callTimeoutTimer)}catch(e){console.error("挂断失败",e)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof J&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await
|
|
117
|
+
`}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.remove()},this.duration+300)}render(){return Jt`<div>${this.content}</div>`}};oi([di({type:String})],gi.prototype,"type",void 0),oi([di({type:String})],gi.prototype,"content",void 0),oi([di({type:Number})],gi.prototype,"duration",void 0),gi=oi([ai("my-message")],gi);const pi=(e,t,s=3e3)=>{let i=document.querySelector("#message-container");i||(i=document.createElement("div"),i.id="message-container",Object.assign(i.style,{position:"fixed",top:"14px",left:"50%",transform:"translateX(-50%)",zIndex:"9999"}),document.body.appendChild(i));const r=document.createElement("my-message");r.setAttribute("type",e),r.setAttribute("content",t),r.setAttribute("duration",String(s)),r.style.setProperty("--fade-delay",s/1e3+"s"),i.appendChild(r)},fi=(e,t=3e3)=>pi("success",e,t),mi=(e,t=3e3)=>pi("error",e,t),vi=(e,t=3e3)=>pi("warning",e,t),wi="/v1/aicc/bmserver",yi="/v1/aicc/ccs";let bi="",Ti="",Si="";async function Ci(e,t){const s=function(){const e=ni(Ti,Si);return ti.create({prefixUrl:`${bi}/api`,timeout:!1,headers:{Authorization:e},hooks:{afterResponse:[async(e,t,s)=>{const i=await s.clone().json();if(0!==i.code)throw mi(i.msg),new Error(JSON.stringify(i)||"请求失败");return s.json=async()=>i,s}]}})}(),i=e.replace(/^\/+/,"");return s.post(i,{json:t}).json()}const Ei=new class extends Qe{updateRttObject(e){this.setState({rttObject:e})}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class Ai{constructor(e,t){this.config=e,this.eventCallback=t,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleMessage=e=>{},this.handleNetworkInfoChange=e=>{if(e.rttObject?.rtt){0===(e.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Ei.subscribe(this.handleNetworkInfoChange)}async start(){const e=Xe.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!e)throw new Error("无效的SIP配置");const t={uri:e,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:0},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:!1};this.userAgent=new Xe(t),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case ee.Connecting:t=st.WEB_RTC_CONNECTING;break;case ee.Connected:t=st.WEB_RTC_CONNECTED,this.reconnectAttempts=0,_s.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case ee.Disconnecting:t=st.WEB_RTC_DISCONNECTING;break;case ee.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=st.WEB_RTC_DISCONNECTED;const e=Rs.get("answerDevice");if(!_s.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const e=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${e}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},e)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.transport.stateChange.addListener(e=>{}),this.userAgent.delegate={onInvite:e=>{this.handleIncomingCall(e)}})}async register(){if(this.userAgent){this.registerer=new ne(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case X.Initial:t="initial";break;case X.Registered:t=st.WEB_RTC_REGISTERED;break;case X.Unregistered:t=st.WEB_RTC_UNREGISTERED;break;case X.Terminated:t=st.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:st.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(e){const t=e.sessionDescriptionHandler;if(t){const e=t.peerConnection;if(!e)return;const s=new MediaStream;e.getReceivers().forEach(e=>{e.track&&"audio"===e.track.kind&&s.addTrack(e.track)});let i=document.getElementById("sip-remote-audio");i||(i=document.createElement("audio"),i.id="sip-remote-audio",i.autoplay=!0,i.style.display="none",document.body.appendChild(i)),i.srcObject=s,i.play().catch(e=>{console.error("音频播放失败,需要用户交互触发",e)})}}handleSessionState(e,t,s){e.stateChange.addListener(t=>{switch(t){case K.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=e,this.attachRemoteAudio(e);break;case K.Terminating:break;case K.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case K.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=_s.agentInfo,i=Rs.get("direction"),r=1===t;if(i===tt.OUTGOING)this.answerCall();else if(r&&i===tt.INCOMING){const e=Number(s)||0;e>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},e):this.answerCall()}}async makeCall(e){if(Rs.getState().isCalling)throw new Error("正在呼叫中,请勿重复点击");if(!this.userAgent)throw Rs.updateIsCalling(!1),Rs.updateDirection(null),new Error("SIP客户端未初始化");Rs.updateIsCalling(!0),Rs.updateDirection(tt.OUTGOING);const t=Xe.makeURI(`sip:${e}@${this.config.server}`);if(!t)throw new Error("无效的被叫号码");const s=new Z(this.userAgent,t);this.handleSessionState(s,!0,e);try{this.activeSession=s,await s.invite(),this.config.callTimeout&&(this.callTimeoutTimer=setTimeout(()=>{s.state!==K.Established&&(this.hangup(),this.eventCallback?.({type:"error",data:{message:"呼叫超时未接通"}}))},this.config.callTimeout))}catch(e){this.eventCallback?.({type:"error",data:{message:"呼叫失败",detail:e}}),Rs.updateIsCalling(!1),Rs.updateDirection(null)}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{console.log((new Date).toLocaleString()),await this.incomingInvitation.accept(),console.log((new Date).toLocaleString()),this.activeSession=this.incomingInvitation,this.incomingInvitation=null}catch(e){this.eventCallback?.({type:st.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,Rs.updateDirection(null),Rs.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(e){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:e}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:st.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession){clearTimeout(this.callTimeoutTimer);const e=this.activeSession;if(!e)return;const t=e.state;try{t===K.Established?await e.bye():t===K.Establishing&&(e instanceof Z?await e.cancel():e instanceof J&&await e.reject()),clearTimeout(this.callTimeoutTimer)}catch(e){console.error("挂断失败",e)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof J&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(e){console.warn("注销失败",e)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!_s.isRtcReconnecting){_s.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),console.log("重连成功"),this.isOffline=!1}catch(e){console.error("重连失败",e)}finally{_s.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const e=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!e)return null;const t=await e.getStats(),s={};return t.forEach(e=>{"candidate-pair"===e.type&&"succeeded"===e.state&&null!=e.currentRoundTripTime&&(s.rtt=+(1e3*e.currentRoundTripTime).toFixed(2)),"inbound-rtp"===e.type&&"audio"===e.kind&&(s.jitter=+(1e3*e.jitter).toFixed(2),s.packetsLost=e.packetsLost,s.packetsReceived=e.packetsReceived,e.bytesReceived&&e.timestamp&&(s.recvBitrate=+(e.bytesReceived/1024).toFixed(2))),"outbound-rtp"===e.type&&"audio"===e.kind&&(s.packetsSent=e.packetsSent,e.bytesSent&&e.timestamp&&(s.sendBitrate=+(e.bytesSent/1024).toFixed(2))),"codec"===e.type&&e.mimeType&&(s.codec=e.mimeType)}),{...s,rtt:s?.rtt||40}}try{const e=Date.now();await Ci(`${wi}/config/ping`,{});const t=Date.now();return{rtt:t-e||1}}catch(e){console.log(e)}}}let _i=class extends fs{static{this.styles=pt`
|
|
118
118
|
.timer-text {
|
|
119
119
|
width: 70px;
|
|
120
120
|
font-size: 14px;
|
|
@@ -358,11 +358,9 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
358
358
|
align-items: center;
|
|
359
359
|
justify-content: center;
|
|
360
360
|
}
|
|
361
|
-
|
|
362
361
|
.select-box.open {
|
|
363
362
|
border-bottom-color: #4096ff;
|
|
364
363
|
}
|
|
365
|
-
|
|
366
364
|
.dropdown {
|
|
367
365
|
position: absolute;
|
|
368
366
|
top: 100%;
|
|
@@ -370,7 +368,6 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
370
368
|
right: 0;
|
|
371
369
|
background: white;
|
|
372
370
|
width: 120px;
|
|
373
|
-
//border: 1px solid #ddd;
|
|
374
371
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
|
375
372
|
border-radius: 4px;
|
|
376
373
|
margin-top: 4px;
|
|
@@ -385,27 +382,22 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
385
382
|
max-height: 200px;
|
|
386
383
|
overflow: auto;
|
|
387
384
|
}
|
|
388
|
-
|
|
389
385
|
.dropdown.show {
|
|
390
386
|
opacity: 1;
|
|
391
387
|
transform: scaleY(1);
|
|
392
388
|
pointer-events: auto;
|
|
393
389
|
}
|
|
394
|
-
|
|
395
390
|
.option {
|
|
396
391
|
padding: 8px 12px;
|
|
397
392
|
cursor: pointer;
|
|
398
393
|
}
|
|
399
|
-
|
|
400
394
|
.option:hover {
|
|
401
395
|
background-color: #f5f5f5;
|
|
402
396
|
}
|
|
403
|
-
|
|
404
397
|
.option[selected] {
|
|
405
398
|
background-color: #e6f4ff;
|
|
406
399
|
color: #1677ff;
|
|
407
400
|
}
|
|
408
|
-
|
|
409
401
|
.selected-label {
|
|
410
402
|
display: inline-flex;
|
|
411
403
|
align-items: center;
|
|
@@ -413,7 +405,10 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
413
405
|
color: #4096ff;
|
|
414
406
|
font-size: 14px;
|
|
415
407
|
}
|
|
416
|
-
|
|
408
|
+
.placeholder {
|
|
409
|
+
color: #999;
|
|
410
|
+
}
|
|
411
|
+
`}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.handleOutsideClick)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("click",this.handleOutsideClick)}toggleDropdown(){this.open?this.closeDropdown():this.openDropdown()}openDropdown(){this.open=!0,requestAnimationFrame(()=>this.animating=!0)}closeDropdown(){this.animating=!1,setTimeout(()=>this.open=!1,200)}handleOptionClick(e,t){const s=t.getAttribute("value");s&&s!==this.value&&(this.dispatchEvent(new CustomEvent("change",{detail:{value:s}})),this.closeDropdown())}updated(e){e.has("value")&&this.updateSelectedContent()}updateSelectedContent(){const e=Array.from(this.children).find(e=>"SELECT-OPTION"===e.tagName&&e.getAttribute("value")===this.value);this.selectedContent=e?e.cloneNode(!0):null}renderSelectedLabel(){return this.selectedContent?Jt`<span class="selected-label">${this.selectedContent}</span>`:Jt`<span class="placeholder">${this.placeholder}</span>`}renderSelectOptions(){return Array.from(this.children).filter(e=>"SELECT-OPTION"===e.tagName).map(e=>{const t=e.getAttribute("value")===this.value;return Jt`
|
|
417
412
|
<div class="option" ?selected=${t} @click=${t=>this.handleOptionClick(t,e)}>
|
|
418
413
|
${e.cloneNode(!0)}
|
|
419
414
|
</div>
|
|
@@ -421,7 +416,6 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
421
416
|
<div style="width: ${this.width};" class="select-box ${this.open?"open":""}" @click=${this.toggleDropdown}>
|
|
422
417
|
${this.renderSelectedLabel()}
|
|
423
418
|
</div>
|
|
424
|
-
|
|
425
419
|
${this.open?Jt`<div class="dropdown ${this.animating?"show":""}">${this.renderSelectOptions()}</div>`:Xt}
|
|
426
420
|
`}};oi([di({type:String})],Di.prototype,"placeholder",void 0),oi([di({type:String})],Di.prototype,"value",void 0),oi([di({type:String})],Di.prototype,"width",void 0),oi([li()],Di.prototype,"open",void 0),oi([li()],Di.prototype,"animating",void 0),oi([li()],Di.prototype,"selectedContent",void 0),Di=oi([ai("my-select")],Di);let xi=class extends fs{constructor(){super(...arguments),this.isDialerVisible=!1,this.inputValue="",this.keys=["1","2","3","4","5","6","7","8","9","*","0","#"],this.handleDocumentClick=e=>{(e.composedPath?.()||[]).includes(this)||(this.isDialerVisible=!1)},this.handleValueSize=()=>this.inputValue.length<10?26:this.inputValue.length>=10&&this.inputValue.length<20?24:this.inputValue.length>=21&&this.inputValue.length<25?18:this.inputValue.length>25?14:16}static{this.styles=pt`
|
|
427
421
|
.key-body {
|
|
@@ -587,7 +581,7 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
587
581
|
<div class="popup ${this.open?"":"hidden"}">
|
|
588
582
|
<slot name="content"></slot>
|
|
589
583
|
</div>
|
|
590
|
-
`}};oi([li()],Ni.prototype,"open",void 0),Ni=oi([ai("my-icon-popup")],Ni);class Hi{constructor(){this.roleData={agentInfo:()=>{if(!_s.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:e=>{if(!e.data)throw new Error("请传入参数")},changeDevice:e=>{if(!e)throw new Error('Parameter "device" is required');const{answer_devices:t}=_s.agentInfo;if(!t.split(",").map(e=>Number(e)).includes(e))throw new Error("当前设备不支持")},changeState:(e,t)=>{if(!e)throw new Error('Parameter "state" is required');if(!t)throw new Error('Parameter "state_name" is required');if(2===e&&"通话中"===t)throw new Error("当前状态不支持");if(![1,2].includes(e))throw new Error("当前状态不支持")}}}async _agentLogin(e){try{const s=await(t={agent_no:e},Ci(`${yi}/agent/login`,t));_s.agentInfo=s.data}catch(e){throw console.log(e),new Error("登录失败")}var t}async changeDevice(e){try{this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;this.roleData.changeDevice(i);const{agent_no:r}=_s.agentInfo;await(e=>Ci(`${yi}/device/change`,e))({agent_no:r,answer_device:i}),Rs.updateAnswerDevice(i);const n=Rs.get("actionConfigs");Rs.updateActionConfigs(n),s?.({code:0,msg:"请求成功"})}catch(e){throw console.log(e),new Error("切换设备失败")}}async changeState(e){try{_s.autoStateTimer&&(clearTimeout(_s.autoStateTimer),_s.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:r}=t;this.roleData.changeState(i,r);const{agent_no:n}=_s.agentInfo;await(e=>Ci(`${yi}/state/change`,e))({agent_no:n,state_name:r,state:i}),i===et.IDLE?Rs.updateActionConfigs(ws):i===et.BUSY&&Rs.updateActionConfigs(ys),_s.stateObject={state:i,state_name:r},s?.({code:0,msg:"请求成功"})}catch(e){console.log(e)}}async getIdleAgentList(e){const{agent_no:t}=_s.agentInfo;try{this.roleData.agentInfo();const s=await(e=>Ci(`${yi}/agent/free`,e))({agent_no:t});e.success?.(s)}catch(e){console.log(e)}}async getAgentState(e){try{const t=await Ci(`${wi}/agent/statecfg/list`,{}),s=(t.data||[]).filter(e=>0===e.enable).filter(e=>0!==e.state&&3!==e.state).map(e=>({state:e.state,state_name:e.state_name})).reverse();e.success?.({...t,data:s})}catch(e){console.log(e)}}}class Pi{constructor({container:e,rttHTML:t,statusParams:s},i){this.VoiceSDKInstance=i,this.apiClient=new Hi,this.isOpenSelect=!1,this.statusParams={state:et.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.handleNetworkInfoChange=e=>{this.rttHTML&&this.renderRtt(e.rttObject)},this.handleCallInfoChange=e=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const e=document.querySelector(".ysyt-select");e.style.height="0px",setTimeout(()=>{e.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=e=>{e.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const t=document.querySelector(".ysyt-select");this.isOpenSelect?(t.style.height=t.scrollHeight+"px",t.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async e=>{const{state:t,statusName:s}=e;await this.apiClient.changeState({data:{state:t,state_name:s},success:()=>{this.statusParams=e;const t=document.getElementById("my-timer");t?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async e=>{await this.apiClient.changeDevice({data:{device:e},success:({code:t})=>{0===t&&(1!==e&&this.VoiceSDKInstance.destroyRtc(),fi("切换成功"),this.render())}})},this.ruleCall=async e=>{if(e)try{await this.VoiceSDKInstance.call_api.makeCall(e)}catch(e){console.error(e)}},this.onCall=()=>{const e=document.querySelector("my-input");this.ruleCall(e.value)},this.renderCallPopover=()=>Jt`
|
|
584
|
+
`}};oi([li()],Ni.prototype,"open",void 0),Ni=oi([ai("my-icon-popup")],Ni);class Hi{constructor(){this.roleData={agentInfo:()=>{if(!_s.agentInfo?.agent_no)throw new Error("请先登录")},requestInfo:e=>{if(!e.data)throw new Error("请传入参数")},changeDevice:e=>{if(!e)throw new Error('Parameter "device" is required');const{answer_devices:t}=_s.agentInfo;if(!t.split(",").map(e=>Number(e)).includes(e))throw new Error("当前设备不支持")},changeState:(e,t)=>{if(!e)throw new Error('Parameter "state" is required');if(!t)throw new Error('Parameter "state_name" is required');if(2===e&&"通话中"===t)throw new Error("当前状态不支持");if(![1,2].includes(e))throw new Error("当前状态不支持")}}}async _agentLogin(e){try{const s=await(t={agent_no:e},Ci(`${yi}/agent/login`,t));_s.agentInfo=s.data}catch(e){throw console.log(e),new Error("登录失败")}var t}async changeDevice(e){try{if(Rs.get("isCalling"))throw new Error("当前正在通话中,请勿切换设备");this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{device:i}=t;this.roleData.changeDevice(i);const{agent_no:r}=_s.agentInfo;await(e=>Ci(`${yi}/device/change`,e))({agent_no:r,answer_device:i}),Rs.updateAnswerDevice(i);const n=Rs.get("actionConfigs");Rs.updateActionConfigs(n),s?.({code:0,msg:"请求成功"})}catch(e){throw console.log(e),new Error("切换设备失败")}}async changeState(e){try{_s.autoStateTimer&&(clearTimeout(_s.autoStateTimer),_s.autoStateTimer=null),this.roleData.agentInfo(),this.roleData.requestInfo(e);const{data:t,success:s}=e,{state:i,state_name:r}=t;this.roleData.changeState(i,r);const{agent_no:n}=_s.agentInfo;await(e=>Ci(`${yi}/state/change`,e))({agent_no:n,state_name:r,state:i}),i===et.IDLE?Rs.updateActionConfigs(ws):i===et.BUSY&&Rs.updateActionConfigs(ys),_s.stateObject={state:i,state_name:r},s?.({code:0,msg:"请求成功"})}catch(e){console.log(e)}}async getIdleAgentList(e){const{agent_no:t}=_s.agentInfo;try{this.roleData.agentInfo();const s=await(e=>Ci(`${yi}/agent/free`,e))({agent_no:t});e.success?.(s)}catch(e){console.log(e)}}async getAgentState(e){try{const t=await Ci(`${wi}/agent/statecfg/list`,{}),s=(t.data||[]).filter(e=>0===e.enable).filter(e=>0!==e.state&&3!==e.state).map(e=>({state:e.state,state_name:e.state_name})).reverse();e.success?.({...t,data:s})}catch(e){console.log(e)}}}class Pi{constructor({container:e,rttHTML:t,statusParams:s},i){this.VoiceSDKInstance=i,this.apiClient=new Hi,this.isOpenSelect=!1,this.statusParams={state:et.IDLE,statusName:"空闲"},this.consultShow=!1,this.modalRoot=null,this.agentStateData=[],this.default_device=1,this.handleNetworkInfoChange=e=>{this.rttHTML&&this.renderRtt(e.rttObject)},this.handleCallInfoChange=e=>{this.render()},this.hiddenSelect=()=>{if(!this.isOpenSelect)return;const e=document.querySelector(".ysyt-select");e.style.height="0px",setTimeout(()=>{e.style.padding="0px"},100),this.isOpenSelect=!1,this.render()},this.toggle=e=>{e.stopPropagation(),this.isOpenSelect=!this.isOpenSelect;const t=document.querySelector(".ysyt-select");this.isOpenSelect?(t.style.height=t.scrollHeight+"px",t.style.padding="4px 0px",this.render()):this.hiddenSelect()},this.changeStatus=async e=>{const{state:t,statusName:s}=e;await this.apiClient.changeState({data:{state:t,state_name:s},success:()=>{this.statusParams=e;const t=document.getElementById("my-timer");t?.reset(),this.hiddenSelect()}})},this.onChangeDevices=async e=>{try{await this.apiClient.changeDevice({data:{device:e},success:({code:t})=>{0===t&&(1!==e&&this.VoiceSDKInstance.destroyRtc(),fi("切换成功"),this.default_device=e,this.render())}})}catch(e){console.log(e),mi(e.message),this.render()}},this.ruleCall=async e=>{if(e)try{await this.VoiceSDKInstance.call_api.makeCall(e)}catch(e){console.error(e)}},this.onCall=()=>{const e=document.querySelector("my-input");this.ruleCall(e.value)},this.renderCallPopover=()=>Jt`
|
|
591
585
|
<my-icon-popup>
|
|
592
586
|
<div slot="icon">
|
|
593
587
|
<i class="ysyt icon-boda my-icon"></i>
|
|
@@ -671,7 +665,7 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
671
665
|
<my-tooltip content="拒接" color="#F5212D" @click="${()=>this.VoiceSDKInstance.call_api.cancelCall()}">
|
|
672
666
|
<i class="ysyt icon-quxiao my-icon" style="color: #F5212D"></i>
|
|
673
667
|
</my-tooltip>
|
|
674
|
-
`,this.container=e,this.statusParams=s,this.rttHTML=t;const{init_state:r}=_s.agentInfo;1===r?this.statusParams={state:et.IDLE,statusName:"空闲"}:2===r&&(this.statusParams={state:et.BUSY,statusName:"忙碌"}),Rs.subscribe(this.handleCallInfoChange),Ei.subscribe(this.handleNetworkInfoChange);const
|
|
668
|
+
`,this.container=e,this.statusParams=s,this.rttHTML=t;const{init_state:r,default_device:n}=_s.agentInfo;this.default_device=n,1===r?this.statusParams={state:et.IDLE,statusName:"空闲"}:2===r&&(this.statusParams={state:et.BUSY,statusName:"忙碌"}),Rs.subscribe(this.handleCallInfoChange),Ei.subscribe(this.handleNetworkInfoChange);const o=()=>{this.hiddenSelect()};document.removeEventListener("click",o),document.addEventListener("click",o),this.eventHandle(),this.getAgentStateList()}eventHandle(){ct.on(it.AGENT_STATE,e=>{this.statusParams={state:e.state,statusName:e.state_name},this.render()}),ct.on(it.CONSULT_FAILED,()=>{mi("咨询失败")}),ct.on(it.OUT_FAILED,e=>{mi(`外呼失败: ${e}`)})}async getAgentStateList(){try{await this.VoiceSDKInstance.agent_api.getAgentState({success:({data:e,code:t})=>{0===t?(this.agentStateData=e,this.render()):mi("获取状态列表失败")}})}catch(e){console.log(e)}}onKeyPress(e){console.log("外部收到按键:",e.detail.key)}async renderConsultModalToBody(){try{await this.VoiceSDKInstance.agent_api.getIdleAgentList({success:e=>{const{data:t}=e,s=t||[];if(0===s.length&&(this.consultShow=!1,vi("没有空闲坐席")),!this.consultShow)return void(this.modalRoot&&(document.body.removeChild(this.modalRoot),this.modalRoot=null));this.modalRoot||(this.modalRoot=document.createElement("div"),document.body.appendChild(this.modalRoot));const i=Jt`
|
|
675
669
|
<my-modal-wrapper
|
|
676
670
|
.visible=${!0}
|
|
677
671
|
.showFooter=${!1}
|
|
@@ -692,16 +686,16 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
692
686
|
</div>`}
|
|
693
687
|
</div>
|
|
694
688
|
</my-modal-wrapper>
|
|
695
|
-
`;gs(i,this.modalRoot)}})}catch(e){mi(e)}}getActionConfigs(){const{show_satisfaction:e}=_s.agentInfo,t=Rs.get("isHold"),s=Rs.get("isMuted"),i=Rs.get("actionConfigs").filter(i=>(0!==e||"satisfaction"!==i)&&(!(!t&&"unhold"===i)&&((!t||"hold"!==i)&&((!s||"mute"!==i)&&!(!s&&"unmute"===i)))));return[{render:this.renderCallPopover,type:"call_number"},{render:this.renderAnswer,type:"answer"},{render:this.renderReject,type:"reject"},{render:this.renderHangup,type:"hangup"},{render:this.renderDialer,type:"dtmf"},{render:this.renderUnhold,type:"unhold"},{render:this.renderHold,type:"hold"},{render:this.renderMute,type:"mute"},{render:this.renderUnmute,type:"unmute"},{render:this.renderSatisfaction,type:"satisfaction"},{render:this.renderConsult,type:"consult"},{render:this.renderTransfer,type:"transfer"},{render:this.renderConsultTransfer,type:"consult_transfer"}].filter(({type:e})=>i.includes(e))}async render(){const{displayText:e}=Rs.getState(),{
|
|
689
|
+
`;gs(i,this.modalRoot)}})}catch(e){mi(e)}}getActionConfigs(){const{show_satisfaction:e}=_s.agentInfo,t=Rs.get("isHold"),s=Rs.get("isMuted"),i=Rs.get("actionConfigs").filter(i=>(0!==e||"satisfaction"!==i)&&(!(!t&&"unhold"===i)&&((!t||"hold"!==i)&&((!s||"mute"!==i)&&!(!s&&"unmute"===i)))));return[{render:this.renderCallPopover,type:"call_number"},{render:this.renderAnswer,type:"answer"},{render:this.renderReject,type:"reject"},{render:this.renderHangup,type:"hangup"},{render:this.renderDialer,type:"dtmf"},{render:this.renderUnhold,type:"unhold"},{render:this.renderHold,type:"hold"},{render:this.renderMute,type:"mute"},{render:this.renderUnmute,type:"unmute"},{render:this.renderSatisfaction,type:"satisfaction"},{render:this.renderConsult,type:"consult"},{render:this.renderTransfer,type:"transfer"},{render:this.renderConsultTransfer,type:"consult_transfer"}].filter(({type:e})=>i.includes(e))}async render(){const{displayText:e}=Rs.getState(),{answer_devices:t}=_s.agentInfo;console.log(t);const s=(t||"").split(","),i=this.getActionConfigs(),r={...vs},{statusColor:n}=r,o=document.querySelector("head");if(o){const e=Jt`
|
|
696
690
|
<style>
|
|
697
691
|
.ysyt-phone-body {
|
|
698
|
-
background: ${
|
|
692
|
+
background: ${n[this.statusParams.state]};
|
|
699
693
|
}
|
|
700
694
|
.ysyt-action-body {
|
|
701
|
-
border-bottom: 1px solid ${
|
|
695
|
+
border-bottom: 1px solid ${n[this.statusParams.state]};
|
|
702
696
|
}
|
|
703
697
|
</style>
|
|
704
|
-
`;gs(e,
|
|
698
|
+
`;gs(e,o)}const a=Jt`
|
|
705
699
|
<i class="ysyt icon-shang select-icon" style="${this.isOpenSelect?"display: block;":"display: none;"}"></i>
|
|
706
700
|
<div
|
|
707
701
|
class="ysyt-select"
|
|
@@ -718,30 +712,30 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
718
712
|
`)}
|
|
719
713
|
</div>
|
|
720
714
|
</div>
|
|
721
|
-
`,
|
|
715
|
+
`,c=Jt`
|
|
722
716
|
<div id="ysyt-body">
|
|
723
717
|
<div id="ysyt-devices-body">
|
|
724
718
|
<my-select
|
|
725
719
|
width="100px"
|
|
726
|
-
value="${String(
|
|
720
|
+
value="${String(this.default_device)}"
|
|
727
721
|
placeholder=""
|
|
728
722
|
@change=${e=>this.onChangeDevices(Number(e.detail.value))}
|
|
729
723
|
>
|
|
730
|
-
${
|
|
724
|
+
${s.includes("1")?Jt`
|
|
731
725
|
<select-option value="1">
|
|
732
726
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
733
727
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAjhJREFUaEPtmM1WwjAQhWeAF0I34kZ5MuDJqBtxo7wQEE9CkzNNk8yktIl4YKOHRvPl9s5PBuEOP3iHzPCALvXWxEq/HBfvGmp2AfPz8/m0LQXp78NCa1gEtQF1hbUfVLirBZ6EXh3neweL0CjAnVZaodpoeIW4/lqemtKKB6E76rawFM48V2oPCM1heV7/CWircMoCr9+LrVa8hk16SufArH7mqoZNboKuZZMetLXG4enMZhatsl1fMij/F7RUuZwYGCvLRJWWQDtPA4DUTmOARwORg6bApdNeD1qaEWy6Kw2s31QwQxigRLWr4eNO3xPyGJfGLDRnoTH8G/of8d5DqX0MijvUVLCuwwxtwPmae14FWm/K+bZW3xENRKtUCsweqkZ7muwvODBJCzuFVdimiAu6GvmaheZKdY3KyELToIz5Nxe8d1lGaPCCH9KLsgia9s2xsk3BU8HprzOeb2/60pZADC0Bp2tMagqMGULBawJ+pt6k8FnQUhu4rNOmDg1vBG3BYorSv0upngXd8XdESZvi9AHpjMSlPmbs4I8vQiOKbOgccP8Alxk00uFOqkYMgh4CPqTIxFrkwdAlwCeBdj0KmflJ0xanfKphu0lpunEnY2QWi+BFJDG9Gg3a2cXLtznBZ+G5tnhUaH9TqqDUNvSNxcYSk0B34Iny5vvWOnaNfhP6d5PTydrU/XNS6F6h8Q8QMnNgHu4vKwLtb2qrJf3eKi4pPlWguXTHPX9AcwqN9fwulf4FD/s5TOGFiLYAAAAASUVORK5CYII="}" width="16" alt="" /><span style="font-size: 14px">软电话</span>
|
|
734
728
|
</div>
|
|
735
729
|
</select-option>
|
|
736
730
|
`:""}
|
|
737
|
-
${
|
|
731
|
+
${s.includes("2")?Jt`
|
|
738
732
|
<select-option value="2">
|
|
739
733
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
740
734
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAWtJREFUaEPtWdFNAzEMdW6Ewgo3BzBOYYi2Q0DHKcxxK0BHaNA7cIVEVD0n8Uck31dVOfbLyzvn9JxkwCcNiFmqQd8fl8eWDX9u5/fa9WbQm9dlnyZ5yFmaQF8BZzmcX+a9ZQMm0HfH5QSwKcnKUr7Ih6XYv9gkO/yHfF/b+YnNRYMGw4IiFczcAlOTlwf9tmQUPz/P9BqWOZwgYlm2aQAbgO7Msm5KZccSQoFGp7hkOUF7SeTAMsjGZZEd3hUX0CyI2jgX0GC6uWMUdqQt1AX0kJoO0H9k4to9gulgutCS9HIJeYQ8Qh7cV0j0aeUpukdBMSGPkMeNRhLyCHmEPIibdujLJcyawgm7+R7T9GPz9nx8bTHSgNQpAev2u1wuYBWuKWt+q+fMxruBtnjIVqN8tZEN3jdl9a5MjzgJAHA9RvzWuUvrC6kzHHYKsNa2Fr0ybl1Ysnh/rWPX6VYHnF1SmJnuUrUxyZCgvwFf6/M9kuThSwAAAABJRU5ErkJggg=="}" width="16" alt="" /><span style="font-size: 14px">手机模式</span>
|
|
741
735
|
</div>
|
|
742
736
|
</select-option>
|
|
743
737
|
`:""}
|
|
744
|
-
${
|
|
738
|
+
${s.includes("3")?Jt`
|
|
745
739
|
<select-option value="3">
|
|
746
740
|
<div style="display: flex; align-items: center; gap: 8px;">
|
|
747
741
|
<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAq5JREFUaEPtmWFywiAQhcEr6Als79F6LdsZdab1WsZ7tJ7AXiF0lmYzC9mFDUGrM/qrmrB8PB7LQq25w4+9Q2bzgL7WrD2UvhmlF8/vr865jXXueD7tt1PAIBZtf/76aPA7PKPf4Xf6Pn2WtMdiud46YzZ9R9Y2P9+fqxLw+dPbwTgXQNvZbIUw8+XaGRJ/0LcxkDV2IJwIHTSytuk7LADnAGDgCOFns20P8NvPae+ZuEFiGxaadtIHpqqPBPcqEsh4plLQg/6tbVhoqZNYfY1VKBC1AwUfBf03+PDDBQg6KFCcTjUoB/Hoos7ag9gT2g+hESphgbGKUygUAKcds4TK0x1TEbTvqEBxaANtMSOhXZJKg4edO5rZrMFMUwxdCk4zgyZ70BkhsxR5WmEPyeOphUbboBXqQTM5M7eZ4ELjVPHKdikviEM3kkSeVilNO5GUE5Xudqx4kANoZpHDO8Hi7GZcD41bbmYT4Tah3KzUeM7viEqL5GxRA5CLIdYe/a5IiprBtHczorFRzQHI0AqL9DvdyFpk6gDkKo9YRMoKuS1/KpzUXl1PSxbIVXCXAM+eEft0JVjgPzJIFjooLYU8rAWvdXTLQsc1hmgTcpzi1kDNo5sKmhY58LdYY0RnSqydnbUv9Lg25ejm+9culKAm1tbaUfAaR7dR0HGxTk/O3MC9HUDh7mOt3QVXBgX1uFia5pQvKf6lmKWx1PaQKruc4pcQoQg6ziipxZmDHsRSlATF0AOPJ+41aoNPgu7BndtgGpPqlLHgqTiToREm3jxK4TWVYzVozuddTvWXhjeptJhdME/DzRK5u4gHEd9CpQZaVekYRLothTQZvEuugDW2uih04Hdafwhe0R7brgIdWAf+G9C2weV6yjbc+K4OrVmQuXce0DmFaj2/S6V/Ae/pt8oTAp/jAAAAAElFTkSuQmCC"}" width="16" alt="" /><span style="font-size: 14px">SIP话机</span>
|
|
@@ -761,14 +755,14 @@ const ai=e=>(t,s)=>{void 0!==s?s.addInitializer(()=>{customElements.define(e,t)}
|
|
|
761
755
|
<span>${t}</span>
|
|
762
756
|
`:void 0)(this.statusParams)}
|
|
763
757
|
<i class="ysyt icon-xia"></i>
|
|
764
|
-
${
|
|
758
|
+
${a}
|
|
765
759
|
`}
|
|
766
760
|
</div>
|
|
767
761
|
<timer-component id="my-timer"></timer-component>
|
|
768
762
|
</div>
|
|
769
|
-
<div class="ysyt-action-body">${
|
|
763
|
+
<div class="ysyt-action-body">${i.map(e=>e.render())}</div>
|
|
770
764
|
</div>
|
|
771
|
-
`;gs(
|
|
765
|
+
`;gs(c,this.container)}async renderRtt(e){const{outCallIsAnswer:t}=Rs.getState(),s=e?.rtt||500,i=Jt`
|
|
772
766
|
<my-popover triggerType="hover">
|
|
773
767
|
<div slot="trigger" id="wifi-body">
|
|
774
768
|
${s>=250?Jt`<img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAlVJREFUaEPtmGFuwyAMhU2PtU1qOVmbk5FKW4+1TCawkcQYG2i3aM2fqirBn83zc1IDO7zMDpnhCf2oU+teaefcKYW31o69k6mGTuDOAWoBmwGNCVwBYKxNSAUdQDWQkiIPuMhae5EsxjUi6ARWUk1pbGrdIIFnoZWwqXbx+NPrqJAQLmXhSWghLELGo1U1m3MuSiFKLXc6JPwGOmyY28yD1jYQRSZIYAP+DV2obnfYdQIF+EV8Dx2AHVGJu8Mq4X3VDSMHUSe3WAV3L8eF0BNxs9XoNpwU2mF0CdwSv6fDxIeRWFrkyYEjNMoi+q9YDkKHyRUT41wlCRBxhqhptCDRWC24S41aRDIMcT2jaCKGZsXESr6aQmM1NRNUBK8Z46mE1tWMumX9W+DHxUkYA7eMcbH+maFCnVxx3xI05SzFTTXCZnok62BZ6MxmYt11AM/G4qCxidIpqfJuDXSm0fWVTgz+pBk0E7wFx/gMn4fRwLv4KTC+EXExxZbHVW6ClwuAOQJMjMWZEWC6GriJ31ByMZug56pOZx6WDD20wFdDT/DqKmDTDKrBq6BnOVDTESXgZ5Z/owGIus5Jx4wGPqy2aWuhV/6NsGbgGm6Wkk9iMVAM3NQM6huwKj+V1jfX6pSqJFIFrT1Oaj1WXmOF6R6/Bt2S+N2gWypZSqg7NOEsVbrlwLtC560QuoL3hqYeZWfnrrC2u4zxdNPgw9R/J2HZwda6xRr+f1d6OXQ2B/t3NU2D1z1fPMw9thrHBpS/AJT8Of7eVdPSoK3rntCtFZTev8tKfwHUBxjzil9I5gAAAABJRU5ErkJggg=="}" alt="" />`:""}
|