fix: 修复多个同样结构客户端只发消息到一个的问题。

main
NorthLan 3 years ago
parent cb776ff165
commit 3f30073a7d

@ -15,7 +15,8 @@ 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() {
if err != nil { member, err := r.group.Member(sid)
logger.SLog.Errorf("未找到直播间[%d]对应客户端", liveRoomId) if err != nil {
return continue
} }
err = sess.Push(route, msg) lRId := member.Value(liveRoomIdKey).(int64)
if err != nil { if lRId == liveRoomId {
logger.SLog.Errorf("推送消息到 直播间[%d] 失败, err:%+v", liveRoomId, err) err = member.Push(route, msg)
if err != nil {
logger.SLog.Errorf("推送消息到 直播间[%d]客户端 失败, err:%+v", liveRoomId, err)
}
}
} }
} }

Loading…
Cancel
Save