diff --git a/worker/include/RTC/IceServer.hpp b/worker/include/RTC/IceServer.hpp index 3b45e3d49c..cd91938bee 100644 --- a/worker/include/RTC/IceServer.hpp +++ b/worker/include/RTC/IceServer.hpp @@ -93,9 +93,11 @@ namespace RTC } bool IsValidTuple(const RTC::TransportTuple* tuple) const; void RemoveTuple(RTC::TransportTuple* tuple); - // This should be just called in 'connected' or completed' state - // and the given tuple must be an already valid tuple. - void ForceSelectedTuple(const RTC::TransportTuple* tuple); + /** + * This should be just called in 'connected' or completed' state and the + * given tuple must be an already valid tuple. + */ + void MayForceSelectedTuple(const RTC::TransportTuple* tuple); private: void HandleTuple( diff --git a/worker/src/RTC/IceServer.cpp b/worker/src/RTC/IceServer.cpp index c627c21db9..e3e963788d 100644 --- a/worker/src/RTC/IceServer.cpp +++ b/worker/src/RTC/IceServer.cpp @@ -337,18 +337,25 @@ namespace RTC } } - void IceServer::ForceSelectedTuple(const RTC::TransportTuple* tuple) + void IceServer::MayForceSelectedTuple(const RTC::TransportTuple* tuple) { MS_TRACE(); - MS_ASSERT( - this->selectedTuple, "cannot force the selected tuple if there was not a selected tuple"); + if (this->state != IceState::CONNECTED && this->state != IceState::COMPLETED) + { + MS_WARN_TAG(ice, "cannot force selected tuple if not in state 'connected' or 'completed'"); + + return; + } auto* storedTuple = HasTuple(tuple); - MS_ASSERT( - storedTuple, - "cannot force the selected tuple if the given tuple was not already a valid tuple"); + if (!storedTuple) + { + MS_WARN_TAG(ice, "cannot force selected tuple if the given tuple was not already a valid one"); + + return; + } // Mark it as selected tuple. SetSelectedTuple(storedTuple); diff --git a/worker/src/RTC/WebRtcTransport.cpp b/worker/src/RTC/WebRtcTransport.cpp index b5a54fd986..70ef85dcca 100644 --- a/worker/src/RTC/WebRtcTransport.cpp +++ b/worker/src/RTC/WebRtcTransport.cpp @@ -1058,10 +1058,11 @@ namespace RTC } // Trick for clients performing aggressive ICE regardless we are ICE-Lite. - // NOTE: Only do it if we already have a selected ICE candidate tuple. - if (this->iceServer->GetSelectedTuple()) + if ( + this->iceServer->GetState() == RTC::IceServer::IceState::CONNECTED || + this->iceServer->GetState() == RTC::IceServer::IceState::COMPLETED) { - this->iceServer->ForceSelectedTuple(tuple); + this->iceServer->MayForceSelectedTuple(tuple); } // Check that DTLS status is 'connecting' or 'connected'. @@ -1146,10 +1147,11 @@ namespace RTC } // Trick for clients performing aggressive ICE regardless we are ICE-Lite. - // NOTE: Only do it if we already have a selected ICE candidate tuple. - if (this->iceServer->GetSelectedTuple()) + if ( + this->iceServer->GetState() == RTC::IceServer::IceState::CONNECTED || + this->iceServer->GetState() == RTC::IceServer::IceState::COMPLETED) { - this->iceServer->ForceSelectedTuple(tuple); + this->iceServer->MayForceSelectedTuple(tuple); } // Pass the packet to the parent transport.