Skip to content
Advertisement

Socketio rooms – how to get list of ALL rooms

I’m getting familiar with socket io using Flask-Socketio library.

I would like to create some kind of chat app/message board. You can create rooms, join rooms and chat with other people in that room.

In order to join an existing room, I would like to get a list of all existing rooms on the server side. So the user can select which room to join, or create a new one.

I’ve tried flask_socketio.rooms, but this gives me only rooms joined by that user.

Does anyone know how to get a list of all existing rooms?

Thanks!

Advertisement

Answer

There is no way to obtain all the rooms that were created. Since your application is creating the rooms, it can keep track of them if you need to have the complete list.

If you are wondering why there is no function that provides the list of rooms, the reason is that Flask-SocketIO is designed as a distributed service. In a multiple-server configuration each server only knows the rooms for the users that it knows about, not the complete list. Generating a list of all the rooms then becomes a complex operation.

Advertisement