Skip to content

Commit b986eaf

Browse files
committed
add 30 second timeout to cleanup room
1 parent 75b3ec3 commit b986eaf

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

pulsebeam-runtime/src/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ async fn run<A: Actor>(mut a: A, mut ctx: ActorContext<A>) -> ActorStatus {
368368
};
369369

370370
tracing::debug!("post_stop successful.");
371-
tracing::info!(status = %status_after_run, "Actor fully shut down.");
371+
tracing::info!(status = %status_after_run, "exited.");
372372

373373
status_after_run
374374
}

pulsebeam/src/room.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use std::{collections::HashMap, sync::Arc};
1+
use std::{collections::HashMap, sync::Arc, time::Duration};
22

3-
use futures::stream::{FuturesUnordered, StreamExt};
3+
use futures::{
4+
future::Either,
5+
stream::{FuturesUnordered, StreamExt},
6+
};
47
use str0m::Rtc;
58

69
use crate::{
@@ -10,6 +13,8 @@ use crate::{
1013
};
1114
use pulsebeam_runtime::actor;
1215

16+
const EMPTY_ROOM_TIMEOUT: Duration = Duration::from_secs(30);
17+
1318
#[derive(Debug)]
1419
pub enum RoomMessage {
1520
PublishTrack(Arc<TrackMeta>),
@@ -60,7 +65,15 @@ impl actor::Actor for RoomActor {
6065
}
6166

6267
async fn run(&mut self, ctx: &mut actor::ActorContext<Self>) -> Result<(), actor::ActorError> {
63-
pulsebeam_runtime::actor_loop!(self, ctx, pre_select: {},
68+
pulsebeam_runtime::actor_loop!(self, ctx,
69+
pre_select: {
70+
let empty_room_timer =
71+
if self.state.participants.is_empty() {
72+
Either::Left(tokio::time::sleep(EMPTY_ROOM_TIMEOUT))
73+
} else {
74+
Either::Right(futures::future::pending::<()>())
75+
};
76+
},
6477
select: {
6578
Some((participant_id, _)) = self.participant_tasks.next() => {
6679
self.handle_participant_left(participant_id).await;
@@ -69,6 +82,11 @@ impl actor::Actor for RoomActor {
6982
Some((track_meta, _)) = self.track_tasks.next() => {
7083
self.handle_track_unpublished(track_meta).await;
7184
}
85+
86+
_ = empty_room_timer => {
87+
tracing::info!("room has been empty for: {EMPTY_ROOM_TIMEOUT:?}, exiting.");
88+
break;
89+
}
7290
}
7391
);
7492

0 commit comments

Comments
 (0)