From e51c8991ac5f66a9be88aa3b2882101b0ab3a1a1 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Tue, 25 Apr 2023 16:44:05 +0200 Subject: [PATCH] Fix SSE --- src/main.rs | 22 +++++++++++----------- templates/index.html | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index baaeb09..4954d39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,18 +127,18 @@ async fn sse(_req: tide::Request<()>, sender: tide::sse::Sender) -> tide::Result loop { stream.write_all(b"idle playlist player\n").await?; - buffer.clear(); - reader.read_line(&mut buffer).await?; - let (_, changed) = buffer - .trim_end() - .split_once(": ") - .ok_or(anyhow!("unexpected response from MPD"))?; - sender.send(changed, "", None).await?; + loop { + buffer.clear(); + reader.read_line(&mut buffer).await?; + if buffer == "OK\n" { + break; + } - buffer.clear(); - reader.read_line(&mut buffer).await?; - if buffer != "OK\n" { - Err(anyhow!("mpd didn't return OK"))?; + let (_, changed) = buffer + .trim_end() + .split_once(": ") + .ok_or(anyhow!("unexpected response from MPD"))?; + sender.send(changed, "", None).await?; } } } diff --git a/templates/index.html b/templates/index.html index d91d3cd..3875377 100644 --- a/templates/index.html +++ b/templates/index.html @@ -187,8 +187,8 @@
-
-
+
+