Skip to main content

o_sfu_core/engine/room/effects/
output.rs

1use crate::engine::room::{
2    UserOutbound,
3    outbound::{MessageFanout, OutboundSender, VersionedRemoteTrackSnapshot},
4    state::LifecycleEffects,
5};
6
7#[derive(Debug, Default)]
8pub(super) struct RoomOutputPlan {
9    pub(super) track_snapshots: Vec<(OutboundSender, VersionedRemoteTrackSnapshot)>,
10    pub(super) user_info_before_policy: Option<MessageFanout>,
11    pub(super) user_info: Option<MessageFanout>,
12    pub(super) lifecycle: LifecycleEffects,
13}
14
15impl RoomOutputPlan {
16    pub(super) fn emit_before_policy(&mut self) {
17        for (recipient, snapshot) in self.track_snapshots.drain(..) {
18            let _ = recipient.send_remote_tracks(snapshot);
19        }
20        self.emit_user_info_before_policy();
21    }
22
23    pub(super) fn emit_user_info_before_policy(&mut self) {
24        if let Some(fanout) = self.user_info_before_policy.take() {
25            fanout.emit();
26        }
27    }
28
29    pub(super) fn emit_after_policy(self) {
30        if let Some(fanout) = self.user_info {
31            fanout.emit();
32        }
33        for close_request in self.lifecycle.close_requests {
34            let _ = close_request
35                .sender
36                .send(UserOutbound::Close(close_request.reason));
37        }
38        for (recipient, snapshot) in self.lifecycle.track_snapshots {
39            let _ = recipient.send_remote_tracks(snapshot);
40        }
41        for fanout in self.lifecycle.fanouts {
42            fanout.emit();
43        }
44    }
45}