+var DEFAULT_TITLE = "ppt-control"
var preloaded = false;
+var preload = [];
function imageRefresh(id) {
img = document.getElementById(id);
}
show_next.onclick = sync_next;
+function sync_shortcuts() {
+ saveSettings();
+}
+shortcuts.onclick = sync_shortcuts;
+
function set_control_width() {
var width = window.innerWidth
|| document.documentElement.clientWidth
}
});
+function sleep(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+function disconnect() {
+ document.title = DEFAULT_TITLE;
+ current_img.src = "/black.jpg";
+ next_img.src = "/black.jpg";
+ users.textContent = "Connection to PowerPoint failed";
+}
+
websocket.onmessage = function (event) {
+ console.log("Received data");
data = JSON.parse(event.data);
switch (data.type) {
case 'state':
+ if (data.connected == "0" || data.connected == 0) {
+ console.log("Disconnected");
+ disconnect();
+ break;
+ }
var d = new Date;
switch (data.visible) {
case 3:
console.error(
"unsupported event", data);
}
- if (!preloaded) {
- var i = 0
- var preload = [];
+ if (preloaded == false && ! isNaN(total.textContent)) {
+ image = document.getElementById("preload_img");
for (let i=1; i<=Number(total.textContent); i++) {
- image = new Image();
image.src = "/cache/" + i + ".jpg";
preload.push(image);
- console.log("Preloaded image " + i);
+ console.log("Preloaded " + total.textContent);
+ //sleep(0.5)
}
preloaded = true;
}
var interval = setInterval(refresh, 5000);
function refresh() {
+ console.log("Refreshing")
websocket.send(JSON.stringify({action: 'refresh'}));
}