var url = "ws://localhost:61614/stomp"; var client = Stomp.client(url); function afterConnect(roomid) { btn.addEventListener('click', function () { var msg = input.value; client.send(roomid, {}, msg); }, false); } function createConnect(roomid, uid) { client.connect(headers, function (error) { if (error.command == "ERROR") { console.error(error.headers.message); } else { afterConnect(roomid); client.subscribe(uid, function (msg) { var body = msg.body; if (msg.headers['content-type'] == 'application/json') { body = JSON.parse(msg.body) } }); } }); } ...... ......