diff options
Diffstat (limited to 'src/main/resources/static/test-ws.js')
-rw-r--r-- | src/main/resources/static/test-ws.js | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/src/main/resources/static/test-ws.js b/src/main/resources/static/test-ws.js index 48104537..662cf811 100644 --- a/src/main/resources/static/test-ws.js +++ b/src/main/resources/static/test-ws.js @@ -6,31 +6,17 @@ function connect() { stompClient = Stomp.over(socket); stompClient.connect({}, function (frame) { console.log('Connected: ' + frame); - - for (var i = 1; i < 10; i++) { - subscribeTest(stompClient, '/test' + i); - subscribeTest(stompClient, '/topic/test' + i); - subscribeTest(stompClient, '/broadcast/test' + i); - subscribeTest(stompClient, '/queue/test' + i); - subscribeTest(stompClient, '/user/queue/test' + i); - subscribeTest(stompClient, '/user/queue/topic/test' + i); - subscribeTest(stompClient, '/user/queue/broadcast/test' + i); - } }); } -function sendTest(indexes) { - for (var i = 0; i < indexes.length; i++) { - stompClient.send("/app/test" + indexes[i], {}, "test payload " + indexes[i]); - } +function send(endpoint, payload) { + stompClient.send(endpoint, {}, payload); } -function subscribeTest(stompClient, endpoint) { - var id = endpoint.replace(new RegExp('/', 'g'), '') + '-data'; - $("#test-feeds").append('<tr><td>' + endpoint + '</td><td id="' + id + '">no data received yet</td></tr>'); +function subscribeTo(endpoint) { + $("#test-feeds").prepend('<tr><td>' + endpoint + '</td><td>Subscribed</td></tr>'); stompClient.subscribe(endpoint, function (data) { - console.log("Received event on " + endpoint + ": data.body=" + data.body); - $("#" + id).html('<strong>received "' + data.body + '"</strong>'); + $("#test-feeds").prepend('<tr><td>' + endpoint + '</td><td>Received: <pre>' + data.body + '</pre></td></tr>'); }); } @@ -38,9 +24,14 @@ $(function () { $("form").on('submit', function (e) { e.preventDefault(); }); - $("#send-test").click(function () { - var indexesToSend = $("#test-index-field").val().split(','); - sendTest(indexesToSend); + $("#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); }); }); |