olahol / melody

:notes: Minimalist websocket framework for Go
BSD 2-Clause "Simplified" License
3.76k stars 365 forks source link

Support for rooms #34

Closed dangodai closed 7 years ago

dangodai commented 7 years ago

Has support for rooms been considered?

As of now it seems the way to do rooms is to set keys on a Session and use BroadcastFilter to broadcast to a room. Perhaps this is unfounded, but it seems like this could lead to poor performance since every Session is iterated over to check the filter.

Suggestions: The list of rooms could look like map[string]map[*Session]bool Thus broadcasting to a room would only have to iterate over those actually in the room.

However, disconnecting would require iterating over all rooms to check for the Session OR each Session would also have to maintain a list of rooms they are in. I think the second option may be favourable if people would be interesting in seeing what room a Session is in easily.

Thoughts?

olahol commented 7 years ago

I want to keep the interface of Melody as small as possible, I think rooms can be implemented by saving sessions to an external data structure.