got connections working

This commit is contained in:
Nickiel12 2024-08-20 20:58:09 -07:00
parent 39f26c19c6
commit 1dd6d1a06a
2 changed files with 27 additions and 10 deletions

2
Cargo.lock generated
View file

@ -2500,7 +2500,7 @@ dependencies = [
[[package]] [[package]]
name = "vcs-common" name = "vcs-common"
version = "0.1.0" 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 = [ dependencies = [
"async-channel", "async-channel",
"bincode", "bincode",

View file

@ -9,7 +9,7 @@ use tracing::{error, info};
use webrtc::{ use webrtc::{
api::media_engine::{MIME_TYPE_VP8, MIME_TYPE_VP9}, api::media_engine::{MIME_TYPE_VP8, MIME_TYPE_VP9},
ice_transport::ice_connection_state::RTCIceConnectionState, 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, rtp_transceiver::rtp_codec::RTCRtpCodecCapability,
track::track_local::{ track::track_local::{
track_local_static_rtp::TrackLocalStaticRTP, TrackLocal, TrackLocalWriter, track_local_static_rtp::TrackLocalStaticRTP, TrackLocal, TrackLocalWriter,
@ -25,10 +25,9 @@ mod web_rtc;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Error> { async fn main() -> Result<(), Error> {
// TRACING SETUP // TRACING SETUP
let sub = tracing_subscriber::FmtSubscriber::new(); let _sub = tracing_subscriber::fmt()
if let Err(e) = tracing::subscriber::set_global_default(sub) { .with_max_level(tracing_subscriber::filter::LevelFilter::TRACE)
panic!("Could not set tracing global: {e}"); .init();
}
let config = config::load_config(); let config = config::load_config();
@ -50,8 +49,10 @@ async fn main() -> Result<(), Error> {
Result<(AppSender, AppReceiver), tokio_tungstenite::tungstenite::Error>, Result<(AppSender, AppReceiver), tokio_tungstenite::tungstenite::Error>,
>(); >();
let rt = tokio::runtime::Handle::current();
// connect to remote server // 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_sender: AppSender;
let app_receiver: AppReceiver; let app_receiver: AppReceiver;
@ -69,19 +70,35 @@ async fn main() -> Result<(), Error> {
} }
info!("Freshly delivered sender is closed?: {:?}", app_sender.is_closed());
let peer_connection = web_rtc::setup_webrtc().await; 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 { info!("Offer sent!");
match msg {
ApplicationMessage::WebRTCPacket(pkt) => { 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}"); peer_connection.set_remote_description(pkt).await.expect("The remote description caused an error! {e}");
break; 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 answer = peer_connection.create_answer(None).await.expect("Couldn't create an answer from the peer connection");