Skip to content

Socket does not emit "DISCONNECTED" properly. #24

Description

@mikw99

Thanks a lot for this project, I use it a lot.

I found one problem in the sockets event emitter:
When calling "disconnectAsync", the socket calls "handleClose", which will not emit "DISCONNECTED" because the socket status is already set to "disconnected" by some other process.

handleClose() {
    this._socket = null;
    this._clearTimers();
    if (this._status !== 'disconnected') {
        this._status = 'disconnected';
        this.emit(S101SocketEvent.DISCONNECTED);
    }

}

When adding an "else if" in case the socket status is already "disconnected", it works for me.

handleClose() {
    this._socket = null;
    this._clearTimers();
    if (this._status !== 'disconnected') {
        this._status = 'disconnected';
        this.emit(S101SocketEvent.DISCONNECTED);
    }
else if (this._status === 'disconnected') {
	this.emit(S101SocketEvent.DISCONNECTED);
}
}

This could be a very specific problem for my use-case, as I am using the library in node-red, but maybe this helps somebody.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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