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

Dynamic Namespaces

FabianHummel opened this issue · comments

I have noticed that dynamic namespaces via regex are not yet implemented. Is this planned?

Is there a way for custom middleware to handle this in the meantime?

It is not planned for the moment. I'll do some research on it and maybe propose directions for anyone who would like to work on it.

Is it possible to work around this issue by using custom Middleware in axum or socketioxide to intercept the connection request and create a namespace with io.ns(request.path /*target path to create dynamically*/) and later delete it again when the client decides to close the session? Currently it only says "invalid namespace" when connecting - there must be a way to intercept that...

Or maybe preflight a connection attempt on the path "/", create the namespace there, and connect a second time then to the namespace, even though that seems quite cumbersome

At any time you can debug the io struct and you should be able to get the map of the current registered namespaces.

I don't think I'll implement regex based matching or function base matching. If the user add a bad regex or a long-computation function it would slow down routing. I'd like to go the "axum-way" and use the matchit crate.

If anyone would like to work on this issue :

  • Replace the Hashmap struct in the client with the matchit::Router struct
  • Throw a panic in case of concurrent route at insertion.
  • Add a simple benchmark to verify that routing is constant with a lot of handlers
  • Propagate the parameters to the handler and add a Param extractor

We need to have node removal feature to use the matchit router : ibraheemdev/matchit#44 as found by @brandonsimpson21.

We need to have node removal feature to use the matchit router : ibraheemdev/matchit#44 as found by @brandonsimpson21.

Do we have nodes in Socketioxide?

you cannot remove nodes with the matchit router, but you could use the active nodes to recreate the router on node deletion or verify the nodes active beforehand.

you cannot remove nodes with the matchit router, but you could use the active nodes to recreate the router on node deletion or verify the nodes active beforehand.

It is a solution that is quite convoluted. I'll try to propose a PR for node removal for the matchit router before thinking about alternative solutions.

@Totodore can we go the regex route and leave the case of engine slowing down due to bad regex upto the user 😄