We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
没有找到具体的重现办法,换了一种方式去实现,但是BUG应该在room.track数据的发送机制里面。 原代码: data, _ := json.Marshal(map[string]any{"event": "userjoin", "data": user}) room.track.Push(data)
data, _ := json.Marshal(map[string]any{"event": "userjoin", "data": user}) room.track.Push(data)
我的处理方案: room.Boardcast("userjoin", user, userId) func (r *Room) Boardcast(evt string, msg any, exceptUserArgs ...string) { if r.Users.Len() == 0 { return } for _, user := range r.Users.Map { bExcept := false if len(exceptUserArgs) > 0 { for _, item := range exceptUserArgs { if item == user.ID { bExcept = true break } } } if !bExcept { user.Send(evt, msg) } } }
room.Boardcast("userjoin", user, userId) func (r *Room) Boardcast(evt string, msg any, exceptUserArgs ...string) { if r.Users.Len() == 0 { return } for _, user := range r.Users.Map { bExcept := false if len(exceptUserArgs) > 0 { for _, item := range exceptUserArgs { if item == user.ID { bExcept = true break } } } if !bExcept { user.Send(evt, msg) } } }
The text was updated successfully, but these errors were encountered:
你这种简单粗暴的方式,其实也不错
Sorry, something went wrong.
不要直接 range,用Map的Range方法,里面会加锁防止并发调用
No branches or pull requests
没有找到具体的重现办法,换了一种方式去实现,但是BUG应该在room.track数据的发送机制里面。
原代码:
data, _ := json.Marshal(map[string]any{"event": "userjoin", "data": user}) room.track.Push(data)
我的处理方案:
room.Boardcast("userjoin", user, userId) func (r *Room) Boardcast(evt string, msg any, exceptUserArgs ...string) { if r.Users.Len() == 0 { return } for _, user := range r.Users.Map { bExcept := false if len(exceptUserArgs) > 0 { for _, item := range exceptUserArgs { if item == user.ID { bExcept = true break } } } if !bExcept { user.Send(evt, msg) } } }
The text was updated successfully, but these errors were encountered: