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