var preloaded = false;
var preload = [];
-function imageRefresh(id) {
- img = document.getElementById(id);
- var d = new Date;
- var http = img.src;
- if (http.indexOf("?t=") != -1) { http = http.split("?t=")[0]; }
- img.src = http + '?t=' + d.getTime();
-}
-
-function startWebsocket() {
- ws = new WebSocket("ws://" + window.location.host + ":5678/");
- ws.onclose = function(){
- //websocket = null;
- setTimeout(function(){startWebsocket()}, 10000);
- }
- return ws;
-}
-
-var websocket = startWebsocket();
-
var prev = document.querySelector('#prev'),
next = document.querySelector('#next'),
first = document.querySelector('#first'),
slide_label = document.querySelector('#slide_label'),
current = document.querySelector('#current'),
total = document.querySelector('#total'),
- users = document.querySelector('.users'),
+ status_text = document.querySelector('.status_text'),
current_img = document.querySelector('#current_img'),
next_img = document.querySelector('#next_img'),
current_div = document.querySelector('#current_div'),
show_next = document.querySelector('#show_next'),
shortcuts = document.querySelector('#shortcuts');
+
+function startWebsocket() {
+ console.log("Attempting to connect")
+ ws = new WebSocket("ws://" + window.location.host + ":5678/");
+ ws.onmessage = receive_message;
+ ws.onclose = function(){
+ ws = null;
+ setTimeout(function(){websocket = startWebsocket()}, 1000);
+ }
+ if (ws.readyState !== WebSocket.OPEN) {
+ disconnect()
+ }
+ return ws;
+}
+
+var websocket = startWebsocket();
+
prev.onclick = function (event) {
websocket.send(JSON.stringify({action: 'prev'}));
}
}
});
-function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
-}
-
function disconnect() {
- document.title = DEFAULT_TITLE;
+ console.log("Disconnecting")
+ document.title = DEFAULT_TITLE;
current_img.src = "/black.jpg";
next_img.src = "/black.jpg";
- users.textContent = "Connection to PowerPoint failed";
-}
-
-function update_current() {
+ status_text.textContent = "Disconnected";
+ total.textContent = "?";
+ current.value = "";
}
-function update_next() {
-}
-
-websocket.onmessage = function (event) {
+function receive_message(event) {
data = JSON.parse(event.data);
switch (data.type) {
case 'state':
if (data.connected == "0" || data.connected == 0) {
- console.log("Disconnected");
disconnect();
break;
+ } else {
+ status_text.textContent = "Connected";
}
var d = new Date;
if (show_current.checked) {
for (let i=1; i<=Number(total.textContent); i++) {
image.src = "/cache/" + i + ".jpg";
preload.push(image);
- console.log("Preloaded " + total.textContent);
- //sleep(0.5)
}
preloaded = true;
}