forked from kolbytn/mindcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewer.html
69 lines (69 loc) · 2.06 KB
/
viewer.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
<html>
<head>
<title>Viewer</title>
<style>
body {
margin: 0;
padding: 0;
}
#container {
display: flex;
flex-wrap: wrap;
width: 100%;
height: 100vh;
}
.iframe-wrapper {
border: none;
}
</style>
</head>
<body>
<div id="container">
<iframe data-port="3000" src="https://localhost:3000" class="iframe-wrapper"></iframe>
<iframe data-port="3001" src="https://localhost:3001" class="iframe-wrapper"></iframe>
<iframe data-port="3002" src="https://localhost:3002" class="iframe-wrapper"></iframe>
<iframe data-port="3003" src="https://localhost:3003" class="iframe-wrapper"></iframe>
</div>
<script>
function updateLayout() {
var width = window.innerWidth;
var height = window.innerHeight;
var iframes = document.querySelectorAll('.iframe-wrapper');
if (width > height) {
iframes.forEach(function(iframe) {
iframe.style.width = '50%';
iframe.style.height = '50%';
});
} else {
iframes.forEach(function(iframe) {
iframe.style.width = '100%';
iframe.style.height = '25%';
});
}
}
window.addEventListener('resize', updateLayout);
window.addEventListener('load', updateLayout);
var iframes = document.querySelectorAll('.iframe-wrapper');
iframes.forEach(function(iframe) {
var port = iframe.getAttribute('data-port');
var loaded = false;
function checkServer() {
fetch('https://localhost:' + port, { method: 'HEAD' })
.then(function(response) {
if (response.ok && !loaded) {
iframe.src = 'https://localhost:' + port;
}
})
.catch(function(error) {});
}
iframe.onload = function() {
loaded = true;
};
iframe.onerror = function() {
loaded = false;
};
setInterval(checkServer, 3000);
});
</script>
</body>
</html>