]> code.octet-stream.net Git - broadcaster/blob - broadcaster-server/templates/index.html
b688947499a864f36cbecca80beba0839bba4d75
[broadcaster] / broadcaster-server / templates / index.html
1 <script type="text/javascript">
2 function connectWebsocket() {
3 console.log("Attempting to create websocket connection for radio status sync")
4 const cookieValue = document.cookie
5 .split("; ")
6 .find((row) => row.startsWith("broadcast_session="))
7 ?.split("=")[1];
8 const socket = new WebSocket("/web-ws");
9 socket.addEventListener("open", (event) => {
10 socket.send(cookieValue);
11 });
12 socket.addEventListener("message", (event) => {
13 console.log("Received a status update from server")
14 const connected = document.getElementById('connected-radios');
15 connected.innerHTML = event.data;
16 });
17 socket.addEventListener("close", (event) => {
18 console.log("Websocket closed. Will retry in 10 seconds.")
19 setTimeout(connectWebsocket, 10000);
20 });
21 }
22 // initial connection on page load
23 connectWebsocket();
24 </script>
25
26 <h1>Welcome!</h1>
27 {{if .LoggedIn}}
28 <p>Your username is: {{.Username}}.</p>
29 <p><a href="/logout">Log Out</a></p>
30 {{else}}
31 <p><a href="/login">Log In</a></p>
32 {{end}}
33 <p><a href="/files/">File Management</a></p>
34 <p><a href="/playlists/">Playlist Management</a></p>
35 <p><a href="/radios/">Radio Management</a></p>
36 <h2>Connected Radios</h2>
37 <div id="connected-radios">
38 <i>Loading...</i>
39 </div>