Emit a custom event to one or more connected clients. :param event: The event name. It can be any string. The event names ``'connect'``, ``'message'`` and ``'disconnect'`` are reserved and should not be used. :param data: The data to send
(self, event, data=None, to=None, room=None, skip_sid=None,
namespace=None, callback=None, ignore_queue=False)
| 117 | ``engineio_logger`` is ``False``. |
| 118 | """ |
| 119 | def emit(self, event, data=None, to=None, room=None, skip_sid=None, |
| 120 | namespace=None, callback=None, ignore_queue=False): |
| 121 | """Emit a custom event to one or more connected clients. |
| 122 | |
| 123 | :param event: The event name. It can be any string. The event names |
| 124 | ``'connect'``, ``'message'`` and ``'disconnect'`` are |
| 125 | reserved and should not be used. |
| 126 | :param data: The data to send to the client or clients. Data can be of |
| 127 | type ``str``, ``bytes``, ``list`` or ``dict``. To send |
| 128 | multiple arguments, use a tuple where each element is of |
| 129 | one of the types indicated above. |
| 130 | :param to: The recipient of the message. This can be set to the |
| 131 | session ID of a client to address only that client, to any |
| 132 | custom room created by the application to address all |
| 133 | the clients in that room, or to a list of custom room |
| 134 | names. If this argument is omitted the event is broadcasted |
| 135 | to all connected clients. |
| 136 | :param room: Alias for the ``to`` parameter. |
| 137 | :param skip_sid: The session ID of a client to skip when broadcasting |
| 138 | to a room or to all clients. This can be used to |
| 139 | prevent a message from being sent to the sender. To |
| 140 | skip multiple sids, pass a list. |
| 141 | :param namespace: The Socket.IO namespace for the event. If this |
| 142 | argument is omitted the event is emitted to the |
| 143 | default namespace. |
| 144 | :param callback: If given, this function will be called to acknowledge |
| 145 | the client has received the message. The arguments |
| 146 | that will be passed to the function are those provided |
| 147 | by the client. Callback functions can only be used |
| 148 | when addressing an individual client. |
| 149 | :param ignore_queue: Only used when a message queue is configured. If |
| 150 | set to ``True``, the event is emitted to the |
| 151 | clients directly, without going through the queue. |
| 152 | This is more efficient, but only works when a |
| 153 | single server process is used. It is recommended |
| 154 | to always leave this parameter with its default |
| 155 | value of ``False``. |
| 156 | |
| 157 | Note: this method is not thread safe. If multiple threads are emitting |
| 158 | at the same time to the same client, then messages composed of |
| 159 | multiple packets may end up being sent in an incorrect sequence. Use |
| 160 | standard concurrency solutions (such as a Lock object) to prevent this |
| 161 | situation. |
| 162 | """ |
| 163 | namespace = namespace or '/' |
| 164 | room = to or room |
| 165 | self.logger.info('emitting event "%s" to %s [%s]', event, |
| 166 | room or 'all', namespace) |
| 167 | self.manager.emit(event, data, namespace, room=room, |
| 168 | skip_sid=skip_sid, callback=callback, |
| 169 | ignore_queue=ignore_queue) |
| 170 | |
| 171 | def send(self, data, to=None, room=None, skip_sid=None, namespace=None, |
| 172 | callback=None, ignore_queue=False): |