socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.32k stars 972 forks source link

Why some EVENTs are removed in v2? #643

Closed XiXiongMaoXiong closed 3 years ago

XiXiongMaoXiong commented 3 years ago

EVENT_RECONNECT_ERROR? EVENT_CONNECTING? EVENT_CONNECT_TIMEOUT? and etc...

I was wondering why you removed these EVENTS, these are so important for some if not all.

darrachequesne commented 3 years ago

Hi! Those events were not removed per se, they are not forwarded by the Socket instance anymore, but they are still emitted by the underlying Manager.

Before:

socket.on(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() {
    @Override
    public void call(Object... objects) {
        // ...
    }
});

After:

socket.io().on(Manager.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() {
    @Override
    public void call(Object... objects) {
        // ...
    }
});

The reason behind this change was to make the existence of the Manager explicit for the end users, and to fix some surprising behavior, like:

socket.on(Socket.EVENT_RECONNECT, new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        System.out.println(socket.connected()); // false ???
    }
});

Added here: http://socketio.github.io/socket.io-client-java/migrating_from_1_x.html#The_Socket_instance_will_no_longer_forward_the_events_emitted_by_its_Manager

XiXiongMaoXiong commented 3 years ago

Hi! Those events were not removed per se, they are not forwarded by the Socket instance anymore, but they are still emitted by the underlying Manager.

Before:

socket.on(Socket.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() {
    @Override
    public void call(Object... objects) {
        // ...
    }
});

After:

socket.io().on(Manager.EVENT_RECONNECT_ATTEMPT, new Emitter.Listener() {
    @Override
    public void call(Object... objects) {
        // ...
    }
});

The reason behind this change was to make the existence of the Manager explicit for the end users, and to fix some surprising behavior, like:

socket.on(Socket.EVENT_RECONNECT, new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        System.out.println(socket.connected()); // false ???
    }
});

Added here: http://socketio.github.io/socket.io-client-java/migrating_from_1_x.html#The_Socket_instance_will_no_longer_forward_the_events_emitted_by_its_Manager

Thanks for clarifying mate, I appreciate your work.

Keep it up 👍

CoolMind commented 3 years ago

Thanks! And EVENT_CONNECT_TIMEOUT disappeared.

darrachequesne commented 3 years ago

@NotNotMarshall thanks for the kind words :+1:

@CoolMind good catch, I've added it here: https://socketio.github.io/socket.io-client-java/migrating_from_1_x.html#The_Socket_instance_will_no_longer_forward_the_events_emitted_by_its_Manager

touhiDroid commented 3 years ago

Thanks! And EVENT_CONNECT_TIMEOUT disappeared.

EVENT_RECONNECTING and EVENT_CONNECTING are also not found.