Script to open websocket for #now_playing updates

This commit is contained in:
scoobybejesus 2021-08-07 22:36:47 -04:00 committed by GitHub
parent c7a48d2bd9
commit 9716feab33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 1 deletions

View File

@ -30,9 +30,29 @@
<title>IRC!Radio</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script>
var ws = new WebSocket('wss://' + document.domain + ':' + location.port + '/ws');
ws.onmessage = function (event) {
// console.log(event.data);
json = JSON.parse(event.data);
np = json.now_playing;
document.querySelector("#now_playing").innerText = np;
// console.log(np);
return false;
};
ws.onclose = function(event) {
console.log("WebSocket is closed now.");
};
</script>
</head>
<body>
{% block content %} {% endblock %}
</body>
</html>
</html>