Skip to content

Commit

Permalink
use leave_request.Action internally
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp committed Aug 19, 2024
1 parent 4a28dd2 commit d4349fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
30 changes: 18 additions & 12 deletions livekit/src/rtc_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,25 @@ impl EngineInner {

async fn on_session_event(self: &Arc<Self>, 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 } => {
Expand Down
18 changes: 6 additions & 12 deletions livekit/src/rtc_engine/rtc_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
);
}
}
Expand Down Expand Up @@ -479,8 +477,7 @@ impl SessionInner {
self.on_session_disconnected(
"server request to leave",
leave.reason(),
leave.can_reconnect,
true,
leave.action(),
true,
);
}
Expand Down Expand Up @@ -550,8 +547,7 @@ impl SessionInner {
self.on_session_disconnected(
"pc_state failed",
DisconnectReason::UnknownReason,
true,
false,
proto::leave_request::Action::Reconnect,
false,
);
}
Expand Down Expand Up @@ -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,
});
}

Expand Down

0 comments on commit d4349fc

Please sign in to comment.