You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using socket.io java client for my android application. My application (1) is a wrapper of another application (2) that listens to socket.io events. From the view of my wrapper application, I don't know the list of specific events that the application (2) listens to. However, I need to access to the returned params of the registered event handlers of the application (2).
Hence I wonder if we can add a special event, e.g. *, that once it's registered by Emitter.on("*", callback), will transfer the response of all event to the * event callback ?
Regarding to the source code, I found out that it's easy to do so by just adding some line of code in the Emitter:
public Emitter emit(String event, Object... args) {
ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event);
if (callbacks != null) {
for (Listener fn : callbacks) {
fn.call(args);
}
}
// Emit to all event handlers if it is registered
ConcurrentLinkedQueue<Listener> allEventCallbacks = this.callbacks.get("*");
if (allEventCallbacks != null) {
for (Listener fn : allEventCallbacks) {
fn.call(event, args);
}
}
return this;
}
It seems the position was to mimic the JS client, which does not handle wildcards: socketio/socket.io-client-java#243 (comment). I'm not sure whether it has changed since then.
Activity
darrachequesne commentedon Jul 31, 2018
It seems the position was to mimic the JS client, which does not handle wildcards: socketio/socket.io-client-java#243 (comment). I'm not sure whether it has changed since then.
tdhman commentedon Aug 6, 2018
You're right. As the js client does not implement the wildcard case, the java client has no intend to do that.
pauljackals commentedon Apr 18, 2022
Hi, JS client has .onAny() now, maybe you'll reconsider adding something like that? 🙂
feat: implement catch-all listeners
feat: implement catch-all listeners