Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong ice_restart value #178

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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