-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.html
98 lines (91 loc) · 2.46 KB
/
main.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-control" content="public">
<style>
html, body {
margin: 0;
height: 100%;
background-color: #000000;
cursor: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7), auto;
}
.imgcontainer {
width: 100%;
height: 100%;
}
.display {
width: 100%;
max-height: 100%;
object-fit: contain;
}
</style>
<script type="text/javascript">
var port = "9001" ;
var currentURL = "";
async function setNewImage(url, refresh = true) {
img = document.getElementById("display");
console.log("Current image src = " + img.src);
if (refresh === true && url === img.src) {
console.log("Same image; not changing display");
return;
}
currentURL = url;
console.log("url: " + url);
img = document.getElementById("display");
img.src = url;
if (refresh) {
await sleep(1000);
await setNewImage(url, refresh = false) ;
}
// img.src = "";
// sleep(100);
// img.src = url;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function fetchURL() {
while (true) {
console.log("Starting fetch");
await fetch("http://localhost:" + port + "/status")
.then(function(response) {
return response.text();
}
)
.then(function(data) {
console.log("New URL: " + data);
setNewImage(data);
}
);
}
}
async function connectToPhotoServer() {
while (true) {
try {
await fetchURL();
} catch(err) {
console.log("PhotoServer not available; sleeping 10 seconds");
await sleep(10000);
}
}
}
function reloadImage() {
var now = new Date();
var img = document.getElementById("display");
console.log("Reload; image.src: " + img.src);
var main_src = img.src.split("?")[0];
img.src = main_src + "?" + now.getTime();
console.log("Reloaded; new image: " + img.src);
// new timeout: 30 min.
setTimeout("reloadImage()", 30 * 60 * 1000);
}
// Force a refresh after 30 seconds
setTimeout("reloadImage()", 30000);
</script>
</head>
<body onload="connectToPhotoServer();">
<div class="imgcontainer">
<img class="display" id="display" src="" alt="display"/>
</div>
</body>
</html>