From 2eff945fb9fc0d17b2098b26aba74ab192ec3727 Mon Sep 17 00:00:00 2001
From: WXL <1785969728@qq.com>
Date: 星期三, 06 八月 2025 17:48:54 +0800
Subject: [PATCH] 测试完成

---
 src/utils/sipService.js |   42 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/src/utils/sipService.js b/src/utils/sipService.js
index 4b12914..8318c1a 100644
--- a/src/utils/sipService.js
+++ b/src/utils/sipService.js
@@ -5,6 +5,7 @@
     this.ua = null;
     this.currentSession = null;
     this.onStatusChange = null; // 鐘舵�佸彉鍖栧洖璋�
+    this.onCallStatusChange = null; // 鏂板閫氳瘽鐘舵�佸洖璋�
   }
 
   // 鍒濆鍖朣IP瀹㈡埛绔�
@@ -17,7 +18,7 @@
         uri: config.sipUri,
         password: config.password,
         display_name: config.displayName,
-        iceservers:[],
+        iceservers: [],
         // realm: config.realm,
         register: true,
         session_expires: 180,
@@ -97,10 +98,18 @@
         "Allow: INVITE, ACK, BYE, CANCEL, OPTIONS",
       ],
       eventHandlers: {
-        progress: (e) => console.log("鍛煎彨涓�..."),
-        failed: (e) => console.error("鍛煎彨澶辫触:", e),
-        ended: (e) => console.log("閫氳瘽缁撴潫"),
-        confirmed: (e) => console.log("閫氳瘽宸叉帴閫�"),
+        progress: (e) => {
+          this.updateCallStatus("calling", "鍛煎彨涓�...");
+        },
+        failed: (e) => {
+          this.updateCallStatus("ended", `鍛煎彨澶辫触: ${e.cause}`);
+        },
+        ended: (e) => {
+          this.updateCallStatus("ended", "閫氳瘽缁撴潫");
+        },
+        confirmed: (e) => {
+          this.updateCallStatus("connected", "閫氳瘽宸叉帴閫�");
+        },
       },
       mediaConstraints: {
         audio: true,
@@ -135,6 +144,7 @@
     );
     // 鍦ㄤ細璇濆垱寤哄悗淇敼 SDP
     this.currentSession.on("peerconnection", (pc) => {
+       this.updateCallStatus('calling', '鍛煎彨涓�...');
       pc.createOffer = (offerOptions) => {
         return RTCPeerConnection.prototype.createOffer
           .call(pc, offerOptions)
@@ -149,6 +159,17 @@
           });
       };
     });
+    this.currentSession.on('failed', (e) => {
+        this.updateCallStatus('failed', `鍛煎彨澶辫触2: ${e.cause}`);
+      });
+
+      this.currentSession.on('ended', () => {
+        this.updateCallStatus('ended', '閫氳瘽宸茬粨鏉�');
+      });
+
+      this.currentSession.on('confirmed', () => {
+        this.updateCallStatus('connected', '閫氳瘽宸叉帴閫�');
+      });
     this.setupAudio(this.currentSession);
   }
   setupAudio(session) {
@@ -161,12 +182,19 @@
   }
   // 鎸傛柇褰撳墠閫氳瘽
   endCall() {
-    if (this.currentSession) {
+  if (this.currentSession) {
       this.currentSession.terminate();
+      this.updateCallStatus('ended', '閫氳瘽宸茬粨鏉�');
       this.currentSession = null;
     }
   }
-
+  // 鏂板鏂规硶锛氭洿鏂伴�氳瘽鐘舵��
+  updateCallStatus(type, text) {
+    console.log(`閫氳瘽鐘舵�佹洿鏂�: ${type} - ${text}`);
+    if (this.onCallStatusChange) {
+      this.onCallStatusChange({ type, text });
+    }
+  }
 }
 
 export default new SipService();

--
Gitblit v1.9.3