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-11 04:58:16 +03:00
|
|
|
|
2025-04-25 04:54:41 +03:00
|
|
|
use crate::{media::audio, 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-26 03:34:07 +03:00
|
|
|
|
|
|
|
let props = ShowProps::builder()
|
2025-04-02 03:27:59 +03:00
|
|
|
.when(move || audio_stream.read().is_some())
|
|
|
|
.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 |_| {
|
|
|
|
log!("{:#?}", webrtc_offer.get_status());
|
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 |_| {
|
|
|
|
log!("{:#?}", webrtc_answer.get_status());
|
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
|
|
|
}
|