From 08881d6b6412822d5035f63a0775ca1f213c8668 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期一, 20 十月 2025 10:17:22 +0800
Subject: [PATCH] 测试完成
---
src/utils/sipService.js | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/src/utils/sipService.js b/src/utils/sipService.js
index 9088bad..a8ce592 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,25 @@
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(); // 璁板綍娉ㄥ唽鎴愬姛鏃堕棿
+ console.log(this.registrationTime, "娉ㄥ唽鏃堕棿");
+
+ this.updateStatus("registered", "宸叉敞鍐�");
+ });
+
+ this.ua.on("registrationFailed", (e) => {
+ this.isRegistered = false;
+ this.updateStatus("failed", `娉ㄥ唽澶辫触: ${e.cause}`);
+ });
+
+ this.ua.on("unregistered", () => {
+ this.isRegistered = false;
+ let registrationTime = Date.now(); // 璁板綍娉ㄩ攢鎴愬姛鏃堕棿
+ console.log(registrationTime, "娉ㄩ攢鏃堕棿");
+ this.updateStatus("disconnected", "宸叉敞閿�");
+ });
this.ua.on("disconnected", () =>
this.updateStatus("disconnected", "杩炴帴鏂紑")
);
@@ -49,8 +64,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) {
@@ -63,7 +100,7 @@
const options = {
sessionTimers: true, // 鍚敤浼氳瘽璁℃椂鍣�
- sessionTimersExpires: 90,
+ sessionTimersExpires: 150,
extraHeaders: ["Accept: application/sdp"],
mediaConstraints: { audio: true, video: false },
rtcOfferConstraints: {
@@ -165,7 +202,7 @@
errorMessage = "浼氳瘽鍙傛暟涓嶆弧瓒虫湇鍔″櫒瑕佹眰";
break;
default:
- errorMessage = `鍛煎彨澶辫触: ${e.cause || e.message}`;
+ errorMessage = `鍛煎彨澶辫触3: ${e.cause || e.message}`;
}
this.updateCallStatus("failed55", errorMessage);
--
Gitblit v1.9.3