stomp-js/stompjs

Stomp auto make new connect after about 1 minute.

KhanamDEV opened this issue · 1 comments

Hi Development Team,
I have issue when config stomp in ReactJS
This is my config:

const [socketReservationClient, setSocketReservationClient] = useState<Client>(new Client({
        brokerURL: process.env.REACT_APP_SOCKET_URL,
        connectHeaders: socketHeaders,
        heartbeatIncoming: 60000,
        heartbeatOutgoing: 60000,
        onDisconnect: eve => {
            console.log("Disconnected")
        }
    }));

But when run it, every 1 minute or so the client will automatically connect and create a new websocket. I'm sure I didn't create any other code to add a new connection. How can I turn it off?

image

The issue most likely is caused the way useState works. It is not a bug. Using this library with React is tricky.

I usually do not program with React, and I do not use this library with React. So, I got someone to prepare a sample to use this library with React. This structure does not suffer from this problem. In addition, it also covers the case when child components use the client.

Please see https://github.com/stomp-js/rx-stomp-react-sample - start with src/App.js and the accompanying tutorial.