Remove listener?
Hello!
It would be great if the onMessage() would return an ID that could be later used to REMOVE that listener.
I am currently using one global websocket that I attach to on every controller. After a routechange I need to remove the registered listeners, but there seems to be no good way to do that.
My current hack is this (obviously ugly and suboptimal)
socket.onMessage(function(message) { ... })
var websocketCB = socket.onMessageCallbacks.last()
(...)
var index = service.socket.onMessageCallbacks.indexOf(websocketCB)
service.socket.onMessageCallbacks.splice(index, 1)
Hm, I'm having the same issue... Quite critical and wondering why this is not just possible to simply remove the listener... This is even more terrible, that we have to remove the message callback, the error callback, and all other events associated with it.
Maybe a slight improvement to the workaround above, would be to remove the function based on its name (assuming this is named function and not an anonymous function which has been passed to the callback). Identifying the function name can be done like that ...onMessageCallbacks[index].fn.name