You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
846 B
Go

package room
import (
"movie-sync-server/entities"
"github.com/zishang520/socket.io/v2/socket"
)
func PlayEndpoint(client *socket.Socket, session *entities.ClientData, msg map[string]any) *entities.ResponseMessage {
room := session.Room
userID := session.UserID
if r, ok := entities.GetCinema().GetRoom(room); ok {
u := r.GetUser(userID)
if u != nil {
u.SetPlaying(true)
}
if u.IsAdmin() {
// 如果是管理员,则广播播放消息
r.SetPlaying(true)
r.Broadcast(entities.MessageTypePlay, entities.UserActionMessage{
Type: entities.MessageTypePlay,
FromUser: u.ToUserStatus(),
})
}
r.BroadcastRoomState()
return &entities.ResponseMessage{
Code: 200,
Message: "success",
}
}
return &entities.ResponseMessage{
Code: 400,
Message: "房间不存在",
Data: nil,
}
}