2025-04-02 03:27:59 +03:00
|
|
|
use leptos::{
|
2025-04-23 17:35:47 +03:00
|
|
|
IntoView, ev,
|
|
|
|
html::{ElementChild, button},
|
|
|
|
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-25 04:54:41 +03:00
|
|
|
let offer_props = ShowProps::builder()
|
2025-04-02 03:27:59 +03:00
|
|
|
.when(move || audio_stream.read().is_some())
|
|
|
|
.children(ToChildren::to_children(move || {
|
|
|
|
button()
|
2025-04-25 04:54:41 +03:00
|
|
|
.on(ev::click, move |_| {
|
|
|
|
WebRTC::init(Some(audio_stream), None, None);
|
|
|
|
LocalResource::new(|| WebRTC::offer());
|
2025-04-02 03:27:59 +03:00
|
|
|
})
|
2025-04-25 04:54:41 +03:00
|
|
|
.child("Offer")
|
2025-04-02 03:27:59 +03:00
|
|
|
.into_view()
|
|
|
|
}))
|
2025-04-25 04:54:41 +03:00
|
|
|
.fallback(|| button().child("Sad Offer Button"))
|
2025-04-02 03:27:59 +03:00
|
|
|
.build();
|
2025-04-25 04:54:41 +03:00
|
|
|
|
|
|
|
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))
|
2025-04-02 03:27:59 +03:00
|
|
|
}
|