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
+11 -1
View File
@@ -126,6 +126,7 @@ type ParticipantImpl struct {
onStateChange func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State)
onParticipantUpdate func(types.LocalParticipant)
onDataPacket func(types.LocalParticipant, *livekit.DataPacket)
onSubscribedTo func(types.LocalParticipant, livekit.ParticipantID)
migrateState atomic.Value // types.MigrateState
pendingOffer *webrtc.SessionDescription
@@ -440,6 +441,10 @@ func (p *ParticipantImpl) OnDataPacket(callback func(types.LocalParticipant, *li
p.onDataPacket = callback
}
func (p *ParticipantImpl) OnSubscribedTo(callback func(types.LocalParticipant, livekit.ParticipantID)) {
p.onSubscribedTo = callback
}
func (p *ParticipantImpl) OnClose(callback func(types.LocalParticipant, map[livekit.TrackID]livekit.ParticipantID)) {
p.onClose = callback
}
@@ -815,7 +820,12 @@ func (p *ParticipantImpl) AddSubscribedTrack(subTrack types.SubscribedTrack) {
subTrack.UpdateSubscriberSettings(settings)
}
p.subscribedTo.Store(subTrack.PublisherID(), struct{}{})
publisherID := subTrack.PublisherID()
isAlreadySubscribed := p.isSubscribedTo(publisherID)
p.subscribedTo.Store(publisherID, struct{}{})
if !isAlreadySubscribed && p.onSubscribedTo != nil {
p.onSubscribedTo(p, publisherID)
}
}
// RemoveSubscribedTrack removes a track to the participant's subscribed list