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

main
NorthLan 3 years ago
parent cb776ff165
commit 3f30073a7d

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

Loading…
Cancel
Save