I am using socket.io-client in a class, such that I do:
constructor() {
socket.on("a", this.a.bind(this));
socket.off("a", this.a.bind(this));
}
But when I construct (both on
and then off
fires), the socket still listens to "a".
The way I test this, is to console.log
on a
method, enter, and when "a" is received" console logs the event.
I also tried socket.removeListener
, but it did not work.
Perhaps it is because it is a class method? How can I fix this to work?