3 * Copyright 2012, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
28 #ifndef PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
29 #define PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
37 #include "talk/app/webrtc/mediastreaminterface.h"
38 #include "talk/app/webrtc/peerconnectioninterface.h"
39 #include "talk/examples/peerconnection/client/main_wnd.h"
40 #include "talk/examples/peerconnection/client/peer_connection_client.h"
41 #include "webrtc/base/scoped_ptr.h"
44 class VideoCaptureModule;
49 } // namespace cricket
52 : public webrtc::PeerConnectionObserver,
53 public webrtc::CreateSessionDescriptionObserver,
54 public PeerConnectionClientObserver,
55 public MainWndCallback {
58 MEDIA_CHANNELS_INITIALIZED = 1,
59 PEER_CONNECTION_CLOSED,
61 PEER_CONNECTION_ERROR,
66 Conductor(PeerConnectionClient* client, MainWindow* main_wnd);
68 bool connection_active() const;
74 bool InitializePeerConnection();
75 void DeletePeerConnection();
76 void EnsureStreamingUI();
78 cricket::VideoCapturer* OpenVideoCaptureDevice();
81 // PeerConnectionObserver implementation.
83 virtual void OnError();
84 virtual void OnStateChange(
85 webrtc::PeerConnectionObserver::StateType state_changed) {}
86 virtual void OnAddStream(webrtc::MediaStreamInterface* stream);
87 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream);
88 virtual void OnRenegotiationNeeded() {}
89 virtual void OnIceChange() {}
90 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate);
93 // PeerConnectionClientObserver implementation.
96 virtual void OnSignedIn();
98 virtual void OnDisconnected();
100 virtual void OnPeerConnected(int id, const std::string& name);
102 virtual void OnPeerDisconnected(int id);
104 virtual void OnMessageFromPeer(int peer_id, const std::string& message);
106 virtual void OnMessageSent(int err);
108 virtual void OnServerConnectionFailure();
111 // MainWndCallback implementation.
114 virtual void StartLogin(const std::string& server, int port);
116 virtual void DisconnectFromServer();
118 virtual void ConnectToPeer(int peer_id);
120 virtual void DisconnectFromCurrentPeer();
122 virtual void UIThreadCallback(int msg_id, void* data);
124 // CreateSessionDescriptionObserver implementation.
125 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
126 virtual void OnFailure(const std::string& error);
129 // Send a message to the remote peer.
130 void SendMessage(const std::string& json_object);
133 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
134 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
135 peer_connection_factory_;
136 PeerConnectionClient* client_;
137 MainWindow* main_wnd_;
138 std::deque<std::string*> pending_messages_;
139 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> >
144 #endif // PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_