From c06e78e78de3d10f9009bf778ad188bf3f4945ed Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 7 Jan 2020 08:13:07 +0000 Subject: [PATCH] Accept skip_sid argument in emit() function (Fixes #1147) --- flask_socketio/__init__.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/flask_socketio/__init__.py b/flask_socketio/__init__.py index 9fe9e5bb..f8353951 100644 --- a/flask_socketio/__init__.py +++ b/flask_socketio/__init__.py @@ -385,6 +385,9 @@ 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 @@ -441,6 +444,9 @@ 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 @@ -748,6 +754,11 @@ def handle_my_custom_event(json): :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. To skip multiple sids + pass a list. :param ignore_queue: Only used when a message queue is configured. If set to ``True``, the event is emitted to the clients directly, without going through the queue. @@ -766,12 +777,13 @@ def handle_my_custom_event(json): if room is None and not broadcast: room = flask.request.sid include_self = kwargs.get('include_self', True) + skip_sid = kwargs.get('skip_sid') ignore_queue = kwargs.get('ignore_queue', False) socketio = flask.current_app.extensions['socketio'] return socketio.emit(event, *args, namespace=namespace, room=room, - include_self=include_self, callback=callback, - ignore_queue=ignore_queue) + include_self=include_self, skip_sid=skip_sid, + callback=callback, ignore_queue=ignore_queue) def send(message, **kwargs): @@ -797,6 +809,11 @@ def send(message, **kwargs): :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. To skip multiple sids + pass a list. :param ignore_queue: Only used when a message queue is configured. If set to ``True``, the event is emitted to the clients directly, without going through the queue. @@ -816,12 +833,13 @@ def send(message, **kwargs): if room is None and not broadcast: room = flask.request.sid include_self = kwargs.get('include_self', True) + skip_sid = kwargs.get('skip_sid') ignore_queue = kwargs.get('ignore_queue', False) socketio = flask.current_app.extensions['socketio'] return socketio.send(message, json=json, namespace=namespace, room=room, - include_self=include_self, callback=callback, - ignore_queue=ignore_queue) + include_self=include_self, skip_sid=skip_sid, + callback=callback, ignore_queue=ignore_queue) def join_room(room, sid=None, namespace=None):