Closed stackp closed 2 years ago
You are correct that the room
parameter was renamed to to
a while ago, but I did not remove room
, and did not intend for it to be ignored.
The to
parameter is obtained as follows:
to = kwargs.pop('to', kwargs.pop('room', None))
Which seems correct. There also unit tests that use room
instead of to
, such as https://github.com/miguelgrinberg/Flask-SocketIO/blob/main/test_socketio.py#L501.
So I don't understand why this isn't working for you.
Thank you for your reply @miguelgrinberg.
Looking at the code, it looks like this is indeed handled correctly in socketio.send() but there is a subtle bug in socketio.SocketIO().send()
self.send(..., room="name")
inserts to=None in the kwargs ofself.emit()
=> kwargs={"to":None, "room": "name"})
kwargs.pop('to', kwargs.pop('room', None))
returns None even though room == "name"
because to
does exists in kwargs
So, the bug in a nutshell:
# self.emit(..., to=None, **{"room": "name"})
>>> kwargs = {"to": None, "room": "name"}
>>> to = kwargs.pop('to', kwargs.pop('room', None))
>>> print(to)
None
Cheers! :)
Okay, yeah, you did mention it was on send()
and not on emit()
. Sorry, I missed that. I'll correct this.
Greetings and thanks for your work !
After upgrading from 4 to 5, the following code started ignoring the
room
parameter and sending a message to everyone. Looking at the changelog, it appears that theroom
parameter has been renamedto
.I believe it would help avoid surprises if an error was thrown when
room
is passed. Or to treatroom
as an alias forto
(like python-socketio) and issuing a deprecation warning.Here's the requirements.txt diff :
Thanks again, Pierre