feat(call): add media type support to call invite functionality
- Updated the WSHandler to include a media type field in the call invite request, allowing differentiation between voice and video calls. - Modified the CallService interface and implementation to accept the media type parameter during call invitations, enhancing call handling capabilities.
This commit is contained in:
@@ -450,6 +450,7 @@ func (h *WSHandler) handleCallInvite(ctx context.Context, client *ws.Client, pay
|
|||||||
var req struct {
|
var req struct {
|
||||||
CalleeID string `json:"callee_id"`
|
CalleeID string `json:"callee_id"`
|
||||||
ConversationID string `json:"conversation_id"`
|
ConversationID string `json:"conversation_id"`
|
||||||
|
MediaType string `json:"call_type"` // voice 或 video
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(payload, &req); err != nil {
|
if err := json.Unmarshal(payload, &req); err != nil {
|
||||||
h.wsHub.SendError(client, "parse_error", "invalid call_invite format")
|
h.wsHub.SendError(client, "parse_error", "invalid call_invite format")
|
||||||
@@ -460,7 +461,13 @@ func (h *WSHandler) handleCallInvite(ctx context.Context, client *ws.Client, pay
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
call, err := h.callService.Invite(ctx, client.UserID, req.CalleeID, req.ConversationID)
|
// 前端传的 call_type 是 voice/video,默认为 voice
|
||||||
|
mediaType := req.MediaType
|
||||||
|
if mediaType != "video" {
|
||||||
|
mediaType = "voice"
|
||||||
|
}
|
||||||
|
|
||||||
|
call, err := h.callService.Invite(ctx, client.UserID, req.CalleeID, req.ConversationID, mediaType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.L().Warn("Failed to invite call",
|
zap.L().Warn("Failed to invite call",
|
||||||
zap.String("caller_id", client.UserID),
|
zap.String("caller_id", client.UserID),
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const (
|
|||||||
|
|
||||||
// CallService 通话服务接口
|
// CallService 通话服务接口
|
||||||
type CallService interface {
|
type CallService interface {
|
||||||
Invite(ctx context.Context, callerID, calleeID, conversationID string) (*model.CallSession, error)
|
Invite(ctx context.Context, callerID, calleeID, conversationID, mediaType string) (*model.CallSession, error)
|
||||||
Accept(ctx context.Context, callID, userID string) (*model.CallSession, error)
|
Accept(ctx context.Context, callID, userID string) (*model.CallSession, error)
|
||||||
Reject(ctx context.Context, callID, userID string) error
|
Reject(ctx context.Context, callID, userID string) error
|
||||||
Busy(ctx context.Context, callID, userID string) error
|
Busy(ctx context.Context, callID, userID string) error
|
||||||
@@ -72,7 +72,7 @@ func NewCallService(
|
|||||||
return svc
|
return svc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *callService) Invite(ctx context.Context, callerID, calleeID, conversationID string) (*model.CallSession, error) {
|
func (s *callService) Invite(ctx context.Context, callerID, calleeID, conversationID, mediaType string) (*model.CallSession, error) {
|
||||||
// === Telegram: 检查被叫方是否在线 ===
|
// === Telegram: 检查被叫方是否在线 ===
|
||||||
if !s.hub.HasClients(calleeID) {
|
if !s.hub.HasClients(calleeID) {
|
||||||
return nil, ErrCalleeOffline
|
return nil, ErrCalleeOffline
|
||||||
@@ -113,6 +113,7 @@ func (s *callService) Invite(ctx context.Context, callerID, calleeID, conversati
|
|||||||
"conversation_id": conversationID,
|
"conversation_id": conversationID,
|
||||||
"caller_id": callerID,
|
"caller_id": callerID,
|
||||||
"call_type": call.CallType,
|
"call_type": call.CallType,
|
||||||
|
"media_type": mediaType,
|
||||||
"created_at": now.UnixMilli(),
|
"created_at": now.UnixMilli(),
|
||||||
"lifetime": CallLifetimeMs,
|
"lifetime": CallLifetimeMs,
|
||||||
"ice_servers": s.config.WebRTC.ICEServers,
|
"ice_servers": s.config.WebRTC.ICEServers,
|
||||||
|
|||||||
Reference in New Issue
Block a user