feat: websocket client

This commit is contained in:
Ahmet Kaan Gümüş 2025-04-22 04:19:52 +03:00
parent 3b122dc4f7
commit 978f082146
5 changed files with 166 additions and 146 deletions

View file

@ -17,7 +17,8 @@ use web_sys::HtmlAudioElement;
use crate::{
media::audio,
rtc::{answer, offer},
signal::start_signalling,
signal::send_auth,
sleep,
};
pub fn app() -> impl IntoView {
@ -46,17 +47,12 @@ pub fn app() -> impl IntoView {
.fallback(|| button().child("Sad Button"))
.build();
let username = signal(String::from(""));
(
Show(props),
signalling(username),
rtc_offer(username.0),
rtc_answer(username.0),
)
(Show(props), signalling(username), rtc_offer(), rtc_answer())
}
fn signalling(username: (ReadSignal<String>, WriteSignal<String>)) -> impl IntoView {
let signalling_trigger = move || {
spawn_local(start_signalling(username.0.get()));
spawn_local(async move { send_auth(&username.0.get()).await.unwrap() });
};
let signalling_server_input = form()
.child(
@ -79,10 +75,17 @@ fn signalling(username: (ReadSignal<String>, WriteSignal<String>)) -> impl IntoV
(signalling_server_input, signalling_submit_button)
}
fn rtc_offer(username: ReadSignal<String>) -> impl IntoView {
fn rtc_offer() -> impl IntoView {
let offer_trigger = move || {
spawn_local(async move {
let peer_connection = offer(username.get()).await;
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;
}
});
};
@ -95,10 +98,15 @@ fn rtc_offer(username: ReadSignal<String>) -> impl IntoView {
offer_button
}
fn rtc_answer(username: ReadSignal<String>) -> impl IntoView {
fn rtc_answer() -> impl IntoView {
let answer_trigger = move || {
spawn_local(async move {
let peer_connection = answer(username.get()).await;
let peer_connection = answer(audio().await).await;
loop {
log!("{:#?}", peer_connection.ice_connection_state());
log!("{:#?}", peer_connection.get_remote_streams());
sleep(1000).await;
}
});
};