|
1 | 1 | use std::{collections::HashMap, sync::Arc, time::Duration}; |
2 | 2 |
|
3 | 3 | use pulsebeam_runtime::{ |
4 | | - actor::{ActorKind, RunnerConfig}, |
| 4 | + actor::{ActorKind, ActorStatus, RunnerConfig}, |
5 | 5 | prelude::*, |
6 | 6 | }; |
7 | 7 | use str0m::Rtc; |
| 8 | +use tokio::task::JoinSet; |
8 | 9 |
|
9 | 10 | use crate::{ |
10 | 11 | entity::{ParticipantId, RoomId, TrackId}, |
@@ -48,6 +49,8 @@ pub struct RoomActor { |
48 | 49 | // participant_factory: Box<dyn actor::ActorFactory<participant::ParticipantActor>>, |
49 | 50 | room_id: Arc<RoomId>, |
50 | 51 | state: RoomState, |
| 52 | + |
| 53 | + participant_tasks: JoinSet<(Arc<ParticipantId>, ActorStatus)>, |
51 | 54 | } |
52 | 55 |
|
53 | 56 | #[derive(Default, Clone, Debug)] |
@@ -80,6 +83,9 @@ impl actor::Actor<RoomMessageSet> for RoomActor { |
80 | 83 | ) -> Result<(), actor::ActorError> { |
81 | 84 | pulsebeam_runtime::actor_loop!(self, ctx, pre_select: {}, |
82 | 85 | select: { |
| 86 | + Some(Ok((participant_id, _))) = self.participant_tasks.join_next() => { |
| 87 | + self.handle_participant_left(participant_id).await; |
| 88 | + } |
83 | 89 | _ = tokio::time::sleep(EMPTY_ROOM_TIMEOUT), if self.state.participants.is_empty() => { |
84 | 90 | tracing::info!("room has been empty for: {EMPTY_ROOM_TIMEOUT:?}, exiting."); |
85 | 91 | break; |
@@ -120,6 +126,7 @@ impl RoomActor { |
120 | 126 | node_ctx, |
121 | 127 | room_id, |
122 | 128 | state: RoomState::default(), |
| 129 | + participant_tasks: JoinSet::new(), |
123 | 130 | } |
124 | 131 | } |
125 | 132 |
|
@@ -156,15 +163,16 @@ impl RoomActor { |
156 | 163 |
|
157 | 164 | let (mut participant_handle, participant_task) = |
158 | 165 | actor::prepare(participant_actor, RunnerConfig::default()); |
159 | | - let mut room_handle = ctx.handle.clone(); |
160 | | - let participant_task = async move { |
161 | | - let (participant_id, _) = participant_task.await; |
162 | | - room_handle |
163 | | - .send(RoomMessage::RemoveParticipant(participant_id)) |
164 | | - .await; |
165 | | - }; |
166 | 166 |
|
167 | | - self.schedule(participant_task.boxed()).await; |
| 167 | + self.participant_tasks.spawn(participant_task); |
| 168 | + |
| 169 | + // let participant_task = async move { |
| 170 | + // let (participant_id, _) = participant_task.await; |
| 171 | + // room_handle |
| 172 | + // .send(RoomMessage::RemoveParticipant(participant_id)) |
| 173 | + // .await; |
| 174 | + // }; |
| 175 | + // self.schedule(participant_task.boxed()).await; |
168 | 176 | self.state.participants.insert( |
169 | 177 | participant_id.clone(), |
170 | 178 | ParticipantMeta { |
|
0 commit comments