fix: ice candidate string transformation

This commit is contained in:
Ahmet Kaan Gümüş 2025-04-27 21:11:18 +03:00
parent 64e89b006a
commit dd0c0cf42a
3 changed files with 8 additions and 6 deletions

View file

@ -5,6 +5,7 @@ use leptos::{
prelude::{OnAttribute, Read, Show, ShowProps, ToChildren},
server::LocalResource,
};
use wasm_bindgen_futures::spawn_local;
use crate::{media::audio, webrtc::WebRTC};
@ -22,7 +23,12 @@ pub fn app() -> impl IntoView {
let webrtc_offer = webrtc.clone();
let offer_button = button()
.on(leptos::ev::click, move |_| {
let webrtc_offer = webrtc_offer.clone();
log!("{:#?}", webrtc_offer.get_status());
spawn_local(async move {
let offer_result = webrtc_offer.offer().await;
log!("Offer Result Is = {:#?}", offer_result);
});
})
.child("Offer");

View file

@ -7,7 +7,7 @@ use web_sys::{
wasm_bindgen::{JsCast, prelude::Closure},
};
static SIGNALLING_ADDRESS: &str = "ws://192.168.1.3:4546";
static SIGNALLING_ADDRESS: &str = "http://192.168.1.3:4546/signal";
thread_local! {
static WEBSOCKET: WebSocket = SignallingChannel::init().unwrap();

View file

@ -44,7 +44,7 @@ impl WebRTC {
let on_ice_candidate = Closure::<dyn Fn(_)>::new(
move |peer_connection_ice_event: RtcPeerConnectionIceEvent| {
if let Some(candidate) = peer_connection_ice_event.candidate() {
if let Err(err_val) = send_ice_candidate(&candidate.as_string().unwrap()) {
if let Err(err_val) = send_ice_candidate(&candidate.candidate()) {
log!("Error: Send ICE Candidate | {}", err_val);
}
}
@ -104,14 +104,12 @@ impl WebRTC {
}
pub async fn offer(&self) -> Result<(), Error> {
log!("Offer Function");
let offer_promise = self.peer_connection.create_offer();
match JsFuture::from(offer_promise)
.await
.map_err(|_| Error::WebRTCOffer)
{
Ok(offer) => {
log!("Offer Created");
let offer_session_description_protocol =
Reflect::get(&offer, &JsValue::from_str("sdp"))
.map_err(|_| Error::WebRTCSessionDescriptionProtocol)?;
@ -129,9 +127,7 @@ impl WebRTC {
.await
.map_err(|_| Error::WebRTCSetLocalDescription)?;
log!("Before Sent Offer");
send_offer(&offer_session_description_protocol)?;
log!("After Sent Offer");
if let Ok(received_answer) = receive_answer().await {
let answer = RtcSessionDescriptionInit::new(RtcSdpType::Answer);
answer.set_sdp(&received_answer.get_data());