diff --git a/src/main.rs b/src/main.rs index 79175b1..169b4f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -250,13 +250,35 @@ fn tracked_events<'a>( } } -#[put("/track/?&")] +#[put("/track/?&", rank = 0)] fn store_pos(id: &str, lat: f32, long: f32, tracking: &State) { if let Some(tracked) = tracking.read().unwrap().get(&id.to_string()) { tracked.write().unwrap().pos = (lat, long); } } +#[put("/track/?&", rank = 1)] +fn set_state(id: &str, inv: bool, col: u8, tracking: &State) -> Option<()> { + let tracking_lock = tracking.read().unwrap(); + let state = &mut tracking_lock + .get(&id.to_string()) + .unwrap() + .write() + .unwrap() + .state; + if let Vieux { + ref mut invisible, + ref mut color, + } = state + { + *invisible = inv; + *color = col; + Some(()) + } else { + None + } +} + #[get("/")] fn index() -> &'static str { "Hello, world!" @@ -285,6 +307,9 @@ fn rocket() -> _ { rocket::build() .attach(Template::fairing()) .manage(RwLock::new(tracking)) - .mount("/", routes![index, store_pos, tracked_view, tracked_events]) + .mount( + "/", + routes![index, store_pos, tracked_view, tracked_events, set_state], + ) .mount("/", FileServer::from(relative!("static"))) } diff --git a/templates/conscrit.html.hbs b/templates/conscrit.html.hbs index 785be2a..21df987 100644 --- a/templates/conscrit.html.hbs +++ b/templates/conscrit.html.hbs @@ -44,6 +44,7 @@ ////////////////////////////////////////////////////////////////////////////// // EVENT LISTENNING + id = "{{id}}"; evtSource = new EventSource("/track/{{id}}/events"); setup_evtlisten_common(); diff --git a/templates/vieux.html.hbs b/templates/vieux.html.hbs index 87f2bf1..ecdd215 100644 --- a/templates/vieux.html.hbs +++ b/templates/vieux.html.hbs @@ -13,9 +13,6 @@ integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ==" crossorigin=""> - - -