@@ -75,7 +75,7 @@ def attach(self, app, socketio_path='socket.io'):
7575 """Attach the Socket.IO server to an application."""
7676 self .eio .attach (app , socketio_path )
7777
78- async def emit (self , event , data = None , room = None , skip_sid = None ,
78+ async def emit (self , event , data = None , to = None , room = None , skip_sid = None ,
7979 namespace = None , callback = None , ** kwargs ):
8080 """Emit a custom event to one or more connected clients.
8181
@@ -85,11 +85,12 @@ async def emit(self, event, data=None, room=None, skip_sid=None,
8585 :param data: The data to send to the client or clients. Data can be of
8686 type ``str``, ``bytes``, ``list`` or ``dict``. If a
8787 ``list`` or ``dict``, the data will be serialized as JSON.
88- :param room: The recipient of the message. This can be set to the
89- session ID of a client to address that client's room, or
90- to any custom room created by the application, If this
91- argument is omitted the event is broadcasted to all
92- connected clients.
88+ :param to: The recipient of the message. This can be set to the
89+ session ID of a client to address only that client, or to
90+ to any custom room created by the application to address all
91+ the clients in that room, If this argument is omitted the
92+ event is broadcasted to all connected clients.
93+ :param room: Alias for the ``to`` parameter.
9394 :param skip_sid: The session ID of a client to skip when broadcasting
9495 to a room or to all clients. This can be used to
9596 prevent a message from being sent to the sender.
@@ -112,14 +113,15 @@ async def emit(self, event, data=None, room=None, skip_sid=None,
112113 Note: this method is a coroutine.
113114 """
114115 namespace = namespace or '/'
116+ room = to or room
115117 self .logger .info ('emitting event "%s" to %s [%s]' , event ,
116118 room or 'all' , namespace )
117119 await self .manager .emit (event , data , namespace , room = room ,
118120 skip_sid = skip_sid , callback = callback ,
119121 ** kwargs )
120122
121- async def send (self , data , room = None , skip_sid = None , namespace = None ,
122- callback = None , ** kwargs ):
123+ async def send (self , data , to = None , room = None , skip_sid = None ,
124+ namespace = None , callback = None , ** kwargs ):
123125 """Send a message to one or more connected clients.
124126
125127 This function emits an event with the name ``'message'``. Use
@@ -128,11 +130,12 @@ async def send(self, data, room=None, skip_sid=None, namespace=None,
128130 :param data: The data to send to the client or clients. Data can be of
129131 type ``str``, ``bytes``, ``list`` or ``dict``. If a
130132 ``list`` or ``dict``, the data will be serialized as JSON.
131- :param room: The recipient of the message. This can be set to the
132- session ID of a client to address that client's room, or
133- to any custom room created by the application, If this
134- argument is omitted the event is broadcasted to all
135- connected clients.
133+ :param to: The recipient of the message. This can be set to the
134+ session ID of a client to address only that client, or to
135+ to any custom room created by the application to address all
136+ the clients in that room, If this argument is omitted the
137+ event is broadcasted to all connected clients.
138+ :param room: Alias for the ``to`` parameter.
136139 :param skip_sid: The session ID of a client to skip when broadcasting
137140 to a room or to all clients. This can be used to
138141 prevent a message from being sent to the sender.
@@ -154,10 +157,11 @@ async def send(self, data, room=None, skip_sid=None, namespace=None,
154157
155158 Note: this method is a coroutine.
156159 """
157- await self .emit ('message' , data = data , room = room , skip_sid = skip_sid ,
158- namespace = namespace , callback = callback , ** kwargs )
160+ await self .emit ('message' , data = data , to = to , room = room ,
161+ skip_sid = skip_sid , namespace = namespace ,
162+ callback = callback , ** kwargs )
159163
160- async def call (self , event , data = None , sid = None , namespace = None ,
164+ async def call (self , event , data = None , to = None , sid = None , namespace = None ,
161165 timeout = 60 , ** kwargs ):
162166 """Emit a custom event to a client and wait for the response.
163167
@@ -167,7 +171,8 @@ async def call(self, event, data=None, sid=None, namespace=None,
167171 :param data: The data to send to the client or clients. Data can be of
168172 type ``str``, ``bytes``, ``list`` or ``dict``. If a
169173 ``list`` or ``dict``, the data will be serialized as JSON.
170- :param sid: The session ID of the recipient client.
174+ :param to: The session ID of the recipient client.
175+ :param sid: Alias for the ``to`` parameter.
171176 :param namespace: The Socket.IO namespace for the event. If this
172177 argument is omitted the event is emitted to the
173178 default namespace.
@@ -192,7 +197,7 @@ def event_callback(*args):
192197 callback_args .append (args )
193198 callback_event .set ()
194199
195- await self .emit (event , data = data , room = sid , namespace = namespace ,
200+ await self .emit (event , data = data , room = to or sid , namespace = namespace ,
196201 callback = event_callback , ** kwargs )
197202 try :
198203 await asyncio .wait_for (callback_event .wait (), timeout )
0 commit comments