feat(call): integrate call handling and WebSocket support
All checks were successful
Build Backend / build (push) Successful in 13m26s
Build Backend / build-docker (push) Successful in 1m22s

- Added CallHandler and related services for managing call sessions and participants.
- Enhanced WSHandler to support call signaling, including invite, answer, reject, and end functionalities.
- Updated router to include call-related routes for history and ICE server retrieval.
- Introduced WebRTC configuration in the application settings for call management.
- Refactored wire generation to include CallService and CallRepository for improved dependency injection.
This commit is contained in:
lafay
2026-03-27 01:54:34 +08:00
parent 9ecb29225a
commit 7e6a65d29d
16 changed files with 1002 additions and 7 deletions

View File

@@ -0,0 +1,60 @@
package handler
import (
"strconv"
"github.com/gin-gonic/gin"
"carrot_bbs/internal/pkg/response"
"carrot_bbs/internal/service"
)
// CallHandler 通话记录处理器
type CallHandler struct {
callService service.CallService
}
// NewCallHandler 创建通话处理器
func NewCallHandler(callService service.CallService) *CallHandler {
return &CallHandler{callService: callService}
}
// GetCallHistory 获取通话记录
// GET /api/v1/calls/history?page=1&page_size=20
func (h *CallHandler) GetCallHistory(c *gin.Context) {
userID, exists := c.Get("user_id")
if !exists {
response.Unauthorized(c, "unauthorized")
return
}
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
if page < 1 {
page = 1
}
if pageSize < 1 || pageSize > 50 {
pageSize = 20
}
calls, total, err := h.callService.GetCallHistory(c.Request.Context(), userID.(string), page, pageSize)
if err != nil {
response.InternalServerError(c, "failed to get call history")
return
}
response.Success(c, gin.H{
"items": calls,
"total": total,
"page": page,
})
}
// GetICEServers 获取 ICE 服务器配置
// GET /api/v1/calls/ice-servers
func (h *CallHandler) GetICEServers(c *gin.Context) {
servers := h.callService.GetICEServers()
response.Success(c, gin.H{
"ice_servers": servers,
})
}