blob: 662cf811cbcb05c8e57d2b6437bd274821ef3de4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
var stompClient = null;
function connect() {
console.log('Connecting...');
var socket = new SockJS('/seven-wonders-websocket');
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {
console.log('Connected: ' + frame);
});
}
function send(endpoint, payload) {
stompClient.send(endpoint, {}, payload);
}
function subscribeTo(endpoint) {
$("#test-feeds").prepend('<tr><td>' + endpoint + '</td><td>Subscribed</td></tr>');
stompClient.subscribe(endpoint, function (data) {
$("#test-feeds").prepend('<tr><td>' + endpoint + '</td><td>Received: <pre>' + data.body + '</pre></td></tr>');
});
}
$(function () {
$("form").on('submit', function (e) {
e.preventDefault();
});
$("#send-btn").click(function () {
var endpoint = $("#path-field").val();
var payload = $("#payload-field").val();
send(endpoint, payload);
});
$("#subscribe-btn").click(function () {
var endpoint = $("#subscribe-path-field").val();
subscribeTo(endpoint);
});
});
// auto-connect
connect();
|