Because of the way listener registration occurs within ws it is not possible to remove the listeners using the originally provided functions.
Not sure that this behaviour can be changed, but I think it's worth noting the limitation (hence this issue - couldn't find another) so people know this might be something they need to workaround themselves.
Yeah, this is also a problem for me.
This is only the case when you use the WC3 events interface. If you just use the Node.js EventEmitter interface, you can do all the normal event things.
function handler(msg) {
console.log('received a message.');
}
ws.on('message', handler);
ws.removeListener('message', handler);
I guess, for the sake of browser users, there should be a W3C emulated removeEventListener.
+1, removeEventListener() needs to be added, I try to use as much as possible the browser API to be sure to be compatible with browsers... :-/
+1 for removeEventListener.
Dear reader of the future: While this issue is still open, removeListener appears to be working.
Looks like this is fixed in #805. I've monkey-patched this PR into my project and it works great. Hopefully this will get merged soon.
Y its not still working :-(
@JoshuaWise and when not ws.on('message',...) but an other listener? For examle eventemitter.on('someevent',...)??? How to be?
Most helpful comment
Dear reader of the future: While this issue is still open,
removeListenerappears to be working.