From 570cba36f0afd6e66661be7763c13a8f9abdaa48 Mon Sep 17 00:00:00 2001 From: zeph Date: Fri, 12 Aug 2022 06:21:30 -0400 Subject: [PATCH] add missing state --- static/js/spotify_widget.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/static/js/spotify_widget.js b/static/js/spotify_widget.js index 477f618..4d83a33 100644 --- a/static/js/spotify_widget.js +++ b/static/js/spotify_widget.js @@ -8,9 +8,14 @@ var content = div.querySelector(".cover-text"); console.log("[ws] asked server to initiate connection..") socket.emit("spotify_status", "listen"); -socket.on("api_update", (song_data) => { - image.src = song_data.cover - text.innerHTML = `${song_data.title} - ${song_data.album}
${song_data.artist}
${song_data.position}/${song_data.duration}`; +socket.on("api_update", (song_data) => { + if (!song_data.position) { + image.src = "https://thatalex.dev/static/bad.png" + text.innerHTML = "Uh oh!
There isn't an active song.
Try again later." + } else { + image.src = song_data.cover + text.innerHTML = `${song_data.title} - ${song_data.album}
${song_data.artist}
${song_data.position}/${song_data.duration}`; + } }); // on connect + error events