mirror of
https://git.wownero.com/dsc/ircradio.git
synced 2024-08-15 01:03:15 +00:00
Merge pull request #1 from scoobybejesus/master
Adds Now Playing w/ websocket and <head> script
This commit is contained in:
commit
628279f78a
4 changed files with 56 additions and 2 deletions
|
@ -4,6 +4,8 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Tuple, Optional
|
from typing import Tuple, Optional
|
||||||
from quart import request, render_template, abort, jsonify
|
from quart import request, render_template, abort, jsonify
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from ircradio.factory import app
|
from ircradio.factory import app
|
||||||
|
@ -108,3 +110,24 @@ async def user_library():
|
||||||
by_karma = []
|
by_karma = []
|
||||||
|
|
||||||
return await render_template("library.html", name=name, by_date=by_date, by_karma=by_karma)
|
return await render_template("library.html", name=name, by_date=by_date, by_karma=by_karma)
|
||||||
|
|
||||||
|
|
||||||
|
@app.websocket("/ws")
|
||||||
|
async def np():
|
||||||
|
last_song = ""
|
||||||
|
while True:
|
||||||
|
"""get current song from history"""
|
||||||
|
history = Radio.history()
|
||||||
|
val = ""
|
||||||
|
if not history:
|
||||||
|
val = f"Nothing is playing?!"
|
||||||
|
else:
|
||||||
|
song = history[0]
|
||||||
|
val = song.title
|
||||||
|
|
||||||
|
if val != last_song:
|
||||||
|
data = json.dumps({"now_playing": val})
|
||||||
|
await websocket.send(f"{data}")
|
||||||
|
|
||||||
|
last_song = val
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
|
|
@ -30,9 +30,29 @@
|
||||||
<title>IRC!Radio</title>
|
<title>IRC!Radio</title>
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
<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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
{% block content %} {% endblock %}
|
{% block content %} {% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
<p>Enjoy the music :)</p>
|
<p>Enjoy the music :)</p>
|
||||||
<hr>
|
<hr>
|
||||||
<audio controls src="/{{ settings.icecast2_mount }}">Your browser does not support the<code>audio</code> element.</audio>
|
<audio controls src="/{{ settings.icecast2_mount }}">Your browser does not support the<code>audio</code> element.</audio>
|
||||||
|
<p> </p>
|
||||||
|
<h5>Now playing: </h5>
|
||||||
|
<div id="now_playing">Nothing here yet</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<h4>Command list:</h4>
|
<h4>Command list:</h4>
|
||||||
|
@ -62,4 +65,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -45,4 +45,12 @@ server {
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
proxy_set_header X-Forwarded-For $remote_addr;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /ws {
|
||||||
|
proxy_pass http://{{ host }}:{{ port }}/ws;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "Upgrade";
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue