diff options
Diffstat (limited to 'src/main/resources')
-rw-r--r-- | src/main/resources/static/app.js | 11 | ||||
-rw-r--r-- | src/main/resources/static/test-ws.js | 35 | ||||
-rw-r--r-- | src/main/resources/static/test.html | 16 |
3 files changed, 35 insertions, 27 deletions
diff --git a/src/main/resources/static/app.js b/src/main/resources/static/app.js index ace23fdb..2b6b160b 100644 --- a/src/main/resources/static/app.js +++ b/src/main/resources/static/app.js @@ -25,8 +25,15 @@ function connect() { stompClient.subscribe('/topic/games', function (msg) { var game = JSON.parse(msg.body); - console.log("Received new game: " + game); - addNewGame(game); + if (Array.isArray(game)) { + console.log("Received new games: " + game); + for (var i = 0; i < game.length; i++) { + addNewGame(game[i]); + } + } else { + console.log("Received new game: " + game); + addNewGame(game); + } }); stompClient.subscribe('/user/queue/join-game', function (msg) { 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); }); }); diff --git a/src/main/resources/static/test.html b/src/main/resources/static/test.html index 93c5d928..e19f9eb3 100644 --- a/src/main/resources/static/test.html +++ b/src/main/resources/static/test.html @@ -21,9 +21,19 @@ <form class="form-inline"> <div class="form-group"> - <label for="test-index-field">Send to /app/testX, with X in </label> - <input id="test-index-field"> - <button id="send-test" class="btn btn-default" type="submit">Send</button> + <label for="subscribe-path-field">Path:</label> + <input id="subscribe-path-field" placeholder="path"> + <button id="subscribe-btn" class="btn btn-default" type="submit">Subscribe</button> + </div> +</form> + +<form class="form-inline"> + <div class="form-group"> + <label for="path-field">Path:</label> + <input id="path-field" placeholder="path"> + <label for="payload-field">Payload:</label> + <input id="payload-field" placeholder="JSON payload"> + <button id="send-btn" class="btn btn-default" type="submit">Send</button> </div> </form> |