Description
Using SocketIO. I wonder if I'm using this correctly, but I'm losing callbacks in the actual socket object when socketFor is called during the socket is in disconnected state and the proxy object is updated with a new socket instance.
Initialize:
let socket = this.socketIOService.socketFor(url);
socket.on('myEvent', this.myHandler, this);
After this socket.listeners
and socket.socket._callbacks
contain all the added listeners.
Now if socket gets disconnected and I call again:
this.socketIOService.socketFor(url);
Inside socketFor
function this.isWebSocketOpen(existingProxy.socket)
is false -> new socket is created and set to existingProxy
:
set(existingProxy, 'socket', newWebSocket);
After this socket.listeners
contain added listeners, but socket.socket._callbacks
does not. It only holds the default connecting
and connect
callbacks.
Is there something that I'm missing in the usage? Based on the examples socketFor
seems to be a function that can be called several times. If I save the socket instance into a property and never call socketFor
again, callbacks are working.