Skip to content

Losing websocket callback handlers when calling socketFor #167

Open
@ramster-vinka

Description

@ramster-vinka

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions