diff --git a/ircradio/routes.py b/ircradio/routes.py index 0a4fd09..eadaa80 100644 --- a/ircradio/routes.py +++ b/ircradio/routes.py @@ -4,6 +4,8 @@ from datetime import datetime from typing import Tuple, Optional from quart import request, render_template, abort, jsonify +import asyncio +import json import settings from ircradio.factory import app @@ -108,3 +110,24 @@ async def user_library(): 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) diff --git a/ircradio/templates/base.html b/ircradio/templates/base.html index 7c4cd48..e13f44e 100644 --- a/ircradio/templates/base.html +++ b/ircradio/templates/base.html @@ -30,9 +30,29 @@ IRC!Radio + + + {% block content %} {% endblock %} - \ No newline at end of file + diff --git a/ircradio/templates/index.html b/ircradio/templates/index.html index bfce5c8..faa94f0 100644 --- a/ircradio/templates/index.html +++ b/ircradio/templates/index.html @@ -12,6 +12,9 @@

Enjoy the music :)


+

+
Now playing:
+
Nothing here yet

Command list:

@@ -62,4 +65,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/ircradio/templates/nginx.jinja2 b/ircradio/templates/nginx.jinja2 index 7f3e8b8..5eea65c 100644 --- a/ircradio/templates/nginx.jinja2 +++ b/ircradio/templates/nginx.jinja2 @@ -45,4 +45,12 @@ server { proxy_set_header X-Forwarded-For $remote_addr; 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; + } }