2025-04-02 03:27:59 +03:00
|
|
|
use leptos::{
|
2025-04-26 03:34:07 +03:00
|
|
|
IntoView,
|
|
|
|
html::{ElementChild, button, label},
|
|
|
|
logging::log,
|
2025-04-23 17:35:47 +03:00
|
|
|
prelude::{OnAttribute, Read, Show, ShowProps, ToChildren},
|
2025-04-02 03:27:59 +03:00
|
|
|
server::LocalResource,
|
|
|
|
};
|
2025-04-27 21:11:18 +03:00
|
|
|
use wasm_bindgen_futures::spawn_local;
|
2025-04-11 04:58:16 +03:00
|
|
|
|
2025-04-28 05:18:36 +03:00
|
|
|
use crate::{media::audio, signal::wait_until_communication_is_ready, webrtc::WebRTC};
|
2025-04-02 03:27:59 +03:00
|
|
|
|
|
|
|
pub fn app() -> impl IntoView {
|
2025-04-11 04:58:16 +03:00
|
|
|
let audio_stream = LocalResource::new(|| audio());
|
2025-04-28 05:18:36 +03:00
|
|
|
let wait_until_communication_is_ready =
|
|
|
|
LocalResource::new(|| wait_until_communication_is_ready());
|
2025-04-26 03:34:07 +03:00
|
|
|
|
|
|
|
let props = ShowProps::builder()
|
2025-04-28 05:18:36 +03:00
|
|
|
.when(move || {
|
|
|
|
audio_stream.read().is_some() && wait_until_communication_is_ready.read().is_some()
|
|
|
|
})
|
2025-04-02 03:27:59 +03:00
|
|
|
.children(ToChildren::to_children(move || {
|
2025-04-26 03:34:07 +03:00
|
|
|
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_offer = webrtc.clone();
|
|
|
|
let offer_button = button()
|
|
|
|
.on(leptos::ev::click, move |_| {
|
2025-04-27 21:11:18 +03:00
|
|
|
let webrtc_offer = webrtc_offer.clone();
|
2025-04-26 03:34:07 +03:00
|
|
|
log!("{:#?}", webrtc_offer.get_status());
|
2025-04-27 21:11:18 +03:00
|
|
|
spawn_local(async move {
|
|
|
|
let offer_result = webrtc_offer.offer().await;
|
|
|
|
log!("Offer Result Is = {:#?}", offer_result);
|
|
|
|
});
|
2025-04-02 03:27:59 +03:00
|
|
|
})
|
2025-04-26 03:34:07 +03:00
|
|
|
.child("Offer");
|
2025-04-25 04:54:41 +03:00
|
|
|
|
2025-04-26 03:34:07 +03:00
|
|
|
let webrtc_answer = webrtc.clone();
|
|
|
|
let answer_button = button()
|
|
|
|
.on(leptos::ev::click, move |_| {
|
2025-04-29 22:58:24 +03:00
|
|
|
let webrtc_answer = webrtc_answer.clone();
|
|
|
|
spawn_local(async move {
|
|
|
|
let answer_result = webrtc_answer.answer().await;
|
|
|
|
log!("Answer Result Is = {:#?}", answer_result);
|
|
|
|
});
|
2025-04-25 04:54:41 +03:00
|
|
|
})
|
2025-04-26 03:34:07 +03:00
|
|
|
.child("Answer");
|
|
|
|
|
|
|
|
(offer_button, answer_button)
|
2025-04-25 04:54:41 +03:00
|
|
|
}))
|
2025-04-26 03:34:07 +03:00
|
|
|
.fallback(|| label().child("NOOOOOOOOOOOO"))
|
2025-04-25 04:54:41 +03:00
|
|
|
.build();
|
|
|
|
|
2025-04-26 03:34:07 +03:00
|
|
|
Show(props)
|
2025-04-02 03:27:59 +03:00
|
|
|
}
|