Totodore / socketioxide

A socket.io server implementation in Rust that integrates with the Tower ecosystem and the Tokio stack.

Home Page:https://docs.rs/socketioxide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Send a socket id different from the engine socket id for each namespace

Totodore opened this issue · comments

Currently the socket id that reference a socket.io socket (one for each namespace) is the same than the engine socket id.

The implementation should match the socket.io server in node which create a new socket id for each new socket connected to a namespace (only for the socket.io v5 protocol) :

https://github.com/socketio/socket.io/blob/9a2a83fdd42faa840d4f11fd223349e5d8e4d52c/lib/socket.ts#L277

It appears that solving this issue implies a big refactoring. Indeed referencing socketio socket with custom sid instead is impossible because of the following architecture :
client recv data from engine socket -> route to corresponding namespace -> route to corresponding socket with <Engine id -> socket> hashmap

Because the socket id is not in the request it is impossible to map socket by their socket id (and not their engine id).
The solution would be to refactor the code to match the official architecture :
client wraps an engine socket and holds a map of the ns -> socket.

Or alternatively to keep the current architecture we could store a hashmap containing all the namespace for a given socket in the SocketData struct