send ring events even if audio is playing

Multiple clients won't get events if the handler to the first one
starts the audio stream before the other handlers check. Later
handlers always see audio.
This commit is contained in:
2020-10-29 03:33:26 -07:00
parent b70f92f6f4
commit ab81bdb708

View File

@@ -64,12 +64,9 @@ async fn main() {
Ok::<_, Infallible>((sse::event("ping"), sse::data("")).into_a())
}),
rx.filter_map(|()| async {
if audio_busy() {
debug!("doorbell still ringing, ignoring press");
return None;
}
debug!("Playing doorbell chime");
rx.map(|()| {
if !audio_busy() {
trace!("Playing doorbell chime");
match process::Command::new("mplayer")
.arg(OUTDOOR_CHIME_FILE)
.stdout(process::Stdio::null())
@@ -78,8 +75,10 @@ async fn main() {
Ok(child) => { AUDIO_CHILD.with(|cell| cell.replace(Some(child))); },
Err(err) => error!("Error playing outdoor chime: {}", err)
};
} else { debug!("doorbell still ringing, not playing new chime"); }
debug!("sending ring sse");
Some(Ok::<_, Infallible>((sse::event("ring"), sse::data("")).into_b()))
Ok::<_, Infallible>((sse::event("ring"), sse::data("")).into_b())
})
);
sse::reply(stream)