blob: 43303a34f0a4422c7606fc5c2e287fea56f31ac8 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
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
braveyao@webrtc.orgc68e0c92015-02-27 09:51:25 +000028#ifndef TALK_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
29#define TALK_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#pragma once
31
32#include <deque>
33#include <map>
34#include <set>
35#include <string>
36
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/app/webrtc/mediastreaminterface.h"
38#include "talk/app/webrtc/peerconnectioninterface.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "talk/examples/peerconnection/client/main_wnd.h"
40#include "talk/examples/peerconnection/client/peer_connection_client.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000041#include "webrtc/base/scoped_ptr.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042
43namespace webrtc {
44class VideoCaptureModule;
45} // namespace webrtc
46
47namespace cricket {
48class VideoRenderer;
49} // namespace cricket
50
51class 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.org28e20752013-07-10 00:45:36 +000061 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.orga742cb12015-01-29 04:23:01 +000074 bool ReinitializePeerConnectionForLoopback();
75 bool CreatePeerConnection(bool dtls);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 void DeletePeerConnection();
77 void EnsureStreamingUI();
78 void AddStreams();
79 cricket::VideoCapturer* OpenVideoCaptureDevice();
80
81 //
82 // PeerConnectionObserver implementation.
83 //
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084 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.orgc2dd5ee2014-11-04 11:31:29 +000088 virtual void OnDataChannel(webrtc::DataChannelInterface* channel) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089 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.orga742cb12015-01-29 04:23:01 +0000134 bool loopback_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000135 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
136 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 peer_connection_factory_;
138 PeerConnectionClient* client_;
139 MainWindow* main_wnd_;
140 std::deque<std::string*> pending_messages_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 active_streams_;
143 std::string server_;
144};
145
braveyao@webrtc.orgc68e0c92015-02-27 09:51:25 +0000146#endif // TALK_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_