fix: now whole gui waits for websocket connection establishment

This commit is contained in:
Ahmet Kaan Gümüş 2025-04-28 05:18:36 +03:00
parent 693c6353a9
commit 16481ed7bd
3 changed files with 16 additions and 14 deletions

View file

@ -7,13 +7,17 @@ use leptos::{
};
use wasm_bindgen_futures::spawn_local;
use crate::{media::audio, webrtc::WebRTC};
use crate::{media::audio, signal::wait_until_communication_is_ready, webrtc::WebRTC};
pub fn app() -> impl IntoView {
let audio_stream = LocalResource::new(|| audio());
let wait_until_communication_is_ready =
LocalResource::new(|| wait_until_communication_is_ready());
let props = ShowProps::builder()
.when(move || audio_stream.read().is_some())
.when(move || {
audio_stream.read().is_some() && wait_until_communication_is_ready.read().is_some()
})
.children(ToChildren::to_children(move || {
let audio_stream = audio_stream.read();
let audio_stream = audio_stream.as_deref().unwrap().clone();

View file

@ -7,6 +7,8 @@ use web_sys::{
wasm_bindgen::{JsCast, prelude::Closure},
};
use crate::sleep;
static SIGNALLING_ADDRESS: &str = "http://192.168.1.3:4546/signal";
thread_local! {
@ -113,8 +115,11 @@ impl SignallingChannel {
.map_err(|err_val| Error::OfferChannelReceive(err_val.to_string()))
}
}
pub fn is_communication_ready() -> bool {
SignallingChannel::is_ready()
pub async fn wait_until_communication_is_ready() {
while !SignallingChannel::is_ready() {
sleep(100).await;
}
}
pub fn send_auth(data: &String) -> Result<(), Error> {

View file

@ -11,12 +11,9 @@ use web_sys::{
wasm_bindgen::{JsCast, JsValue, prelude::Closure},
};
use crate::{
signal::{
is_communication_ready, receive_answer, receive_ice_candidate, receive_offer, send_answer,
send_ice_candidate, send_offer,
},
sleep,
use crate::signal::{
receive_answer, receive_ice_candidate, receive_offer, send_answer, send_ice_candidate,
send_offer,
};
pub struct WebRTC {
@ -107,10 +104,6 @@ impl WebRTC {
}
pub async fn offer(&self) -> Result<(), Error> {
while !is_communication_ready() {
log!("Waiting for Communication State");
sleep(100).await;
}
let offer_promise = self.peer_connection.create_offer();
match JsFuture::from(offer_promise)
.await