From 8a14aa01f801389f125885b4eb2c5a8ffd7da85d Mon Sep 17 00:00:00 2001 From: WXL (wul) <wl_5969728@163.com> Date: 星期四, 11 九月 2025 12:07:27 +0800 Subject: [PATCH] 测试完成 --- src/utils/sipService.js | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/utils/sipService.js b/src/utils/sipService.js index df2cda9..b6f0220 100644 --- a/src/utils/sipService.js +++ b/src/utils/sipService.js @@ -7,6 +7,8 @@ this.onStatusChange = null; this.onCallStatusChange = null; this.onIncomingCall = null; + this.isRegistered = false; // 鏂板娉ㄥ唽鐘舵�佹爣蹇� + this.registrationTime = null; // 鏂板娉ㄥ唽鎴愬姛鏃堕棿鎴� } init(config) { @@ -28,12 +30,22 @@ this.ua.start(); // 浜嬩欢鐩戝惉 - this.ua.on("registered", () => - this.updateStatus("registered", "宸叉敞鍐�56") - ); - this.ua.on("registrationFailed", (e) => - this.updateStatus("failed", `娉ㄥ唽澶辫触11: ${e.cause}`) - ); + // 浜嬩欢鐩戝惉 + this.ua.on("registered", () => { + this.isRegistered = true; + this.registrationTime = Date.now(); // 璁板綍娉ㄥ唽鎴愬姛鏃堕棿 + this.updateStatus("registered", "宸叉敞鍐�"); + }); + + this.ua.on("registrationFailed", (e) => { + this.isRegistered = false; + this.updateStatus("failed", `娉ㄥ唽澶辫触: ${e.cause}`); + }); + + this.ua.on("unregistered", () => { + this.isRegistered = false; + this.updateStatus("disconnected", "宸叉敞閿�"); + }); this.ua.on("disconnected", () => this.updateStatus("disconnected", "杩炴帴鏂紑") ); @@ -49,8 +61,30 @@ throw error; } } +// 鏂板鏂规硶锛氭鏌ユ槸鍚﹀彲浠ュ懠鍙� + canMakeCall(minDelay = 2000) { + if (!this.isRegistered) { + return { canCall: false, reason: "SIP鏈敞鍐岋紝鏃犳硶鍛煎彨" }; + } + const now = Date.now(); + const timeSinceRegistration = now - this.registrationTime; + + if (timeSinceRegistration < minDelay) { + const remaining = minDelay - timeSinceRegistration; + return { + canCall: false, + reason: `娉ㄥ唽鎴愬姛锛岃绛夊緟 ${Math.ceil(remaining / 1000)} 绉掑悗鍐嶅懠鍙玚 + }; + } + + return { canCall: true, reason: "" }; + } makeCall(targetNumber) { + const { canCall, reason } = this.canMakeCall(); + if (!canCall) { + return Promise.reject(new Error(reason)); + } return new Promise((resolve, reject) => { try { if (!this.ua) { -- Gitblit v1.9.3