diff --git a/src/main.rs b/src/main.rs
index e5bb914..6b32735 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,14 @@
use std::convert::Infallible;
use std::sync::{Arc, Mutex};
+use std::time::Duration;
-use futures_util::StreamExt;
+use futures_util::{stream, StreamExt};
#[allow(unused_imports)] use log::{debug, error, info, trace};
-use rppal::gpio::{ Gpio, Level, Trigger };
+use rppal::gpio::{Gpio, Level, Trigger};
use smallvec::SmallVec;
-use tokio::sync::mpsc;
-use warp::{Filter, sse};
+use tokio::{ sync::mpsc,
+ time::interval };
+use warp::{Filter, sse, sse::ServerSentEvent};
const BUTTON_PIN: u8 = 26;
@@ -51,11 +53,16 @@ async fn main() {
let (tx, rx) = mpsc::channel(1);
clients.lock().unwrap().push(tx);
- let stream = rx.map(|()| {
- debug!("sending sse");
- Ok::<_, Infallible>((sse::event("ring"),
- sse::data("")))
- });
+ let stream = stream::select(
+ interval(Duration::from_secs(5)).map(move |_| {
+ Ok::<_, Infallible>((sse::event("ping"), sse::data("")).into_a())
+ }),
+
+ rx.map(|()| {
+ debug!("sending ring sse");
+ Ok::<_, Infallible>((sse::event("ring"), sse::data("")).into_b())
+ })
+ );
sse::reply(stream)
});
diff --git a/static/main.html b/static/main.html
index fdc9a9f..976df28 100644
--- a/static/main.html
+++ b/static/main.html
@@ -8,12 +8,19 @@
+
+ Ping
+
Ring!