From 5e966b872c8db4d848cd0009c7ba02fc2ce78744 Mon Sep 17 00:00:00 2001 From: scoobybejesus <21372487+scoobybejesus@users.noreply.github.com> Date: Sun, 8 Aug 2021 13:00:30 -0400 Subject: [PATCH] Websocket only sends new track (or updated name) --- ircradio/routes.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ircradio/routes.py b/ircradio/routes.py index 9a56514..eadaa80 100644 --- a/ircradio/routes.py +++ b/ircradio/routes.py @@ -113,7 +113,8 @@ async def user_library(): @app.websocket("/ws") -+async def np(): +async def np(): + last_song = "" while True: """get current song from history""" history = Radio.history() @@ -124,7 +125,9 @@ async def user_library(): song = history[0] val = song.title - data = json.dumps({"now_playing": val}) + if val != last_song: + data = json.dumps({"now_playing": val}) + await websocket.send(f"{data}") - await websocket.send(f"{data}") + last_song = val await asyncio.sleep(5)