diff --git a/prototype/channel-native/src/peer.rs b/prototype/channel-native/src/peer.rs index 9f99f53a9..e99ae9406 100644 --- a/prototype/channel-native/src/peer.rs +++ b/prototype/channel-native/src/peer.rs @@ -1008,7 +1008,10 @@ impl Driver { ) -> Result> { let scoped = |id: Uuid| { self.publications.get(&id).is_some_and(|info| { - info.room_id == room && publication.is_none_or(|selected| selected == id) + info.room_id == room + && publication.is_none_or(|selected| { + selected == id || info.kind == piik_channel_core::wire::Kind::Voice + }) }) }; let mut connections = Vec::new(); diff --git a/prototype/channel-native/src/peer/tests/transit.rs b/prototype/channel-native/src/peer/tests/transit.rs index cb61e2f76..23a7a5ace 100644 --- a/prototype/channel-native/src/peer/tests/transit.rs +++ b/prototype/channel-native/src/peer/tests/transit.rs @@ -2,6 +2,65 @@ use super::*; use support::{vp8, Fixture}; +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn selected_screen_metrics_keep_room_voice_and_exclude_other_room() -> Result<()> { + let mut f = Fixture::new(vp8()).await?; + let mut voice = f.publication.clone(); + voice.id = Uuid::new_v4(); + voice.kind = piik_channel_core::wire::Kind::Voice; + let voice_input = f.plans[1].incoming[0].id; + let voice_output = f.plans.iter().find(|p| p.id == f.sink).unwrap().outgoing[1].id; + for plan in &mut f.plans { + for flow in plan.incoming.iter_mut().chain(&mut plan.outgoing) { + if flow.id == voice_input || flow.id == voice_output { + flow.publication_id = voice.id; + } + } + } + f.driver + .update( + f.plans.clone(), + vec![f.publication.clone(), voice.clone()], + vec![], + ) + .await?; + f.until(|f| f.frame >= 70).await?; + let measured = f + .driver + .connection_metrics("room", Some(f.publication.id)) + .await?; + let streams: Vec<_> = measured.iter().flat_map(|pair| &pair.streams).collect(); + ensure!(streams + .iter() + .any(|stream| stream.publication_id == f.publication.id && stream.media == "video")); + ensure!(streams + .iter() + .any(|stream| stream.publication_id == voice.id && stream.media == "audio")); + ensure!(f + .driver + .connection_metrics("other", Some(f.publication.id)) + .await? + .is_empty()); + voice.room_id = "other".into(); + f.driver + .update( + f.plans.clone(), + vec![f.publication.clone(), voice.clone()], + vec![], + ) + .await?; + let measured = f + .driver + .connection_metrics("room", Some(f.publication.id)) + .await?; + ensure!(measured + .iter() + .flat_map(|pair| &pair.streams) + .all(|stream| stream.publication_id != voice.id)); + f.close().await; + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn screen_pause_stops_both_outputs_and_resumes_the_same_source_clock() -> Result<()> { let mut f = Fixture::new(vp8()).await?;