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

how to check and add events dynamically

Open rmControls opened this issue 2 years ago • 2 comments

I want to check if event already exists and add the event only if it is missing....

how to do it...??

I am using getx controller attached to the page to connect and destroy socket io... but however after multiple close and open of the same page, seems like same event triggered multiple time...

I am destroying socket at onClose event but still seems like it remembers all the events and when you estatblish connection it calls same event multiple times...


 @override
  void onClose() {
    if (socket.connected) {
      socket.disconnect();
      socket.destroy();
    }
    super.onClose();
  }

rmControls avatar Aug 02 '22 00:08 rmControls

seems like issue is simlar to #230

rmControls avatar Aug 02 '22 00:08 rmControls

after some research in google I found one workaround solution which seems like working...

you need to add clearListeners() call... though you are destroying socket still it remembers listeners....

 @override
  void onClose() {
    if (socket.connected) {
      socket.clearListeners();
      socket.disconnect();
      socket.destroy();
    }
    super.onClose();
  }

rmControls avatar Aug 02 '22 00:08 rmControls