2011-05-30 13:39:02 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
|
|
|
|
#define PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
|
|
|
|
#pragma once
|
|
|
|
|
2011-08-25 17:03:52 +02:00
|
|
|
#include <deque>
|
2011-09-01 10:37:05 +02:00
|
|
|
#include <set>
|
2011-05-30 13:39:02 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "peerconnection/samples/client/main_wnd.h"
|
|
|
|
#include "peerconnection/samples/client/peer_connection_client.h"
|
2011-08-04 19:44:30 +02:00
|
|
|
#include "talk/app/webrtc/peerconnection.h"
|
2011-08-25 17:03:52 +02:00
|
|
|
#include "talk/app/webrtc/peerconnectionfactory.h"
|
2011-05-30 13:39:02 +02:00
|
|
|
#include "talk/base/scoped_ptr.h"
|
|
|
|
|
2011-06-08 13:24:32 +02:00
|
|
|
namespace cricket {
|
|
|
|
class VideoRenderer;
|
|
|
|
} // namespace cricket
|
2011-05-30 13:39:02 +02:00
|
|
|
|
|
|
|
class Conductor
|
|
|
|
: public webrtc::PeerConnectionObserver,
|
|
|
|
public PeerConnectionClientObserver,
|
2011-08-25 17:03:52 +02:00
|
|
|
public MainWndCallback {
|
2011-05-30 13:39:02 +02:00
|
|
|
public:
|
2011-08-25 17:03:52 +02:00
|
|
|
enum CallbackID {
|
|
|
|
MEDIA_CHANNELS_INITIALIZED = 1,
|
2011-05-30 13:39:02 +02:00
|
|
|
PEER_CONNECTION_CLOSED,
|
|
|
|
SEND_MESSAGE_TO_PEER,
|
2011-08-04 19:44:30 +02:00
|
|
|
PEER_CONNECTION_ADDSTREAMS,
|
2011-08-25 17:03:52 +02:00
|
|
|
PEER_CONNECTION_ERROR,
|
2011-09-01 10:37:05 +02:00
|
|
|
NEW_STREAM_ADDED,
|
|
|
|
STREAM_REMOVED,
|
2011-05-30 13:39:02 +02:00
|
|
|
};
|
|
|
|
|
2011-08-25 17:03:52 +02:00
|
|
|
Conductor(PeerConnectionClient* client, MainWindow* main_wnd);
|
2011-05-30 13:39:02 +02:00
|
|
|
~Conductor();
|
|
|
|
|
|
|
|
bool connection_active() const;
|
|
|
|
|
2011-08-25 17:03:52 +02:00
|
|
|
virtual void Close();
|
2011-05-30 13:39:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool InitializePeerConnection();
|
|
|
|
void DeletePeerConnection();
|
|
|
|
void StartCaptureDevice();
|
2011-09-01 10:37:05 +02:00
|
|
|
bool AddStream(const std::string& id, bool video);
|
2011-08-04 19:44:30 +02:00
|
|
|
void AddStreams();
|
2011-05-30 13:39:02 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// PeerConnectionObserver implementation.
|
|
|
|
//
|
|
|
|
virtual void OnError();
|
|
|
|
virtual void OnSignalingMessage(const std::string& msg);
|
|
|
|
|
|
|
|
// Called when a remote stream is added
|
2011-08-04 19:44:30 +02:00
|
|
|
virtual void OnAddStream(const std::string& stream_id, bool video);
|
2011-05-30 13:39:02 +02:00
|
|
|
|
|
|
|
virtual void OnRemoveStream(const std::string& stream_id,
|
|
|
|
bool video);
|
|
|
|
|
|
|
|
//
|
|
|
|
// PeerConnectionClientObserver implementation.
|
|
|
|
//
|
|
|
|
|
|
|
|
virtual void OnSignedIn();
|
|
|
|
|
|
|
|
virtual void OnDisconnected();
|
|
|
|
|
|
|
|
virtual void OnPeerConnected(int id, const std::string& name);
|
|
|
|
|
2011-08-25 17:03:52 +02:00
|
|
|
virtual void OnPeerDisconnected(int id);
|
2011-05-30 13:39:02 +02:00
|
|
|
|
|
|
|
virtual void OnMessageFromPeer(int peer_id, const std::string& message);
|
|
|
|
|
2011-08-25 17:03:52 +02:00
|
|
|
virtual void OnMessageSent(int err);
|
|
|
|
|
2011-05-30 13:39:02 +02:00
|
|
|
//
|
|
|
|
// MainWndCallback implementation.
|
|
|
|
//
|
|
|
|
|
2011-08-25 17:03:52 +02:00
|
|
|
virtual bool StartLogin(const std::string& server, int port);
|
2011-05-30 13:39:02 +02:00
|
|
|
|
|
|
|
virtual void DisconnectFromServer();
|
|
|
|
|
|
|
|
virtual void ConnectToPeer(int peer_id);
|
|
|
|
|
|
|
|
virtual void DisconnectFromCurrentPeer();
|
|
|
|
|
2011-08-25 17:03:52 +02:00
|
|
|
virtual void UIThreadCallback(int msg_id, void* data);
|
2011-05-30 13:39:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int peer_id_;
|
|
|
|
talk_base::scoped_ptr<webrtc::PeerConnection> peer_connection_;
|
2011-08-25 17:03:52 +02:00
|
|
|
talk_base::scoped_ptr<webrtc::PeerConnectionFactory> peer_connection_factory_;
|
2011-08-04 19:44:30 +02:00
|
|
|
talk_base::scoped_ptr<talk_base::Thread> worker_thread_;
|
2011-05-30 13:39:02 +02:00
|
|
|
PeerConnectionClient* client_;
|
2011-08-25 17:03:52 +02:00
|
|
|
MainWindow* main_wnd_;
|
|
|
|
std::deque<std::string*> pending_messages_;
|
2011-09-01 10:37:05 +02:00
|
|
|
std::set<std::string> active_streams_;
|
2011-05-30 13:39:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
|