-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
43 lines (39 loc) · 1.3 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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Which Bus - skyqrose</title>
<script src="/js/elm.js"></script>
<link rel="stylesheet" type="text/css" href="https://rsms.me/inter/inter.css">
<meta name=viewport content="width=400">
</head>
<body>
<noscript>
JavaScript is required for this page
</noscript>
<script>
var eventNames = ["reset", "add", "update", "remove"];
var app = Elm.Main.init();
var eventSource = undefined;
app.ports.startStream.subscribe(function (url) {
if (eventSource !== undefined) {
eventSource.close();
}
eventSource = new EventSource(url);
for (i = 0; i < eventNames.length; i++) {
let eventName = eventNames[i];
console.log("adding " + eventName);
eventSource.addEventListener(eventName, function (eventData) {
console.log(eventName);
console.log(eventData);
app.ports.streamEventPort.send({
eventName: eventName,
data: JSON.parse(eventData.data),
});
}, false);
}
console.log("watching");
})
</script>
</body>
</html>