Skip to content

Commit

Permalink
Merge 9a44cf9 into cddf631
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliusz Chroboczek authored Feb 2, 2021
2 parents cddf631 + 9a44cf9 commit 723c598
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"errors"
"fmt"
"io"
"strconv"
Expand Down Expand Up @@ -576,6 +577,8 @@ func (pc *PeerConnection) hasLocalDescriptionChanged(desc *SessionDescription) b
return false
}

var errExcessiveRetries = errors.New("excessive retries in CreateOffer")

// CreateOffer starts the PeerConnection and generates the localDescription
// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-createoffer
func (pc *PeerConnection) CreateOffer(options *OfferOptions) (SessionDescription, error) { //nolint:gocognit
Expand Down Expand Up @@ -603,6 +606,7 @@ func (pc *PeerConnection) CreateOffer(options *OfferOptions) (SessionDescription
// audio RTCRtpTransceiver was added to connection, but while performing the in-parallel
// steps to create an offer, a video RTCRtpTransceiver was added, requiring additional
// inspection of video system resources.
count := 0
for {
// We cache current transceivers to ensure they aren't
// mutated during offer generation. We later check if they have
Expand Down Expand Up @@ -673,6 +677,10 @@ func (pc *PeerConnection) CreateOffer(options *OfferOptions) (SessionDescription
if isPlanB || !pc.hasLocalDescriptionChanged(&offer) {
break
}
count++
if count >= 128 {
return SessionDescription{}, errExcessiveRetries
}
}

pc.lastOffer = offer.SDP
Expand Down

0 comments on commit 723c598

Please sign in to comment.