Skip to content
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 allEvent listener to emitter #99

Open
tdhman opened this issue Jul 30, 2018 · 3 comments
Open

Add allEvent listener to emitter #99

tdhman opened this issue Jul 30, 2018 · 3 comments

Comments

@tdhman
Copy link

tdhman commented Jul 30, 2018

Hello,

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;
    }

What do you think if it's possible to do that ?

Thanks for any help.

@darrachequesne
Copy link
Member

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
Copy link
Author

tdhman commented 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
Copy link

Hi, JS client has .onAny() now, maybe you'll reconsider adding something like that? 🙂

darrachequesne added a commit to socketio/socket.io-client-java that referenced this issue Jul 8, 2022
Syntax:

```java
socket.onAnyIncoming(new Emitter.Listener() {
    @OverRide
    public void call(Object... args) {
        // ...
    }
});

socket.onAnyOutgoing(new Emitter.Listener() {
    @OverRide
    public void call(Object... args) {
        // ...
    }
});
```

Related:

- socketio/engine.io-client-java#99
- #243
- #475
cedev935 added a commit to cedev935/socket-java that referenced this issue Sep 14, 2023
Syntax:

```java
socket.onAnyIncoming(new Emitter.Listener() {
    @OverRide
    public void call(Object... args) {
        // ...
    }
});

socket.onAnyOutgoing(new Emitter.Listener() {
    @OverRide
    public void call(Object... args) {
        // ...
    }
});
```

Related:

- socketio/engine.io-client-java#99
- socketio/socket.io-client-java#243
- socketio/socket.io-client-java#475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants