more reliable handling of ICE restart

This commit is contained in:
David Zhao
2021-05-14 22:03:08 -07:00
parent c76cdf11c2
commit ccb322c9c2
2 changed files with 94 additions and 3 deletions
+12 -3
View File
@@ -161,11 +161,20 @@ func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error {
}
state := t.negotiationState.Load().(int)
// when there's an ongoing negotiation, let it finish and not disrupt its state
if state == negotiationStateClient {
logger.Debugw("skipping negotiation, trying again later")
t.negotiationState.Store(negotiationRetry)
return nil
currentSD := t.pc.CurrentRemoteDescription()
if options != nil && options.ICERestart && currentSD != nil {
logger.Debugw("recovering from client negotiation state")
if err := t.pc.SetRemoteDescription(*currentSD); err != nil {
return err
}
} else {
logger.Debugw("skipping negotiation, trying again later")
t.negotiationState.Store(negotiationRetry)
return nil
}
}
offer, err := t.pc.CreateOffer(options)