blob: f5f16a3d10659ccbcdcaa99a50cb7eef14243610 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
Donald E Curtisa8736442015-08-05 15:48:13 -07002 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
Donald E Curtisa8736442015-08-05 15:48:13 -07004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
braveyao@webrtc.orgc68e0c92015-02-27 09:51:25 +000011#ifndef TALK_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
12#define TALK_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013#pragma once
14
15#include <deque>
16#include <map>
17#include <set>
18#include <string>
19
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include "talk/app/webrtc/mediastreaminterface.h"
21#include "talk/app/webrtc/peerconnectioninterface.h"
Donald E Curtisa8736442015-08-05 15:48:13 -070022#include "webrtc/examples/peerconnection/client/main_wnd.h"
23#include "webrtc/examples/peerconnection/client/peer_connection_client.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000024#include "webrtc/base/scoped_ptr.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
26namespace webrtc {
27class VideoCaptureModule;
28} // namespace webrtc
29
30namespace cricket {
31class VideoRenderer;
32} // namespace cricket
33
34class 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.org28e20752013-07-10 00:45:36 +000044 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.orga742cb12015-01-29 04:23:01 +000057 bool ReinitializePeerConnectionForLoopback();
58 bool CreatePeerConnection(bool dtls);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059 void DeletePeerConnection();
60 void EnsureStreamingUI();
61 void AddStreams();
62 cricket::VideoCapturer* OpenVideoCaptureDevice();
63
64 //
65 // PeerConnectionObserver implementation.
66 //
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 virtual void OnStateChange(
68 webrtc::PeerConnectionObserver::StateType state_changed) {}
69 virtual void OnAddStream(webrtc::MediaStreamInterface* stream);
70 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +000071 virtual void OnDataChannel(webrtc::DataChannelInterface* channel) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 virtual void OnRenegotiationNeeded() {}
73 virtual void OnIceChange() {}
74 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate);
75
76 //
77 // PeerConnectionClientObserver implementation.
78 //
79
80 virtual void OnSignedIn();
81
82 virtual void OnDisconnected();
83
84 virtual void OnPeerConnected(int id, const std::string& name);
85
86 virtual void OnPeerDisconnected(int id);
87
88 virtual void OnMessageFromPeer(int peer_id, const std::string& message);
89
90 virtual void OnMessageSent(int err);
91
92 virtual void OnServerConnectionFailure();
93
94 //
95 // MainWndCallback implementation.
96 //
97
98 virtual void StartLogin(const std::string& server, int port);
99
100 virtual void DisconnectFromServer();
101
102 virtual void ConnectToPeer(int peer_id);
103
104 virtual void DisconnectFromCurrentPeer();
105
106 virtual void UIThreadCallback(int msg_id, void* data);
107
108 // CreateSessionDescriptionObserver implementation.
109 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
110 virtual void OnFailure(const std::string& error);
111
112 protected:
113 // Send a message to the remote peer.
114 void SendMessage(const std::string& json_object);
115
116 int peer_id_;
braveyao@webrtc.orga742cb12015-01-29 04:23:01 +0000117 bool loopback_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000118 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
119 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 peer_connection_factory_;
121 PeerConnectionClient* client_;
122 MainWindow* main_wnd_;
123 std::deque<std::string*> pending_messages_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000124 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 active_streams_;
126 std::string server_;
127};
128
braveyao@webrtc.orgc68e0c92015-02-27 09:51:25 +0000129#endif // TALK_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_