|
|
@ -16,6 +16,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
roomKey = "ROOM"
|
|
|
|
roomKey = "ROOM"
|
|
|
|
|
|
|
|
liveRoomIdKey = "LIVE_ROOM_ID"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
type (
|
|
|
@ -74,12 +75,13 @@ func (m *Manager) Join(s *session.Session, msg *pbRoom.JoinRoomReq) error {
|
|
|
|
room := m.RoomByGameType(msg.GameType)
|
|
|
|
room := m.RoomByGameType(msg.GameType)
|
|
|
|
game.CacheGameType(msg.LiveRoomId, msg.GameType)
|
|
|
|
game.CacheGameType(msg.LiveRoomId, msg.GameType)
|
|
|
|
|
|
|
|
|
|
|
|
// uid - liveRoomId
|
|
|
|
// uid - uuid
|
|
|
|
err := s.Bind(msg.LiveRoomId)
|
|
|
|
err := s.Bind(uuid.NextId())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Set(roomKey, room)
|
|
|
|
s.Set(roomKey, room)
|
|
|
|
|
|
|
|
s.Set(liveRoomIdKey, msg.LiveRoomId)
|
|
|
|
|
|
|
|
|
|
|
|
// members
|
|
|
|
// members
|
|
|
|
var resp = &pbRoom.JoinRoomResp{
|
|
|
|
var resp = &pbRoom.JoinRoomResp{
|
|
|
@ -136,14 +138,18 @@ func (m *Manager) Broadcast(route string, msg proto.Message) {
|
|
|
|
|
|
|
|
|
|
|
|
// PushToLiveRoom 消息Push到直播间ID指定客户端
|
|
|
|
// PushToLiveRoom 消息Push到直播间ID指定客户端
|
|
|
|
func (r *Room) PushToLiveRoom(liveRoomId int64, route string, msg proto.Message) {
|
|
|
|
func (r *Room) PushToLiveRoom(liveRoomId int64, route string, msg proto.Message) {
|
|
|
|
sess, err := r.group.Member(liveRoomId)
|
|
|
|
for _, sid := range r.group.Members() {
|
|
|
|
|
|
|
|
member, err := r.group.Member(sid)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logger.SLog.Errorf("未找到直播间[%d]对应客户端", liveRoomId)
|
|
|
|
continue
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = sess.Push(route, msg)
|
|
|
|
lRId := member.Value(liveRoomIdKey).(int64)
|
|
|
|
|
|
|
|
if lRId == liveRoomId {
|
|
|
|
|
|
|
|
err = member.Push(route, msg)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logger.SLog.Errorf("推送消息到 直播间[%d] 失败, err:%+v", liveRoomId, err)
|
|
|
|
logger.SLog.Errorf("推送消息到 直播间[%d]客户端 失败, err:%+v", liveRoomId, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|