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:
29
src/main.rs
29
src/main.rs
@@ -64,22 +64,21 @@ async fn main() {
|
|||||||
Ok::<_, Infallible>((sse::event("ping"), sse::data("")).into_a())
|
Ok::<_, Infallible>((sse::event("ping"), sse::data("")).into_a())
|
||||||
}),
|
}),
|
||||||
|
|
||||||
rx.filter_map(|()| async {
|
rx.map(|()| {
|
||||||
if audio_busy() {
|
if !audio_busy() {
|
||||||
debug!("doorbell still ringing, ignoring press");
|
trace!("Playing doorbell chime");
|
||||||
return None;
|
match process::Command::new("mplayer")
|
||||||
}
|
.arg(OUTDOOR_CHIME_FILE)
|
||||||
debug!("Playing doorbell chime");
|
.stdout(process::Stdio::null())
|
||||||
match process::Command::new("mplayer")
|
.stderr(process::Stdio::null())
|
||||||
.arg(OUTDOOR_CHIME_FILE)
|
.spawn() {
|
||||||
.stdout(process::Stdio::null())
|
Ok(child) => { AUDIO_CHILD.with(|cell| cell.replace(Some(child))); },
|
||||||
.stderr(process::Stdio::null())
|
Err(err) => error!("Error playing outdoor chime: {}", err)
|
||||||
.spawn() {
|
};
|
||||||
Ok(child) => { AUDIO_CHILD.with(|cell| cell.replace(Some(child))); },
|
} else { debug!("doorbell still ringing, not playing new chime"); }
|
||||||
Err(err) => error!("Error playing outdoor chime: {}", err)
|
|
||||||
};
|
|
||||||
debug!("sending ring sse");
|
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)
|
sse::reply(stream)
|
||||||
|
|||||||
Reference in New Issue
Block a user