From d4349fc8d60d00635357a61444ae6498dbbc6535 Mon Sep 17 00:00:00 2001 From: aoife cassidy Date: Mon, 19 Aug 2024 10:25:58 -0700 Subject: [PATCH] use leave_request.Action internally --- livekit/src/rtc_engine/mod.rs | 30 ++++++++++++++++----------- livekit/src/rtc_engine/rtc_session.rs | 18 ++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/livekit/src/rtc_engine/mod.rs b/livekit/src/rtc_engine/mod.rs index 3d068a11..aa5d9dc6 100644 --- a/livekit/src/rtc_engine/mod.rs +++ b/livekit/src/rtc_engine/mod.rs @@ -401,19 +401,25 @@ impl EngineInner { async fn on_session_event(self: &Arc, event: SessionEvent) -> EngineResult<()> { match event { - SessionEvent::Close { source, reason, can_reconnect, retry_now, full_reconnect } => { + SessionEvent::Close { source, reason, action, retry_now } => { log::debug!("received session close: {}, {:?}", source, reason); - if can_reconnect { - self.reconnection_needed(retry_now, full_reconnect); - } else { - // Spawning a new task because the close function wait for the engine_task to - // finish. (So it doesn't make sense to await it here) - livekit_runtime::spawn({ - let inner = self.clone(); - async move { - inner.close(reason).await; - } - }); + match action { + proto::leave_request::Action::Resume => { + self.reconnection_needed(retry_now, false) + } + proto::leave_request::Action::Reconnect => { + self.reconnection_needed(retry_now, true) + } + proto::leave_request::Action::Disconnect => { + // Spawning a new task because the close function wait for the engine_task to + // finish. (So it doesn't make sense to await it here) + livekit_runtime::spawn({ + let inner = self.clone(); + async move { + inner.close(reason).await; + } + }); + } } } SessionEvent::Data { participant_sid, participant_identity, payload, topic, kind } => { diff --git a/livekit/src/rtc_engine/rtc_session.rs b/livekit/src/rtc_engine/rtc_session.rs index 060fc7c3..4a7cadeb 100644 --- a/livekit/src/rtc_engine/rtc_session.rs +++ b/livekit/src/rtc_engine/rtc_session.rs @@ -112,8 +112,7 @@ pub enum SessionEvent { Close { source: String, reason: DisconnectReason, - can_reconnect: bool, - full_reconnect: bool, + action: proto::leave_request::Action, retry_now: bool, }, RequestResponse { @@ -419,9 +418,8 @@ impl SessionInner { self.on_session_disconnected( format!("signal client closed: {:?}", reason).as_str(), DisconnectReason::UnknownReason, - true, + proto::leave_request::Action::Resume, false, - false ); } } @@ -479,8 +477,7 @@ impl SessionInner { self.on_session_disconnected( "server request to leave", leave.reason(), - leave.can_reconnect, - true, + leave.action(), true, ); } @@ -550,8 +547,7 @@ impl SessionInner { self.on_session_disconnected( "pc_state failed", DisconnectReason::UnknownReason, - true, - false, + proto::leave_request::Action::Reconnect, false, ); } @@ -767,16 +763,14 @@ impl SessionInner { &self, source: &str, reason: DisconnectReason, - can_reconnect: bool, + action: proto::leave_request::Action, retry_now: bool, - full_reconnect: bool, ) { let _ = self.emitter.send(SessionEvent::Close { source: source.to_owned(), reason, - can_reconnect, + action, retry_now, - full_reconnect, }); }