diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 1e09b5cf..5b041fff 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -40,14 +40,15 @@ type ParticipantParams struct { } type ParticipantImpl struct { - params ParticipantParams - id string - publisher *PCTransport - subscriber *PCTransport - isClosed utils.AtomicFlag - permission *livekit.ParticipantPermission - state atomic.Value // livekit.ParticipantInfo_State - rtcpCh chan []rtcp.Packet + params ParticipantParams + id string + publisher *PCTransport + subscriber *PCTransport + isClosed utils.AtomicFlag + permission *livekit.ParticipantPermission + state atomic.Value // livekit.ParticipantInfo_State + updateAfterActive atomic.Value // bool + rtcpCh chan []rtcp.Packet // reliable and unreliable data channels reliableDC *webrtc.DataChannel @@ -94,6 +95,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) { connectedAt: time.Now(), } p.state.Store(livekit.ParticipantInfo_JOINING) + p.updateAfterActive.Store(false) var err error p.publisher, err = NewPCTransport(TransportParams{ @@ -147,6 +149,10 @@ func (p *ParticipantImpl) State() livekit.ParticipantInfo_State { return p.state.Load().(livekit.ParticipantInfo_State) } +func (p *ParticipantImpl) UpdateAfterActive() bool { + return p.updateAfterActive.Load().(bool) +} + func (p *ParticipantImpl) ProtocolVersion() types.ProtocolVersion { return p.params.ProtocolVersion } @@ -468,10 +474,19 @@ func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticip } func (p *ParticipantImpl) SendParticipantUpdate(participants []*livekit.ParticipantInfo) error { + participantsToUpdate := participants + if p.State() == livekit.ParticipantInfo_JOINING { + // have not fully joined, it will not know how to handle updates + // make a note so that Room could resend updates once fully joined + p.updateAfterActive.Store(true) + return nil + } + + p.updateAfterActive.Store(false) return p.writeMessage(&livekit.SignalResponse{ Message: &livekit.SignalResponse_Update{ Update: &livekit.ParticipantUpdate{ - Participants: participants, + Participants: participantsToUpdate, }, }, }) diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index de2e21e2..1ede889d 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -167,6 +167,10 @@ func (r *Room) Join(participant types.Participant, opts *ParticipantOptions) err r.broadcastParticipantState(p, true) if p.State() == livekit.ParticipantInfo_ACTIVE { + if p.UpdateAfterActive() { + _ = p.SendParticipantUpdate(ToProtoParticipants(r.GetParticipants())) + } + // subscribe participant to existing publishedTracks r.subscribeToExistingTracks(p) diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index 1cdc2c41..7651824f 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -77,6 +77,7 @@ type Participant interface { AddSubscribedTrack(participantId string, st SubscribedTrack) RemoveSubscribedTrack(participantId string, st SubscribedTrack) SubscriberPC() *webrtc.PeerConnection + UpdateAfterActive() bool } // PublishedTrack is the main interface representing a track published to the room diff --git a/pkg/rtc/types/typesfakes/fake_participant.go b/pkg/rtc/types/typesfakes/fake_participant.go index 1ac1701d..f56fd861 100644 --- a/pkg/rtc/types/typesfakes/fake_participant.go +++ b/pkg/rtc/types/typesfakes/fake_participant.go @@ -371,6 +371,16 @@ type FakeParticipant struct { toProtoReturnsOnCall map[int]struct { result1 *livekit.ParticipantInfo } + UpdateAfterActiveStub func() bool + updateAfterActiveMutex sync.RWMutex + updateAfterActiveArgsForCall []struct { + } + updateAfterActiveReturns struct { + result1 bool + } + updateAfterActiveReturnsOnCall map[int]struct { + result1 bool + } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } @@ -2348,6 +2358,59 @@ func (fake *FakeParticipant) ToProtoReturnsOnCall(i int, result1 *livekit.Partic }{result1} } +func (fake *FakeParticipant) UpdateAfterActive() bool { + fake.updateAfterActiveMutex.Lock() + ret, specificReturn := fake.updateAfterActiveReturnsOnCall[len(fake.updateAfterActiveArgsForCall)] + fake.updateAfterActiveArgsForCall = append(fake.updateAfterActiveArgsForCall, struct { + }{}) + stub := fake.UpdateAfterActiveStub + fakeReturns := fake.updateAfterActiveReturns + fake.recordInvocation("UpdateAfterActive", []interface{}{}) + fake.updateAfterActiveMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *FakeParticipant) UpdateAfterActiveCallCount() int { + fake.updateAfterActiveMutex.RLock() + defer fake.updateAfterActiveMutex.RUnlock() + return len(fake.updateAfterActiveArgsForCall) +} + +func (fake *FakeParticipant) UpdateAfterActiveCalls(stub func() bool) { + fake.updateAfterActiveMutex.Lock() + defer fake.updateAfterActiveMutex.Unlock() + fake.UpdateAfterActiveStub = stub +} + +func (fake *FakeParticipant) UpdateAfterActiveReturns(result1 bool) { + fake.updateAfterActiveMutex.Lock() + defer fake.updateAfterActiveMutex.Unlock() + fake.UpdateAfterActiveStub = nil + fake.updateAfterActiveReturns = struct { + result1 bool + }{result1} +} + +func (fake *FakeParticipant) UpdateAfterActiveReturnsOnCall(i int, result1 bool) { + fake.updateAfterActiveMutex.Lock() + defer fake.updateAfterActiveMutex.Unlock() + fake.UpdateAfterActiveStub = nil + if fake.updateAfterActiveReturnsOnCall == nil { + fake.updateAfterActiveReturnsOnCall = make(map[int]struct { + result1 bool + }) + } + fake.updateAfterActiveReturnsOnCall[i] = struct { + result1 bool + }{result1} +} + func (fake *FakeParticipant) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() @@ -2435,6 +2498,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} { defer fake.subscriberPCMutex.RUnlock() fake.toProtoMutex.RLock() defer fake.toProtoMutex.RUnlock() + fake.updateAfterActiveMutex.RLock() + defer fake.updateAfterActiveMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value