window.stompClient;
const stompConfig = {
// Typically, login, passcode and vhost
// Adjust these for your broker
connectHeaders: {
login: "guest",
passcode: "guest",
broadcast: "123"
},
// Broker URL, should start with ws:// or wss:// - adjust for your broker setup
brokerURL: "ws://172.3.3.160:20000/streaming/ws",
// Keep it off for production, it can be quit verbose
// Skip this key to disable
debug: function (str) {
console.log('STOMP: ' + str);
},
// If disconnected, it will retry after 200ms
reconnectDelay: 200,
// Subscriptions should be done inside onConnect as those need to reinstated when the broker reconnects
onConnect: function (frame) {
// The return object has a method called `unsubscribe`
const subscription = stompClient.subscribe('/topic/chat', function (message) {
const payload = JSON.parse(message.body);
displayIncomingMessage(payload.user, payload.usrMsg);
});
}
};
// Create an instance
stompClient = new StompJs.Client(stompConfig);
stompClient.activate();