summaryrefslogtreecommitdiff
path: root/src/main/resources
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2016-12-11 14:03:28 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2016-12-11 14:03:28 +0100
commit4beb63343f658a17b9ccd6236fced501e5d15dea (patch)
treef3a8f14a6b25ad82c958dd1192ced7a539ac1d4f /src/main/resources
parentAdd special action skeleton to finish wonders data parsing (diff)
downloadseven-wonders-4beb63343f658a17b9ccd6236fced501e5d15dea.tar.gz
seven-wonders-4beb63343f658a17b9ccd6236fced501e5d15dea.tar.bz2
seven-wonders-4beb63343f658a17b9ccd6236fced501e5d15dea.zip
Add WS experiment test page
This pages allows to test spring/STOMP config to see which messages are properly broadcasted to all users, which are just sent to the caller, and which are sent a specific user from the server.
Diffstat (limited to 'src/main/resources')
-rw-r--r--src/main/resources/static/index.html3
-rw-r--r--src/main/resources/static/test-ws.js48
-rw-r--r--src/main/resources/static/test.html45
3 files changed, 96 insertions, 0 deletions
diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html
index 1b959d56..6131e912 100644
--- a/src/main/resources/static/index.html
+++ b/src/main/resources/static/index.html
@@ -19,6 +19,9 @@
<p>This is a stub index page for the project, for the sake of vertical completeness. We will soon get to work on it!</p>
+<a href="test.html">Go to WS test page</a>
+
+
<h2>Connection</h2>
<form class="form-inline">
diff --git a/src/main/resources/static/test-ws.js b/src/main/resources/static/test-ws.js
new file mode 100644
index 00000000..48104537
--- /dev/null
+++ b/src/main/resources/static/test-ws.js
@@ -0,0 +1,48 @@
+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);
+
+ 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 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>');
+ stompClient.subscribe(endpoint, function (data) {
+ console.log("Received event on " + endpoint + ": data.body=" + data.body);
+ $("#" + id).html('<strong>received "' + data.body + '"</strong>');
+ });
+}
+
+$(function () {
+ $("form").on('submit', function (e) {
+ e.preventDefault();
+ });
+ $("#send-test").click(function () {
+ var indexesToSend = $("#test-index-field").val().split(',');
+ sendTest(indexesToSend);
+ });
+});
+
+// auto-connect
+connect(); \ No newline at end of file
diff --git a/src/main/resources/static/test.html b/src/main/resources/static/test.html
new file mode 100644
index 00000000..93c5d928
--- /dev/null
+++ b/src/main/resources/static/test.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Seven Wonders</title>
+ <link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet">
+ <link href="/main.css" rel="stylesheet">
+ <script src="/webjars/jquery/jquery.min.js"></script>
+ <script src="/webjars/sockjs-client/sockjs.min.js"></script>
+ <script src="/webjars/stomp-websocket/stomp.min.js"></script>
+ <script src="test-ws.js"></script>
+</head>
+<body>
+<noscript>
+ <h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websocket relies on Javascript being
+ enabled. Please enable Javascript and reload this page!</h2>
+</noscript>
+
+<h1>Seven Wonders Test Page</h1>
+
+<h2>WS messages tests</h2>
+
+<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>
+ </div>
+</form>
+
+<h2>Subscribed feeds</h2>
+
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Endpoint</th>
+ <th>Data received</th>
+ </tr>
+ </thead>
+ <tbody id="test-feeds">
+ </tbody>
+</table>
+
+
+</body>
+</html> \ No newline at end of file
bgstack15