fix: ⚡ browser freezing because of blocking channel
This commit is contained in:
parent
8391ef31ba
commit
1e27b9280e
9 changed files with 172 additions and 386 deletions
|
@ -1,41 +1,48 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use leptos::{
|
||||
IntoView, ev,
|
||||
html::{ElementChild, button},
|
||||
IntoView,
|
||||
html::{ElementChild, button, label},
|
||||
logging::log,
|
||||
prelude::{OnAttribute, Read, Show, ShowProps, ToChildren},
|
||||
server::LocalResource,
|
||||
};
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
use crate::{media::audio, webrtc::WebRTC};
|
||||
|
||||
pub fn app() -> impl IntoView {
|
||||
let audio_stream = LocalResource::new(|| audio());
|
||||
let offer_props = ShowProps::builder()
|
||||
|
||||
let props = ShowProps::builder()
|
||||
.when(move || audio_stream.read().is_some())
|
||||
.children(ToChildren::to_children(move || {
|
||||
button()
|
||||
.on(ev::click, move |_| {
|
||||
WebRTC::init(Some(audio_stream), None, None);
|
||||
LocalResource::new(|| WebRTC::offer());
|
||||
let audio_stream = audio_stream.read();
|
||||
let audio_stream = audio_stream.as_deref().unwrap().clone();
|
||||
|
||||
let webrtc = WebRTC::new(Some(audio_stream), None, None).unwrap();
|
||||
let webrtc = Arc::new(webrtc);
|
||||
let webrtc_init = webrtc.clone();
|
||||
spawn_local(async move { webrtc_init.init().await });
|
||||
|
||||
let webrtc_offer = webrtc.clone();
|
||||
let offer_button = button()
|
||||
.on(leptos::ev::click, move |_| {
|
||||
log!("{:#?}", webrtc_offer.get_status());
|
||||
})
|
||||
.child("Offer")
|
||||
.into_view()
|
||||
.child("Offer");
|
||||
|
||||
let webrtc_answer = webrtc.clone();
|
||||
let answer_button = button()
|
||||
.on(leptos::ev::click, move |_| {
|
||||
log!("{:#?}", webrtc_answer.get_status());
|
||||
})
|
||||
.child("Answer");
|
||||
|
||||
(offer_button, answer_button)
|
||||
}))
|
||||
.fallback(|| button().child("Sad Offer Button"))
|
||||
.fallback(|| label().child("NOOOOOOOOOOOO"))
|
||||
.build();
|
||||
|
||||
let answer_props = ShowProps::builder()
|
||||
.when(move || audio_stream.read().is_some())
|
||||
.children(ToChildren::to_children(move || {
|
||||
button()
|
||||
.on(ev::click, move |_| {
|
||||
WebRTC::init(Some(audio_stream), None, None);
|
||||
LocalResource::new(|| WebRTC::answer());
|
||||
})
|
||||
.child("Answer")
|
||||
.into_view()
|
||||
}))
|
||||
.fallback(|| button().child("Sad Answer Button"))
|
||||
.build();
|
||||
|
||||
(Show(offer_props), Show(answer_props))
|
||||
Show(props)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue