how to listen for a event only in specific rooms not globally. In the docs I couldn't found a way to do that! #3951
-
I want something like this I have an admin room in my app which only admins can access and I want to listen to client events only in that room I want something like this
|
Beta Was this translation helpful? Give feedback.
Answered by
darrachequesne
Jun 1, 2021
Replies: 1 comment 2 replies
-
Hi! I see two possible solutions:
io.on("connection", (socket) => {
socket.on("my-event", () => {
const isAllowed = socket.rooms.has("admin");
if (isAllowed) {
// ...
}
});
});
io.of("/admin").on("connection", (socket) => {
socket.on("my-event", () => {
// ...
});
}); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
arnav-kr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I see two possible solutions: