diff --git a/Cargo.lock b/Cargo.lock index 5cb3699..3e6471d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2500,7 +2500,7 @@ dependencies = [ [[package]] name = "vcs-common" version = "0.1.0" -source = "git+https://git.nickiel.net/VCC/vcs-common.git?branch=main#1e37189866720e8d99b22492a78f47d220742831" +source = "git+https://git.nickiel.net/VCC/vcs-common.git?branch=main#0765f70fa773261f38dddb1819aaad47f88e12d7" dependencies = [ "async-channel", "bincode", diff --git a/src/main.rs b/src/main.rs index 1888488..d102fc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use tracing::{error, info}; use webrtc::{ api::media_engine::{MIME_TYPE_VP8, MIME_TYPE_VP9}, ice_transport::ice_connection_state::RTCIceConnectionState, - peer_connection::{peer_connection_state::RTCPeerConnectionState, sdp::session_description::RTCSessionDescription}, + peer_connection::peer_connection_state::RTCPeerConnectionState, rtp_transceiver::rtp_codec::RTCRtpCodecCapability, track::track_local::{ track_local_static_rtp::TrackLocalStaticRTP, TrackLocal, TrackLocalWriter, @@ -25,10 +25,9 @@ mod web_rtc; #[tokio::main] async fn main() -> Result<(), Error> { // TRACING SETUP - let sub = tracing_subscriber::FmtSubscriber::new(); - if let Err(e) = tracing::subscriber::set_global_default(sub) { - panic!("Could not set tracing global: {e}"); - } + let _sub = tracing_subscriber::fmt() + .with_max_level(tracing_subscriber::filter::LevelFilter::TRACE) + .init(); let config = config::load_config(); @@ -50,8 +49,10 @@ async fn main() -> Result<(), Error> { Result<(AppSender, AppReceiver), tokio_tungstenite::tungstenite::Error>, >(); + let rt = tokio::runtime::Handle::current(); + // connect to remote server - tokio::spawn(vcs_common::connect_to_server(format!("ws://{}:{}", config.destination_ip, config.destination_port), send_oneshot)); + tokio::spawn(vcs_common::connect_to_server(format!("ws://{}:{}", config.destination_ip, config.destination_port), send_oneshot, rt)); let app_sender: AppSender; let app_receiver: AppReceiver; @@ -69,20 +70,36 @@ async fn main() -> Result<(), Error> { } + info!("Freshly delivered sender is closed?: {:?}", app_sender.is_closed()); + let peer_connection = web_rtc::setup_webrtc().await; + let offer = peer_connection.create_offer(None).await.unwrap(); + info!("Freshly delivered sender is closed?: {:?}", app_sender.is_closed()); + if let Err(e) = app_sender.send(ApplicationMessage::WebRTCPacket(offer)).await { + error!("Could not send offer to app_sender!"); + panic!("{}", e); + } - while let Ok(msg) = app_receiver.recv().await { - match msg { - ApplicationMessage::WebRTCPacket(pkt) => { + info!("Offer sent!"); + + loop { + match app_receiver.recv().await { + Ok(ApplicationMessage::WebRTCPacket(pkt)) => { + info!("Recieved response package!"); peer_connection.set_remote_description(pkt).await.expect("The remote description caused an error! {e}"); break; } + Err(e) => { + panic!("Channel was closed?!"); + } } } + info!("Get a response assumedly"); + let answer = peer_connection.create_answer(None).await.expect("Couldn't create an answer from the peer connection"); let mut gather_complete = peer_connection.gathering_complete_promise().await;