diff --git a/assets/api_keys_template.json b/assets/api_keys_template.json index a5ffe1b..f8a99b6 100644 --- a/assets/api_keys_template.json +++ b/assets/api_keys_template.json @@ -2,5 +2,6 @@ "spinitron": "SPINITRON API KEY HERE", "twilio_account_sid": "TWILIO ACCOUNT SID HERE", "twilio_auth_token": "TWILIO AUTH TOKEN HERE", - "tomorrow_io": " TOMORROW.IO API KEY HERE" + "tomorrow_io": " TOMORROW.IO API KEY HERE", + "streaming_server_now_playing_url": "STREAMING SERVER URL HERE (PROBABLY 'https://azura.wbor.org/api/nowplaying/2' FOR THE NEAR FUTURE)" } diff --git a/assets/funky_transition_images/bird_battle.png b/assets/funky_transition_images/bird_battle.png new file mode 100644 index 0000000..15384de Binary files /dev/null and b/assets/funky_transition_images/bird_battle.png differ diff --git a/assets/funky_transition_images/dog_boot.png b/assets/funky_transition_images/dog_boot.png new file mode 100644 index 0000000..d54c180 Binary files /dev/null and b/assets/funky_transition_images/dog_boot.png differ diff --git a/assets/funky_transition_images/eye_painting.png b/assets/funky_transition_images/eye_painting.png new file mode 100644 index 0000000..a8e7de0 Binary files /dev/null and b/assets/funky_transition_images/eye_painting.png differ diff --git a/assets/funky_transition_images/horse_wine.jpeg b/assets/funky_transition_images/horse_wine.jpeg new file mode 100644 index 0000000..93e7e99 Binary files /dev/null and b/assets/funky_transition_images/horse_wine.jpeg differ diff --git a/assets/funky_transition_images/meat_man.png b/assets/funky_transition_images/meat_man.png new file mode 100644 index 0000000..e266bc7 Binary files /dev/null and b/assets/funky_transition_images/meat_man.png differ diff --git a/assets/funky_transition_images/sponge_purple.jpeg b/assets/funky_transition_images/sponge_purple.jpeg new file mode 100644 index 0000000..5f513d7 Binary files /dev/null and b/assets/funky_transition_images/sponge_purple.jpeg differ diff --git a/src/dashboard_defs/error.rs b/src/dashboard_defs/error.rs index 9ce6112..1821682 100644 --- a/src/dashboard_defs/error.rs +++ b/src/dashboard_defs/error.rs @@ -60,7 +60,7 @@ impl ErrorState { let (subsection_ending, maybe_and) = if is_last_source {(".", "and ")} else {("", "")}; let subsection = if is_first_source { - format!("Internal dashboard error{plural_suffix} from '{source}'{subsection_ending}") + format!("Error{plural_suffix} encountered from '{source}'{subsection_ending}") } else { format!(", {maybe_and}'{source}'{subsection_ending}") diff --git a/src/dashboard_defs/mod.rs b/src/dashboard_defs/mod.rs index 905aba5..481694b 100644 --- a/src/dashboard_defs/mod.rs +++ b/src/dashboard_defs/mod.rs @@ -7,6 +7,7 @@ mod spinitron; mod easing_fns; mod shared_window_state; mod updatable_text_pattern; +mod streaming_server_status; mod funky_remake_transitions; pub mod error; diff --git a/src/dashboard_defs/streaming_server_status.rs b/src/dashboard_defs/streaming_server_status.rs new file mode 100644 index 0000000..e0c60b0 --- /dev/null +++ b/src/dashboard_defs/streaming_server_status.rs @@ -0,0 +1,70 @@ +use crate::{ + request, + dashboard_defs::shared_window_state::SharedWindowState, + + window_tree::{ + Window, + WindowContents, + WindowUpdaterParams + }, + + utility_types::{ + vec2f::Vec2f, + generic_result::*, + update_rate::UpdateRate, + dynamic_optional::DynamicOptional, + continually_updated::{ContinuallyUpdated, Updatable} + } +}; + +#[derive(Clone)] +struct ServerStatusChecker { + url: String, + num_retries: u8 +} + +impl ServerStatusChecker { + fn new(url: &str, num_retries: u8) -> Self { + Self {url: url.to_owned(), num_retries} + } +} + +impl Updatable for ServerStatusChecker { + type Param = (); + + async fn update(&mut self, _: &Self::Param) -> MaybeError { + for _ in 0..self.num_retries { + match request::get(&self.url).await { + Ok(_) => return Ok(()), + Err(_) => continue + } + } + + error_msg!("Could not reach the streaming server!") + } +} + +fn server_status_updater_fn(params: WindowUpdaterParams) -> MaybeError { + let inner_shared_state = params.shared_window_state.get_mut::(); + let individual_window_state = params.window.get_state_mut::>(); + individual_window_state.update(&(), &mut inner_shared_state.error_state)?; + Ok(()) +} + +pub async fn make_streaming_server_status_window(url: &str, ping_rate: UpdateRate, num_retries: u8) -> Window { + let pinger_updater = ContinuallyUpdated::new( + &ServerStatusChecker::new(url, num_retries), + &(), + "the online streaming server" + ).await; + + Window::new( + Some((server_status_updater_fn, ping_rate)), + DynamicOptional::new(pinger_updater), + WindowContents::Nothing, + None, + Vec2f::ZERO, + Vec2f::ZERO, + None + ) +} diff --git a/src/dashboard_defs/themes/barebones.rs b/src/dashboard_defs/themes/barebones.rs index 6a36840..9e555b3 100644 --- a/src/dashboard_defs/themes/barebones.rs +++ b/src/dashboard_defs/themes/barebones.rs @@ -29,6 +29,7 @@ use crate::{ twilio::{make_twilio_window, TwilioState}, surprise::{make_surprise_window, SurpriseCreationInfo}, clock::{ClockHandConfig, ClockHandConfigs, ClockHands}, + streaming_server_status::make_streaming_server_status_window, spinitron::{make_spinitron_windows, SpinitronModelWindowInfo, SpinitronModelWindowsInfo} } }; @@ -168,6 +169,13 @@ pub async fn make_dashboard( &all_model_windows_info, shared_update_rate ); + ////////// Making a streaming server status window + + let streaming_server_status_window = make_streaming_server_status_window( + &api_keys.streaming_server_now_playing_url, + update_rate_creator.new_instance(5.0), 3 + ).await; + ////////// Making an error window let error_window = make_error_window( @@ -348,7 +356,7 @@ pub async fn make_dashboard( ////////// Making some static texture windows - let mut all_main_windows = vec![twilio_window, weather_window, credit_window]; + let mut all_main_windows = vec![twilio_window, weather_window, credit_window, streaming_server_status_window]; all_main_windows.extend(spinitron_windows); add_static_texture_set(&mut all_main_windows, &main_static_texture_info, &main_static_texture_creation_info, texture_pool); diff --git a/src/dashboard_defs/themes/retro_room.rs b/src/dashboard_defs/themes/retro_room.rs index 4770b1d..1fe68c0 100644 --- a/src/dashboard_defs/themes/retro_room.rs +++ b/src/dashboard_defs/themes/retro_room.rs @@ -29,6 +29,7 @@ use crate::{ twilio::{make_twilio_window, TwilioState}, surprise::{make_surprise_window, SurpriseCreationInfo}, clock::{ClockHandConfig, ClockHandConfigs, ClockHands}, + streaming_server_status::make_streaming_server_status_window, spinitron::{make_spinitron_windows, SpinitronModelWindowInfo, SpinitronModelWindowsInfo} } }; @@ -161,6 +162,13 @@ pub async fn make_dashboard( &all_model_windows_info, shared_update_rate ); + ////////// Making a streaming server status window + + let streaming_server_status_window = make_streaming_server_status_window( + &api_keys.streaming_server_now_playing_url, + update_rate_creator.new_instance(5.0), 3 + ).await; + ////////// Making an error window let error_window = make_error_window( @@ -349,7 +357,7 @@ pub async fn make_dashboard( let mut all_main_windows = Vec::new(); all_main_windows.extend(spinitron_windows); - all_main_windows.extend([twilio_window, credit_window, clock_window, weather_window]); + all_main_windows.extend([twilio_window, credit_window, clock_window, weather_window, streaming_server_status_window]); add_static_texture_set(&mut all_main_windows, &main_static_texture_info, &main_static_texture_creation_info, texture_pool); /* The error window goes last (so that it can manage diff --git a/src/dashboard_defs/themes/shared_utils.rs b/src/dashboard_defs/themes/shared_utils.rs index f6dd8b3..4e2b6f7 100644 --- a/src/dashboard_defs/themes/shared_utils.rs +++ b/src/dashboard_defs/themes/shared_utils.rs @@ -18,9 +18,10 @@ use crate::{ #[derive(serde::Deserialize)] pub struct ApiKeys { pub spinitron: String, - pub tomorrow_io: String, pub twilio_account_sid: String, - pub twilio_auth_token: String + pub twilio_auth_token: String, + pub tomorrow_io: String, + pub streaming_server_now_playing_url: String // Not really an API key, but this is the best place to put it anyways } ////////// diff --git a/src/dashboard_defs/themes/standard.rs b/src/dashboard_defs/themes/standard.rs index 14e278c..6449524 100644 --- a/src/dashboard_defs/themes/standard.rs +++ b/src/dashboard_defs/themes/standard.rs @@ -29,6 +29,7 @@ use crate::{ twilio::{make_twilio_window, TwilioState}, surprise::{make_surprise_window, SurpriseCreationInfo}, clock::{ClockHandConfig, ClockHandConfigs, ClockHands}, + streaming_server_status::make_streaming_server_status_window, spinitron::{make_spinitron_windows, SpinitronModelWindowInfo, SpinitronModelWindowsInfo} } }; @@ -163,6 +164,13 @@ pub async fn make_dashboard( &all_model_windows_info, shared_update_rate ); + ////////// Making a streaming server status window + + let streaming_server_status_window = make_streaming_server_status_window( + &api_keys.streaming_server_now_playing_url, + update_rate_creator.new_instance(5.0), 3 + ).await; + ////////// Making an error window let error_window = make_error_window( @@ -352,7 +360,7 @@ pub async fn make_dashboard( ////////// Making some static texture windows - let mut all_main_windows = vec![twilio_window, credit_window]; + let mut all_main_windows = vec![twilio_window, credit_window, streaming_server_status_window]; all_main_windows.extend(spinitron_windows); add_static_texture_set(&mut all_main_windows, &main_static_texture_info, &main_static_texture_creation_info, texture_pool); diff --git a/src/dashboard_defs/weather.rs b/src/dashboard_defs/weather.rs index 2153e21..2ca61aa 100644 --- a/src/dashboard_defs/weather.rs +++ b/src/dashboard_defs/weather.rs @@ -105,7 +105,7 @@ impl Updatable for WeatherStateData { ////////// // TODO: use the updatable text pattern here -pub fn weather_updater_fn(params: WindowUpdaterParams) -> MaybeError { +fn weather_updater_fn(params: WindowUpdaterParams) -> MaybeError { let inner_shared_state = params.shared_window_state.get_mut::(); let individual_window_state = params.window.get_state_mut::>();