-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (85 loc) · 2.29 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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Birb Cam™</title>
<!-- https://github.com/jmhobbs/birb-cam -->
<script src="//cdn.jsdelivr.net/npm/hls.js@1"></script>
<style>
body {
text-align: center;
font-family: Avenir, Montserrat, Corbel, 'URW Gothic', source-sans-pro, sans-serif;
}
h1 {
margin: 0;
padding: 0;
}
#wrap {
max-width: 1440px;
width: 100%;
margin: 0 auto;
}
#container{
display: flex;
justify-content: center;
}
video {
width: 100%;
height: 100%;
max-width: 1440px;
max-height: 810px;
}
#error {
display: none;
border: 1px solid red;
background: lightpink;
color: black;
padding: 10px 0;
}
</style>
</head>
<body>
<div id="wrap">
<h1>BIRB CAM</h1>
<p>
Hastily assembled by <a href="https://noc.social/@jmhobbs">@jmhobbs</a> -
Current Birb Watchers: <strong id="count">?</strong>
</p>
<p id="error"></p>
<div id="container"><video id="video" controls autoplay muted></video></div>
</div>
<script>
var error = document.getElementById("error");
var clearErrorTimout = null;
if (Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
video.play();
});
hls.on(Hls.Events.ERROR, function (_, data) {
console.error(data);
error.innerText = data.error.message;
error.style.display = "block";
if (clearErrorTimout) {
clearTimeout(clearErrorTimout);
}
clearErrorTimout = setTimeout(() => {
error.style.display = "none";
}, 5000);
});
hls.loadSource('index.m3u8');
hls.attachMedia(video);
} else {
console.error('HLS is not supported');
}
const count = document.getElementById("count");
const wsUrl = new URL("/ws", window.location.href);
wsUrl.protocol = wsUrl.protocol.replace("http", "ws");
const ws = new WebSocket(wsUrl.href);
ws.onmessage = (event) => {
count.innerText = event.data;
};
</script>
</body>
</html>