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

specify namespace in room related functions #433

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def send(message, **kwargs):
include_self=include_self, callback=callback)


def join_room(room, sid=None):
def join_room(room, sid=None, namespace=None):
"""Join a room.

This function puts the user in a room, under the current namespace. The
Expand All @@ -710,15 +710,15 @@ def on_join(data):
"""
socketio = flask.current_app.extensions['socketio']
sid = sid or flask.request.sid
socketio.server.enter_room(sid, room, namespace=flask.request.namespace)
namespace = namespace or flask.request.namespace
socketio.server.enter_room(sid, room, namespace=namespace)


def leave_room(room, sid=None):
def leave_room(room, sid=None, namespace=None):
"""Leave a room.

This function removes the user from a room, under the current namespace.
The user and the namespace are obtained from the event context. This is
a function that can only be called from a SocketIO event handler. Example::
The user and the namespace are obtained from the event context. Example::

@socketio.on('leave')
def on_leave(data):
Expand All @@ -733,35 +733,36 @@ def on_leave(data):
"""
socketio = flask.current_app.extensions['socketio']
sid = sid or flask.request.sid
socketio.server.leave_room(sid, room, namespace=flask.request.namespace)
namespace = namespace or flask.request.namespace
socketio.server.leave_room(sid, room, namespace=namespace)


def close_room(room):
def close_room(room, namespace=None):
"""Close a room.

This function removes any users that are in the given room and then deletes
the room from the server. This is a function that can only be called from
a SocketIO event handler.
the room from the server.

:param room: The name of the room to close.
"""
socketio = flask.current_app.extensions['socketio']
socketio.server.close_room(room, namespace=flask.request.namespace)
namespace = namespace or flask.request.namespace
socketio.server.close_room(room, namespace=namespace)


def rooms(sid=None):
def rooms(sid=None, namespace=None):
"""Return a list of the rooms the client is in.

This function returns all the rooms the client has entered, including its
own room, assigned by the Socket.IO server. This is a function that can
only be called from a SocketIO event handler.
own room, assigned by the Socket.IO server.

:param sid: The session id of the client. If not provided, the client is
obtained from the request context.
"""
socketio = flask.current_app.extensions['socketio']
sid = sid or flask.request.sid
return socketio.server.rooms(sid, namespace=flask.request.namespace)
namespace = namespace or flask.request.namespace
return socketio.server.rooms(sid, namespace=namespace)


def disconnect(silent=False):
Expand Down