视频会议
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/echochat/backend/app/dto"
|
||||
"github.com/echochat/backend/app/meeting/model"
|
||||
"github.com/echochat/backend/app/meeting/service"
|
||||
"github.com/echochat/backend/config"
|
||||
"github.com/echochat/backend/pkg/logs"
|
||||
"github.com/echochat/backend/pkg/middleware"
|
||||
"github.com/echochat/backend/pkg/utils"
|
||||
@@ -20,11 +21,48 @@ import (
|
||||
// Task 5 完成:填充 12 个接口的请求解析、业务调用、DTO 转换、错误码映射
|
||||
type MeetingController struct {
|
||||
meetingService *service.MeetingService
|
||||
meetingConfig *config.MeetingConfig
|
||||
}
|
||||
|
||||
// NewMeetingController 创建 MeetingController 实例
|
||||
func NewMeetingController(meetingService *service.MeetingService) *MeetingController {
|
||||
return &MeetingController{meetingService: meetingService}
|
||||
func NewMeetingController(meetingService *service.MeetingService, meetingConfig *config.MeetingConfig) *MeetingController {
|
||||
return &MeetingController{meetingService: meetingService, meetingConfig: meetingConfig}
|
||||
}
|
||||
|
||||
type cloudLawCreateMeetingRequest struct {
|
||||
CallID string `json:"callId"`
|
||||
CallerID int64 `json:"callerId"`
|
||||
ReceiverID int64 `json:"receiverId"`
|
||||
ReceiverType string `json:"receiverType"`
|
||||
Title string `json:"title"`
|
||||
CallType string `json:"callType"`
|
||||
}
|
||||
|
||||
func (ctl *MeetingController) requireCloudLawInternalToken(c *gin.Context) bool {
|
||||
expected := ""
|
||||
if ctl.meetingConfig != nil {
|
||||
expected = ctl.meetingConfig.CloudLawInternalToken
|
||||
}
|
||||
if expected == "" {
|
||||
utils.ResponseForbidden(c, "云律内部接口未配置")
|
||||
return false
|
||||
}
|
||||
if c.GetHeader("X-Internal-Token") != expected {
|
||||
utils.ResponseUnauthorized(c, "内部访问令牌无效")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func cloudLawMeetingPayload(room *model.MeetingRoom, onlineCount int64) gin.H {
|
||||
return gin.H{
|
||||
"roomId": strconv.FormatInt(room.ID, 10),
|
||||
"roomCode": room.RoomCode,
|
||||
"code": room.RoomCode,
|
||||
"meetingCode": room.RoomCode,
|
||||
"status": room.Status,
|
||||
"onlineCount": onlineCount,
|
||||
}
|
||||
}
|
||||
|
||||
// requireUserID 统一的当前用户取值,失败直接写 401 并返回 false
|
||||
@@ -162,6 +200,72 @@ func chatToDTO(m *model.MeetingChat, userMap map[int64]service.UserDisplayInfo)
|
||||
|
||||
// ====== REST API ======
|
||||
|
||||
func (ctl *MeetingController) CloudLawCreateMeeting(c *gin.Context) {
|
||||
if !ctl.requireCloudLawInternalToken(c) {
|
||||
return
|
||||
}
|
||||
var req cloudLawCreateMeetingRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
utils.ResponseBadRequest(c, "参数校验失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.CallerID <= 0 {
|
||||
utils.ResponseBadRequest(c, "callerId不能为空")
|
||||
return
|
||||
}
|
||||
title := req.Title
|
||||
if title == "" {
|
||||
title = "云律立即连线"
|
||||
}
|
||||
room, _, _, err := ctl.meetingService.CreateRoom(c.Request.Context(), req.CallerID, &dto.CreateMeetingRoomRequest{
|
||||
Title: title,
|
||||
MaxMembers: 2,
|
||||
})
|
||||
if err != nil {
|
||||
ctl.handleError(c, err, "创建云律会议失败")
|
||||
return
|
||||
}
|
||||
payload := cloudLawMeetingPayload(room, 1)
|
||||
payload["callId"] = req.CallID
|
||||
payload["receiverId"] = req.ReceiverID
|
||||
payload["receiverType"] = req.ReceiverType
|
||||
payload["callType"] = req.CallType
|
||||
utils.ResponseOK(c, payload)
|
||||
}
|
||||
|
||||
func (ctl *MeetingController) CloudLawGetMeeting(c *gin.Context) {
|
||||
if !ctl.requireCloudLawInternalToken(c) {
|
||||
return
|
||||
}
|
||||
code := c.Param("code")
|
||||
if code == "" {
|
||||
utils.ResponseBadRequest(c, "会议号不能为空")
|
||||
return
|
||||
}
|
||||
room, _, onlineCount, err := ctl.meetingService.GetRoomForInternal(c.Request.Context(), code)
|
||||
if err != nil {
|
||||
ctl.handleError(c, err, "获取云律会议详情失败")
|
||||
return
|
||||
}
|
||||
utils.ResponseOK(c, cloudLawMeetingPayload(room, onlineCount))
|
||||
}
|
||||
|
||||
func (ctl *MeetingController) CloudLawEndMeeting(c *gin.Context) {
|
||||
if !ctl.requireCloudLawInternalToken(c) {
|
||||
return
|
||||
}
|
||||
code := c.Param("code")
|
||||
if code == "" {
|
||||
utils.ResponseBadRequest(c, "会议号不能为空")
|
||||
return
|
||||
}
|
||||
if err := ctl.meetingService.EndRoomForInternal(c.Request.Context(), code); err != nil {
|
||||
ctl.handleError(c, err, "结束云律会议失败")
|
||||
return
|
||||
}
|
||||
utils.ResponseOK(c, gin.H{"roomCode": code, "code": code, "meetingCode": code})
|
||||
}
|
||||
|
||||
// CreateRoom POST /api/v1/meeting/rooms
|
||||
func (ctl *MeetingController) CreateRoom(c *gin.Context) {
|
||||
userID, ok := requireUserID(c)
|
||||
|
||||
Reference in New Issue
Block a user