From 17efc8b0fb7d3fa66eb8e22f32b81e3e14bcd7f6 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期二, 06 一月 2026 17:37:57 +0800
Subject: [PATCH] 测试完成
---
src/utils/sipService.js | 117 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 97 insertions(+), 20 deletions(-)
diff --git a/src/utils/sipService.js b/src/utils/sipService.js
index df2cda9..35ba077 100644
--- a/src/utils/sipService.js
+++ b/src/utils/sipService.js
@@ -1,5 +1,21 @@
import JsSIP from "jssip";
-
+import { Notification, MessageBox, Message, Loading } from "element-ui";
+// 鍖婚櫌鏈烘瀯涓嶴IP鏈嶅姟鍣ㄦ槧灏勯厤缃�
+const HOSPITAL_CONFIG = {
+ 涓芥按甯備腑鍖婚櫌: {
+ wsUrl: "wss://192.168.10.124:7443",
+ domain: "192.168.10.124",
+ },
+ 榫欐硥甯備汉姘戝尰闄�: {
+ wsUrl: "wss://10.10.0.220:7443",
+ domain: "10.10.0.220",
+ },
+ // 鍙互缁х画娣诲姞鍏朵粬鍖婚櫌閰嶇疆
+ default: {
+ wsUrl: "wss://192.168.10.124:7443",
+ domain: "192.168.10.124",
+ },
+};
class SipService {
constructor() {
this.ua = null;
@@ -7,17 +23,42 @@
this.onStatusChange = null;
this.onCallStatusChange = null;
this.onIncomingCall = null;
+ this.isRegistered = false; // 鏂板娉ㄥ唽鐘舵�佹爣蹇�
+ this.registrationTime = null; // 鏂板娉ㄥ唽鎴愬姛鏃堕棿鎴�
+ this.currentConfig = null; // 瀛樺偍褰撳墠閰嶇疆
}
-
- init(config) {
+ // 鑾峰彇鍖婚櫌閰嶇疆鏂规硶
+ getHospitalConfig() {
+ const orgName=localStorage.getItem("orgname");
+ return HOSPITAL_CONFIG[orgName] || HOSPITAL_CONFIG.default;
+ }
+ init(baseConfig) {
try {
- this.updateStatus("connecting", "杩炴帴涓�;...");
+ // 鑾峰彇鏈烘瀯鍚嶇О锛屽鏋滄病鏈変紶鍏ュ垯浠巐ocalStorage璇诲彇
+ const orgName = baseConfig.orgName || localStorage.getItem("orgname");
+
+ // 鏍规嵁鏈烘瀯鍚嶇О鑾峰彇瀵瑰簲鐨勬湇鍔″櫒閰嶇疆
+ const hospitalConfig = this.getHospitalConfig(orgName);
+console.log(hospitalConfig,'88');
+
+ // 鍚堝苟閰嶇疆
+ this.currentConfig = {
+ ...baseConfig,
+ ...hospitalConfig,
+ };
+
+ console.log(
+ `褰撳墠鏈烘瀯: ${orgName}, 浣跨敤鏈嶅姟鍣�: ${this.currentConfig.domain}`
+ );
+
+ this.updateStatus("connecting", "杩炴帴涓�...");
+console.log(baseConfig.sipUri,'baseConfig.sipUri');
this.ua = new JsSIP.UA({
- sockets: [new JsSIP.WebSocketInterface(config.wsUrl)],
- uri: config.sipUri,
- password: config.password,
- display_name: config.displayName,
+ sockets: [new JsSIP.WebSocketInterface(this.currentConfig.wsUrl)],
+ uri: baseConfig.sipUri, // 杩欓噷浣跨敤鍩虹鐨剆ipUri锛宒omain閮ㄥ垎浼氳鍔ㄦ�佹浛鎹�
+ password: baseConfig.password,
+ display_name: baseConfig.displayName,
iceServers: [],
register: true,
sessionExpires: 1800,
@@ -28,12 +69,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 +103,33 @@
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) {
+ Message.error(reason);
+ return Promise.reject(new Error(reason));
+ }
return new Promise((resolve, reject) => {
try {
if (!this.ua) {
@@ -60,7 +139,8 @@
if (!this.ua.isRegistered()) {
throw new Error("SIP鏈敞鍐岋紝鏃犳硶鍛煎彨");
}
-
+ const targetUri = `sip:${targetNumber}@${this.currentConfig.domain}`;
+ console.log(`鍛煎彨鐩爣: ${targetUri}`);
const options = {
sessionTimers: true, // 鍚敤浼氳瘽璁℃椂鍣�
sessionTimersExpires: 150,
@@ -83,10 +163,7 @@
},
};
- this.currentSession = this.ua.call(
- `sip:${targetNumber}@192.169.129.198`,
- options
- );
+ this.currentSession = this.ua.call(targetUri, options);
this.setupPeerConnection(this.currentSession);
this.setupAudio(this.currentSession);
@@ -165,7 +242,7 @@
errorMessage = "浼氳瘽鍙傛暟涓嶆弧瓒虫湇鍔″櫒瑕佹眰";
break;
default:
- errorMessage = `鍛煎彨澶辫触: ${e.cause || e.message}`;
+ errorMessage = `鍛煎彨澶辫触3: ${e.cause || e.message}`;
}
this.updateCallStatus("failed55", errorMessage);
--
Gitblit v1.9.3