Skip to content

Commit

Permalink
Merge branch 'main' of github.com:WBOR-91-1-FM/wbor-studio-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
CaspianA1 committed Jan 21, 2025
2 parents e5f0865 + f190c3b commit 07be1c4
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 8 deletions.
3 changes: 2 additions & 1 deletion assets/api_keys_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
Binary file added assets/funky_transition_images/bird_battle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/funky_transition_images/dog_boot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/funky_transition_images/eye_painting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/funky_transition_images/horse_wine.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/funky_transition_images/meat_man.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/dashboard_defs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
1 change: 1 addition & 0 deletions src/dashboard_defs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 70 additions & 0 deletions src/dashboard_defs/streaming_server_status.rs
Original file line number Diff line number Diff line change
@@ -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::<SharedWindowState>();
let individual_window_state = params.window.get_state_mut::<ContinuallyUpdated<ServerStatusChecker>>();
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
)
}
10 changes: 9 additions & 1 deletion src/dashboard_defs/themes/barebones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
};
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 9 additions & 1 deletion src/dashboard_defs/themes/retro_room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
};
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/dashboard_defs/themes/shared_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

//////////
Expand Down
10 changes: 9 additions & 1 deletion src/dashboard_defs/themes/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
};
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/dashboard_defs/weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<SharedWindowState>();
let individual_window_state = params.window.get_state_mut::<ContinuallyUpdated<WeatherStateData>>();

Expand Down

0 comments on commit 07be1c4

Please sign in to comment.