MCPcopy
hub / github.com/miguelgrinberg/Flask-SocketIO / emit

Function emit

src/flask_socketio/__init__.py:877–935  ·  view source on GitHub ↗

Emit a SocketIO event. This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This is a function that can only be called from a SocketIO event handler, as in obtains some information from the current client context

(event, *args, **kwargs)

Source from the content-addressed store, hash-verified

875
876
877def emit(event, *args, **kwargs):
878 """Emit a SocketIO event.
879
880 This function emits a SocketIO event to one or more connected clients. A
881 JSON blob can be attached to the event as payload. This is a function that
882 can only be called from a SocketIO event handler, as in obtains some
883 information from the current client context. Example::
884
885 @socketio.on('my event')
886 def handle_my_custom_event(json):
887 emit('my response', {'data': 42})
888
889 :param event: The name of the user event to emit.
890 :param args: A dictionary with the JSON data to send as payload.
891 :param namespace: The namespace under which the message is to be sent.
892 Defaults to the namespace used by the originating event.
893 A ``'/'`` can be used to explicitly specify the global
894 namespace.
895 :param callback: Callback function to invoke with the client's
896 acknowledgement.
897 :param broadcast: ``True`` to send the message to all clients, or ``False``
898 to only reply to the sender of the originating event.
899 :param to: Send the message to all the users in the given room, or to the
900 user with the given session ID. If this argument is not set and
901 ``broadcast`` is ``False``, then the message is sent only to the
902 originating user.
903 :param include_self: ``True`` to include the sender when broadcasting or
904 addressing a room, or ``False`` to send to everyone
905 but the sender.
906 :param skip_sid: The session id of a client to ignore when broadcasting
907 or addressing a room. This is typically set to the
908 originator of the message, so that everyone except
909 that client receive the message. To skip multiple sids
910 pass a list.
911 :param ignore_queue: Only used when a message queue is configured. If
912 set to ``True``, the event is emitted to the
913 clients directly, without going through the queue.
914 This is more efficient, but only works when a
915 single server process is used, or when there is a
916 single addressee. It is recommended to always leave
917 this parameter with its default value of ``False``.
918 """
919 if 'namespace' in kwargs:
920 namespace = kwargs['namespace']
921 else:
922 namespace = flask.request.namespace
923 callback = kwargs.get('callback')
924 broadcast = kwargs.get('broadcast')
925 to = kwargs.pop('to', None) or kwargs.pop('room', None)
926 if to is None and not broadcast:
927 to = flask.request.sid
928 include_self = kwargs.get('include_self', True)
929 skip_sid = kwargs.get('skip_sid')
930 ignore_queue = kwargs.get('ignore_queue', False)
931
932 socketio = flask.current_app.extensions['socketio']
933 return socketio.emit(event, *args, namespace=namespace, to=to,
934 include_self=include_self, skip_sid=skip_sid,

Callers 15

on_connectFunction · 0.90
on_custom_eventFunction · 0.90
get_request_eventFunction · 0.90
get_request_event2Function · 0.90
catch_allFunction · 0.90
on_custom_event_testFunction · 0.90
on_custom_event_test2Function · 0.90
on_room_eventFunction · 0.90
on_bad_responseFunction · 0.90
on_changing_responseFunction · 0.90

Calls 1

emitMethod · 0.45

Tested by 15

on_connectFunction · 0.72
on_custom_eventFunction · 0.72
get_request_eventFunction · 0.72
get_request_event2Function · 0.72
catch_allFunction · 0.72
on_custom_event_testFunction · 0.72
on_custom_event_test2Function · 0.72
on_room_eventFunction · 0.72
on_bad_responseFunction · 0.72
on_changing_responseFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…