Set IsPublisher to true for data-only publishers (#1348)

This commit is contained in:
David Zhao
2023-01-29 23:10:26 -08:00
committed by GitHub
parent 52fd0a641b
commit a24eb62b83
+22 -13
View File
@@ -488,19 +488,9 @@ func (p *ParticipantImpl) onPublisherAnswer(answer webrtc.SessionDescription) er
return err return err
} }
if p.isPublisher.Load() != p.CanPublish() { // received an offer from the client, if publishing is allowed, mark this
p.isPublisher.Store(p.CanPublish()) // participant as a publisher
// trigger update as well if participant is already fully connected p.setIsPublisher(p.CanPublish())
if p.State() == livekit.ParticipantInfo_ACTIVE {
p.lock.RLock()
onParticipantUpdate := p.onParticipantUpdate
p.lock.RUnlock()
if onParticipantUpdate != nil {
onParticipantUpdate(p)
}
}
}
if p.MigrateState() == types.MigrateStateSync { if p.MigrateState() == types.MigrateStateSync {
go p.handleMigrateMutedTrack() go p.handleMigrateMutedTrack()
@@ -1067,6 +1057,21 @@ func (p *ParticipantImpl) updateState(state livekit.ParticipantInfo_State) {
} }
} }
func (p *ParticipantImpl) setIsPublisher(isPublisher bool) {
if p.isPublisher.Swap(isPublisher) != isPublisher {
// trigger update as well if participant is already fully connected
if p.State() == livekit.ParticipantInfo_ACTIVE {
p.lock.RLock()
onParticipantUpdate := p.onParticipantUpdate
p.lock.RUnlock()
if onParticipantUpdate != nil {
onParticipantUpdate(p)
}
}
}
}
// when the server has an offer for participant // when the server has an offer for participant
func (p *ParticipantImpl) onSubscriberOffer(offer webrtc.SessionDescription) error { func (p *ParticipantImpl) onSubscriberOffer(offer webrtc.SessionDescription) error {
p.params.Logger.Debugw("sending offer", "transport", livekit.SignalTarget_SUBSCRIBER) p.params.Logger.Debugw("sending offer", "transport", livekit.SignalTarget_SUBSCRIBER)
@@ -1145,6 +1150,10 @@ func (p *ParticipantImpl) onDataMessage(kind livekit.DataPacket_Kind, data []byt
default: default:
p.params.Logger.Warnw("received unsupported data packet", nil, "payload", payload) p.params.Logger.Warnw("received unsupported data packet", nil, "payload", payload)
} }
if !p.IsPublisher() {
p.setIsPublisher(true)
}
} }
func (p *ParticipantImpl) onICECandidate(c *webrtc.ICECandidate, target livekit.SignalTarget) error { func (p *ParticipantImpl) onICECandidate(c *webrtc.ICECandidate, target livekit.SignalTarget) error {