Totodore / socketioxide

A socket.io server implementation in Rust that integrates with the Tower ecosystem and the Tokio stack.
https://docs.rs/socketioxide
MIT License
1.21k stars 52 forks source link

Add default event "connection" #292

Closed sikelio closed 6 months ago

sikelio commented 6 months ago

Is your feature request related to a problem? Please describe. Currently the library doesn't include a native event like "connection" like the node js lib

Describe the solution you'd like An implementation of the "connection" event for getting informations when a user connects to the websocket instance.

io.on("connection", (socket) => {
  console.log(socket.id); // ojIckSD2jqNzOqIrAGzL
});

It could be useful like getting in realtime the users connected to the instance and not getting the socket id when a specific event is triggered. I could be interesting to get the user IP, MAC or device name for administration on this event.

Describe alternatives you've considered Parsing information from every triggered event but it's not really realtime because it needs that a user sends an event.

Totodore commented 6 months ago

In the socket.io API, the connection event is an alias of the connect event. Which corresponds to a connection of a socket to a namespace (the default in the example you gave).

https://docs.rs/socketioxide/latest/socketioxide/handler/connect/index.html