Send active speaker update on subscription. (#676)

Newly joining participant does not get information about
currently active speaker till there is a speaker state change.
This addresses it by sending a speaker update on subscription
if the subscribed to participant is actively speaking.
This commit is contained in:
Raja Subramanian
2022-05-10 12:31:26 +05:30
committed by GitHub
parent bd7e3beda4
commit 9f37239af3
4 changed files with 65 additions and 1 deletions
+14
View File
@@ -225,6 +225,19 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
participant.OnTrackUpdated(r.onTrackUpdated)
participant.OnParticipantUpdate(r.onParticipantUpdate)
participant.OnDataPacket(r.onDataPacket)
participant.OnSubscribedTo(func(p types.LocalParticipant, publisherID livekit.ParticipantID) {
// when a participant subscribed to another participant,
// send speaker update if the subscribed to participant is active.
go func() {
speakers := r.GetActiveSpeakers()
for _, speaker := range speakers {
if livekit.ParticipantID(speaker.Sid) == publisherID {
p.SendSpeakerUpdate(speakers)
break
}
}
}()
})
r.Logger.Infow("new participant joined",
"pID", participant.ID(),
"participant", participant.Identity(),
@@ -332,6 +345,7 @@ func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity) {
p.OnStateChange(nil)
p.OnParticipantUpdate(nil)
p.OnDataPacket(nil)
p.OnSubscribedTo(nil)
// close participant as well
r.Logger.Infow("closing participant for removal", "pID", p.ID(), "participant", p.Identity())