WXL (wul)
2 天以前 d3c60e18b95b50751f8088fa2d23cd8ff7f173bc
src/components/CallButton/index.vue
@@ -162,7 +162,10 @@
          // 处理各种状态
          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();
@@ -172,7 +175,8 @@
        // 监听通话状态变化
        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);
@@ -180,7 +184,6 @@
        // 设置超时处理
        this.setupRegistrationTimeout();
      } catch (error) {
        console.error("SIP服务初始化失败:", error);
        this.handleDisconnected();
@@ -272,7 +275,10 @@
      }
      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}次尝试`);
@@ -295,12 +301,11 @@
        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;
@@ -338,7 +343,7 @@
    async startCall() {
      if (!this.phoneNumber) {
        this.$message.error("请输入电话号码");
        this.$message.warning("请输入电话号码");
        return;
      }
@@ -357,6 +362,15 @@
      } 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();
@@ -371,7 +385,7 @@
        } catch (error) {
          this.callStatus = "ended";
          this.isCalling = false;
          this.$message.error("呼叫失败,请检查网络或号码");
          this.$message.warning("当前呼叫占线中,请稍后再拨");
        }
      }
    },
@@ -451,7 +465,11 @@
    },
  },
  beforeUnmount() {
    this.cleanupResources();
    if (this.isCalling) {
      this.endCall(); // 内部设置了 isManualEnd
    }
    // 其他清理(如定时器)...
    this.cleanupResources(); // 但注意不要重复清理定时器,可优化判断
  },
};
</script>