stomp-js / stompjs

Javascript and Typescript Stomp client for Web browsers and node.js apps
Apache License 2.0
738 stars 80 forks source link

Stomp auto make new connect after about 1 minute. #629

Open KhanamDEV opened 2 months ago

KhanamDEV commented 2 months ago

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

kum-deepak commented 2 months ago

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.