feat(call): enhance call handling with error differentiation and online notifications
- Added error handling for call invite and answer processes to differentiate between callee offline and call already answered scenarios. - Introduced a new method to publish messages only to online users, improving real-time communication during call signaling. - Updated call service to check callee's online status before sending call invites, ensuring better user experience. - Enhanced call acceptance logic to notify both caller and callee about call status changes, including when a call is answered on another device.
This commit is contained in:
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -466,6 +467,15 @@ func (h *WSHandler) handleCallInvite(ctx context.Context, client *ws.Client, pay
|
||||
zap.String("callee_id", req.CalleeID),
|
||||
zap.Error(err),
|
||||
)
|
||||
// === 区分不同错误类型 ===
|
||||
if errors.Is(err, service.ErrCalleeOffline) {
|
||||
h.wsHub.SendError(client, "callee_offline", "对方当前离线,无法拨打")
|
||||
return
|
||||
}
|
||||
if errors.Is(err, service.ErrCallInProgress) {
|
||||
h.wsHub.SendError(client, "call_in_progress", err.Error())
|
||||
return
|
||||
}
|
||||
h.wsHub.SendError(client, "call_invite_failed", err.Error())
|
||||
return
|
||||
}
|
||||
@@ -499,6 +509,11 @@ func (h *WSHandler) handleCallAnswer(ctx context.Context, client *ws.Client, pay
|
||||
|
||||
call, err := h.callService.Accept(ctx, req.CallID, client.UserID)
|
||||
if err != nil {
|
||||
// === 区分已接听错误 ===
|
||||
if errors.Is(err, service.ErrCallAlreadyAnswered) {
|
||||
h.wsHub.SendError(client, "call_already_answered", "通话已被其他设备接听")
|
||||
return
|
||||
}
|
||||
h.wsHub.SendError(client, "call_accept_failed", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user