Add OnSubscirberReady callback on LocalParticipant. (#3600)

Was setting the state to ACTIVE prematurely to enable the subscription
inter-lock in one shot signalling mode. But, that is incorrectly
changing state.

Use a callback to indicate subscriber ready and let the participant
ACTIVE happen when the connection actually establishes.
This commit is contained in:
Raja Subramanian
2025-04-09 15:02:27 +05:30
committed by GitHub
parent 5c2d96b9d3
commit 7e16106a0e
4 changed files with 60 additions and 1 deletions
+16 -1
View File
@@ -241,6 +241,7 @@ type ParticipantImpl struct {
onTrackUpdated func(types.LocalParticipant, types.MediaTrack)
onTrackUnpublished func(types.LocalParticipant, types.MediaTrack)
onStateChange func(p types.LocalParticipant)
onSubscriberReady func(p types.LocalParticipant)
onMigrateStateChange func(p types.LocalParticipant, migrateState types.MigrateState)
onParticipantUpdate func(types.LocalParticipant)
onDataPacket func(types.LocalParticipant, livekit.DataPacket_Kind, *livekit.DataPacket)
@@ -752,6 +753,18 @@ func (p *ParticipantImpl) getOnStateChange() func(p types.LocalParticipant) {
return p.onStateChange
}
func (p *ParticipantImpl) OnSubscriberReady(callback func(p types.LocalParticipant)) {
p.lock.Lock()
p.onSubscriberReady = callback
p.lock.Unlock()
}
func (p *ParticipantImpl) getOnSubscriberReady() func(p types.LocalParticipant) {
p.lock.RLock()
defer p.lock.RUnlock()
return p.onSubscriberReady
}
func (p *ParticipantImpl) OnMigrateStateChange(callback func(p types.LocalParticipant, state types.MigrateState)) {
p.lock.Lock()
p.onMigrateStateChange = callback
@@ -905,7 +918,9 @@ func (p *ParticipantImpl) HandleOffer(offer webrtc.SessionDescription) error {
offer = p.setCodecPreferencesForPublisher(offer)
err := p.TransportManager.HandleOffer(offer, shouldPend)
if p.params.UseOneShotSignallingMode {
p.updateState(livekit.ParticipantInfo_ACTIVE)
if onSubscriberReady := p.getOnSubscriberReady(); onSubscriberReady != nil {
go onSubscriberReady(p)
}
}
return err
}