-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
217 lines (184 loc) · 6.69 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html>
<head>
<title>TokenViewer</title>
<style type="text/css">
html {
height: 100%;
padding: 0;
width: 100%;
}
body {
overflow: hidden;
height: 100%;
padding: 0;
margin: 0;
background: black url("loading.png") no-repeat 50% 50%;
}
#main {
height: 100%;
background: black url("bg1.png") no-repeat 50% 50%;
opacity: 0;
transition: opacity 4s ease;
}
#main, iframe {
background: black url("bg1.png") no-repeat 50% 50%;
}
#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="tokenviewer">
<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="//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"></script>
<script type="text/javascript">
var reload_time = 0;
var timer_id = null;
// Taken from: https://github.com/home-assistant/frontend/blob/dev/cast/src/receiver/entrypoint.ts
function playDummyMedia() {
const loadRequestData = new cast.framework.messages.LoadRequestData();
loadRequestData.autoplay = true;
loadRequestData.media = new cast.framework.messages.MediaInformation();
loadRequestData.media.contentId = "https://lindsgil.github.io/custom-web-receiver/loading.png";
loadRequestData.media.contentType = "image/jpeg";
loadRequestData.media.streamType = cast.framework.messages.StreamType.NONE;
const metadata = new cast.framework.messages.GenericMediaMetadata();
metadata.title = "Dummy " + (new Date().toTimeString());
loadRequestData.media.metadata = metadata;
loadRequestData.requestId = 0;
window.playerManager.load(loadRequestData);
window.setTimeout(playDummyMedia, 60 * 9 * 1000);
}
function removeTouchControls() {
var controls = document.body.querySelector("touch-controls");
if (controls) {
controls.remove();
}
}
function setupMutationObserver() {
// This is to allow the touch display to work
const observer = new MutationObserver(removeTouchControls);
observer.observe(document.body, { childList: true, subtree: true });
}
function createMediaPlayer() {
const mediaPlayer = document.createElement("cast-media-player");
mediaPlayer.style.display = "none";
document.body.append(mediaPlayer);
setupMutationObserver();
}
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);
}
createMediaPlayer();
window.castReceiverContext = cast.framework.CastReceiverContext.getInstance();
window.castReceiverContext.setLoggerLevel(cast.framework.LoggerLevel.DEBUG);
window.castReceiverContext.addEventListener(cast.framework.system.EventType.READY, function(event) {
window.castReceiverContext.setApplicationState("Application ready");
setStatus("Waiting for address")
});
window.playerManager = window.castReceiverContext.getPlayerManager();
const options = new cast.framework.CastReceiverOptions();
const customNS = "urn:x-cast:es.offd.tokenviewer";
options.customNamespaces = {};
options.customNamespaces[customNS] = cast.framework.system.MessageType.JSON;
window.castReceiverContext.addCustomMessageListener(customNS, function(event) {
var msg = event.data;
if (msg.force) {
return loadPage(msg.url);
}
playDummyMedia();
loadFrame(msg.url, (msg.reload) ? parseInt(msg.reload_time, 10) : 0);
// inform all senders on the message bus of the incoming message event
// sender message listener will be invoked
window.castReceiverContext.sendCustomMessage(customNS, event.senderId, event.data);
});
options.statusText = "Application is starting";
options.disableIdleTimeout = true;
// initialize the CastReceiverContext with options
window.castReceiverContext.start(options);
};
</script>
</body>
</html>