Send a SocketIO message. This function sends a simple SocketIO message to one or more connected clients. The message can be a string or a JSON blob. This is a simpler version of ``emit()``, which should be preferred. This is a function that can only be called from a SocketIO event h
(message, **kwargs)
| 982 | |
| 983 | |
| 984 | def send(message, **kwargs): |
| 985 | """Send a SocketIO message. |
| 986 | |
| 987 | This function sends a simple SocketIO message to one or more connected |
| 988 | clients. The message can be a string or a JSON blob. This is a simpler |
| 989 | version of ``emit()``, which should be preferred. This is a function that |
| 990 | can only be called from a SocketIO event handler. |
| 991 | |
| 992 | :param message: The message to send, either a string or a JSON blob. |
| 993 | :param json: ``True`` if ``message`` is a JSON blob, ``False`` |
| 994 | otherwise. |
| 995 | :param namespace: The namespace under which the message is to be sent. |
| 996 | Defaults to the namespace used by the originating event. |
| 997 | An empty string can be used to use the global namespace. |
| 998 | :param callback: Callback function to invoke with the client's |
| 999 | acknowledgement. |
| 1000 | :param broadcast: ``True`` to send the message to all connected clients, or |
| 1001 | ``False`` to only reply to the sender of the originating |
| 1002 | event. |
| 1003 | :param to: Send the message to all the users in the given room, or to the |
| 1004 | user with the given session ID. If this argument is not set and |
| 1005 | ``broadcast`` is ``False``, then the message is sent only to the |
| 1006 | originating user. |
| 1007 | :param include_self: ``True`` to include the sender when broadcasting or |
| 1008 | addressing a room, or ``False`` to send to everyone |
| 1009 | but the sender. |
| 1010 | :param skip_sid: The session id of a client to ignore when broadcasting |
| 1011 | or addressing a room. This is typically set to the |
| 1012 | originator of the message, so that everyone except |
| 1013 | that client receive the message. To skip multiple sids |
| 1014 | pass a list. |
| 1015 | :param ignore_queue: Only used when a message queue is configured. If |
| 1016 | set to ``True``, the event is emitted to the |
| 1017 | clients directly, without going through the queue. |
| 1018 | This is more efficient, but only works when a |
| 1019 | single server process is used, or when there is a |
| 1020 | single addressee. It is recommended to always leave |
| 1021 | this parameter with its default value of ``False``. |
| 1022 | """ |
| 1023 | json = kwargs.get('json', False) |
| 1024 | if 'namespace' in kwargs: |
| 1025 | namespace = kwargs['namespace'] |
| 1026 | else: |
| 1027 | namespace = flask.request.namespace |
| 1028 | callback = kwargs.get('callback') |
| 1029 | broadcast = kwargs.get('broadcast') |
| 1030 | to = kwargs.pop('to', None) or kwargs.pop('room', None) |
| 1031 | if to is None and not broadcast: |
| 1032 | to = flask.request.sid |
| 1033 | include_self = kwargs.get('include_self', True) |
| 1034 | skip_sid = kwargs.get('skip_sid') |
| 1035 | ignore_queue = kwargs.get('ignore_queue', False) |
| 1036 | |
| 1037 | socketio = flask.current_app.extensions['socketio'] |
| 1038 | return socketio.send(message, json=json, namespace=namespace, to=to, |
| 1039 | include_self=include_self, skip_sid=skip_sid, |
| 1040 | callback=callback, ignore_queue=ignore_queue) |
| 1041 |
searching dependent graphs…