henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_ |
| 29 | #define PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_ |
| 30 | #pragma once |
| 31 | |
| 32 | #include <deque> |
| 33 | #include <map> |
| 34 | #include <set> |
| 35 | #include <string> |
| 36 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | #include "talk/app/webrtc/mediastreaminterface.h" |
| 38 | #include "talk/app/webrtc/peerconnectioninterface.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 39 | #include "talk/examples/peerconnection/client/main_wnd.h" |
| 40 | #include "talk/examples/peerconnection/client/peer_connection_client.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 41 | #include "webrtc/base/scoped_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
| 43 | namespace webrtc { |
| 44 | class VideoCaptureModule; |
| 45 | } // namespace webrtc |
| 46 | |
| 47 | namespace cricket { |
| 48 | class VideoRenderer; |
| 49 | } // namespace cricket |
| 50 | |
| 51 | class Conductor |
| 52 | : public webrtc::PeerConnectionObserver, |
| 53 | public webrtc::CreateSessionDescriptionObserver, |
| 54 | public PeerConnectionClientObserver, |
| 55 | public MainWndCallback { |
| 56 | public: |
| 57 | enum CallbackID { |
| 58 | MEDIA_CHANNELS_INITIALIZED = 1, |
| 59 | PEER_CONNECTION_CLOSED, |
| 60 | SEND_MESSAGE_TO_PEER, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | NEW_STREAM_ADDED, |
| 62 | STREAM_REMOVED, |
| 63 | }; |
| 64 | |
| 65 | Conductor(PeerConnectionClient* client, MainWindow* main_wnd); |
| 66 | |
| 67 | bool connection_active() const; |
| 68 | |
| 69 | virtual void Close(); |
| 70 | |
| 71 | protected: |
| 72 | ~Conductor(); |
| 73 | bool InitializePeerConnection(); |
braveyao@webrtc.org | a742cb1 | 2015-01-29 04:23:01 +0000 | [diff] [blame^] | 74 | bool ReinitializePeerConnectionForLoopback(); |
| 75 | bool CreatePeerConnection(bool dtls); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | void DeletePeerConnection(); |
| 77 | void EnsureStreamingUI(); |
| 78 | void AddStreams(); |
| 79 | cricket::VideoCapturer* OpenVideoCaptureDevice(); |
| 80 | |
| 81 | // |
| 82 | // PeerConnectionObserver implementation. |
| 83 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | virtual void OnStateChange( |
| 85 | webrtc::PeerConnectionObserver::StateType state_changed) {} |
| 86 | virtual void OnAddStream(webrtc::MediaStreamInterface* stream); |
| 87 | virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 88 | virtual void OnDataChannel(webrtc::DataChannelInterface* channel) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | virtual void OnRenegotiationNeeded() {} |
| 90 | virtual void OnIceChange() {} |
| 91 | virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate); |
| 92 | |
| 93 | // |
| 94 | // PeerConnectionClientObserver implementation. |
| 95 | // |
| 96 | |
| 97 | virtual void OnSignedIn(); |
| 98 | |
| 99 | virtual void OnDisconnected(); |
| 100 | |
| 101 | virtual void OnPeerConnected(int id, const std::string& name); |
| 102 | |
| 103 | virtual void OnPeerDisconnected(int id); |
| 104 | |
| 105 | virtual void OnMessageFromPeer(int peer_id, const std::string& message); |
| 106 | |
| 107 | virtual void OnMessageSent(int err); |
| 108 | |
| 109 | virtual void OnServerConnectionFailure(); |
| 110 | |
| 111 | // |
| 112 | // MainWndCallback implementation. |
| 113 | // |
| 114 | |
| 115 | virtual void StartLogin(const std::string& server, int port); |
| 116 | |
| 117 | virtual void DisconnectFromServer(); |
| 118 | |
| 119 | virtual void ConnectToPeer(int peer_id); |
| 120 | |
| 121 | virtual void DisconnectFromCurrentPeer(); |
| 122 | |
| 123 | virtual void UIThreadCallback(int msg_id, void* data); |
| 124 | |
| 125 | // CreateSessionDescriptionObserver implementation. |
| 126 | virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc); |
| 127 | virtual void OnFailure(const std::string& error); |
| 128 | |
| 129 | protected: |
| 130 | // Send a message to the remote peer. |
| 131 | void SendMessage(const std::string& json_object); |
| 132 | |
| 133 | int peer_id_; |
braveyao@webrtc.org | a742cb1 | 2015-01-29 04:23:01 +0000 | [diff] [blame^] | 134 | bool loopback_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 135 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 136 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | peer_connection_factory_; |
| 138 | PeerConnectionClient* client_; |
| 139 | MainWindow* main_wnd_; |
| 140 | std::deque<std::string*> pending_messages_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 141 | std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> > |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | active_streams_; |
| 143 | std::string server_; |
| 144 | }; |
| 145 | |
| 146 | #endif // PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_ |