-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
164 lines (142 loc) · 4.5 KB
/
index.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html>
<head>
<title>YoctuCast</title>
<style type="text/css">
html{
height: 100%;
padding:0;
width: 100%;
}
body {
overflow:hidden;
height: 100%;
padding: 0;
margin: 0;
background: white url("yoctu.svg") no-repeat 50% 50%;
}
#main{
height: 100%;
opacity: 0;
transition: opacity 4s ease;
}
#main.show{
opacity: 1;
}
#status{
transition: opacity 1s;
position: absolute;
bottom:0;
left:0;
right:0;
color: #555;
font-weight: bold;
height: 1.2em;
text-align: center;
padding: 10px;
background: rgba(32, 27,37,0.9);
z-index: 10;
}
#status.empty{
opacity: 0;
}
iframe{
position: absolute;
left:0; top:0; right:0; bottom:0;
opacity: 0;
transition: opacity 0;
width: 100%;
height: 100%;
border: 0 transparent;
}
iframe.show{
transition: opacity 1s;
opacity: 1;
}
</style>
</head>
<body id="dcast">
<div id="main" class="fade">
<iframe id="if1"></iframe>
<iframe id="if2"></iframe>
</div>
<div id="status" class="empty">
</div>
<script type="text/javascript" src="https://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript">
var reload_time = 0;
var timer_id = null;
window.onload = function() {
var main = document.getElementById("main");
var status = document.getElementById("status");
var if1 = document.getElementById("if1");
var if2 = document.getElementById("if2");
var current = if2;
var candidate = if1;
main.classList.add("show");
function setStatus(msg) {
if (msg){ status.classList.remove("empty");}
else { status.classList.add("empty"); }
status.textContent = msg;
}
if2.onload = if1.onload = function(e){
var the_if = this;
if (the_if.src.indexOf("dashcast_is_error_page_zz") > 0) {
the_if.src = the_if.getAttribute("target-src");
return;
}
if (the_if === candidate) {
if(timer_id) { window.clearTimeout(timer_id); }
setStatus("");
current.style.zIndex = 2;
candidate.style.zIndex = 3;
candidate.classList.add("show");
var temp = current;
current = candidate;
candidate = temp;
if (reload_time) {
console.log("GOT RELOAD", reload_time)
timer_id = setTimeout(function() {
console.log("RELOADING");
loadFrame(the_if.src, reload_time);
}, reload_time);
}
}
}
function loadFrame(url, reload_time) {
setStatus("Loading: " + url);
window.reload_time = reload_time;
candidate.src="error.html?dashcast_is_error_page_zz";
candidate.setAttribute("target-src", url);
candidate.classList.remove("show");
//candidate.src = url;
}
function loadPage(url) {
setStatus("Force loading: " + url);
window.setTimeout(function() { window.location = url; }, 1000);
}
cast.receiver.logger.setLevelValue(0);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
castReceiverManager.onReady = function(event) {
window.castReceiverManager.setApplicationState("Application ready");
setStatus("Waiting for address")
};
// create a CastMessageBus to handle messages for a custom namespace
window.messageBus = window.castReceiverManager.getCastMessageBus('urn:x-cast:lu.offd.yoctucast');
// handler for the CastMessageBus message event
window.messageBus.onMessage = function(event) {
var msg = JSON.parse(event.data);
if (msg.force) {
return loadPage(msg.url);
}
loadFrame(msg.url, (msg.reload) ? parseInt(msg.reload_time, 10) : 0);
// inform all senders on the CastMessageBus of the incoming message event
// sender message listener will be invoked
window.messageBus.send(event.senderId, event.data);
}
// initialize the CastReceiverManager with an application status message
window.castReceiverManager.start({statusText: "Application is starting"});
};
</script>
</body>
</html>