From 46446ef04710728b72d71cc63954f65c455a963a Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Tue, 4 Jan 2022 22:37:13 +0530 Subject: [PATCH] Send speaker update with inactive speaker when participant (#315) * Send speaker update with inactive speaker when participant leaves/unsubscribes * Check that protocol version supports speaker updates --- pkg/rtc/participant.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 44e54f1a..d962740c 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -734,6 +734,28 @@ func (p *ParticipantImpl) RemoveSubscribedTrack(subTrack types.SubscribedTrack) p.lock.Unlock() if numRemaining == 0 { p.subscribedTo.Delete(subTrack.PublisherID()) + + // + // When a participant leaves OR + // this participant unsubscribes from all tracks of another participant, + // have to send speaker update indicating that the participant speaker is no long active + // so that clients can clean up their speaker state for the leaving/unsubscribed participant + // + if p.ProtocolVersion().SupportsSpeakerChanged() { + _ = p.writeMessage(&livekit.SignalResponse{ + Message: &livekit.SignalResponse_SpeakersChanged{ + SpeakersChanged: &livekit.SpeakersChanged{ + Speakers: []*livekit.SpeakerInfo{ + &livekit.SpeakerInfo{ + Sid: string(subTrack.PublisherID()), + Level: 0, + Active: false, + }, + }, + }, + }, + }) + } } }