henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
jbauch | 70625e5 | 2015-12-09 14:18:14 -0800 | [diff] [blame] | 11 | #ifndef WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_ |
| 12 | #define WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | #pragma once |
| 14 | |
| 15 | #include <deque> |
| 16 | #include <map> |
| 17 | #include <set> |
| 18 | #include <string> |
| 19 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame^] | 20 | #include "webrtc/api/mediastreaminterface.h" |
| 21 | #include "webrtc/api/peerconnectioninterface.h" |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 22 | #include "webrtc/examples/peerconnection/client/main_wnd.h" |
| 23 | #include "webrtc/examples/peerconnection/client/peer_connection_client.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 24 | #include "webrtc/base/scoped_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | class VideoCaptureModule; |
| 28 | } // namespace webrtc |
| 29 | |
| 30 | namespace cricket { |
| 31 | class VideoRenderer; |
| 32 | } // namespace cricket |
| 33 | |
| 34 | class Conductor |
| 35 | : public webrtc::PeerConnectionObserver, |
| 36 | public webrtc::CreateSessionDescriptionObserver, |
| 37 | public PeerConnectionClientObserver, |
| 38 | public MainWndCallback { |
| 39 | public: |
| 40 | enum CallbackID { |
| 41 | MEDIA_CHANNELS_INITIALIZED = 1, |
| 42 | PEER_CONNECTION_CLOSED, |
| 43 | SEND_MESSAGE_TO_PEER, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | NEW_STREAM_ADDED, |
| 45 | STREAM_REMOVED, |
| 46 | }; |
| 47 | |
| 48 | Conductor(PeerConnectionClient* client, MainWindow* main_wnd); |
| 49 | |
| 50 | bool connection_active() const; |
| 51 | |
| 52 | virtual void Close(); |
| 53 | |
| 54 | protected: |
| 55 | ~Conductor(); |
| 56 | bool InitializePeerConnection(); |
braveyao@webrtc.org | a742cb1 | 2015-01-29 04:23:01 +0000 | [diff] [blame] | 57 | bool ReinitializePeerConnectionForLoopback(); |
| 58 | bool CreatePeerConnection(bool dtls); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | void DeletePeerConnection(); |
| 60 | void EnsureStreamingUI(); |
| 61 | void AddStreams(); |
| 62 | cricket::VideoCapturer* OpenVideoCaptureDevice(); |
| 63 | |
| 64 | // |
| 65 | // PeerConnectionObserver implementation. |
| 66 | // |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 67 | |
| 68 | void OnSignalingChange( |
| 69 | webrtc::PeerConnectionInterface::SignalingState new_state) override{}; |
| 70 | void OnAddStream(webrtc::MediaStreamInterface* stream) override; |
| 71 | void OnRemoveStream(webrtc::MediaStreamInterface* stream) override; |
| 72 | void OnDataChannel(webrtc::DataChannelInterface* channel) override {} |
| 73 | void OnRenegotiationNeeded() override {} |
| 74 | void OnIceConnectionChange( |
| 75 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override{}; |
| 76 | void OnIceGatheringChange( |
| 77 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override{}; |
| 78 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
| 79 | void OnIceConnectionReceivingChange(bool receiving) override {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | |
| 81 | // |
| 82 | // PeerConnectionClientObserver implementation. |
| 83 | // |
| 84 | |
| 85 | virtual void OnSignedIn(); |
| 86 | |
| 87 | virtual void OnDisconnected(); |
| 88 | |
| 89 | virtual void OnPeerConnected(int id, const std::string& name); |
| 90 | |
| 91 | virtual void OnPeerDisconnected(int id); |
| 92 | |
| 93 | virtual void OnMessageFromPeer(int peer_id, const std::string& message); |
| 94 | |
| 95 | virtual void OnMessageSent(int err); |
| 96 | |
| 97 | virtual void OnServerConnectionFailure(); |
| 98 | |
| 99 | // |
| 100 | // MainWndCallback implementation. |
| 101 | // |
| 102 | |
| 103 | virtual void StartLogin(const std::string& server, int port); |
| 104 | |
| 105 | virtual void DisconnectFromServer(); |
| 106 | |
| 107 | virtual void ConnectToPeer(int peer_id); |
| 108 | |
| 109 | virtual void DisconnectFromCurrentPeer(); |
| 110 | |
| 111 | virtual void UIThreadCallback(int msg_id, void* data); |
| 112 | |
| 113 | // CreateSessionDescriptionObserver implementation. |
| 114 | virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc); |
| 115 | virtual void OnFailure(const std::string& error); |
| 116 | |
| 117 | protected: |
| 118 | // Send a message to the remote peer. |
| 119 | void SendMessage(const std::string& json_object); |
| 120 | |
| 121 | int peer_id_; |
braveyao@webrtc.org | a742cb1 | 2015-01-29 04:23:01 +0000 | [diff] [blame] | 122 | bool loopback_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 123 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 124 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | peer_connection_factory_; |
| 126 | PeerConnectionClient* client_; |
| 127 | MainWindow* main_wnd_; |
| 128 | std::deque<std::string*> pending_messages_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 129 | std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> > |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | active_streams_; |
| 131 | std::string server_; |
| 132 | }; |
| 133 | |
jbauch | 70625e5 | 2015-12-09 14:18:14 -0800 | [diff] [blame] | 134 | #endif // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_ |