fix: ⚡ ice candidate string transformation
This commit is contained in:
parent
64e89b006a
commit
dd0c0cf42a
3 changed files with 8 additions and 6 deletions
|
@ -5,6 +5,7 @@ use leptos::{
|
||||||
prelude::{OnAttribute, Read, Show, ShowProps, ToChildren},
|
prelude::{OnAttribute, Read, Show, ShowProps, ToChildren},
|
||||||
server::LocalResource,
|
server::LocalResource,
|
||||||
};
|
};
|
||||||
|
use wasm_bindgen_futures::spawn_local;
|
||||||
|
|
||||||
use crate::{media::audio, webrtc::WebRTC};
|
use crate::{media::audio, webrtc::WebRTC};
|
||||||
|
|
||||||
|
@ -22,7 +23,12 @@ pub fn app() -> impl IntoView {
|
||||||
let webrtc_offer = webrtc.clone();
|
let webrtc_offer = webrtc.clone();
|
||||||
let offer_button = button()
|
let offer_button = button()
|
||||||
.on(leptos::ev::click, move |_| {
|
.on(leptos::ev::click, move |_| {
|
||||||
|
let webrtc_offer = webrtc_offer.clone();
|
||||||
log!("{:#?}", webrtc_offer.get_status());
|
log!("{:#?}", webrtc_offer.get_status());
|
||||||
|
spawn_local(async move {
|
||||||
|
let offer_result = webrtc_offer.offer().await;
|
||||||
|
log!("Offer Result Is = {:#?}", offer_result);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.child("Offer");
|
.child("Offer");
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use web_sys::{
|
||||||
wasm_bindgen::{JsCast, prelude::Closure},
|
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! {
|
thread_local! {
|
||||||
static WEBSOCKET: WebSocket = SignallingChannel::init().unwrap();
|
static WEBSOCKET: WebSocket = SignallingChannel::init().unwrap();
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl WebRTC {
|
||||||
let on_ice_candidate = Closure::<dyn Fn(_)>::new(
|
let on_ice_candidate = Closure::<dyn Fn(_)>::new(
|
||||||
move |peer_connection_ice_event: RtcPeerConnectionIceEvent| {
|
move |peer_connection_ice_event: RtcPeerConnectionIceEvent| {
|
||||||
if let Some(candidate) = peer_connection_ice_event.candidate() {
|
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);
|
log!("Error: Send ICE Candidate | {}", err_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,14 +104,12 @@ impl WebRTC {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn offer(&self) -> Result<(), Error> {
|
pub async fn offer(&self) -> Result<(), Error> {
|
||||||
log!("Offer Function");
|
|
||||||
let offer_promise = self.peer_connection.create_offer();
|
let offer_promise = self.peer_connection.create_offer();
|
||||||
match JsFuture::from(offer_promise)
|
match JsFuture::from(offer_promise)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| Error::WebRTCOffer)
|
.map_err(|_| Error::WebRTCOffer)
|
||||||
{
|
{
|
||||||
Ok(offer) => {
|
Ok(offer) => {
|
||||||
log!("Offer Created");
|
|
||||||
let offer_session_description_protocol =
|
let offer_session_description_protocol =
|
||||||
Reflect::get(&offer, &JsValue::from_str("sdp"))
|
Reflect::get(&offer, &JsValue::from_str("sdp"))
|
||||||
.map_err(|_| Error::WebRTCSessionDescriptionProtocol)?;
|
.map_err(|_| Error::WebRTCSessionDescriptionProtocol)?;
|
||||||
|
@ -129,9 +127,7 @@ impl WebRTC {
|
||||||
.await
|
.await
|
||||||
.map_err(|_| Error::WebRTCSetLocalDescription)?;
|
.map_err(|_| Error::WebRTCSetLocalDescription)?;
|
||||||
|
|
||||||
log!("Before Sent Offer");
|
|
||||||
send_offer(&offer_session_description_protocol)?;
|
send_offer(&offer_session_description_protocol)?;
|
||||||
log!("After Sent Offer");
|
|
||||||
if let Ok(received_answer) = receive_answer().await {
|
if let Ok(received_answer) = receive_answer().await {
|
||||||
let answer = RtcSessionDescriptionInit::new(RtcSdpType::Answer);
|
let answer = RtcSessionDescriptionInit::new(RtcSdpType::Answer);
|
||||||
answer.set_sdp(&received_answer.get_data());
|
answer.set_sdp(&received_answer.get_data());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue