Ws: Not possible to `removeListener` for specific events

Created on 28 Apr 2015  路  8Comments  路  Source: websockets/ws

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.

Most helpful comment

Dear reader of the future: While this issue is still open, removeListener appears to be working.

All 8 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dcflow picture dcflow  路  4Comments

sherikapotein picture sherikapotein  路  3Comments

bartosz-m picture bartosz-m  路  3Comments

cmnstmntmn picture cmnstmntmn  路  4Comments

HanHtoonAung picture HanHtoonAung  路  3Comments