更新时间:2022-06-14 23:00:08
正如来自 muttonUp stomp.js 所指出的https://github.com/jmesnil/stomp-websocket/ 将覆盖 onclose 处理程序.另一方面,它提供了在连接时传递错误回调的选项:
As pointed out by muttonUp stomp.js from https://github.com/jmesnil/stomp-websocket/ will overwrite the onclose handler. On the other hand it provides the option to pass an error-callback on connect:
stompClient.connect({}, function(frame) {
...
}, function(message) {
// check message for disconnect
});
由于您的回调会收到多种错误,因此您必须检查消息,它确实是哎呀![...]",表示连接丢失.
Since you will get several kinds of errors delivered to your callback, you have to check the message it it was indeed the "Whoops! [...]" which indicates a connection loss.