How to find out when the Stomp server is disconnected from the Stomp.JS client

I am sending a Stomp message through the Sock.JS client. When I shut down the server, I would like a warning message to appear on the client. For this, I implemented a server-side heartbeat ...

stompClient = Stomp.over(socket);
stompClient.heartbeat.outgoing = 20000;
stompClient.heartbeat.incoming = 20000;
stompClient.connect({}, function(frame) {
  ...
}

In the Chrome Developer Console, I see a message ...

POST http://localhost:8080/hello/800/8n_btbxb/xhr_streaming net::ERR_CONNECTION_RESET sockjs-0.3.min.js:27
Whoops! Lost connection to undefined 

But I'm not sure how to fix this error in JS. I'm sure I miss something easy, but a little help would be great.

+4
source share
2 answers

muttonUp stomp.js https://github.com/jmesnil/stomp-websocket/ onclose. , :

stompClient.connect({}, function(frame) {
    ...
}, function(message) {
    // check message for disconnect
});

, , , "! [...]", .

+6

, , , . SockJS- Stomp one...

var socket = new SockJS('/hello');
...
socket.onclose = function() {
    console.log('close');
    stompClient.disconnect();
    setConnected();
};
+2

Source: https://habr.com/ru/post/1546708/


All Articles