src/components/CallButton/index.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/utils/sipService.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/components/CallButton/index.vue
@@ -78,7 +78,7 @@ }, }, mounted() { console.log('当前分机号',this.sipConfig); console.log("当前分机号", this.sipConfig); sipService.init(this.sipConfig); sipService.onStatusChange = (status) => { @@ -111,11 +111,13 @@ } this.callStatus = "calling"; this.isCalling = true; console.log('开始呼叫:',sipService); console.log("开始呼叫:", sipService); await sipService.makeCall(this.phoneNumber); } catch (error) { console.error("呼叫失败:", error); let registrationTime = Date.now(); // 记录注销成功时间 console.log(registrationTime, "呼叫失败时间"); console.error("呼叫失败1:", error); this.callStatus = "ended"; this.isCalling = false; this.$message.error(`呼叫失败: ${error.message}`); src/utils/sipService.js
@@ -30,10 +30,11 @@ this.ua.start(); // 事件监听 // 事件监听 this.ua.on("registered", () => { this.isRegistered = true; this.registrationTime = Date.now(); // 记录注册成功时间 console.log(this.registrationTime, "注册时间"); this.updateStatus("registered", "已注册"); }); @@ -44,6 +45,8 @@ this.ua.on("unregistered", () => { this.isRegistered = false; let registrationTime = Date.now(); // 记录注销成功时间 console.log(registrationTime, "注销时间"); this.updateStatus("disconnected", "已注销"); }); this.ua.on("disconnected", () => @@ -61,7 +64,7 @@ throw error; } } // 新增方法:检查是否可以呼叫 // 新增方法:检查是否可以呼叫 canMakeCall(minDelay = 2000) { if (!this.isRegistered) { return { canCall: false, reason: "SIP未注册,无法呼叫" }; @@ -74,7 +77,7 @@ const remaining = minDelay - timeSinceRegistration; return { canCall: false, reason: `注册成功,请等待 ${Math.ceil(remaining / 1000)} 秒后再呼叫` reason: `注册成功,请等待 ${Math.ceil(remaining / 1000)} 秒后再呼叫`, }; } @@ -199,7 +202,7 @@ errorMessage = "会话参数不满足服务器要求"; break; default: errorMessage = `呼叫失败: ${e.cause || e.message}`; errorMessage = `呼叫失败3: ${e.cause || e.message}`; } this.updateCallStatus("failed55", errorMessage);