Websocket only sends new track (or updated name)

This commit is contained in:
scoobybejesus 2021-08-08 13:00:30 -04:00 committed by GitHub
parent c43ad4bffd
commit 5e966b872c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)