tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

conductor.h (4444B)


      1 /*
      2 *  Copyright 2012 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 EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
     12 #define EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
     13 
     14 #include <deque>
     15 #include <memory>
     16 #include <string>
     17 #include <vector>
     18 
     19 #include "absl/base/nullability.h"
     20 #include "api/data_channel_interface.h"
     21 #include "api/environment/environment.h"
     22 #include "api/jsep.h"
     23 #include "api/media_stream_interface.h"
     24 #include "api/peer_connection_interface.h"
     25 #include "api/rtc_error.h"
     26 #include "api/rtp_receiver_interface.h"
     27 #include "api/scoped_refptr.h"
     28 #include "examples/peerconnection/client/main_wnd.h"
     29 #include "examples/peerconnection/client/peer_connection_client.h"
     30 #include "rtc_base/thread.h"
     31 
     32 namespace webrtc {
     33 class VideoCaptureModule;
     34 }  // namespace webrtc
     35 
     36 class Conductor : public webrtc::PeerConnectionObserver,
     37                  public webrtc::CreateSessionDescriptionObserver,
     38                  public PeerConnectionClientObserver,
     39                  public MainWndCallback {
     40 public:
     41  enum CallbackID {
     42    MEDIA_CHANNELS_INITIALIZED = 1,
     43    PEER_CONNECTION_CLOSED,
     44    SEND_MESSAGE_TO_PEER,
     45    NEW_TRACK_ADDED,
     46    TRACK_REMOVED,
     47  };
     48 
     49  Conductor(const webrtc::Environment& env,
     50            PeerConnectionClient* absl_nonnull client,
     51            MainWindow* absl_nonnull main_wnd);
     52 
     53  bool connection_active() const;
     54 
     55  void Close() override;
     56 
     57 protected:
     58  ~Conductor();
     59  bool InitializePeerConnection();
     60  bool ReinitializePeerConnectionForLoopback();
     61  bool CreatePeerConnection();
     62  void DeletePeerConnection();
     63  void EnsureStreamingUI();
     64  void AddTracks();
     65 
     66  //
     67  // PeerConnectionObserver implementation.
     68  //
     69 
     70  void OnSignalingChange(
     71      webrtc::PeerConnectionInterface::SignalingState new_state) override {}
     72  void OnAddTrack(
     73      webrtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
     74      const std::vector<webrtc::scoped_refptr<webrtc::MediaStreamInterface>>&
     75          streams) override;
     76  void OnRemoveTrack(
     77      webrtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) override;
     78  void OnDataChannel(
     79      webrtc::scoped_refptr<webrtc::DataChannelInterface> channel) override {}
     80  void OnRenegotiationNeeded() override {}
     81  void OnIceConnectionChange(
     82      webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
     83  void OnIceGatheringChange(
     84      webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
     85  void OnIceCandidate(const webrtc::IceCandidate* candidate) override;
     86  void OnIceConnectionReceivingChange(bool receiving) override {}
     87  void OnIceCandidateRemoved(const webrtc::IceCandidate* candidate) override {}
     88 
     89  //
     90  // PeerConnectionClientObserver implementation.
     91  //
     92 
     93  void OnSignedIn() override;
     94 
     95  void OnDisconnected() override;
     96 
     97  void OnPeerConnected(int id, const std::string& name) override;
     98 
     99  void OnPeerDisconnected(int id) override;
    100 
    101  void OnMessageFromPeer(int peer_id, const std::string& message) override;
    102 
    103  void OnMessageSent(int err) override;
    104 
    105  void OnServerConnectionFailure() override;
    106 
    107  //
    108  // MainWndCallback implementation.
    109  //
    110 
    111  void StartLogin(const std::string& server, int port) override;
    112 
    113  void DisconnectFromServer() override;
    114 
    115  void ConnectToPeer(int peer_id) override;
    116 
    117  void DisconnectFromCurrentPeer() override;
    118 
    119  void UIThreadCallback(int msg_id, void* data) override;
    120 
    121  // CreateSessionDescriptionObserver implementation.
    122  void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
    123  void OnFailure(webrtc::RTCError error) override;
    124 
    125 protected:
    126  // Send a message to the remote peer.
    127  void SendMessage(const std::string& json_object);
    128 
    129  int peer_id_;
    130  bool loopback_;
    131  const webrtc::Environment env_;
    132  std::unique_ptr<webrtc::Thread> signaling_thread_;
    133  webrtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
    134  webrtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
    135      peer_connection_factory_;
    136  PeerConnectionClient* client_;
    137  MainWindow* main_wnd_;
    138  std::deque<std::string*> pending_messages_;
    139  std::string server_;
    140 };
    141 
    142 #endif  // EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_