Skip to content

Commit

Permalink
src: webpage: src: Fix WebSocket breaking in higher frequencies
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Nov 4, 2024
1 parent 8ac5e20 commit 99cb33c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/webpage/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ impl Default for App {
"ws:"
};

let options = ewebsock::Options {
// Setting higher to avoid broken pipes at higher frequencies. The default is 10ms.
delay_blocking: std::time::Duration::from_millis(100),
..Default::default()
};

let url = format!("{protocol}//{host}/rest/ws");
let (mavlink_sender, mavlink_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

let stats_frequency = Arc::new(Mutex::new(1.));
Expand All @@ -71,19 +77,19 @@ impl Default for App {
let url = format!("{protocol}//{host}/stats/messages/ws");
let (hub_messages_stats_sender, hub_messages_stats_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

let url = format!("{protocol}//{host}/stats/hub/ws");
let (hub_stats_sender, hub_stats_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

let url = format!("{protocol}//{host}/stats/drivers/ws");
let (drivers_stats_sender, drivers_stats_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

Self {
Expand Down Expand Up @@ -121,30 +127,36 @@ impl App {
"ws:"
};

let options = ewebsock::Options {
// Setting higher to avoid broken pipes at higher frequencies. The default is 10ms.
delay_blocking: std::time::Duration::from_millis(100),
..Default::default()
};

let url = format!("{protocol}//{host}/rest/ws");
let (mavlink_sender, mavlink_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

set_stats_frequency(&self.stats_frequency.clone(), *self.stats_frequency.lock());

let url = format!("{protocol}//{host}/stats/messages/ws");
let (hub_messages_stats_sender, hub_messages_stats_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

let url = format!("{protocol}//{host}/stats/hub/ws");
let (hub_stats_sender, hub_stats_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

let url = format!("{protocol}//{host}/stats/drivers/ws");
let (drivers_stats_sender, drivers_stats_receiver) = {
let url = Url::parse(&url).unwrap().to_string();
connect(url, ewebsock::Options::default()).expect("Can't connect")
connect(url, options.clone()).expect("Can't connect")
};

self.mavlink_sender = mavlink_sender;
Expand Down

0 comments on commit 99cb33c

Please sign in to comment.