Skip to content

Commit

Permalink
specify sid in room related functions
Browse files Browse the repository at this point in the history
Fixes #420
  • Loading branch information
miguelgrinberg committed Mar 2, 2017
1 parent f69af89 commit 6a3462d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 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):
def join_room(room, sid=None):
"""Join a room.
This function puts the user in a room, under the current namespace. The
Expand All @@ -705,13 +705,15 @@ def on_join(data):
send(username + ' has entered the room.', room=room)
:param room: The name of the room to join.
: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']
socketio.server.enter_room(flask.request.sid, room,
namespace=flask.request.namespace)
sid = sid or flask.request.sid
socketio.server.enter_room(sid, room, namespace=flask.request.namespace)


def leave_room(room):
def leave_room(room, sid=None):
"""Leave a room.
This function removes the user from a room, under the current namespace.
Expand All @@ -726,10 +728,12 @@ def on_leave(data):
send(username + ' has left the room.', room=room)
:param room: The name of the room to leave.
: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']
socketio.server.leave_room(flask.request.sid, room,
namespace=flask.request.namespace)
sid = sid or flask.request.sid
socketio.server.leave_room(sid, room, namespace=flask.request.namespace)


def close_room(room):
Expand All @@ -745,16 +749,19 @@ def close_room(room):
socketio.server.close_room(room, namespace=flask.request.namespace)


def rooms():
def rooms(sid=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.
: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']
return socketio.server.rooms(flask.request.sid,
namespace=flask.request.namespace)
sid = sid or flask.request.sid
return socketio.server.rooms(sid, namespace=flask.request.namespace)


def disconnect(silent=False):
Expand Down

0 comments on commit 6a3462d

Please sign in to comment.