Home | History | Annotate | Download | only in client
      1 /*
      2  *  Copyright 2010 The WebRTC Project Authors. All rights reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_P2P_CLIENT_AUTOPORTALLOCATOR_H_
     12 #define WEBRTC_P2P_CLIENT_AUTOPORTALLOCATOR_H_
     13 
     14 #include <string>
     15 #include <vector>
     16 
     17 #include "webrtc/p2p/client/httpportallocator.h"
     18 #include "webrtc/base/sigslot.h"
     19 
     20 // This class sets the relay and stun servers using XmppClient.
     21 // It enables the client to traverse Proxy and NAT.
     22 class AutoPortAllocator : public cricket::HttpPortAllocator {
     23  public:
     24   AutoPortAllocator(rtc::NetworkManager* network_manager,
     25                     const std::string& user_agent)
     26       : cricket::HttpPortAllocator(network_manager, user_agent) {
     27   }
     28 
     29   // Creates and initiates a task to get relay token from XmppClient and set
     30   // it appropriately.
     31   void SetXmppClient(buzz::XmppClient* client) {
     32     // The JingleInfoTask is freed by the task-runner.
     33     buzz::JingleInfoTask* jit = new buzz::JingleInfoTask(client);
     34     jit->SignalJingleInfo.connect(this, &AutoPortAllocator::OnJingleInfo);
     35     jit->Start();
     36     jit->RefreshJingleInfoNow();
     37   }
     38 
     39  private:
     40   void OnJingleInfo(
     41       const std::string& token,
     42       const std::vector<std::string>& relay_hosts,
     43       const std::vector<rtc::SocketAddress>& stun_hosts) {
     44     SetRelayToken(token);
     45     SetStunHosts(stun_hosts);
     46     SetRelayHosts(relay_hosts);
     47   }
     48 };
     49 
     50 #endif  // WEBRTC_P2P_CLIENT_AUTOPORTALLOCATOR_H_
     51