WXL (wul)
昨天 071e3ed6253ce4d87f6c7a58d7cab02bb3916373
src/components/CallButton/index.vue
@@ -33,42 +33,54 @@
  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",
        wsUrl: "wss://192.168.100.6:7443",
        sipUri: `${randomNum}` + "@192.168.100.6",
        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];
    },
    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 +90,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 +104,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>