Do not re-use transceiver when negotiation is pending. (#862)

This commit is contained in:
Raja Subramanian
2022-07-31 10:50:55 +05:30
committed by GitHub
parent 997461a2b6
commit a393d64ccc
6 changed files with 143 additions and 5 deletions
+15
View File
@@ -63,6 +63,7 @@ type PCTransport struct {
lock sync.RWMutex
pendingCandidates []webrtc.ICECandidateInit
debouncedNegotiate func(func())
negotiationPending map[livekit.ParticipantID]bool
onOffer func(offer webrtc.SessionDescription)
restartAfterGathering bool
restartAtNextOffer bool
@@ -194,6 +195,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
params: params,
debouncedNegotiate: debounce.New(negotiationFrequency),
negotiationState: negotiationStateNone,
negotiationPending: make(map[livekit.ParticipantID]bool),
}
if params.Target == livekit.SignalTarget_SUBSCRIBER {
t.streamAllocator = sfu.NewStreamAllocator(sfu.StreamAllocatorParams{
@@ -324,6 +326,12 @@ func (t *PCTransport) OnNegotiationFailed(f func()) {
t.onNegotiationFailed = f
}
func (t *PCTransport) AddNegotiationPending(publisherID livekit.ParticipantID) {
t.lock.Lock()
t.negotiationPending[publisherID] = true
t.lock.Unlock()
}
func (t *PCTransport) Negotiate(force bool) {
if force {
t.debouncedNegotiate(func() {
@@ -341,6 +349,12 @@ func (t *PCTransport) Negotiate(force bool) {
}
}
func (t *PCTransport) IsNegotiationPending(publisherID livekit.ParticipantID) bool {
t.lock.RLock()
defer t.lock.RUnlock()
return t.negotiationPending[publisherID]
}
func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error {
t.lock.Lock()
defer t.lock.Unlock()
@@ -438,6 +452,7 @@ func (t *PCTransport) createAndSendOffer(options *webrtc.OfferOptions) error {
// indicate waiting for client
t.negotiationState = negotiationStateClient
t.restartAfterGathering = false
t.negotiationPending = make(map[livekit.ParticipantID]bool)
negotiateVersion := t.negotiateCounter.Inc()
if t.signalStateCheckTimer != nil {