kataras / neffos

A modern, fast and scalable websocket framework with elegant API written in Go
http://bit.ly/neffos-wiki
MIT License
574 stars 49 forks source link

How do I get a list of connected users in a room? #14

Closed ehsaaniqbal closed 5 years ago

kataras commented 5 years ago

Hello @EhsaanIqbal, neffos does not give you a list of connections per room. But it's quite easy to do it by yourself, depends on your needs. For example, you have a mutex and a map of map[string][]neffos.Conn or neffos.NSConn, key is the room name and value is a list of connections. Neffos has the neffos.OnRoomJoined event which you can use to take actions when a connections joins to a room. In that event's callback you can append the connection to the specific room's list.

You can get an idea at one of our examples:

https://github.com/kataras/neffos/blob/6583461bb16f4b312672a145bb428e6366294a99/_examples/wrap-conns-to-user/main.go#L26-L29