Behaviorial difference between socket.to in Socket.io and socket.to in Socketioxide #564
-
Thank you for creating and maintaining this excellent library ! While implementing the server, I came across what appears to be a difference in the behavior of the In Socket.IO's documentation, it's possible to emit a private message to a specific socket using its ID: // a private message to another socket
socket.to(/* another socket id */).emit('hey'); In contrast, based on the socketioxide documentation, the .to() method targets rooms: socket
.to("room1")
.to(["room2", "room3"])
.emit("test", &data)
.await; I wanted to confirm whether my understanding is correct; that in Socket.IO, this works because each socket is automatically added to a room named after its ID, whereas in socketioxide, that behavior does not occur by default. Was there a specific design reason for this difference in the Rust implementation? I’d greatly appreciate any insights you could share on this decision. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey, indeed, the socket doesn't join a room corresponding to its ID when it connects. I don't want to do it by default because it creates a new room automatically whereas it is not always used. You can still make a socket join a room corresponding to its ID with |
Beta Was this translation helpful? Give feedback.
Hey, indeed, the socket doesn't join a room corresponding to its ID when it connects. I don't want to do it by default because it creates a new room automatically whereas it is not always used.
You can still make a socket join a room corresponding to its ID with
socket.join(socket.id)
when it is connected.