WXL (wul)
2 天以前 22bd207587899810e9afb4c1a53f0d5dae1e2ece
src/utils/sipService.js
@@ -1,4 +1,5 @@
import JsSIP from "jssip";
import { Notification, MessageBox, Message, Loading } from "element-ui";
class SipService {
  constructor() {
@@ -30,10 +31,11 @@
      this.ua.start();
      // 事件监听
     // 事件监听
      this.ua.on("registered", () => {
        this.isRegistered = true;
        this.registrationTime = Date.now(); // 记录注册成功时间
        console.log(this.registrationTime, "注册时间");
        this.updateStatus("registered", "已注册");
      });
@@ -44,6 +46,8 @@
      this.ua.on("unregistered", () => {
        this.isRegistered = false;
        let registrationTime = Date.now(); // 记录注销成功时间
        console.log(registrationTime, "注销时间");
        this.updateStatus("disconnected", "已注销");
      });
      this.ua.on("disconnected", () =>
@@ -61,7 +65,7 @@
      throw error;
    }
  }
// 新增方法:检查是否可以呼叫
  // 新增方法:检查是否可以呼叫
  canMakeCall(minDelay = 2000) {
    if (!this.isRegistered) {
      return { canCall: false, reason: "SIP未注册,无法呼叫" };
@@ -74,7 +78,7 @@
      const remaining = minDelay - timeSinceRegistration;
      return {
        canCall: false,
        reason: `注册成功,请等待 ${Math.ceil(remaining / 1000)} 秒后再呼叫`
        reason: `注册成功,资源加载中请等待 ${Math.ceil(remaining / 1000)} 秒后再呼叫`,
      };
    }
@@ -83,6 +87,7 @@
  makeCall(targetNumber) {
    const { canCall, reason } = this.canMakeCall();
    if (!canCall) {
      Message.error(reason);
      return Promise.reject(new Error(reason));
    }
    return new Promise((resolve, reject) => {
@@ -118,7 +123,7 @@
        };
        this.currentSession = this.ua.call(
          `sip:${targetNumber}@192.169.129.198`,
          `sip:${targetNumber}@192.168.10.124`,
          options
        );
@@ -199,7 +204,7 @@
        errorMessage = "会话参数不满足服务器要求";
        break;
      default:
        errorMessage = `呼叫失败: ${e.cause || e.message}`;
        errorMessage = `呼叫失败3: ${e.cause || e.message}`;
    }
    this.updateCallStatus("failed55", errorMessage);