New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to listen for events globally? #2626
Comments
Yeah this is one that's been discussed a huge amount over many years: #434 This is the best solution at the moment imho: https://www.npmjs.com/package/socketio-wildcard |
Hmm, thanks for the reply, but I don't think it's the same thing I'm after. It is indeed a good feature to have wildcards, but what I'm really after is a many-to-one handler. e.g. io.on('login', (data)=> {
// do login stuff
}); instead of io.on('connection', (socket)=> {
socket.on('login', (data)=> {
// do login stuff
});
}); As you can see the current structure creates an overhead of a nested handler. |
Ahh. No, as far as I'm aware, connect and disconnect events are very much fundamental to the way client connections work. How could a user login without being connected first, for example? Nothing can be sent outside of the handshake. |
If you don't like the nesting, consider |
Hi there, I'm trying to make a global event that can be listened from any connection. A use case would be so that for each connection doesn't need a separate handler. So far the only "global" event is "connection", I want to be able to listen to any event globally. Is this possible?
The text was updated successfully, but these errors were encountered: