-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add wildcard support for events #434
Comments
agreed. EventEmitter2 |
+1 |
|
+1
I'm quite interested in this idea. |
some of the EE2 choices are not what I would consider ideal but I +1 the general idea of this, even if only "*" is supported |
truly catchall: |
i don't remember any resistance to just adding a catchall listener, the only debate I remember was whether or not we use "*" or if we go with another method name like .addGlobalListener() |
+1 |
Please get this issue in motion :) |
Well, ok, I just added EE2 to a branch in my fork: einaros@2107ff0 The branch is at: https://github.com/einaros/socket.io/commits/ee2 Thoughts are most welcome. |
if EE2 gets rid of the weird method names and adds |
I'm a -1 on EE2 It adds more bloat to the code, we also need to support it on the client side. Which means we would have to ship a extra 11.8 KB library (minified ~3.5kb). But with the up coming mobile market I would like to save as much bytes as possible. If this is really only about having a wildcard / catch all listeners.. Then this should be done by overriding the existing emit function that just does one extra call to a |
catch-all is definitely the more important part, it's easy enough to switch on the event after that if necessary |
Don't really care about wildcard's, or EE2, but a way, to intercept all events is a must. |
TJ you crazy bro...
That's from the README of EE2. Naturally, the "foo." is optional.
I agree. |
@pyrotechnick the EE2 |
It's inefficient; but it does work as expected. |
I was mistaken. You're right... {EventEmitter2} = require 'eventemitter2'
emitter = new EventEmitter2 wildcard: on
emitter.on '*', ->
console.log @event, arguments...
emitter.emit 'foo'
emitter.emit 'foo.bar'
I almost prefer this behaviour when it comes to wildcards though. When I think about all of this wildcard/"namespaced" events stuff it kind of makes me sad; JavaScript already has a fantastic way to match patterns -- they live in // or are constructed with |
Can I +1 the importance of this again. I'd love to see this in an upcoming release. |
Someone posted a solution here: http://stackoverflow.com/questions/8832414/overriding-socket-ios-emit-and-on/8838225 |
That doesn't work because I still can't connect to the event. In my application the server doesn't know the name of the room from the client. So I want to be able to respond to all messages for any room and ideally find out the name of the room that the message was sent on. |
Add regular expression support for events.. this way, ranges of verbs and nouns can be caught. |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
I would be fond of a super global method wich handle everything io.set('global_listener', function(namespace, event, args, emit){ io.set('global_authorization', function(namespace, handshakeData, callback){ |
I needed an emitter that supported catch-alls a. la. |
@HenrikJoreteg |
@n2liquid all feedback is welcome – thank you (and to @hden for that quick fix on socket.io-wildcard). |
scoketio-wildcard seems like a perfectly valid solution. I found myself also wanting to get the event name in callback, so that I could wrap the socket listener and propagate events through the wrapper, rather than directly exposing the socket to the rest of my application. My understanding is that this would require Event Emitter 2 if I wanted to do this with a wildcard. Is this just something silly to do, better to directly expose the socket? Something based on listening for 'newListener' in the wrapper (but don't know how to trigger on socket event, only how to register the socket event based on the calling functions registering a new event in the wrapper)? Anyone else interested in being able to access the event name within the callback? |
@akotlar The event name is available in the callback if you are using scoketio-wildcard. |
Ah, thanks! It may be useful to specify this in the socket.io-wildcard readme. |
how it's going? |
+1 all the way |
@alexey-sh @emin93 If you would kindly read the document from https://github.com/hden/socketio-wildcard, yes it's possible to do so for both client and server. |
@hden Thanks and yes i saw that and i'm already using it. But it's an extra dependency and nothing speaks against integrating it directly into Socket.IO core, that's why it gets a +1 from me. |
It can be handled in the app logic using one event name for all events:
|
+1 even though issue is closed. |
+💯 bang! |
+1 !!!! |
Please use |
Is there a way to hook into engine.io's PING/PONG mechanism using socket.use() ? I am having an issue where many users are losing connection, and despite extensive logging on server, it just says they disconnected due to Ping Timeout. I'd like to log the PING/PONG packets, but it seems socket.use() can only hook into the high level user-event messages, and not engine.io's underlying protocol |
+1 |
1 similar comment
+1 |
+1 since 2011? They ain't doing it. :( |
Again, |
@darrachequesne I don't see how a method on the server-side helps with this request (which is for the client). |
Any more on this? Since |
I don't understand
with something like
or
Found a small workaround - listing all possibilities:
|
Inspired from EventEmitter2 [1] ```js io.on("connect", socket => { socket.onAny((event, ...args) => {}); socket.prependAny((event, ...args) => {}); socket.offAny(); // remove all listeners socket.offAny(listener); const listeners = socket.listenersAny(); }); ``` Breaking change: the socket.use() method is removed This method was introduced in [2] for the same feature (having a catch-all listener), but there were two issues: - the API is not very user-friendly, since the user has to know the structure of the packet argument - it uses an ERROR packet, which is reserved for Namespace authentication issues (see [3]) [1]: https://github.com/EventEmitter2/EventEmitter2 [2]: #434 [3]: https://github.com/socketio/socket.io-protocol
can i use subscribe like this |
@nomi9995 no, but implementing this should be quite straightforward: socket.onAny((eventName, ...args) => {
if (/posting\/.*/.test(eventName)) {
// ...
}
}); Reference: https://socket.io/docs/v4/listening-to-events/#socketonanylistener |
Inspired from EventEmitter2 [1] ```js io.on("connect", socket => { socket.onAny((event, ...args) => {}); socket.prependAny((event, ...args) => {}); socket.offAny(); // remove all listeners socket.offAny(listener); const listeners = socket.listenersAny(); }); ``` Breaking change: the socket.use() method is removed This method was introduced in [2] for the same feature (having a catch-all listener), but there were two issues: - the API is not very user-friendly, since the user has to know the structure of the packet argument - it uses an ERROR packet, which is reserved for Namespace authentication issues (see [3]) [1]: https://github.com/EventEmitter2/EventEmitter2 [2]: socketio#434 [3]: https://github.com/socketio/socket.io-protocol
It would be great if you could use a wildcard to capture all events. For example:
The text was updated successfully, but these errors were encountered: