socket.io-stream icon indicating copy to clipboard operation
socket.io-stream copied to clipboard

socket.removeAllListeners() breaks ss(socket)

Open peteruithoven opened this issue 11 years ago • 4 comments
trafficstars

Currently when you call removeAllListeners on the socket connection that's used by socket.io-stream you break the socket.io-stream insance. Should we overrule the removeAllListeners method and make sure we re-add the socket.io-stream listeners? Something like:

var originalRemoveAllListeners = sio.removeAllListeners;
  sio.removeAllListeners = function() {
  originalRemoveAllListeners.apply(sio, arguments);
  // re-add socket.io listeners
}

peteruithoven avatar Oct 21 '14 13:10 peteruithoven

I think calling removeAllListeners without the target event can break socket of socket.io too. So I recommend to specify what to remove like:

socket.removeListener('myevent', listener);
socket.removeAllListener('myevent');

nkzawa avatar Oct 21 '14 14:10 nkzawa

I don't think removeAllListeners on socket.io breaks it. I use the general removeAllListeners to clean up after each (Mocha) unit test (in a general afterEach). This didn't break any socket.io sockets yet. It would be great if these cleanups could remain as generic as possible.

peteruithoven avatar Oct 21 '14 15:10 peteruithoven

Actually, a socket listens an event at least internally like the following, even though removing the listener doesn't affect apparently.

https://github.com/Automattic/socket.io-client/blob/master/lib/manager.js#L301

anyway, I will think about solutions.

nkzawa avatar Oct 21 '14 15:10 nkzawa

+1

NicoleY77 avatar Nov 06 '15 03:11 NicoleY77