annot-server/templates/annot.html
changeset 0 e1d4d7a8255a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/annot-server/templates/annot.html	Wed Oct 08 15:14:58 2014 +0200
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html>
+   <head>
+      <link rel="icon" href="data:;base64,=">
+      <script type="text/javascript">
+         var sock = null;
+         var ellog = null;
+
+         window.onload = function() {
+
+            ellog = document.getElementById('log');
+
+            var wsuri;
+            if (window.location.protocol === "file:") {
+               wsuri = "ws://127.0.0.1:8090/annot";
+            } else {
+               wsuri = "ws://" + window.location.hostname + ":8090/annot";
+            }
+            wsuri = wsuri + "?event=test"
+
+            if ("WebSocket" in window) {
+               sock = new WebSocket(wsuri);
+            } else if ("MozWebSocket" in window) {
+               sock = new MozWebSocket(wsuri);
+            } else {
+               log("Browser does not support WebSocket!");
+               window.location = "http://autobahn.ws/unsupportedbrowser";
+            }
+
+            if (sock) {
+               sock.onopen = function() {
+                  log("Connected to " + wsuri);
+               }
+
+               sock.onclose = function(e) {
+                  log("Connection closed (wasClean = " + e.wasClean + ", code = " + e.code + ", reason = '" + e.reason + "')");
+                  sock = null;
+               }
+
+               sock.onmessage = function(e) {
+                  log("Got message: " + e.data);
+               }
+            }
+         };
+
+         function send() {
+            var msg = document.getElementById('message').value;
+            if (sock) {
+                new_annot = {
+                   categories : [msg],
+                   user : "admin"
+               }
+               sock.send(JSON.stringify(new_annot));
+               log("Sent: " + JSON.stringify(new_annot));
+            } else {
+               log("Not connected.");
+            }
+         };
+
+         function log(m) {
+            ellog.innerHTML += m + '\n';
+            ellog.scrollTop = ellog.scrollHeight;
+         };
+      </script>
+   </head>
+   <body>
+      <h1>OSC websocket Test</h1>
+      <noscript>You must enable JavaScript</noscript>
+      <form>
+         <p>Message: <input id="message" type="text" size="50" maxlength="50" value="Hello, world!"></p>
+      </form>
+      <button onclick='send();'>Send Message</button>
+      <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
+   </body>
+</html>