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.
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package room
|
|
|
|
import (
|
|
"movie-sync-server/entities"
|
|
"movie-sync-server/utils"
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/zishang520/socket.io/v2/socket"
|
|
)
|
|
|
|
func GetInfoEndpoint(client *socket.Socket, cliMsg *entities.ClientMessage) []byte {
|
|
room := cliMsg.Room
|
|
userID := string(client.Id())
|
|
if r, ok := entities.GetCinema().GetRoom(room); ok {
|
|
u := r.GetUser(userID)
|
|
if u != nil {
|
|
u.Send(entities.MessageTypeRoomInfo, entities.RoomStateChangedMessage{
|
|
ServerTime: time.Now().Unix(),
|
|
URL: r.GetUrl(),
|
|
UserStatus: r.GetAllUserStatus(),
|
|
Playing: r.GetPlaying(),
|
|
PlayTime: r.GetPlayTime(),
|
|
})
|
|
} else {
|
|
logrus.Warnf("user [%s] not in room [%s]", userID, room)
|
|
rawMsg, err := utils.StructToMapViaJSON(entities.RoomStateChangedMessage{
|
|
ServerTime: time.Now().Unix(),
|
|
URL: r.GetUrl(),
|
|
UserStatus: r.GetAllUserStatus(),
|
|
Playing: r.GetPlaying(),
|
|
PlayTime: r.GetPlayTime(),
|
|
})
|
|
if err != nil {
|
|
logrus.WithError(err).Error("json marshal error")
|
|
return nil
|
|
}
|
|
client.Emit(entities.MessageTypeRoomInfo, rawMsg)
|
|
}
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|