-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now displaying the status of the online streaming server in the littl…
…e pop-up error window. If it's down, something will display there.
- Loading branch information
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1a32679
There was a problem hiding this comment.
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.
1a32679
There was a problem hiding this comment.
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