feat: ✨ rtc receive offer, receive answer
This commit is contained in:
parent
f781afe995
commit
96199f71ef
4 changed files with 134 additions and 33 deletions
|
@ -14,7 +14,11 @@ use leptos::{
|
|||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::HtmlAudioElement;
|
||||
|
||||
use crate::{media::audio, rtc::offer, signal::start_signalling};
|
||||
use crate::{
|
||||
media::audio,
|
||||
rtc::{answer, offer},
|
||||
signal::start_signalling,
|
||||
};
|
||||
|
||||
pub fn app() -> impl IntoView {
|
||||
let audio_stream = LocalResource::new(|| audio());
|
||||
|
@ -42,7 +46,12 @@ pub fn app() -> impl IntoView {
|
|||
.fallback(|| button().child("Sad Button"))
|
||||
.build();
|
||||
let username = signal(String::from(""));
|
||||
(Show(props), signalling(username), rtc(username.0))
|
||||
(
|
||||
Show(props),
|
||||
signalling(username),
|
||||
rtc_offer(username.0),
|
||||
rtc_answer(username.0),
|
||||
)
|
||||
}
|
||||
|
||||
fn signalling(username: (ReadSignal<String>, WriteSignal<String>)) -> impl IntoView {
|
||||
|
@ -70,16 +79,30 @@ fn signalling(username: (ReadSignal<String>, WriteSignal<String>)) -> impl IntoV
|
|||
(signalling_server_input, signalling_submit_button)
|
||||
}
|
||||
|
||||
fn rtc(username: ReadSignal<String>) -> impl IntoView {
|
||||
let rtc_trigger = move || {
|
||||
fn rtc_offer(username: ReadSignal<String>) -> impl IntoView {
|
||||
let offer_trigger = move || {
|
||||
spawn_local(offer(username.get()));
|
||||
};
|
||||
|
||||
let rtc_start_button = button()
|
||||
let offer_button = button()
|
||||
.on(ev::click, move |event| {
|
||||
event.prevent_default();
|
||||
rtc_trigger();
|
||||
offer_trigger();
|
||||
})
|
||||
.child("RTC Offer");
|
||||
rtc_start_button
|
||||
offer_button
|
||||
}
|
||||
|
||||
fn rtc_answer(username: ReadSignal<String>) -> impl IntoView {
|
||||
let answer_trigger = move || {
|
||||
spawn_local(answer(username.get()));
|
||||
};
|
||||
|
||||
let answer_button = button()
|
||||
.on(ev::click, move |event| {
|
||||
event.prevent_default();
|
||||
answer_trigger();
|
||||
})
|
||||
.child("RTC Answer");
|
||||
answer_button
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue