Have to go through the full ICE restart checks after gatheting finishes. (#963)

This commit is contained in:
Raja Subramanian
2022-08-29 09:45:38 +05:30
committed by GitHub
parent b99d128c6c
commit 4217f198d6
2 changed files with 16 additions and 12 deletions
+10 -6
View File
@@ -1229,7 +1229,7 @@ func (t *PCTransport) handleICEGatheringCompleteOfferer() error {
t.params.Logger.Debugw("restarting ICE after ICE gathering") t.params.Logger.Debugw("restarting ICE after ICE gathering")
t.restartAfterGathering = false t.restartAfterGathering = false
return t.createAndSendOffer(&webrtc.OfferOptions{ICERestart: true}) return t.doICERestart()
} }
func (t *PCTransport) handleICEGatheringCompleteAnswerer() error { func (t *PCTransport) handleICEGatheringCompleteAnswerer() error {
@@ -1664,7 +1664,7 @@ func (t *PCTransport) handleRemoteAnswerReceived(sd *webrtc.SessionDescription)
return nil return nil
} }
func (t *PCTransport) handleICERestart(e *event) error { func (t *PCTransport) doICERestart() error {
if t.pc.ConnectionState() == webrtc.PeerConnectionStateClosed { if t.pc.ConnectionState() == webrtc.PeerConnectionStateClosed {
t.params.Logger.Warnw("trying to restart ICE on closed peer connection", nil) t.params.Logger.Warnw("trying to restart ICE on closed peer connection", nil)
return nil return nil
@@ -1672,7 +1672,7 @@ func (t *PCTransport) handleICERestart(e *event) error {
// if restart is requested, and we are not ready, then continue afterwards // if restart is requested, and we are not ready, then continue afterwards
if t.pc.ICEGatheringState() == webrtc.ICEGatheringStateGathering { if t.pc.ICEGatheringState() == webrtc.ICEGatheringStateGathering {
t.params.Logger.Debugw("restart ICE after gathering") t.params.Logger.Debugw("deferring ICE restart to after gathering")
t.restartAfterGathering = true t.restartAfterGathering = true
return nil return nil
} }
@@ -1681,8 +1681,8 @@ func (t *PCTransport) handleICERestart(e *event) error {
return t.createAndSendOffer(&webrtc.OfferOptions{ICERestart: true}) return t.createAndSendOffer(&webrtc.OfferOptions{ICERestart: true})
} }
currentSD := t.pc.CurrentRemoteDescription() currentRemoteDescription := t.pc.CurrentRemoteDescription()
if currentSD == nil { if currentRemoteDescription == nil {
// restart without current remote description, send current local description again to try recover // restart without current remote description, send current local description again to try recover
offer := t.pc.LocalDescription() offer := t.pc.LocalDescription()
if offer == nil { if offer == nil {
@@ -1707,7 +1707,7 @@ func (t *PCTransport) handleICERestart(e *event) error {
} else { } else {
// recover by re-applying the last answer // recover by re-applying the last answer
t.params.Logger.Infow("recovering from client negotiation state on ICE restart") t.params.Logger.Infow("recovering from client negotiation state on ICE restart")
if err := t.pc.SetRemoteDescription(*currentSD); err != nil { if err := t.pc.SetRemoteDescription(*currentRemoteDescription); err != nil {
prometheus.ServiceOperationCounter.WithLabelValues("offer", "error", "remote_description").Add(1) prometheus.ServiceOperationCounter.WithLabelValues("offer", "error", "remote_description").Add(1)
return errors.Wrap(err, "set remote description failed") return errors.Wrap(err, "set remote description failed")
} else { } else {
@@ -1716,3 +1716,7 @@ func (t *PCTransport) handleICERestart(e *event) error {
} }
} }
} }
func (t *PCTransport) handleICERestart(e *event) error {
return t.doICERestart()
}
+5 -5
View File
@@ -234,7 +234,12 @@ func TestFirstAnswerMissedDuringICERestart(t *testing.T) {
// first anwser missed // first anwser missed
var firstAnswerReceived atomic.Bool var firstAnswerReceived atomic.Bool
transportB.OnAnswer(func(sd webrtc.SessionDescription) error { transportB.OnAnswer(func(sd webrtc.SessionDescription) error {
if firstAnswerReceived.Load() {
transportA.HandleRemoteDescription(sd)
} else {
// do not send first answer so that remote misses the first answer
firstAnswerReceived.Store(true) firstAnswerReceived.Store(true)
}
return nil return nil
}) })
transportA.OnOffer(func(sd webrtc.SessionDescription) error { transportA.OnOffer(func(sd webrtc.SessionDescription) error {
@@ -250,11 +255,6 @@ func TestFirstAnswerMissedDuringICERestart(t *testing.T) {
// set offer/answer with restart ICE, will negotiate twice, // set offer/answer with restart ICE, will negotiate twice,
// first one is recover from missed offer // first one is recover from missed offer
// second one is restartICE // second one is restartICE
transportB.OnAnswer(func(answer webrtc.SessionDescription) error {
transportA.HandleRemoteDescription(answer)
return nil
})
var offerCount atomic.Int32 var offerCount atomic.Int32
transportA.OnOffer(func(sd webrtc.SessionDescription) error { transportA.OnOffer(func(sd webrtc.SessionDescription) error {
offerCount.Inc() offerCount.Inc()