-
let io_clone - io.clone();
let _ = io.dyn_ns("/{client_id}", |s: SocketRef| async move {
let auth_token = s.ns().to_string();
let namespace_size = io_clone.of(&auth_token[1..]).unwrap().sockets().unwrap().len(); // pls help !!
// ..........
}); |
Beta Was this translation helpful? Give feedback.
Answered by
Totodore
Jan 15, 2025
Replies: 1 comment 1 reply
-
If you want to get the number of sockets for this namespace variant: let _ = io.dyn_ns("/{client_id}", |s: SocketRef, io: SocketIo| async move {
let namespace_size = io.of(s.ns()).unwrap().sockets().unwrap().len(); // this should work
}); But if you want all the sockets of all the namespaces variants corresponding to this dynamic namespace, you can't. Currently dynamic namespace features are quite limited. It will be added to the roadmap though. It is a bit hacky but can maintain an external counter or a set of the created namespaces and fetch + sum the number of sockets for each namespace. Btw you can use let _ = io.dyn_ns("/{client_id}", |s: SocketRef, io: SocketIo| async move {
let auth_token = s.ns().to_string();
let namespace_size = io.of(&auth_token[1..]).unwrap().sockets().unwrap().len(); // pls help !!
// ..........
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Axnjr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to get the number of sockets for this namespace variant:
But if you want all the sockets of all the namespaces variants corresponding to this dynamic namespace, you can't. Currently dynamic namespace features are quite limited. It will be added to the roadmap though.
It is a bit hacky but can maintain an external counter or a set of the created namespaces and fetch + sum the number of sockets for each namespace.
Btw you can use
SocketIo
as a param extractor rather than cloning it: