Browse Source

add clients_room in server.py and client_in_room in base_manager.py to get the number of clients in a room

pull/979/head
elia Bottos 3 years ago
parent
commit
3ddadcf846
  1. 7
      src/socketio/base_manager.py
  2. 10
      src/socketio/server.py

7
src/socketio/base_manager.py

@ -154,6 +154,13 @@ class BaseManager(object):
pass
return r
def client_in_room(self, room_in, namespace):
"""Return the number of client in room"""
try:
return len(self.rooms[namespace][room_in])
except KeyError:
pass
def emit(self, event, data, namespace, room=None, skip_sid=None,
callback=None, **kwargs):
"""Emit a message to a single client, a room, or all the clients

10
src/socketio/server.py

@ -472,6 +472,16 @@ class Server(object):
namespace = namespace or '/'
return self.manager.get_rooms(sid, namespace)
def clients_room(self, room, namespace=None):
"""Return the number of clients in a room.
:param room: room selected.
:param namespace: The Socket.IO namespace for the event. If this
argument is omitted the default namespace is used.
"""
namespace = namespace or '/'
return self.manager.client_in_room(room, namespace)
def get_session(self, sid, namespace=None):
"""Return the user session for a client.

Loading…
Cancel
Save