Skip to content
New issue

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

通过room.track.Push发送的消息经常收不到 #1

Open
saner-qu opened this issue Aug 4, 2022 · 2 comments
Open

通过room.track.Push发送的消息经常收不到 #1

saner-qu opened this issue Aug 4, 2022 · 2 comments

Comments

@saner-qu
Copy link

saner-qu commented Aug 4, 2022

没有找到具体的重现办法,换了一种方式去实现,但是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) } } }

@langhuihui
Copy link
Member

你这种简单粗暴的方式,其实也不错

@langhuihui
Copy link
Member

不要直接 range,用Map的Range方法,里面会加锁防止并发调用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants