(t *testing.T)
| 88 | } |
| 89 | |
| 90 | func TestRoomJoin(t *testing.T) { |
| 91 | t.Run("joining returns existing participant data", func(t *testing.T) { |
| 92 | rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants}) |
| 93 | pNew := NewMockParticipant("new", types.CurrentProtocol, false, false, rm.LocalParticipantListener()) |
| 94 | |
| 95 | _ = rm.Join(pNew, nil, nil, iceServersForRoom) |
| 96 | |
| 97 | // expect new participant to get a JoinReply |
| 98 | res := pNew.SendJoinResponseArgsForCall(0) |
| 99 | require.Equal(t, livekit.RoomID(res.Room.Sid), rm.ID()) |
| 100 | require.Len(t, res.OtherParticipants, numParticipants) |
| 101 | require.Len(t, rm.GetParticipants(), numParticipants+1) |
| 102 | require.NotEmpty(t, res.IceServers) |
| 103 | }) |
| 104 | |
| 105 | t.Run("subscribe to existing channels upon join", func(t *testing.T) { |
| 106 | numExisting := 3 |
| 107 | rm := newRoomWithParticipants(t, testRoomOpts{num: numExisting}) |
| 108 | lpl := rm.LocalParticipantListener() |
| 109 | p := NewMockParticipant("new", types.CurrentProtocol, false, false, lpl) |
| 110 | |
| 111 | err := rm.Join(p, nil, &ParticipantOptions{AutoSubscribe: true}, iceServersForRoom) |
| 112 | require.NoError(t, err) |
| 113 | |
| 114 | p.StateReturns(livekit.ParticipantInfo_ACTIVE) |
| 115 | lpl.OnStateChange(p) |
| 116 | |
| 117 | // it should become a subscriber when connectivity changes |
| 118 | numTracks := 0 |
| 119 | for _, op := range rm.GetParticipants() { |
| 120 | if p == op { |
| 121 | continue |
| 122 | } |
| 123 | |
| 124 | numTracks += len(op.GetPublishedTracks()) |
| 125 | } |
| 126 | require.Equal(t, numTracks, p.SubscribeToTrackCallCount()) |
| 127 | }) |
| 128 | |
| 129 | t.Run("participant state change is broadcasted to others", func(t *testing.T) { |
| 130 | rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants}) |
| 131 | var changedParticipant types.Participant |
| 132 | rm.OnParticipantChanged(func(participant types.Participant) { |
| 133 | changedParticipant = participant |
| 134 | }) |
| 135 | participants := rm.GetParticipants() |
| 136 | p := participants[0].(*typesfakes.FakeLocalParticipant) |
| 137 | disconnectedParticipant := participants[1].(*typesfakes.FakeLocalParticipant) |
| 138 | disconnectedParticipant.StateReturns(livekit.ParticipantInfo_DISCONNECTED) |
| 139 | |
| 140 | rm.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonClientRequestLeave) |
| 141 | time.Sleep(defaultDelay) |
| 142 | |
| 143 | require.Equal(t, p, changedParticipant) |
| 144 | |
| 145 | numUpdates := 0 |
| 146 | for _, op := range participants { |
| 147 | if op == p || op == disconnectedParticipant { |
nothing calls this directly
no test coverage detected