netty-socketio icon indicating copy to clipboard operation
netty-socketio copied to clipboard

Cannot get the client list of joined rooms from the server disconnect

Open nantoniazzi opened this issue 6 years ago • 3 comments

I would like to add a listener on a client disconnect event on my server and get the current list of rooms used by this client. Unfortunatly, it's not possible since all the rooms are automatically left just before the server disconnect listener handler.

Code from Namespace.java:

    public void onDisconnect(SocketIOClient client) {
        Set<String> joinedRooms = client.getAllRooms();        
        allClients.remove(client.getSessionId());

        leave(getName(), client.getSessionId());
        storeFactory.pubSubStore().publish(PubSubType.LEAVE, new JoinLeaveMessage(client.getSessionId(), getName(), getName()));

        for (String joinedRoom : joinedRooms) {
            leave(roomClients, joinedRoom, client.getSessionId());
        }
        clientRooms.remove(client.getSessionId());

        try {
            for (DisconnectListener listener : disconnectListeners) {
                listener.onDisconnect(client);
            }
        } catch (Exception e) {
            exceptionListener.onDisconnectException(e, client);
        }
    }

Listeners are called just after a force leave of all rooms.

There was the same kind of problem with the node socketio server and the solved it by adding a new disconnecting listener called just before the disconnect. https://github.com/socketio/socket.io/issues/1814

Is there a way to have the same behaviour or is there a way to know the room used by a client on a disconnect event?

nantoniazzi avatar Jun 22 '18 13:06 nantoniazzi

FYI, u can still get the room set after the onDisconnect evnet by using the version 1.7.7. After I upgraded to 1.7.17 i encountered the same problem, and my solution is to record the client and room relationship using a HashMap when your specific join room event happens.

xixiuxiu avatar Dec 05 '18 08:12 xixiuxiu

I have the same problem,When the client is disconnected,client leave the room automatically,so when client reconnection,bring the client back into the room. I using the version 1.7.18

zengxiangwu avatar May 30 '20 06:05 zengxiangwu

I have the same problem,When the client is disconnected,client leave the room automatically,so when client reconnection,bring the client back into the room. I using the version 1.7.18

老铁,咨询一下你们用这个项目做socket多久了?我最近接手的前任留的代码,也是这玩意,我咋感觉到处漏风~

warriorsfly avatar Jul 11 '21 16:07 warriorsfly