import * as Stomp from "stompjs";
import _ from "lodash";
export const MESSAGE_TYPE_CHAT_TYPING = "ChatTyping";
export const MESSAGE_TYPE_CHAT_MESSAGE = "ChatMessage";
export const RECONNECT_DELAY = 3000;
export function wsConnect(user, callback, ondisconnected) {
const webSocket = Stomp.client(url);
webSocket.debug = () => {};
webSocket.connect({},() => {
callback ? callback(webSocket) : _.noop();
},
error => {
// console.log(error);
console.log("Connection lost...");
if (ondisconnected) {
ondisconnected();
}
}
);
return webSocket;
}
仅当应用程序处于调试模式时,才通过 WebSocket 建立 StompJ 之间的连接。