diff --git a/erizo/src/erizo/NicerConnection.cpp b/erizo/src/erizo/NicerConnection.cpp index a5871a869a..99004a2604 100644 --- a/erizo/src/erizo/NicerConnection.cpp +++ b/erizo/src/erizo/NicerConnection.cpp @@ -322,20 +322,25 @@ void NicerConnection::startGathering() { bool NicerConnection::setRemoteCandidates(const std::vector &candidates, bool is_bundle) { std::vector cands(candidates); auto remote_candidates_promise = std::make_shared>(); - nr_ice_peer_ctx *peer = peer_; - nr_ice_media_stream *stream = stream_; - std::shared_ptr nicer = nicer_; - async([cands, nicer, peer, stream, this, remote_candidates_promise] + async([cands, this, remote_candidates_promise] (std::shared_ptr this_ptr) { ELOG_DEBUG("%s message: adding remote candidates (%ld)", toLog(), cands.size()); + nr_ice_peer_ctx *peer = this_ptr->peer_; + nr_ice_media_stream *stream = this_ptr->stream_; + std::shared_ptr nicer = this_ptr->nicer_; for (const CandidateInfo &cand : cands) { std::string sdp = cand.sdp; std::size_t pos = sdp.find(","); std::string candidate = sdp.substr(0, pos); ELOG_DEBUG("%s message: New remote ICE candidate (%s)", toLog(), candidate.c_str()); - UINT4 r = nicer->IcePeerContextParseTrickleCandidate(peer, stream, const_cast(candidate.c_str())); - if (r && r != R_ALREADY) { - ELOG_WARN("%s message: Couldn't add remote ICE candidate (%s) (%d)", toLog(), candidate.c_str(), r); + if (peer != nullptr) { + UINT4 r = nicer->IcePeerContextParseTrickleCandidate(peer, stream, const_cast(candidate.c_str())); + if (r && r != R_ALREADY) { + ELOG_WARN("%s message: Couldn't add remote ICE candidate (%s) (%d)", toLog(), candidate.c_str(), r); + } + } else { + ELOG_WARN("%s message: Couldn't add remote ICE candidate (%s) bacause peer is NULL", + toLog(), candidate.c_str()); } } remote_candidates_promise->set_value(); diff --git a/erizo/src/erizo/NicerConnection.h b/erizo/src/erizo/NicerConnection.h index e467358826..fc44a83400 100644 --- a/erizo/src/erizo/NicerConnection.h +++ b/erizo/src/erizo/NicerConnection.h @@ -107,6 +107,7 @@ class NicerConnection : public IceConnection, public std::enable_shared_from_thi nr_ice_handler* ice_handler_; std::promise close_promise_; std::promise start_promise_; + std::future start_future_; boost::mutex close_mutex_; boost::mutex close_sync_mutex_; }; diff --git a/erizo/src/test/NicerConnectionTest.cpp b/erizo/src/test/NicerConnectionTest.cpp index c5fa0823e5..b1337619b7 100644 --- a/erizo/src/test/NicerConnectionTest.cpp +++ b/erizo/src/test/NicerConnectionTest.cpp @@ -348,7 +348,8 @@ TEST_F(NicerConnectionTest, setRemoteCandidates_Success_WhenCalled) { std::vector candidate_list; candidate_list.push_back(arbitrary_candidate); - EXPECT_CALL(*nicer, IcePeerContextParseTrickleCandidate(_, _, _)).Times(1); + EXPECT_CALL(*nicer, IcePeerContextParseTrickleCandidate(_, _, _)).Times(2); + nicer_connection->setRemoteCandidates(candidate_list, true); nicer_connection->setRemoteCandidates(candidate_list, true); }