feat(call): enhance call handling with user connection events and active call management
- Updated CallService to handle user connection and disconnection events, allowing for automatic management of active calls based on user status. - Introduced methods to retrieve active calls for users and send pending call invites when users reconnect. - Modified the Invite method to return the callee's online status, improving user experience during call invitations. - Enhanced WSHandler to support connection and disconnection event handlers, ensuring accurate call state management.
This commit is contained in:
@@ -467,18 +467,13 @@ func (h *WSHandler) handleCallInvite(ctx context.Context, client *ws.Client, pay
|
||||
mediaType = "voice"
|
||||
}
|
||||
|
||||
call, err := h.callService.Invite(ctx, client.UserID, req.CalleeID, req.ConversationID, mediaType)
|
||||
call, _, err := h.callService.Invite(ctx, client.UserID, req.CalleeID, req.ConversationID, mediaType)
|
||||
if err != nil {
|
||||
zap.L().Warn("Failed to invite call",
|
||||
zap.String("caller_id", client.UserID),
|
||||
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
|
||||
@@ -487,6 +482,7 @@ func (h *WSHandler) handleCallInvite(ctx context.Context, client *ws.Client, pay
|
||||
return
|
||||
}
|
||||
|
||||
// 返回给呼叫方的响应
|
||||
resp := ws.ResponseMessage{
|
||||
EventID: h.wsHub.NextID(),
|
||||
Type: "call_invited",
|
||||
@@ -495,6 +491,7 @@ func (h *WSHandler) handleCallInvite(ctx context.Context, client *ws.Client, pay
|
||||
"call_id": call.ID,
|
||||
"conversation_id": req.ConversationID,
|
||||
"callee_id": req.CalleeID,
|
||||
"lifetime": service.CallLifetimeMs,
|
||||
},
|
||||
}
|
||||
data, _ := json.Marshal(resp)
|
||||
|
||||
Reference in New Issue
Block a user