修复:

1. 本地视频流能获取到了
2. 不知道为什么偶尔能连接成功

现有问题:
1. 不稳定,连接不是每次都成功10%大约
2. 对方获取不到本地推送
This commit is contained in:
2025-07-09 14:05:12 +08:00
parent 252b29fd5e
commit 95ddd9925c
3 changed files with 362 additions and 480 deletions

View File

@@ -334,7 +334,15 @@ export const useChatStore = defineStore("chat", () => {
try {
const offer = JSON.parse(data.content || data.message_content || "{}")
console.log("收到Offer:", offer)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
console.log("📥 收到对方 OFFER 信令:")
console.log("📋 Offer 类型:", offer.type)
console.log("📋 Offer SDP (前200字符):", offer.sdp ? offer.sdp.substring(0, 200) + "..." : "无SDP")
console.log("📋 通话ID:", data.call_id)
console.log("📋 发送方:", data.sender_user_id)
console.log("📋 完整 Offer 对象:", offer)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
if (!webrtc.peerConnection.value) {
console.log("创建 WebRTC 连接以处理 Offer")
@@ -343,9 +351,18 @@ export const useChatStore = defineStore("chat", () => {
const answer = await webrtc.createAnswer(offer, data.call_id, data.sender_user_id)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
console.log("📤 准备发送 ANSWER 信令:")
console.log("📋 Answer 类型:", answer.type)
console.log("📋 Answer SDP (前200字符):", answer.sdp ? answer.sdp.substring(0, 200) + "..." : "无SDP")
console.log("📋 通话ID:", data.call_id)
console.log("📋 接收方:", data.sender_user_id)
console.log("📋 完整 Answer 对象:", answer)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
await callAPI.sendAnswer(userStore.currentUser.id, data.sender_user_id, data.call_id, answer, data.message_type)
console.log("发送Answer成功")
console.log("发送Answer成功")
} catch (error) {
console.error("处理Offer失败:", error)
rejectCall("failed")
@@ -363,12 +380,22 @@ export const useChatStore = defineStore("chat", () => {
try {
const answer = JSON.parse(data.content || data.message_content || "{}")
console.log("收到Answer:", answer)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
console.log("📥 收到对方 ANSWER 信令:")
console.log("📋 Answer 类型:", answer.type)
console.log("📋 Answer SDP (前200字符):", answer.sdp ? answer.sdp.substring(0, 200) + "..." : "无SDP")
console.log("📋 通话ID:", data.call_id)
console.log("📋 发送方:", data.sender_user_id)
console.log("📋 完整 Answer 对象:", answer)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
await webrtc.setRemoteAnswer(answer)
callStatus.value = "connecting"
callConnectionStatus.value = "正在建立连接..."
console.log("✅ Answer处理成功开始建立连接")
} catch (error) {
console.error("处理Answer失败:", error)
endCall("failed")
@@ -481,6 +508,13 @@ export const useChatStore = defineStore("chat", () => {
callConnectionStatus.value = "对方已接听,正在连接..."
console.log("通话已被接受,开始交换信令")
// 显示友好提示
setTimeout(() => {
if (callStatus.value === "connecting") {
callConnectionStatus.value = "对方已接听,正在建立连接..."
}
}, 1000)
try {
if (!webrtc.localStream.value) {
console.log("获取本地媒体用于创建Offer")
@@ -492,6 +526,15 @@ export const useChatStore = defineStore("chat", () => {
const offer = await webrtc.createOffer(currentCall.value.callId, currentCall.value.peerId)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
console.log("📤 准备发送 OFFER 信令:")
console.log("📋 Offer 类型:", offer.type)
console.log("📋 Offer SDP (前200字符):", offer.sdp ? offer.sdp.substring(0, 200) + "..." : "无SDP")
console.log("📋 通话ID:", currentCall.value.callId)
console.log("📋 接收方:", currentCall.value.peerId)
console.log("📋 完整 Offer 对象:", offer)
console.log("🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯🎯")
await callAPI.sendOffer(
userStore.currentUser.id,
currentCall.value.peerId,
@@ -500,7 +543,7 @@ export const useChatStore = defineStore("chat", () => {
currentCall.value.callType === "video" ? 6 : 7,
)
console.log("发送Offer成功")
console.log("发送Offer成功")
} catch (error) {
console.error("创建Offer失败:", error)
endCall("failed")