Skip to content

Commit

Permalink
Daemon fix RTC connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 19, 2024
1 parent 26ac7b3 commit 1e5618b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions platforms/unix/daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use tower_http::{
cors::{Any, CorsLayer},
trace::{DefaultMakeSpan, TraceLayer},
};
use webrtc::data_channel::data_channel_state::RTCDataChannelState;
use webrtc::data_channel::RTCDataChannel;
use webrtc::ice_transport::ice_server::RTCIceServer;

Expand Down Expand Up @@ -132,16 +133,19 @@ async fn main() {

tokio::spawn(async move {
loop {
let hw_message = receiver.recv().await.unwrap();
let network_data = NetworkData {
r#type: "data".to_string(),
data: hw_message.clone(),
};

dc.send_text(serde_json::to_string(&network_data).unwrap())
.await
.unwrap();
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
if dc.ready_state() == RTCDataChannelState::Open {
let hw_message = receiver.recv().await.unwrap();
let network_data = NetworkData {
r#type: "data".to_string(),
data: hw_message.clone(),
};

dc.send_text(serde_json::to_string(&network_data).unwrap())
.await
.unwrap();
}

tokio::time::sleep(std::time::Duration::from_secs(2)).await;
}
});
}
Expand All @@ -166,7 +170,7 @@ async fn main() {
info!("RTC started");

loop {
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
tokio::time::sleep(std::time::Duration::from_secs(100)).await;
}
});

Expand Down

0 comments on commit 1e5618b

Please sign in to comment.