From c47c1e105ebe8bbeb2303a0775804128026661d6 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 2 Feb 2021 23:29:58 +0100 Subject: [PATCH] Fix check for unchanged transceivers in CreateOffer We used to reverse-engineer the list of transceivers from the generated offer, which is fragile. Check that the list of transceivers hasn't been changed instead. --- peerconnection.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/peerconnection.go b/peerconnection.go index f8c0d153e91..0922c24afce 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -561,18 +561,16 @@ func (pc *PeerConnection) getStatsID() string { return pc.statsID } -func (pc *PeerConnection) hasLocalDescriptionChanged(desc *SessionDescription) bool { - for _, t := range pc.GetTransceivers() { - m := getByMid(t.Mid(), desc) - if m == nil { - return true - } - - if getPeerDirection(m) != t.Direction() { +func (pc *PeerConnection) hasLocalDescriptionChanged(old []*RTPTransceiver) bool { + transceivers := pc.GetTransceivers() + if len(transceivers) != len(old) { + return true + } + for i, t := range transceivers { + if t != old[i] { return true } } - return false } @@ -670,7 +668,7 @@ func (pc *PeerConnection) CreateOffer(options *OfferOptions) (SessionDescription // Verify local media hasn't changed during offer // generation. Recompute if necessary - if isPlanB || !pc.hasLocalDescriptionChanged(&offer) { + if isPlanB || !pc.hasLocalDescriptionChanged(currentTransceivers) { break } }