From ebff666f223d920fb34cc79942fbbd59cc3038cb Mon Sep 17 00:00:00 2001 From: sinake <sinake1@qq.com> Date: 星期一, 15 九月 2025 11:16:01 +0800 Subject: [PATCH] 拨号失败后二次拨号 --- src/components/CallButton/index.vue | 83 +++++++++++++++++++++++++++++------------ 1 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/components/CallButton/index.vue b/src/components/CallButton/index.vue index 93ff496..378376d 100644 --- a/src/components/CallButton/index.vue +++ b/src/components/CallButton/index.vue @@ -33,20 +33,20 @@ props: { phoneNumber: { type: String, - default: '' - } + default: "", + }, }, data() { + const randomNum = Math.floor(Math.random() * 20) + 1000; // 鍐呴儴瀹氫箟 return { isCalling: false, - callStatus: 'idle', // idle, calling, connected, ended + callStatus: "idle", // idle, calling, connected, ended sipStatus: "鏈繛鎺�", sipStatusClass: "status-disconnected", - randomNum : Math.floor(Math.random() * 11) + 1000, // 鐢熸垚 1000-1010 鐨勯殢鏈烘暣鏁� sipConfig: { - wsUrl: "wss://192.168.10.124:7443", - sipUri: `${randomNum}`+"@192.168.10.124", - password: "Smartor@2023", + wsUrl: "wss://192.169.129.198:7443", + sipUri: `${randomNum}` + "@192.169.129.198", + password: "heskj@1234", displayName: "Web 灏忛緳", }, }; @@ -54,21 +54,32 @@ computed: { callStatusText() { const statusMap = { - idle: '鍑嗗灏辩华', - calling: '鍛煎彨涓�...', - connected: '閫氳瘽涓�', - ended: '閫氳瘽缁撴潫' + idle: "鍑嗗灏辩华", + calling: "鍛煎彨涓�...", + connected: "閫氳瘽涓�", + ended: "閫氳瘽缁撴潫", }; return statusMap[this.callStatus]; + }, + countdownText() { + if (this.sipStatus !== "宸叉敞鍐�") return ""; + + const { canCall, reason } = sipService.canMakeCall(); + if (!canCall && reason.includes("绛夊緟")) { + return reason; + } + return ""; }, callStatusClass() { return `status-${this.callStatus}`; }, callButtonText() { return this.isCalling ? "閫氳瘽涓�..." : "涓�閿懠鍙�"; - } + }, }, mounted() { + console.log("褰撳墠鍒嗘満鍙�", this.sipConfig); + sipService.init(this.sipConfig); sipService.onStatusChange = (status) => { this.sipStatus = status.text; @@ -78,10 +89,10 @@ // 鐩戝惉閫氳瘽鐘舵�佸彉鍖� sipService.onCallStatusChange = (status) => { this.callStatus = status.type; - this.isCalling = status.type === 'calling' || status.type === 'connected'; + this.isCalling = status.type === "calling" || status.type === "connected"; // 閫氱煡鐖剁粍浠堕�氳瘽鐘舵�佸彉鍖� - this.$emit('call-status-change', status); + this.$emit("call-status-change", status); }; }, methods: { @@ -92,25 +103,49 @@ } try { - this.callStatus = 'calling'; + // 鍏堟鏌ユ槸鍚﹀彲浠ュ懠鍙� + const { canCall, reason } = sipService.canMakeCall(); + if (!canCall) { + const { canCall, reason } = sipService.canMakeCall(); + //this.$message.warning(reason); + //return; + } + this.callStatus = "calling"; this.isCalling = true; + console.log("寮�濮嬪懠鍙細", sipService); - await sipService.makeCall(this.phoneNumber); - + await sipService.makeCall("0"+this.phoneNumber); } catch (error) { - console.error("鍛煎彨澶辫触:", error); - this.callStatus = 'ended'; - this.isCalling = false; - this.$message.error(`鍛煎彨澶辫触: ${error.message}`); + let registrationTime = Date.now(); // 璁板綍娉ㄩ攢鎴愬姛鏃堕棿 + console.log(registrationTime, "鍛煎彨澶辫触鏃堕棿"); + console.error("鍛煎彨澶辫触1:", error); + // this.callStatus = "ended"; + // this.isCalling = false; + //this.$message.error(`鍛煎彨澶辫触: ${error.message}`); + try { + // 鍏堟鏌ユ槸鍚﹀彲浠ュ懠鍙� + const { canCall, reason } = sipService.canMakeCall(); + if (!canCall) { + const { canCall, reason } = sipService.canMakeCall(); + } + this.callStatus = "calling"; + this.isCalling = true; + console.log("寮�濮嬪懠鍙細", sipService); + + await sipService.makeCall("0"+this.phoneNumber); + } catch (error) { + this.callStatus = "ended"; + this.isCalling = false; + } } }, endCall() { sipService.endCall(); - this.callStatus = 'ended'; + this.callStatus = "ended"; this.isCalling = false; - } - } + }, + }, }; </script> -- Gitblit v1.9.3