blob: 21d838aae4551d9c59bde7b97713f30ce041b5d0 [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
jbauch70625e52015-12-09 14:18:14 -080011#ifndef WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_
12#define WEBRTC_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 //
perkjdfb769d2016-02-09 03:09:43 -080067
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.org28e20752013-07-10 00:45:36 +000080
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.orga742cb12015-01-29 04:23:01 +0000122 bool loopback_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000123 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
124 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 peer_connection_factory_;
126 PeerConnectionClient* client_;
127 MainWindow* main_wnd_;
128 std::deque<std::string*> pending_messages_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000129 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 active_streams_;
131 std::string server_;
132};
133
jbauch70625e52015-12-09 14:18:14 -0800134#endif // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_