fix: ⚡ now whole gui waits for websocket connection establishment
This commit is contained in:
parent
693c6353a9
commit
16481ed7bd
3 changed files with 16 additions and 14 deletions
|
@ -7,13 +7,17 @@ use leptos::{
|
||||||
};
|
};
|
||||||
use wasm_bindgen_futures::spawn_local;
|
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 {
|
pub fn app() -> impl IntoView {
|
||||||
let audio_stream = LocalResource::new(|| audio());
|
let audio_stream = LocalResource::new(|| audio());
|
||||||
|
let wait_until_communication_is_ready =
|
||||||
|
LocalResource::new(|| wait_until_communication_is_ready());
|
||||||
|
|
||||||
let props = ShowProps::builder()
|
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 || {
|
.children(ToChildren::to_children(move || {
|
||||||
let audio_stream = audio_stream.read();
|
let audio_stream = audio_stream.read();
|
||||||
let audio_stream = audio_stream.as_deref().unwrap().clone();
|
let audio_stream = audio_stream.as_deref().unwrap().clone();
|
||||||
|
|
|
@ -7,6 +7,8 @@ use web_sys::{
|
||||||
wasm_bindgen::{JsCast, prelude::Closure},
|
wasm_bindgen::{JsCast, prelude::Closure},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::sleep;
|
||||||
|
|
||||||
static SIGNALLING_ADDRESS: &str = "http://192.168.1.3:4546/signal";
|
static SIGNALLING_ADDRESS: &str = "http://192.168.1.3:4546/signal";
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
@ -113,8 +115,11 @@ impl SignallingChannel {
|
||||||
.map_err(|err_val| Error::OfferChannelReceive(err_val.to_string()))
|
.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> {
|
pub fn send_auth(data: &String) -> Result<(), Error> {
|
||||||
|
|
|
@ -11,12 +11,9 @@ use web_sys::{
|
||||||
wasm_bindgen::{JsCast, JsValue, prelude::Closure},
|
wasm_bindgen::{JsCast, JsValue, prelude::Closure},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::signal::{
|
||||||
signal::{
|
receive_answer, receive_ice_candidate, receive_offer, send_answer, send_ice_candidate,
|
||||||
is_communication_ready, receive_answer, receive_ice_candidate, receive_offer, send_answer,
|
send_offer,
|
||||||
send_ice_candidate, send_offer,
|
|
||||||
},
|
|
||||||
sleep,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct WebRTC {
|
pub struct WebRTC {
|
||||||
|
@ -107,10 +104,6 @@ impl WebRTC {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn offer(&self) -> Result<(), Error> {
|
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();
|
let offer_promise = self.peer_connection.create_offer();
|
||||||
match JsFuture::from(offer_promise)
|
match JsFuture::from(offer_promise)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue