@@ -32,26 +32,23 @@ pub fn channel_assignments_for_participants(
3232 _ => return vec ! [ ] ,
3333 } ;
3434
35- let remote_id = unique_other_participant ( participant_human_ids, self_id) ;
36- let remote_id = match remote_id {
37- Some ( id) => id,
38- None => return vec ! [ ] ,
39- } ;
40-
41- vec ! [
42- IdentityAssignment {
43- human_id: self_id. to_string( ) ,
44- scope: IdentityScope :: Channel {
45- channel: ChannelProfile :: DirectMic ,
46- } ,
35+ let mut assignments = vec ! [ IdentityAssignment {
36+ human_id: self_id. to_string( ) ,
37+ scope: IdentityScope :: Channel {
38+ channel: ChannelProfile :: DirectMic ,
4739 } ,
48- IdentityAssignment {
40+ } ] ;
41+
42+ if let Some ( remote_id) = unique_other_participant ( participant_human_ids, self_id) {
43+ assignments. push ( IdentityAssignment {
4944 human_id : remote_id. to_string ( ) ,
5045 scope : IdentityScope :: Channel {
5146 channel : ChannelProfile :: RemoteParty ,
5247 } ,
53- } ,
54- ]
48+ } ) ;
49+ }
50+
51+ assignments
5552}
5653
5754pub fn segment_options_for_participants (
@@ -97,3 +94,67 @@ fn unique_other_participant<'a>(
9794 None
9895 }
9996}
97+
98+ #[ cfg( test) ]
99+ mod tests {
100+ use super :: * ;
101+
102+ #[ test]
103+ fn assigns_self_to_direct_mic_without_unique_remote ( ) {
104+ let assignments = channel_assignments_for_participants ( & [ ] , Some ( "self" ) ) ;
105+
106+ assert_eq ! (
107+ assignments,
108+ vec![ IdentityAssignment {
109+ human_id: "self" . to_string( ) ,
110+ scope: IdentityScope :: Channel {
111+ channel: ChannelProfile :: DirectMic ,
112+ } ,
113+ } ]
114+ ) ;
115+ }
116+
117+ #[ test]
118+ fn assigns_unique_remote_to_remote_party ( ) {
119+ let assignments = channel_assignments_for_participants (
120+ & [ "self" . to_string ( ) , "remote" . to_string ( ) ] ,
121+ Some ( "self" ) ,
122+ ) ;
123+
124+ assert_eq ! (
125+ assignments,
126+ vec![
127+ IdentityAssignment {
128+ human_id: "self" . to_string( ) ,
129+ scope: IdentityScope :: Channel {
130+ channel: ChannelProfile :: DirectMic ,
131+ } ,
132+ } ,
133+ IdentityAssignment {
134+ human_id: "remote" . to_string( ) ,
135+ scope: IdentityScope :: Channel {
136+ channel: ChannelProfile :: RemoteParty ,
137+ } ,
138+ } ,
139+ ]
140+ ) ;
141+ }
142+
143+ #[ test]
144+ fn skips_remote_assignment_when_remote_is_ambiguous ( ) {
145+ let assignments = channel_assignments_for_participants (
146+ & [ "remote-a" . to_string ( ) , "remote-b" . to_string ( ) ] ,
147+ Some ( "self" ) ,
148+ ) ;
149+
150+ assert_eq ! (
151+ assignments,
152+ vec![ IdentityAssignment {
153+ human_id: "self" . to_string( ) ,
154+ scope: IdentityScope :: Channel {
155+ channel: ChannelProfile :: DirectMic ,
156+ } ,
157+ } ]
158+ ) ;
159+ }
160+ }
0 commit comments