webrtc连通性检查

1. 保活机制

webrtc会每隔两秒,检查一下网络状态是否有变化,若是有变化,就重新探测网络,选择其他的传输方式。代码如下:

const int kNetworksUpdateIntervalMs = 2000;

void BasicNetworkManager::UpdateNetworksContinually() {
  UpdateNetworksOnce();
  thread_->PostDelayed(RTC_FROM_HERE, kNetworksUpdateIntervalMs, this,
                       kUpdateNetworksMessage);
}

void BasicNetworkManager::UpdateNetworksOnce() {
  if (!start_count_)
    return;

  RTC_DCHECK(Thread::Current() == thread_);

  NetworkList list;
  if (!CreateNetworks(false, &list)) {
    SignalError();
  } else {
    bool changed;
    NetworkManager::Stats stats;
    MergeNetworkList(list, &changed, &stats);
    set_default_local_addresses(QueryDefaultLocalAddress(AF_INET),
                                QueryDefaultLocalAddress(AF_INET6));
    if (changed || !sent_first_update_) {
      SignalNetworksChanged();
      sent_first_update_ = true;
    }
  }
}

代码函数调用关系如下:

P2PTransportChannel::AddRemoteCandidate
P2PTransportChannel::SortConnectionsAndUpdateState
P2PTransportChannel::MaybeStartPinging
thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING);  (连接建立才会通知无ping,在P2PTransportChannel::IsPingable接口判断)
P2PTransportChannel::OnCheckAndPing()

 

2. 连接删除

webrtc连通性检查_第1张图片

转载于:https://my.oschina.net/xgcode/blog/2870333

你可能感兴趣的:(webrtc连通性检查)