Closed rts-gordon closed 3 years ago
Sorry for the late response, let me see if I can answer these questions:
SocketIOWrapper
wraps individual sockets and holds the rooms
that a particular socket is connected to. SocketIOSocket
, although poorly named, is created on a per-handler basis. That is, when a particular piece of socket.io middleware is triggered, the SocketIOWrapper
creates a new SocketIOSocket
and uses its copy of rooms so that the developer can query what rooms this socket is in. SocketIOSocket
's copy of rooms should be readonly from a developer perspective.
ROOMS
is a different pattern altogether. Whereas SocketIOWrapper::rooms
represents a socket -> Vec<Room>
, ROOMS
can be thought of as the inverse direction -- Room -> Vec<Socket>
.
So for your questions specifically,
ROOMS
and SocketIOWrapper::rooms
are kept in sync because they join/leave functionality updates both sequentially.ROOMS
and you should get an accurate count.Does this help?
P.S. I'll put out an update for https://github.com/thruster-rs/thruster-socketio/issues/19 shortly.
Thanks for your explain, it is much clear.
Hi @trezm I realized that there are three rooms design in thruster-socketio: 1, SocketIOSocket
2, SocketIOWrapper
3, static ROOMS
My question is: 1, How to ensure consistency between the three rooms data? For example, when a client socket leave a room, SocketIOWrapper rooms.remove successful, but remove_socket_from_room failed.
2, If I want to get how many rooms in my process, which rooms data shall be correct? SocketIOSocket.rooms, SocketIOWrapper.rooms, or static ROOMS?
Thanks for your reply.