-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path14_hello_mqtt.html
More file actions
54 lines (54 loc) · 1.28 KB
/
14_hello_mqtt.html
File metadata and controls
54 lines (54 loc) · 1.28 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>hello color web</title>
<style>
* {
margin: 0;
padding: 0;
border: none;
}
html, body {
height: 100%;
width: 100%;
}
iframe {
display: block;
}
</style>
</head>
<body>
<iframe
id="frame"
src=""
width="100%"
height="100%"
></iframe>
<script>
const frame = document.getElementById('frame');
const baseUrl = './14_hello_mqtt-inner.html'
// heartbeat detection
let lastHeartbeat = 0;
window.addEventListener('message', (event) => {
if (event.origin !== window.location.origin) {
return;
}
lastHeartbeat = Date.now();
})
const testHeartbeat = () => {
const now = Date.now();
if(lastHeartbeat < now - 5000) {
console.log('it ded, reload')
frame.src = baseUrl + '?time=' + now;
}
}
testHeartbeat();
setInterval(
testHeartbeat,
5000,
);
</script>
</body>
</html>