From b32cdf5c4f5d0b4f31b3bcfa64fe9328ed78d818 Mon Sep 17 00:00:00 2001 From: jbion Date: Fri, 20 Jan 2017 16:11:24 +0100 Subject: Move frontend and backend into 2 separate subprojects --- backend/src/main/resources/static/test-ws.js | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/src/main/resources/static/test-ws.js (limited to 'backend/src/main/resources/static/test-ws.js') diff --git a/backend/src/main/resources/static/test-ws.js b/backend/src/main/resources/static/test-ws.js new file mode 100644 index 00000000..1c64349e --- /dev/null +++ b/backend/src/main/resources/static/test-ws.js @@ -0,0 +1,40 @@ +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); + subscribeTo('/user/queue/errors'); + }); +} + +function send(endpoint, payload) { + stompClient.send(endpoint, {}, payload); +} + +function subscribeTo(endpoint) { + $("#test-feeds").prepend('' + endpoint + 'Subscribed'); + stompClient.subscribe(endpoint, function (data) { + $("#test-feeds").prepend('' + endpoint + 'Received:
' + data.body + '
'); + }); +} + +$(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(); \ No newline at end of file -- cgit