视频会议

This commit is contained in:
duoaohui
2026-05-22 09:17:14 +08:00
parent e7921556e1
commit 1f4a0da8d4
4 changed files with 51 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import (
"strconv"
"strings"
authSvc "github.com/echochat/backend/app/auth/service"
"github.com/echochat/backend/app/constants"
"github.com/echochat/backend/app/dto"
"github.com/echochat/backend/app/meeting/model"
@@ -23,11 +24,12 @@ import (
type MeetingController struct {
meetingService *service.MeetingService
meetingConfig *config.MeetingConfig
authService *authSvc.AuthService
}
// NewMeetingController 创建 MeetingController 实例
func NewMeetingController(meetingService *service.MeetingService, meetingConfig *config.MeetingConfig) *MeetingController {
return &MeetingController{meetingService: meetingService, meetingConfig: meetingConfig}
func NewMeetingController(meetingService *service.MeetingService, meetingConfig *config.MeetingConfig, authService *authSvc.AuthService) *MeetingController {
return &MeetingController{meetingService: meetingService, meetingConfig: meetingConfig, authService: authService}
}
type cloudLawCreateMeetingRequest struct {
@@ -49,6 +51,11 @@ type cloudLawJoinMeetingRequest struct {
CallID string `json:"callId"`
}
type cloudLawSessionRequest struct {
Phone string `json:"phone"`
Name string `json:"name"`
}
func (ctl *MeetingController) requireCloudLawInternalToken(c *gin.Context) bool {
expected := ""
if ctl.meetingConfig != nil {
@@ -278,6 +285,34 @@ func (ctl *MeetingController) CloudLawGetMeeting(c *gin.Context) {
utils.ResponseOK(c, cloudLawMeetingPayload(room, onlineCount))
}
func (ctl *MeetingController) CloudLawSession(c *gin.Context) {
if !ctl.requireCloudLawInternalToken(c) {
return
}
var req cloudLawSessionRequest
if err := c.ShouldBindJSON(&req); err != nil {
utils.ResponseBadRequest(c, "参数校验失败: "+err.Error())
return
}
req.Phone = strings.TrimSpace(req.Phone)
req.Name = strings.TrimSpace(req.Name)
if req.Phone == "" {
utils.ResponseBadRequest(c, "phone不能为空")
return
}
user, _, err := ctl.meetingService.EnsureCloudLawUserByPhone(c.Request.Context(), req.Phone, req.Name)
if err != nil {
ctl.handleError(c, err, "创建云律 EchoChat 用户失败")
return
}
resp, err := ctl.authService.BuildLoginResponseForUser(c.Request.Context(), user, c.ClientIP(), constants.ClientTypeFrontend)
if err != nil {
utils.ResponseError(c, "创建云律 EchoChat 登录态失败")
return
}
utils.ResponseOK(c, resp)
}
func (ctl *MeetingController) CloudLawJoinMeeting(c *gin.Context) {
if !ctl.requireCloudLawInternalToken(c) {
return

View File

@@ -50,6 +50,7 @@ func RegisterRoutes(
registerCloudLawRoutes := func(group *gin.RouterGroup) {
group.POST("/meetings", ctrl.CloudLawCreateMeeting)
group.GET("/meetings/:code", ctrl.CloudLawGetMeeting)
group.POST("/auth/session", ctrl.CloudLawSession)
group.POST("/meetings/:code/join", ctrl.CloudLawJoinMeeting)
group.POST("/meetings/:code/end", ctrl.CloudLawEndMeeting)
}