Skip to content

Conversation

@shahzaib-deriv
Copy link
Contributor

Description:

In the current implementation of the isSocketClosingOrClosed method, the state of the WebSocket connection is checked using the following logic:

isSocketClosingOrClosed() {
    return ![2, 3].includes(this.websocket.readyState);
}

This condition currently checks if the WebSocket connection is in the CLOSED (3) or CLOSING (2) states but does not handle the CONNECTING (0) state. As a result, if send is called while the WebSocket is still in the CONNECTING state, it may throw an error.

Suggested Improvement:

To enhance robustness, updating the condition to explicitly account for the CONNECTING state as follows:

isSocketReadyForSending() {
    return this.websocket.readyState === WebSocket.OPEN; // 1
}

This modification would prevent sending messages when the WebSocket is not fully open, reducing the likelihood of encountering runtime errors and improving the overall stability of the application.

Copy link
Contributor

@yashim-deriv yashim-deriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit on naming. the rest lgtm

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants