radioweb/index.html
2019-04-15 01:34:01 +02:00

86 lines
2.0 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<title>APR</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./assets/stylesheets/mini-dark.css">
<link rel="stylesheet" href="./assets/stylesheets/custom.css">
</head>
<body>
<div id="content">
<h1 aria-label="Anarchy Planet Radio">Anarchy PlⒶnet Radio</h1>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
<audio id="player" controls="controls" preload="all" src="https://radio.anarchyplanet.org:8443/radio.ogg">
Your browser does not support the HTML5 Audio element.
</audio>
<ul id="history">
<li><div class="spinner"></div></li>
</ul>
<footer>
<p></p>
</footer>
</div>
</div>
</div>
</div>
<script>
var url = 'wss://radio.anarchyplanet.org/ws';
var audioUrl = "https://radio.anarchyplanet.org:8443/radio.ogg";
var player = document.getElementById('player');
player.onerror = play;
player.onended = play;
var hist = document.getElementById("history");
function update(msg) {
document.title = msg.data + " - APR";
hist.insertAdjacentHTML("afterbegin", `<li>${msg.data}</li>`);
if(hist.childElementCount >= 10) {
hist.removeChild(hist.lastChild);
}
};
function connect() {
var ws = new WebSocket(url);
ws.onopen = function(e) {
hist.innerHTML = "";
};
ws.onclose = function(e) {
hist.innerHTML = '<li><div class="spinner"></div></li>';
setTimeout(connect, 1000);
};
ws.onerror = function(e) {
ws.close();
};
ws.onmessage = function(e) {
update(e);
};
}
function play(e) {
if(e !== undefined) console.log(e);
var rng = Math.floor(Math.random() * 1000000);
player.src = audioUrl + '?nocache=' + rng;
player.load();
player.play();
}
play();
connect();
</script>
<noscript>Enable javascript for song information.</noscript>
</body>
</html>