diff --git a/src/main.rs b/src/main.rs index 1f87f9e..795407d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,6 @@ async fn main() { JsonValue::Number(Number::from( SystemTime::now() .duration_since(UNIX_EPOCH) - .unwrap() .unwrap_or(Duration::from_millis(0)) .as_millis() as i64, )), @@ -127,8 +126,6 @@ async fn main() { let iface: NetworkInterface = iface; if iface.ips.len() > 0 { let ipsv = format!("{}", iface.ips[0]); - let ips: &str = ipsv.split('/').next().unwrap(); - let ips: &str = ipsv.split('/').next().unwrap_or(""); if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") { ip = ips.to_string(); diff --git a/src/omikron/omikron_connection.rs b/src/omikron/omikron_connection.rs index fd54ced..f697951 100644 --- a/src/omikron/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -15,7 +15,6 @@ use hyper::upgrade::Upgraded; use hyper_util::rt::TokioIo; use json::JsonValue; use json::number::Number; -use ratatui::crossterm::event::poll; use std::collections::HashMap; use std::sync::{Arc, LazyLock}; use std::time::{SystemTime, UNIX_EPOCH}; @@ -38,6 +37,8 @@ pub enum ConnectionVariant { pub struct OmikronConnection { pub variant: Arc>, pub user_id: Arc>, + pub(crate) writer: + Arc + Send + Unpin>>>>, waiting: Arc>>>, pingpong: Arc>>>, pub last_ping: Arc>, @@ -69,6 +70,8 @@ impl OmikronConnection { as Box + Send + Unpin>))), waiting: Arc::new(Mutex::new(HashMap::new())), pingpong: Arc::new(Mutex::new(None)), + last_ping: Arc::new(Mutex::new(-1)), + message_send_times: Arc::new(Mutex::new(HashMap::new())), is_connected: Arc::new(Mutex::new(true)), }); let boxed_reader: Box< @@ -155,6 +158,8 @@ impl OmikronConnection { { ACTIVE_TASKS.lock().unwrap().push("Listener".to_string()); + } + tokio::spawn(async move { while let Some(msg) = read_half.next().await { if *SHUTDOWN.read().await { break; @@ -335,6 +340,8 @@ impl OmikronConnection { let other_id = cv .get_data(DataTypes::receiver_id) .unwrap_or(&JsonValue::Null) + .as_i64() + .unwrap_or(0); let now_ms = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() @@ -381,7 +388,9 @@ impl OmikronConnection { cv.get_data(DataTypes::content).unwrap().to_string(), ), ); - + Self::send_message_static( + &writer.clone(), + is_connected, forward.to_json().to_string(), ) .await;