Skip to content

Commit

Permalink
fix: wrong ice_restart value (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Sep 6, 2023
1 parent cbdde55 commit 8270466
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion livekit/src/rtc_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl EngineInner {
inner.reconnecting.store(false, Ordering::Release);

if res.is_ok() {
log::info!("RTCEngine successfully reconnected")
log::info!("RtcEngine successfully reconnected")
} else {
log::error!("failed to reconnect after {} attempts", RECONNECT_ATTEMPTS);
inner.close(DisconnectReason::UnknownReason).await;
Expand Down
36 changes: 14 additions & 22 deletions livekit/src/rtc_engine/peer_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use livekit_protocol as proto;
use livekit_webrtc::prelude::*;
use log::{debug, error};
use parking_lot::Mutex;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
Expand Down Expand Up @@ -82,10 +81,6 @@ impl PeerTransport {
self.peer_connection.close();
}

pub async fn prepare_ice_restart(&self) {
self.inner.lock().await.restarting_ice = true;
}

pub async fn add_ice_candidate(&self, ice_candidate: IceCandidate) -> EngineResult<()> {
let mut inner = self.inner.lock().await;

Expand Down Expand Up @@ -144,30 +139,27 @@ impl PeerTransport {
let mut inner = self.inner.lock().await;

if options.ice_restart {
debug!("restarting ICE");
inner.restarting_ice = false;
log::debug!("restarting ICE");
inner.restarting_ice = true;
}

if self.peer_connection.signaling_state() == SignalingState::HaveLocalOffer {
if options.ice_restart {
if let Some(remote_description) = self.peer_connection.current_remote_description()
{
self.peer_connection
.set_remote_description(remote_description)
.await?;
} else {
error!("trying to restart ICE when the pc doesn't have remote description");
}
let remote_sdp = self.peer_connection.current_remote_description();
if options.ice_restart && remote_sdp.is_some() {
let remote_sdp = remote_sdp.unwrap();

// Cancel the old renegotiation (Basically say the server rejected the previous offer)
// So we can resend a new offer just after this
self.peer_connection
.set_remote_description(remote_sdp)
.await?;
} else {
inner.renegotiate = true;
return Ok(());
}
}

// TODO(theomonnom): Check that the target_os isn't wasm
// Not sure if this is really needed
if options.ice_restart {
self.peer_connection.restart_ice();
} else if self.peer_connection.signaling_state() == SignalingState::Closed {
log::warn!("peer connection is closed, cannot create offer");
return Ok(());
}

let offer = self.peer_connection.create_offer(options).await?;
Expand Down
5 changes: 2 additions & 3 deletions livekit/src/rtc_engine/rtc_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,6 @@ impl SessionInner {
.peer_connection()
.set_configuration(rtc_config)?;

self.subscriber_pc.prepare_ice_restart().await;

if self.has_published.load(Ordering::Acquire) {
self.publisher_pc
.create_and_send_offer(OfferOptions {
Expand Down Expand Up @@ -837,7 +835,7 @@ impl SessionInner {

/// Start publisher negotiation
fn publisher_negotiation_needed(self: &Arc<Self>) {
self.has_published.store(true, Ordering::Relaxed);
self.has_published.store(true, Ordering::Release);

let mut debouncer = self.negotiation_debouncer.lock();

Expand All @@ -848,6 +846,7 @@ impl SessionInner {
*debouncer = Some(debouncer::debounce(
PUBLISHER_NEGOTIATION_FREQUENCY,
async move {
log::debug!("negotiating the publisher");
if let Err(err) = session
.publisher_pc
.create_and_send_offer(OfferOptions::default())
Expand Down

0 comments on commit 8270466

Please sign in to comment.