socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

dispose() and clearListeners() not working

Open ElegantSoft opened this issue 2 years ago • 6 comments

Hello, I am using socket.io and when user logout I call

  void logout() {
    debugPrint("will logout socket");
    chatSocket?.clearListeners();
    chatSocket?.dispose();
  }

I use websocketService class and use it with getIt

class WebsocketService {
  // final Socket? socket;
  Socket? chatSocket;

  WebsocketService()
      : chatSocket =
            io("$Server/${SocketConstants.ChatNameSpace}", <String, dynamic>{
          'transports': <String>['websocket'],
          'query': <String, dynamic>{
            "access_token": token,
          }
        });

  void logout() {
    debugPrint("will logout socket");
    chatSocket?.clearListeners();
    chatSocket?.dispose();
  }

}


after calling logout function the app keeps handle sockets and doesn't clear listeners

ElegantSoft avatar Apr 02 '22 18:04 ElegantSoft

which version are you using?

jumperchen avatar Apr 18 '22 02:04 jumperchen

@jumperchen The latest version After debugging I found the issue was I create the connection 2 times so when I close connection it closes 1 connection. you must handle that.

ElegantSoft avatar Apr 19 '22 00:04 ElegantSoft

Please see https://github.com/rikulo/socket.io-client-dart/issues/258#issuecomment-1049585853

ljmatan avatar Aug 24 '22 21:08 ljmatan

Any updates i faces the same in version 2.0.0

hatemragab avatar Nov 05 '22 21:11 hatemragab