Skip to content

Commit

Permalink
Now displaying the status of the online streaming server in the littl…
Browse files Browse the repository at this point in the history
…e pop-up error window. If it's down, something will display there.
  • Loading branch information
CaspianA1 committed Jan 11, 2025
1 parent 57d9275 commit 1a32679
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
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
69 changes: 69 additions & 0 deletions src/dashboard_defs/streaming_server_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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 {
num_retries: u8
}

impl ServerStatusChecker {
fn new(num_retries: u8) -> Self {
Self {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("https://azura.wbor.org/api/nowplaying/2").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(ping_rate: UpdateRate, num_retries: u8) -> Window {
let pinger_updater = ContinuallyUpdated::new(
&ServerStatusChecker::new(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
)
}
9 changes: 8 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,12 @@ 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(
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 +355,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
9 changes: 8 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,12 @@ 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(
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 +356,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
9 changes: 8 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,12 @@ 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(
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 +359,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 comments on commit 1a32679

@mdrxy
Copy link
Member

@mdrxy mdrxy commented on 1a32679 Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. Instead of hard coding the URL, we should add it as a config/.env option.

@CaspianA1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i just made it a param

Please sign in to comment.