Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready state timeout not working as excpected #238

Open
alex-frx opened this issue Jun 24, 2024 · 0 comments
Open

Ready state timeout not working as excpected #238

alex-frx opened this issue Jun 24, 2024 · 0 comments

Comments

@alex-frx
Copy link

Im using the websocket like this

const {sendMessage, lastMessage, readyState} = useWebSocket(WEBSOCKET_URL, {
        heartbeat: {
            message: 'ping',
            returnMessage: 'pong',
            timeout: 2000,
            interval: 1000,
        },
        onClose:()=>{
            console.log("WebSocket connection closed")
        },
        shouldReconnect: (closeEvent) => {
            /*
            useWebSocket will handle unmounting for you, but this is an example of a
            case in which you would not want it to automatically reconnect
          */
            console.log("try reconnect")
           return true
        },
        reconnectAttempts: 2,
        reconnectInterval: 2000,
    });

But the heartbeat is not working like expected / described in the doc.
The heartbeat is send in the specified interval. But the timeout is not working. With these settings I would except that after 2000ms (2s) of receiving the last pong the ready state would change to closed. But this is not happing. The heartbeat continues sending producing this message in the console react-use-websocket.js?v=b1dceef9:142 WebSocket is already in CLOSING or CLOSED state. The. logging of the message start roughly after two seconds of the last received pong and continues for around a minute (the default value?) only after this the readystate is changed to closed.

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

No branches or pull requests

1 participant