feat: ✨ webrtc ice candidate handling
This commit is contained in:
parent
978f082146
commit
7bf876b87b
6 changed files with 174 additions and 284 deletions
|
@ -1,25 +1,15 @@
|
|||
use leptos::{
|
||||
IntoView,
|
||||
attr::Value,
|
||||
ev,
|
||||
html::{ElementChild, button, form, input},
|
||||
IntoView, ev,
|
||||
html::{ElementChild, button},
|
||||
logging::log,
|
||||
prelude::{
|
||||
BindAttribute, Get, OnAttribute, Read, ReadSignal, Show, ShowProps, ToChildren,
|
||||
WriteSignal, signal,
|
||||
},
|
||||
prelude::{OnAttribute, Read, Show, ShowProps, ToChildren},
|
||||
server::LocalResource,
|
||||
task::spawn_local,
|
||||
};
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::HtmlAudioElement;
|
||||
|
||||
use crate::{
|
||||
media::audio,
|
||||
rtc::{answer, offer},
|
||||
signal::send_auth,
|
||||
sleep,
|
||||
};
|
||||
use crate::media::audio;
|
||||
|
||||
pub fn app() -> impl IntoView {
|
||||
let audio_stream = LocalResource::new(|| audio());
|
||||
|
@ -46,75 +36,5 @@ pub fn app() -> impl IntoView {
|
|||
}))
|
||||
.fallback(|| button().child("Sad Button"))
|
||||
.build();
|
||||
let username = signal(String::from(""));
|
||||
(Show(props), signalling(username), rtc_offer(), rtc_answer())
|
||||
}
|
||||
|
||||
fn signalling(username: (ReadSignal<String>, WriteSignal<String>)) -> impl IntoView {
|
||||
let signalling_trigger = move || {
|
||||
spawn_local(async move { send_auth(&username.0.get()).await.unwrap() });
|
||||
};
|
||||
let signalling_server_input = form()
|
||||
.child(
|
||||
input()
|
||||
.bind(Value, username)
|
||||
.placeholder("Some Username")
|
||||
.r#type("text"),
|
||||
)
|
||||
.on(ev::submit, move |event| {
|
||||
event.prevent_default();
|
||||
signalling_trigger();
|
||||
});
|
||||
|
||||
let signalling_submit_button = button()
|
||||
.on(ev::click, move |event| {
|
||||
event.prevent_default();
|
||||
signalling_trigger();
|
||||
})
|
||||
.child("Signal");
|
||||
(signalling_server_input, signalling_submit_button)
|
||||
}
|
||||
|
||||
fn rtc_offer() -> impl IntoView {
|
||||
let offer_trigger = move || {
|
||||
spawn_local(async move {
|
||||
let peer_connection = offer(audio().await).await;
|
||||
let audio_stream = audio().await;
|
||||
peer_connection.add_stream(&audio_stream);
|
||||
loop {
|
||||
log!("{:#?}", peer_connection.ice_connection_state());
|
||||
log!("{:#?}", peer_connection.get_remote_streams());
|
||||
sleep(1000).await;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let offer_button = button()
|
||||
.on(ev::click, move |event| {
|
||||
event.prevent_default();
|
||||
offer_trigger();
|
||||
})
|
||||
.child("RTC Offer");
|
||||
offer_button
|
||||
}
|
||||
|
||||
fn rtc_answer() -> impl IntoView {
|
||||
let answer_trigger = move || {
|
||||
spawn_local(async move {
|
||||
let peer_connection = answer(audio().await).await;
|
||||
loop {
|
||||
log!("{:#?}", peer_connection.ice_connection_state());
|
||||
log!("{:#?}", peer_connection.get_remote_streams());
|
||||
sleep(1000).await;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let answer_button = button()
|
||||
.on(ev::click, move |event| {
|
||||
event.prevent_default();
|
||||
answer_trigger();
|
||||
})
|
||||
.child("RTC Answer");
|
||||
answer_button
|
||||
Show(props)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue