Conductor::OnSuccess中调用 peer_connection_->SetLocalDescription(DummySetSessionDescriptionObserver::Create(), desc);就会触发candidate的收集,具体的收集逻辑如下:
收集 host candidate 流程
===>void PeerConnection::SetLocalDescription(
SetSessionDescriptionObserver* observer,
SessionDescriptionInterface* desc_ptr) ===> this_weak_ptr->DoSetLocalDescription(
std::move(desc),
rtc::scoped_refptr<SetLocalDescriptionObserverInterface>(
new rtc::RefCountedObject<SetSessionDescriptionObserverAdapter>(
this_weak_ptr, observer_refptr)));
===> PeerConnection::DoSetLocalDescription(
std::unique_ptr<SessionDescriptionInterface> desc,
rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) ===> transport_controller_->MaybeStartGathering();
===> JsepTransportController::MaybeStartGathering() ===> dtls->ice_transport()->MaybeStartGathering();
===> P2PTransportChannel::MaybeStartGathering() ===> allocator_sessions_.back()->StartGettingPorts();
===> BasicPortAllocatorSession::StartGettingPorts() ===> network_thread_->Post(RTC_FROM_HERE, this, MSG_CONFIG_START);
===> BasicPortAllocatorSession::OnMessage(rtc::Message* message) ===> GetPortConfigurations();
===> BasicPortAllocatorSession::GetPortConfigurations() ===> ConfigReady(config);
===> BasicPortAllocatorSession::ConfigReady(PortConfiguration* config) ===> network_thread_->Post(RTC_FROM_HERE, this, MSG_CONFIG_READY, config);
===> BasicPortAllocatorSession::OnConfigReady(PortConfiguration* config) ===> AllocatePorts();
===> BasicPortAllocatorSession::AllocatePorts() ===> network_thread_->Post(RTC_FROM_HERE, this, MSG_ALLOCATE);
===> BasicPortAllocatorSession::OnAllocate() ===> DoAllocate(disable_equivalent_phases);
===> BasicPortAllocatorSession::DoAllocate(bool disable_equivalent) ===> sequence->Start();
===> AllocationSequence::Start() ===> CreateUDPPorts();
===> AllocationSequence::CreateUDPPorts() ===> session_->AddAllocatedPort(port.release(), this, true);
===> BasicPortAllocatorSession::AddAllocatedPort ===> port->PrepareAddress();
===> UDPPort::PrepareAddress() ===> OnLocalAddressReady(socket_, socket_->GetLocalAddress());
===> UDPPort::OnLocalAddressReady ===> AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "",
LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, "", false);
===> Port::AddAddress ===> FinishAddingAddress(c, is_final);
===> Port::FinishAddingAddress ===> SignalCandidateReady(this, c);
===> BasicPortAllocatorSession::OnCandidateReady ===> SignalCandidatesReady(this, candidates);
===> P2PTransportChannel::OnCandidatesReady ===> SignalCandidateGathered(this, candidates[i]);
===> JsepTransportController::OnTransportCandidateGathered_n ===> SignalIceCandidatesGathered(transport_name, {candidate});
===> PeerConnection::OnTransportControllerCandidatesGathered ===> OnIceCandidate(std::move(candidate));