Skip to content

Commit

Permalink
Support for "skip_sid" option.
Browse files Browse the repository at this point in the history
Fixes #365
  • Loading branch information
miguelgrinberg committed Nov 26, 2016
1 parent e14e5de commit a8ae479
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,23 +314,24 @@ def ping():
:param room: Send the message to all the users in the given room. If
this parameter is not included, the event is sent to
all connected users.
:param include_self: ``True`` to include the sender when broadcasting
or addressing a room, or ``False`` to send to
everyone but the sender.
:param skip_sid: The session id of a client to ignore when broadcasting
or addressing a room. This is typically set to the
originator of the message, so that everyone except
that client receive the message.
:param callback: If given, this function will be called to acknowledge
that the client has received the message. The
arguments that will be passed to the function are
those provided by the client. Callback functions can
only be used when addressing an individual client.
"""
skip_sid = flask.request.sid \
if not kwargs.get('include_self', True) else None
if not kwargs.get('include_self', True) else kwargs.get('skip_sid')
self.server.emit(event, *args, namespace=kwargs.get('namespace', '/'),
room=kwargs.get('room'), skip_sid=skip_sid,
callback=kwargs.get('callback'))

def send(self, data, json=False, namespace=None, room=None,
callback=None, include_self=True):
callback=None, include_self=True, skip_sid=None):
"""Send a server-generated SocketIO message.
This function sends a simple SocketIO message to one or more connected
Expand All @@ -347,16 +348,17 @@ def send(self, data, json=False, namespace=None, room=None,
:param room: Send the message only to the users in the given room. If
this parameter is not included, the message is sent to
all connected users.
:param include_self: ``True`` to include the sender when broadcasting
or addressing a room, or ``False`` to send to
everyone but the sender.
:param skip_sid: The session id of a client to ignore when broadcasting
or addressing a room. This is typically set to the
originator of the message, so that everyone except
that client receive the message.
:param callback: If given, this function will be called to acknowledge
that the client has received the message. The
arguments that will be passed to the function are
those provided by the client. Callback functions can
only be used when addressing an individual client.
"""
skip_sid = flask.request.sid if not include_self else None
skip_sid = flask.request.sid if not include_self else skip_sid
if json:
self.emit('json', data, namespace=namespace, room=room,
skip_sid=skip_sid, callback=callback)
Expand Down

0 comments on commit a8ae479

Please sign in to comment.