<!doctype html>
<html>
-<title>Merica Terminal</title>
-<script type="text/javascript" src="//dejvice.merica.cz:5000/js" async></script>
+<title>IID Coffee Terminal</title>
<script>
- var socket = new WebSocket(
- "ws://" + document.domain + ':' + location.port,
- "merica-terminal-protocol"
- );
-
- function updateLocal(msg) {
- document.getElementById("localJSON").innerHTML = msg;
+ function loadServerScript() {
+ let script = document.createElement('script');
+ script.src = "//rtime.felk.cvut.cz:5000/js";
+ document.head.append(script);
+ script.onerror = function() {
+ this.parentElement.removeChild(this);
+ setTimeout(loadServerScript, 10000);
+ };
}
- socket.onopen = function() {
- console.log("socket open");
- updateLocal("socket open");
- }
+ loadServerScript();
- socket.onclose = function() {
- console.log("socket closed");
- updateLocal("socket closed");
- }
+ var socket;
- socket.onmessage = function(msg) {
- updateLocal(msg.data);
- if (typeof updateRemote === "function") {
- updateRemote(msg.data);
- } else {
- if (localStorage) {
- var now = Date.now();
- localStorage.setItem(now, msg.data);
- console.log(now + ": " + msg.data);
+ function connect() {
+ console.log("connecting...");
+ socket = new WebSocket(
+ "ws://" + document.domain + ':' + location.port,
+ "merica-terminal-protocol"
+ );
+
+ socket.onopen = function() {
+ console.log("socket open");
+ document.getElementById("inputStatus").innerHTML = "connected";
+ }
+
+ socket.onclose = function() {
+ console.log("socket closed");
+ document.getElementById("inputStatus").innerHTML = "disconnected";
+ delete socket;
+ setTimeout(connect, 10000);
+ }
+
+ socket.onmessage = function(msg) {
+ updateJSONmsg(msg.data);
+ if (typeof updateRemote === "function") {
+ updateRemote(msg.data);
+ } else {
+ if (localStorage) {
+ var now = Date.now();
+ localStorage.setItem(now, msg.data);
+ console.log(now + ": " + msg.data);
+ }
}
- }
+ }
}
+ connect();
+
+ function updateJSONmsg(msg) {
+ document.getElementById("localJSON").innerHTML = msg;
+ }
function printLocalStorage() {
var output = "";
if (localStorage) {
output += "localStorage not supported";
}
- updateLocal(output);
+ updateJSONmsg(output);
}
function clearLocalStorage() {
</script>
<body>
+ <center>
+ <h1>IID Coffee Terminal</h1>
+ </center>
+
+<div id="remote"><center>No data from server.</center></div>
<div id="local">
+ <hr>
<center>
- <h1>Merica Terminal</h1>
+ <h2>Debug area</h2>
<button onclick="sendReset()">reset</button>
<span style="display:inline-block; width: 20pt;"></span>
<button onclick="sendClose()">close</button>
<button onclick="clearLocalStorage()">clear</button>
<span style="display:inline-block; width: 20pt;"></span>
<button onclick="location.reload()">reload</button>
- <p id="localJSON">no data received</p>
+ <p>Input: <span id="inputStatus"></span>, JSON message: <span id="localJSON">no data received</span></p>
</center>
<hr>
</div>
-<div id="remote"><center>all alone in a danger zone...</center></div>
</body>
</html>