summaryrefslogtreecommitdiff
path: root/backend/src/main/resources/static/test-ws.js
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2017-01-20 16:11:24 +0100
committerjbion <joffrey.bion@amadeus.com>2017-01-20 16:11:35 +0100
commitb32cdf5c4f5d0b4f31b3bcfa64fe9328ed78d818 (patch)
treebdda009d448cb6b56415d90eae90eceb138318e4 /backend/src/main/resources/static/test-ws.js
parentMerge remote-tracking branch 'origin/feature/front' (diff)
downloadseven-wonders-b32cdf5c4f5d0b4f31b3bcfa64fe9328ed78d818.tar.gz
seven-wonders-b32cdf5c4f5d0b4f31b3bcfa64fe9328ed78d818.tar.bz2
seven-wonders-b32cdf5c4f5d0b4f31b3bcfa64fe9328ed78d818.zip
Move frontend and backend into 2 separate subprojects
Diffstat (limited to 'backend/src/main/resources/static/test-ws.js')
-rw-r--r--backend/src/main/resources/static/test-ws.js40
1 files changed, 40 insertions, 0 deletions
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('<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(); \ No newline at end of file
bgstack15