From f4609c62152cab3bd9b7f8efd3f967f82650ee40 Mon Sep 17 00:00:00 2001 From: WXL (wul) <wl_5969728@163.com> Date: 星期三, 27 八月 2025 09:28:06 +0800 Subject: [PATCH] 测试完成 --- src/components/CallButton/index.vue | 44 ++++++++++++++++++++++++++------------------ 1 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/components/CallButton/index.vue b/src/components/CallButton/index.vue index 55db2ca..ef5dbf4 100644 --- a/src/components/CallButton/index.vue +++ b/src/components/CallButton/index.vue @@ -33,31 +33,32 @@ 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() * 21) + 1000, // 鐢熸垚 1000-1020 鐨勯殢鏈烘暣鏁� sipConfig: { wsUrl: "wss://192.168.10.124:7443", - sipUri: `${randomNum}`+"@192.168.10.124", + sipUri: `${randomNum}` + "@192.168.10.124", password: "Smartor@2023", displayName: "Web 灏忛緳", + // realm: "9.208.5.18:8090", }, }; }, computed: { callStatusText() { const statusMap = { - idle: '鍑嗗灏辩华', - calling: '鍛煎彨涓�...', - connected: '閫氳瘽涓�', - ended: '閫氳瘽缁撴潫' + idle: "鍑嗗灏辩华", + calling: "鍛煎彨涓�...", + connected: "閫氳瘽涓�", + ended: "閫氳瘽缁撴潫", }; return statusMap[this.callStatus]; }, @@ -66,9 +67,17 @@ }, callButtonText() { return this.isCalling ? "閫氳瘽涓�..." : "涓�閿懠鍙�"; - } + }, }, mounted() { + // 娴嬭瘯 + const ws = new WebSocket("wss://9.208.5.18:7443"); + ws.onopen = () => console.log("WebSocket 杩炴帴鎴愬姛"); + ws.onerror = (e) => console.error("WebSocket 閿欒:", e); + + + // 鍒濆鍖朣IP杩炴帴 + sipService.init(this.sipConfig); sipService.onStatusChange = (status) => { this.sipStatus = status.text; @@ -78,10 +87,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,14 +101,13 @@ } try { - this.callStatus = 'calling'; + this.callStatus = "calling"; this.isCalling = true; await sipService.makeCall(this.phoneNumber); - } catch (error) { console.error("鍛煎彨澶辫触:", error); - this.callStatus = 'ended'; + this.callStatus = "ended"; this.isCalling = false; this.$message.error(`鍛煎彨澶辫触: ${error.message}`); } @@ -107,10 +115,10 @@ endCall() { sipService.endCall(); - this.callStatus = 'ended'; + this.callStatus = "ended"; this.isCalling = false; - } - } + }, + }, }; </script> -- Gitblit v1.9.3