| | |
| | | // 处理各种状态 |
| | | if (status.type === "registered") { |
| | | this.handleRegistered(); |
| | | } else if (status.type === "failed" || status.type === "disconnected") { |
| | | } else if ( |
| | | status.type === "failed" || |
| | | status.type === "disconnected" |
| | | ) { |
| | | this.handleDisconnected(); |
| | | } else if (status.type === "connecting") { |
| | | this.handleConnecting(); |
| | |
| | | // 监听通话状态变化 |
| | | sipService.onCallStatusChange = (status) => { |
| | | this.callStatus = status.type; |
| | | this.isCalling = status.type === "calling" || status.type === "connected"; |
| | | this.isCalling = |
| | | status.type === "calling" || status.type === "connected"; |
| | | this.updateLastActivityTime(); // 通话状态变化时更新活动时间 |
| | | |
| | | this.$emit("call-status-change", status); |
| | |
| | | |
| | | // 设置超时处理 |
| | | this.setupRegistrationTimeout(); |
| | | |
| | | } catch (error) { |
| | | console.error("SIP服务初始化失败:", error); |
| | | this.handleDisconnected(); |
| | |
| | | } |
| | | |
| | | this.reconnectCount++; |
| | | const delay = Math.min(this.reconnectDelay * Math.pow(1.5, this.reconnectCount - 1), 30000); |
| | | const delay = Math.min( |
| | | this.reconnectDelay * Math.pow(1.5, this.reconnectCount - 1), |
| | | 30000 |
| | | ); |
| | | |
| | | console.log(`计划在${delay}ms后重连,第${this.reconnectCount}次尝试`); |
| | | |
| | |
| | | this.cleanupSipConnection(); |
| | | |
| | | // 等待一段时间 |
| | | await new Promise(resolve => setTimeout(resolve, 1000)); |
| | | await new Promise((resolve) => setTimeout(resolve, 1000)); |
| | | |
| | | // 重新初始化 |
| | | await this.CallgetList(); // 重新获取分机号 |
| | | this.initSipService(); |
| | | |
| | | } catch (error) { |
| | | console.error("重连失败:", error); |
| | | this.isReconnecting = false; |
| | |
| | | |
| | | async startCall() { |
| | | if (!this.phoneNumber) { |
| | | this.$message.error("请输入电话号码"); |
| | | this.$message.warning("请输入电话号码"); |
| | | return; |
| | | } |
| | | |
| | |
| | | } catch (error) { |
| | | console.error("呼叫失败1:", error); |
| | | |
| | | if ( |
| | | error.message.includes("Canceled") || |
| | | error.message.includes("未注册") |
| | | ) { |
| | | console.warn("呼叫因页面离开或未注册而取消,不重试"); |
| | | this.callStatus = "ended"; |
| | | this.isCalling = false; |
| | | return; |
| | | } |
| | | try { |
| | | // 尝试加0再次呼叫 |
| | | const { canCall, reason } = sipService.canMakeCall(); |
| | |
| | | } catch (error) { |
| | | this.callStatus = "ended"; |
| | | this.isCalling = false; |
| | | this.$message.error("呼叫失败,请检查网络或号码"); |
| | | this.$message.warning("当前呼叫占线中,请稍后再拨"); |
| | | } |
| | | } |
| | | }, |
| | |
| | | }, |
| | | }, |
| | | beforeUnmount() { |
| | | this.cleanupResources(); |
| | | if (this.isCalling) { |
| | | this.endCall(); // 内部设置了 isManualEnd |
| | | } |
| | | // 其他清理(如定时器)... |
| | | this.cleanupResources(); // 但注意不要重复清理定时器,可优化判断 |
| | | }, |
| | | }; |
| | | </script> |