修复:

1. 接听电话的动作完成

现有问题:
1. 连接有问题
This commit is contained in:
2025-07-09 10:37:57 +08:00
parent 56d6a51754
commit 3644b21262
3 changed files with 92 additions and 15 deletions

View File

@@ -496,6 +496,14 @@ export const useChatStore = defineStore("chat", () => {
callConnectionStatus.value = "收到来电"
console.log("收到来电:", incomingCall.value)
// 设置来电超时(30秒后自动拒绝)
setCallTimeout(() => {
if (callStatus.value === "ringing" && incomingCall.value) {
console.log("来电超时,自动拒绝")
rejectCall("no-answer")
}
}, 30000)
}
// 处理通话接受
@@ -921,7 +929,10 @@ export const useChatStore = defineStore("chat", () => {
// 接听来电
const acceptCall = async () => {
if (!incomingCall.value) return
if (!incomingCall.value) {
console.log("没有来电,无法接听")
return
}
// 防止重复接听
if (callStatus.value === "connecting" || callStatus.value === "ongoing") {
@@ -929,6 +940,11 @@ export const useChatStore = defineStore("chat", () => {
return
}
// 清除任何可能的超时定时器
clearCallTimeout()
console.log("开始接听通话:", incomingCall.value)
callStatus.value = "connecting"
callConnectionStatus.value = "正在连接..."
@@ -964,7 +980,18 @@ export const useChatStore = defineStore("chat", () => {
// 拒绝来电
const rejectCall = async (reason = "rejected") => {
if (!incomingCall.value) return
if (!incomingCall.value) {
console.log("没有来电,无法拒绝")
return
}
// 如果已经在连接中,不允许拒绝
if (callStatus.value === "connecting" || callStatus.value === "ongoing") {
console.log("通话已在进行中,无法拒绝")
return
}
console.log("开始拒绝通话:", reason)
try {
// 发送拒绝信号 - 使用便捷方法
@@ -987,7 +1014,7 @@ export const useChatStore = defineStore("chat", () => {
// 添加通话记录
const friend = friends.value.find((f) => f.id === incomingCall.value.callerId)
if (friend) {
const content = reason === "busy" ? "[对方忙线]" : "[已拒绝]"
const content = reason === "busy" ? "[对方忙线]" : reason === "no-answer" ? "[未接来电]" : "[已拒绝]"
const callMessage = {
type: incomingCall.value.callType === "video" ? "video-call" : "audio-call",
@@ -1006,7 +1033,7 @@ export const useChatStore = defineStore("chat", () => {
}
resetCallState()
callConnectionStatus.value = reason === "busy" ? "对方忙线" : "已拒绝"
callConnectionStatus.value = reason === "busy" ? "对方忙线" : reason === "no-answer" ? "无人接听" : "已拒绝"
// 5秒后清除状态
setTimeout(() => {