blob: 74e5f6c5a2e56b8f35c30ede06c0e9504bdb05f1 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010020#include "webrtc/api/mediastreaminterface.h"
21#include "webrtc/api/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"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024
25namespace webrtc {
26class VideoCaptureModule;
27} // namespace webrtc
28
29namespace cricket {
30class VideoRenderer;
31} // namespace cricket
32
33class Conductor
34 : public webrtc::PeerConnectionObserver,
35 public webrtc::CreateSessionDescriptionObserver,
36 public PeerConnectionClientObserver,
37 public MainWndCallback {
38 public:
39 enum CallbackID {
40 MEDIA_CHANNELS_INITIALIZED = 1,
41 PEER_CONNECTION_CLOSED,
42 SEND_MESSAGE_TO_PEER,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043 NEW_STREAM_ADDED,
44 STREAM_REMOVED,
45 };
46
47 Conductor(PeerConnectionClient* client, MainWindow* main_wnd);
48
49 bool connection_active() const;
50
51 virtual void Close();
52
53 protected:
54 ~Conductor();
55 bool InitializePeerConnection();
braveyao@webrtc.orga742cb12015-01-29 04:23:01 +000056 bool ReinitializePeerConnectionForLoopback();
57 bool CreatePeerConnection(bool dtls);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058 void DeletePeerConnection();
59 void EnsureStreamingUI();
60 void AddStreams();
61 cricket::VideoCapturer* OpenVideoCaptureDevice();
62
63 //
64 // PeerConnectionObserver implementation.
65 //
perkjdfb769d2016-02-09 03:09:43 -080066
67 void OnSignalingChange(
68 webrtc::PeerConnectionInterface::SignalingState new_state) override{};
Taylor Brandstetter98cde262016-05-31 13:02:21 -070069 void OnAddStream(
70 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
71 void OnRemoveStream(
72 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
73 void OnDataChannel(
74 rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override {}
perkjdfb769d2016-02-09 03:09:43 -080075 void OnRenegotiationNeeded() override {}
76 void OnIceConnectionChange(
77 webrtc::PeerConnectionInterface::IceConnectionState new_state) override{};
78 void OnIceGatheringChange(
79 webrtc::PeerConnectionInterface::IceGatheringState new_state) override{};
80 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
81 void OnIceConnectionReceivingChange(bool receiving) override {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
83 //
84 // PeerConnectionClientObserver implementation.
85 //
86
87 virtual void OnSignedIn();
88
89 virtual void OnDisconnected();
90
91 virtual void OnPeerConnected(int id, const std::string& name);
92
93 virtual void OnPeerDisconnected(int id);
94
95 virtual void OnMessageFromPeer(int peer_id, const std::string& message);
96
97 virtual void OnMessageSent(int err);
98
99 virtual void OnServerConnectionFailure();
100
101 //
102 // MainWndCallback implementation.
103 //
104
105 virtual void StartLogin(const std::string& server, int port);
106
107 virtual void DisconnectFromServer();
108
109 virtual void ConnectToPeer(int peer_id);
110
111 virtual void DisconnectFromCurrentPeer();
112
113 virtual void UIThreadCallback(int msg_id, void* data);
114
115 // CreateSessionDescriptionObserver implementation.
116 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
117 virtual void OnFailure(const std::string& error);
118
119 protected:
120 // Send a message to the remote peer.
121 void SendMessage(const std::string& json_object);
122
123 int peer_id_;
braveyao@webrtc.orga742cb12015-01-29 04:23:01 +0000124 bool loopback_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000125 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
126 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 peer_connection_factory_;
128 PeerConnectionClient* client_;
129 MainWindow* main_wnd_;
130 std::deque<std::string*> pending_messages_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000131 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 active_streams_;
133 std::string server_;
134};
135
jbauch70625e52015-12-09 14:18:14 -0800136#endif // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_CONDUCTOR_H_