Removing PeerConnection sample client and libjingle from webrtc.
The new PeerConnection and sample client can be found in libjingle. http://code.google.com/p/libjingle/ BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/389005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1658 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
15
DEPS
15
DEPS
@ -4,9 +4,6 @@ vars = {
|
|||||||
"googlecode_url": "http://%s.googlecode.com/svn",
|
"googlecode_url": "http://%s.googlecode.com/svn",
|
||||||
"chromium_trunk" : "http://src.chromium.org/svn/trunk",
|
"chromium_trunk" : "http://src.chromium.org/svn/trunk",
|
||||||
"chromium_revision": "120526",
|
"chromium_revision": "120526",
|
||||||
# TODO(andrew): libjingle should be rolled to 114 (or later) after fixing:
|
|
||||||
# http://code.google.com/p/webrtc/issues/detail?id=264
|
|
||||||
"libjingle_revision": "101",
|
|
||||||
|
|
||||||
# External resources like video and audio files used for testing purposes.
|
# External resources like video and audio files used for testing purposes.
|
||||||
# Downloaded on demand when needed.
|
# Downloaded on demand when needed.
|
||||||
@ -55,24 +52,15 @@ deps = {
|
|||||||
"trunk/third_party/libjpeg/":
|
"trunk/third_party/libjpeg/":
|
||||||
Var("chromium_trunk") + "/src/third_party/libjpeg@" + Var("chromium_revision"),
|
Var("chromium_trunk") + "/src/third_party/libjpeg@" + Var("chromium_revision"),
|
||||||
|
|
||||||
"trunk/third_party/libsrtp/":
|
|
||||||
Var("chromium_trunk") + "/deps/third_party/libsrtp@119742",
|
|
||||||
|
|
||||||
"trunk/third_party/yasm/":
|
"trunk/third_party/yasm/":
|
||||||
Var("chromium_trunk") + "/src/third_party/yasm@" + Var("chromium_revision"),
|
Var("chromium_trunk") + "/src/third_party/yasm@" + Var("chromium_revision"),
|
||||||
|
|
||||||
"trunk/third_party/expat/":
|
"trunk/third_party/expat/":
|
||||||
Var("chromium_trunk") + "/src/third_party/expat@" + Var("chromium_revision"),
|
Var("chromium_trunk") + "/src/third_party/expat@" + Var("chromium_revision"),
|
||||||
|
|
||||||
"trunk/third_party/libjingle/":
|
|
||||||
Var("chromium_trunk") + "/src/third_party/libjingle@" + Var("chromium_revision"),
|
|
||||||
|
|
||||||
"trunk/third_party/google-gflags/src":
|
"trunk/third_party/google-gflags/src":
|
||||||
(Var("googlecode_url") % "google-gflags") + "/trunk/src@45",
|
(Var("googlecode_url") % "google-gflags") + "/trunk/src@45",
|
||||||
|
|
||||||
"trunk/third_party/libjingle/source":
|
|
||||||
(Var("googlecode_url") % "libjingle") + "/trunk@" + Var("libjingle_revision"),
|
|
||||||
|
|
||||||
"trunk/third_party/yasm/source/patched-yasm":
|
"trunk/third_party/yasm/source/patched-yasm":
|
||||||
Var("chromium_trunk") + "/deps/third_party/yasm/patched-yasm@73761",
|
Var("chromium_trunk") + "/deps/third_party/yasm/patched-yasm@73761",
|
||||||
|
|
||||||
@ -80,9 +68,6 @@ deps = {
|
|||||||
"trunk/third_party/yasm/binaries":
|
"trunk/third_party/yasm/binaries":
|
||||||
Var("chromium_trunk") + "/deps/third_party/yasm/binaries@74228",
|
Var("chromium_trunk") + "/deps/third_party/yasm/binaries@74228",
|
||||||
|
|
||||||
"trunk/third_party/jsoncpp/":
|
|
||||||
"http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/jsoncpp@248",
|
|
||||||
|
|
||||||
# TODO(andrew): roll to 164 after fixing:
|
# TODO(andrew): roll to 164 after fixing:
|
||||||
# http://code.google.com/p/webrtc/issues/detail?id=267
|
# http://code.google.com/p/webrtc/issues/detail?id=267
|
||||||
"trunk/third_party/libyuv":
|
"trunk/third_party/libyuv":
|
||||||
|
@ -1 +0,0 @@
|
|||||||
tommi@webrtc.org
|
|
@ -1,103 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
{
|
|
||||||
'includes': [ '../src/build/common.gypi', ],
|
|
||||||
'targets': [
|
|
||||||
{
|
|
||||||
'target_name': 'peerconnection_server',
|
|
||||||
'type': 'executable',
|
|
||||||
'sources': [
|
|
||||||
'samples/server/data_socket.cc',
|
|
||||||
'samples/server/data_socket.h',
|
|
||||||
'samples/server/main.cc',
|
|
||||||
'samples/server/peer_channel.cc',
|
|
||||||
'samples/server/peer_channel.h',
|
|
||||||
'samples/server/utils.cc',
|
|
||||||
'samples/server/utils.h',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'conditions': [
|
|
||||||
['OS=="win"', {
|
|
||||||
'targets': [
|
|
||||||
{
|
|
||||||
'target_name': 'peerconnection_client',
|
|
||||||
'type': 'executable',
|
|
||||||
'sources': [
|
|
||||||
'samples/client/conductor.cc',
|
|
||||||
'samples/client/conductor.h',
|
|
||||||
'samples/client/defaults.cc',
|
|
||||||
'samples/client/defaults.h',
|
|
||||||
'samples/client/main.cc',
|
|
||||||
'samples/client/main_wnd.cc',
|
|
||||||
'samples/client/main_wnd.h',
|
|
||||||
'samples/client/peer_connection_client.cc',
|
|
||||||
'samples/client/peer_connection_client.h',
|
|
||||||
'../third_party/libjingle/source/talk/base/win32socketinit.cc',
|
|
||||||
'../third_party/libjingle/source/talk/base/win32socketserver.cc',
|
|
||||||
],
|
|
||||||
'msvs_settings': {
|
|
||||||
'VCLinkerTool': {
|
|
||||||
'SubSystem': '2', # Windows
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'dependencies': [
|
|
||||||
'../third_party_mods/libjingle/libjingle.gyp:libjingle_app',
|
|
||||||
],
|
|
||||||
'include_dirs': [
|
|
||||||
'../third_party/libjingle/source',
|
|
||||||
'../third_party_mods/libjingle/source',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
], # targets
|
|
||||||
}, ], # OS="win"
|
|
||||||
['OS=="linux"', {
|
|
||||||
'targets': [
|
|
||||||
{
|
|
||||||
'target_name': 'peerconnection_client',
|
|
||||||
'type': 'executable',
|
|
||||||
'sources': [
|
|
||||||
'samples/client/conductor.cc',
|
|
||||||
'samples/client/conductor.h',
|
|
||||||
'samples/client/defaults.cc',
|
|
||||||
'samples/client/defaults.h',
|
|
||||||
'samples/client/linux/main.cc',
|
|
||||||
'samples/client/linux/main_wnd.cc',
|
|
||||||
'samples/client/linux/main_wnd.h',
|
|
||||||
'samples/client/peer_connection_client.cc',
|
|
||||||
'samples/client/peer_connection_client.h',
|
|
||||||
],
|
|
||||||
'dependencies': [
|
|
||||||
'../third_party_mods/libjingle/libjingle.gyp:libjingle_app',
|
|
||||||
# TODO(tommi): Switch to this and remove specific gtk dependency
|
|
||||||
# sections below for cflags and link_settings.
|
|
||||||
# '<(DEPTH)/build/linux/system.gyp:gtk',
|
|
||||||
],
|
|
||||||
'include_dirs': [
|
|
||||||
'../third_party/libjingle/source',
|
|
||||||
'../third_party_mods/libjingle/source',
|
|
||||||
],
|
|
||||||
'cflags': [
|
|
||||||
'<!@(pkg-config --cflags gtk+-2.0)',
|
|
||||||
],
|
|
||||||
'link_settings': {
|
|
||||||
'ldflags': [
|
|
||||||
'<!@(pkg-config --libs-only-L --libs-only-other gtk+-2.0 gthread-2.0)',
|
|
||||||
],
|
|
||||||
'libraries': [
|
|
||||||
'<!@(pkg-config --libs-only-l gtk+-2.0 gthread-2.0)',
|
|
||||||
'-lX11',
|
|
||||||
'-lXext',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
], # targets
|
|
||||||
}, ], # OS="linux"
|
|
||||||
],
|
|
||||||
}
|
|
@ -1,399 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/conductor.h"
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/defaults.h"
|
|
||||||
#include "talk/base/common.h"
|
|
||||||
#include "talk/base/logging.h"
|
|
||||||
#include "talk/p2p/client/basicportallocator.h"
|
|
||||||
#include "talk/session/phone/videorendererfactory.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
// Used when passing stream information from callback threads to the UI thread.
|
|
||||||
struct StreamInfo {
|
|
||||||
StreamInfo(const std::string& id, bool video) : id_(id), video_(video) {}
|
|
||||||
|
|
||||||
std::string id_;
|
|
||||||
bool video_;
|
|
||||||
};
|
|
||||||
} // end anonymous.
|
|
||||||
|
|
||||||
Conductor::Conductor(PeerConnectionClient* client, MainWindow* main_wnd)
|
|
||||||
: peer_id_(-1),
|
|
||||||
client_(client),
|
|
||||||
main_wnd_(main_wnd) {
|
|
||||||
client_->RegisterObserver(this);
|
|
||||||
main_wnd->RegisterObserver(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Conductor::~Conductor() {
|
|
||||||
ASSERT(peer_connection_.get() == NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Conductor::connection_active() const {
|
|
||||||
return peer_connection_.get() != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::Close() {
|
|
||||||
client_->SignOut();
|
|
||||||
DeletePeerConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Conductor::InitializePeerConnection() {
|
|
||||||
ASSERT(peer_connection_factory_.get() == NULL);
|
|
||||||
ASSERT(peer_connection_.get() == NULL);
|
|
||||||
ASSERT(worker_thread_.get() == NULL);
|
|
||||||
|
|
||||||
worker_thread_.reset(new talk_base::Thread());
|
|
||||||
if (!worker_thread_->SetName("ConductorWT", this) ||
|
|
||||||
!worker_thread_->Start()) {
|
|
||||||
LOG(LS_ERROR) << "Failed to start libjingle worker thread";
|
|
||||||
worker_thread_.reset();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
peer_connection_factory_.reset(
|
|
||||||
new webrtc::PeerConnectionFactory(worker_thread_.get()));
|
|
||||||
if (!peer_connection_factory_->Initialize()) {
|
|
||||||
main_wnd_->MessageBox("Error",
|
|
||||||
"Failed to initialize PeerConnectionFactory", true);
|
|
||||||
DeletePeerConnection();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
port_allocator_.reset(new cricket::BasicPortAllocator(
|
|
||||||
new talk_base::BasicNetworkManager(),
|
|
||||||
talk_base::SocketAddress("stun.l.google.com", 19302),
|
|
||||||
talk_base::SocketAddress(),
|
|
||||||
talk_base::SocketAddress(),
|
|
||||||
talk_base::SocketAddress()));
|
|
||||||
|
|
||||||
// Since we only ever use a single PeerConnection instance, we share
|
|
||||||
// the worker thread between the factory and the PC instance.
|
|
||||||
peer_connection_.reset(peer_connection_factory_->CreatePeerConnection(
|
|
||||||
port_allocator_.get(), worker_thread_.get()));
|
|
||||||
if (!peer_connection_.get()) {
|
|
||||||
main_wnd_->MessageBox("Error",
|
|
||||||
"CreatePeerConnection failed", true);
|
|
||||||
DeletePeerConnection();
|
|
||||||
} else {
|
|
||||||
peer_connection_->RegisterObserver(this);
|
|
||||||
bool audio = peer_connection_->SetAudioDevice("", "", 0);
|
|
||||||
LOG(INFO) << "SetAudioDevice " << (audio ? "succeeded." : "failed.");
|
|
||||||
}
|
|
||||||
return peer_connection_.get() != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::DeletePeerConnection() {
|
|
||||||
peer_connection_.reset();
|
|
||||||
active_streams_.clear();
|
|
||||||
port_allocator_.reset();
|
|
||||||
peer_connection_factory_.reset();
|
|
||||||
worker_thread_.reset();
|
|
||||||
peer_id_ = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::SwitchToStreamingUi() {
|
|
||||||
ASSERT(peer_connection_.get() != NULL);
|
|
||||||
if (main_wnd_->IsWindow()) {
|
|
||||||
if (main_wnd_->current_ui() != MainWindow::STREAMING)
|
|
||||||
main_wnd_->SwitchToStreamingUI();
|
|
||||||
|
|
||||||
if (peer_connection_->SetVideoCapture("")) {
|
|
||||||
peer_connection_->SetLocalVideoRenderer(main_wnd_->local_renderer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// PeerConnectionObserver implementation.
|
|
||||||
//
|
|
||||||
|
|
||||||
void Conductor::OnError() {
|
|
||||||
LOG(LS_ERROR) << __FUNCTION__;
|
|
||||||
main_wnd_->QueueUIThreadCallback(PEER_CONNECTION_ERROR, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::OnSignalingMessage(const std::string& msg) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
|
|
||||||
std::string* msg_copy = new std::string(msg);
|
|
||||||
main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg_copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a remote stream is added
|
|
||||||
void Conductor::OnAddStream(const std::string& stream_id, bool video) {
|
|
||||||
LOG(INFO) << __FUNCTION__ << " " << stream_id;
|
|
||||||
|
|
||||||
main_wnd_->QueueUIThreadCallback(NEW_STREAM_ADDED,
|
|
||||||
new StreamInfo(stream_id, video));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::OnRemoveStream(const std::string& stream_id, bool video) {
|
|
||||||
LOG(INFO) << __FUNCTION__ << (video ? " video: " : " audio: ") << stream_id;
|
|
||||||
|
|
||||||
main_wnd_->QueueUIThreadCallback(STREAM_REMOVED,
|
|
||||||
new StreamInfo(stream_id, video));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// PeerConnectionClientObserver implementation.
|
|
||||||
//
|
|
||||||
|
|
||||||
void Conductor::OnSignedIn() {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
main_wnd_->SwitchToPeerList(client_->peers());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::OnDisconnected() {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
|
|
||||||
DeletePeerConnection();
|
|
||||||
|
|
||||||
if (main_wnd_->IsWindow())
|
|
||||||
main_wnd_->SwitchToConnectUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::OnPeerConnected(int id, const std::string& name) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
// Refresh the list if we're showing it.
|
|
||||||
if (main_wnd_->current_ui() == MainWindow::LIST_PEERS)
|
|
||||||
main_wnd_->SwitchToPeerList(client_->peers());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::OnPeerDisconnected(int id) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
if (id == peer_id_) {
|
|
||||||
LOG(INFO) << "Our peer disconnected";
|
|
||||||
main_wnd_->QueueUIThreadCallback(PEER_CONNECTION_CLOSED, NULL);
|
|
||||||
} else {
|
|
||||||
// Refresh the list if we're showing it.
|
|
||||||
if (main_wnd_->current_ui() == MainWindow::LIST_PEERS)
|
|
||||||
main_wnd_->SwitchToPeerList(client_->peers());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::OnMessageFromPeer(int peer_id, const std::string& message) {
|
|
||||||
ASSERT(peer_id_ == peer_id || peer_id_ == -1);
|
|
||||||
ASSERT(!message.empty());
|
|
||||||
|
|
||||||
if (!peer_connection_.get()) {
|
|
||||||
ASSERT(peer_id_ == -1);
|
|
||||||
peer_id_ = peer_id;
|
|
||||||
|
|
||||||
// Got an offer. Give it to the PeerConnection instance.
|
|
||||||
// Once processed, we will get a callback to OnSignalingMessage with
|
|
||||||
// our 'answer' which we'll send to the peer.
|
|
||||||
LOG(INFO) << "Got an offer from our peer: " << peer_id;
|
|
||||||
if (!InitializePeerConnection()) {
|
|
||||||
LOG(LS_ERROR) << "Failed to initialize our PeerConnection instance";
|
|
||||||
client_->SignOut();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (peer_id != peer_id_) {
|
|
||||||
ASSERT(peer_id_ != -1);
|
|
||||||
LOG(WARNING) << "Received an offer from a peer while already in a "
|
|
||||||
"conversation with a different peer.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
peer_connection_->SignalingMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::OnMessageSent(int err) {
|
|
||||||
// Process the next pending message if any.
|
|
||||||
main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// MainWndCallback implementation.
|
|
||||||
//
|
|
||||||
|
|
||||||
bool Conductor::StartLogin(const std::string& server, int port) {
|
|
||||||
if (client_->is_connected())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!client_->Connect(server, port, GetPeerName())) {
|
|
||||||
main_wnd_->MessageBox("Error", ("Failed to connect to " + server).c_str(),
|
|
||||||
true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::DisconnectFromServer() {
|
|
||||||
if (client_->is_connected())
|
|
||||||
client_->SignOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::ConnectToPeer(int peer_id) {
|
|
||||||
ASSERT(peer_id_ == -1);
|
|
||||||
ASSERT(peer_id != -1);
|
|
||||||
|
|
||||||
if (peer_connection_.get()) {
|
|
||||||
main_wnd_->MessageBox("Error",
|
|
||||||
"We only support connecting to one peer at a time", true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (InitializePeerConnection()) {
|
|
||||||
peer_id_ = peer_id;
|
|
||||||
main_wnd_->SwitchToStreamingUI();
|
|
||||||
SwitchToStreamingUi();
|
|
||||||
AddStreams();
|
|
||||||
} else {
|
|
||||||
main_wnd_->MessageBox("Error", "Failed to initialize PeerConnection", true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Conductor::AddStream(const std::string& id, bool video) {
|
|
||||||
// NOTE: Must be called from the UI thread.
|
|
||||||
if (active_streams_.find(id) != active_streams_.end())
|
|
||||||
return false; // Already added.
|
|
||||||
|
|
||||||
active_streams_.insert(id);
|
|
||||||
bool ret = peer_connection_->AddStream(id, video);
|
|
||||||
if (!ret) {
|
|
||||||
active_streams_.erase(id);
|
|
||||||
} else if (video) {
|
|
||||||
LOG(INFO) << "Setting video renderer for stream: " << id;
|
|
||||||
bool ok = peer_connection_->SetVideoRenderer(id,
|
|
||||||
main_wnd_->remote_renderer());
|
|
||||||
ASSERT(ok);
|
|
||||||
UNUSED(ok);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::AddStreams() {
|
|
||||||
int streams = 0;
|
|
||||||
if (AddStream(kVideoLabel, true))
|
|
||||||
++streams;
|
|
||||||
|
|
||||||
if (AddStream(kAudioLabel, false))
|
|
||||||
++streams;
|
|
||||||
|
|
||||||
// At the initiator of the call, after adding streams we need
|
|
||||||
// kick start the ICE candidates discovery process, which
|
|
||||||
// is done by the Connect method. Earlier this was done after
|
|
||||||
// getting the OnLocalStreamInitialized callback which is removed
|
|
||||||
// now. Connect will trigger OnSignalingMessage callback when
|
|
||||||
// ICE candidates are available.
|
|
||||||
if (streams)
|
|
||||||
peer_connection_->Connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::DisconnectFromCurrentPeer() {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
if (peer_connection_.get()) {
|
|
||||||
client_->SendHangUp(peer_id_);
|
|
||||||
DeletePeerConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (main_wnd_->IsWindow())
|
|
||||||
main_wnd_->SwitchToPeerList(client_->peers());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conductor::UIThreadCallback(int msg_id, void* data) {
|
|
||||||
switch (msg_id) {
|
|
||||||
case PEER_CONNECTION_CLOSED:
|
|
||||||
LOG(INFO) << "PEER_CONNECTION_CLOSED";
|
|
||||||
DeletePeerConnection();
|
|
||||||
|
|
||||||
ASSERT(active_streams_.empty());
|
|
||||||
|
|
||||||
if (main_wnd_->IsWindow()) {
|
|
||||||
if (client_->is_connected()) {
|
|
||||||
main_wnd_->SwitchToPeerList(client_->peers());
|
|
||||||
} else {
|
|
||||||
main_wnd_->SwitchToConnectUI();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DisconnectFromServer();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SEND_MESSAGE_TO_PEER: {
|
|
||||||
LOG(INFO) << "SEND_MESSAGE_TO_PEER";
|
|
||||||
std::string* msg = reinterpret_cast<std::string*>(data);
|
|
||||||
if (msg) {
|
|
||||||
// For convenience, we always run the message through the queue.
|
|
||||||
// This way we can be sure that messages are sent to the server
|
|
||||||
// in the same order they were signaled without much hassle.
|
|
||||||
pending_messages_.push_back(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pending_messages_.empty() && !client_->IsSendingMessage()) {
|
|
||||||
msg = pending_messages_.front();
|
|
||||||
pending_messages_.pop_front();
|
|
||||||
|
|
||||||
if (!client_->SendToPeer(peer_id_, *msg) && peer_id_ != -1) {
|
|
||||||
LOG(LS_ERROR) << "SendToPeer failed";
|
|
||||||
DisconnectFromServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!peer_connection_.get())
|
|
||||||
peer_id_ = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case PEER_CONNECTION_ADDSTREAMS:
|
|
||||||
AddStreams();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PEER_CONNECTION_ERROR:
|
|
||||||
main_wnd_->MessageBox("Error", "an unknown error occurred", true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NEW_STREAM_ADDED: {
|
|
||||||
talk_base::scoped_ptr<StreamInfo> info(
|
|
||||||
reinterpret_cast<StreamInfo*>(data));
|
|
||||||
if (info->video_) {
|
|
||||||
LOG(INFO) << "Setting video renderer for stream: " << info->id_;
|
|
||||||
bool ok = peer_connection_->SetVideoRenderer(info->id_,
|
|
||||||
main_wnd_->remote_renderer());
|
|
||||||
ASSERT(ok);
|
|
||||||
if (!ok)
|
|
||||||
LOG(LS_ERROR) << "SetVideoRenderer failed for : " << info->id_;
|
|
||||||
|
|
||||||
// TODO(tommi): For the initiator, we shouldn't have to make this call
|
|
||||||
// here (which is actually the second time this is called for the
|
|
||||||
// initiator). Look into why this is needed.
|
|
||||||
SwitchToStreamingUi();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we haven't shared any streams with this peer (we're the receiver)
|
|
||||||
// then do so now.
|
|
||||||
if (active_streams_.empty())
|
|
||||||
AddStreams();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case STREAM_REMOVED: {
|
|
||||||
talk_base::scoped_ptr<StreamInfo> info(
|
|
||||||
reinterpret_cast<StreamInfo*>(data));
|
|
||||||
active_streams_.erase(info->id_);
|
|
||||||
if (active_streams_.empty()) {
|
|
||||||
LOG(INFO) << "All streams have been closed.";
|
|
||||||
main_wnd_->QueueUIThreadCallback(PEER_CONNECTION_CLOSED, NULL);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
ASSERT(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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
|
|
||||||
|
|
||||||
#include <deque>
|
|
||||||
#include <set>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/main_wnd.h"
|
|
||||||
#include "peerconnection/samples/client/peer_connection_client.h"
|
|
||||||
#include "talk/app/webrtc/peerconnection.h"
|
|
||||||
#include "talk/app/webrtc/peerconnectionfactory.h"
|
|
||||||
#include "talk/base/scoped_ptr.h"
|
|
||||||
|
|
||||||
namespace cricket {
|
|
||||||
class VideoRenderer;
|
|
||||||
class PortAllocator;
|
|
||||||
} // namespace cricket
|
|
||||||
|
|
||||||
class Conductor
|
|
||||||
: public webrtc::PeerConnectionObserver,
|
|
||||||
public PeerConnectionClientObserver,
|
|
||||||
public MainWndCallback {
|
|
||||||
public:
|
|
||||||
enum CallbackID {
|
|
||||||
MEDIA_CHANNELS_INITIALIZED = 1,
|
|
||||||
PEER_CONNECTION_CLOSED,
|
|
||||||
SEND_MESSAGE_TO_PEER,
|
|
||||||
PEER_CONNECTION_ADDSTREAMS,
|
|
||||||
PEER_CONNECTION_ERROR,
|
|
||||||
NEW_STREAM_ADDED,
|
|
||||||
STREAM_REMOVED,
|
|
||||||
};
|
|
||||||
|
|
||||||
Conductor(PeerConnectionClient* client, MainWindow* main_wnd);
|
|
||||||
~Conductor();
|
|
||||||
|
|
||||||
bool connection_active() const;
|
|
||||||
|
|
||||||
virtual void Close();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool InitializePeerConnection();
|
|
||||||
void DeletePeerConnection();
|
|
||||||
void SwitchToStreamingUi();
|
|
||||||
bool AddStream(const std::string& id, bool video);
|
|
||||||
void AddStreams();
|
|
||||||
|
|
||||||
//
|
|
||||||
// PeerConnectionObserver implementation.
|
|
||||||
//
|
|
||||||
virtual void OnError();
|
|
||||||
virtual void OnSignalingMessage(const std::string& msg);
|
|
||||||
|
|
||||||
// Called when a remote stream is added
|
|
||||||
virtual void OnAddStream(const std::string& stream_id, bool video);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
virtual void OnPeerDisconnected(int id);
|
|
||||||
|
|
||||||
virtual void OnMessageFromPeer(int peer_id, const std::string& message);
|
|
||||||
|
|
||||||
virtual void OnMessageSent(int err);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MainWndCallback implementation.
|
|
||||||
//
|
|
||||||
|
|
||||||
virtual bool StartLogin(const std::string& server, int port);
|
|
||||||
|
|
||||||
virtual void DisconnectFromServer();
|
|
||||||
|
|
||||||
virtual void ConnectToPeer(int peer_id);
|
|
||||||
|
|
||||||
virtual void DisconnectFromCurrentPeer();
|
|
||||||
|
|
||||||
virtual void UIThreadCallback(int msg_id, void* data);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int peer_id_;
|
|
||||||
talk_base::scoped_ptr<webrtc::PeerConnection> peer_connection_;
|
|
||||||
talk_base::scoped_ptr<webrtc::PeerConnectionFactory> peer_connection_factory_;
|
|
||||||
talk_base::scoped_ptr<talk_base::Thread> worker_thread_;
|
|
||||||
PeerConnectionClient* client_;
|
|
||||||
MainWindow* main_wnd_;
|
|
||||||
std::deque<std::string*> pending_messages_;
|
|
||||||
std::set<std::string> active_streams_;
|
|
||||||
talk_base::scoped_ptr<cricket::PortAllocator> port_allocator_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_CLIENT_CONDUCTOR_H_
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/defaults.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <winsock2.h>
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "talk/base/common.h"
|
|
||||||
|
|
||||||
const char kAudioLabel[] = "audio_label";
|
|
||||||
const char kVideoLabel[] = "video_label";
|
|
||||||
const uint16 kDefaultServerPort = 8888;
|
|
||||||
|
|
||||||
std::string GetEnvVarOrDefault(const char* env_var_name,
|
|
||||||
const char* default_value) {
|
|
||||||
std::string value;
|
|
||||||
const char* env_var = getenv(env_var_name);
|
|
||||||
if (env_var)
|
|
||||||
value = env_var;
|
|
||||||
|
|
||||||
if (value.empty())
|
|
||||||
value = default_value;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetPeerConnectionString() {
|
|
||||||
return GetEnvVarOrDefault("WEBRTC_CONNECT", "STUN stun.l.google.com:19302");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetDefaultServerName() {
|
|
||||||
return GetEnvVarOrDefault("WEBRTC_SERVER", "localhost");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetPeerName() {
|
|
||||||
char computer_name[256];
|
|
||||||
if (gethostname(computer_name, ARRAY_SIZE(computer_name)) != 0)
|
|
||||||
strcpy(computer_name, "host");
|
|
||||||
std::string ret(GetEnvVarOrDefault("USERNAME", "user"));
|
|
||||||
ret += '@';
|
|
||||||
ret += computer_name;
|
|
||||||
return ret;
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_DEFAULTS_H_
|
|
||||||
#define PEERCONNECTION_SAMPLES_CLIENT_DEFAULTS_H_
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "talk/base/basictypes.h"
|
|
||||||
|
|
||||||
extern const char kAudioLabel[];
|
|
||||||
extern const char kVideoLabel[];
|
|
||||||
extern const uint16 kDefaultServerPort;
|
|
||||||
|
|
||||||
std::string GetEnvVarOrDefault(const char* env_var_name,
|
|
||||||
const char* default_value);
|
|
||||||
std::string GetPeerConnectionString();
|
|
||||||
std::string GetDefaultServerName();
|
|
||||||
std::string GetPeerName();
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_CLIENT_DEFAULTS_H_
|
|
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/conductor.h"
|
|
||||||
#include "peerconnection/samples/client/linux/main_wnd.h"
|
|
||||||
#include "peerconnection/samples/client/peer_connection_client.h"
|
|
||||||
|
|
||||||
#include "talk/base/thread.h"
|
|
||||||
|
|
||||||
class CustomSocketServer : public talk_base::PhysicalSocketServer {
|
|
||||||
public:
|
|
||||||
CustomSocketServer(talk_base::Thread* thread, GtkMainWnd* wnd)
|
|
||||||
: thread_(thread), wnd_(wnd), conductor_(NULL), client_(NULL) {}
|
|
||||||
virtual ~CustomSocketServer() {}
|
|
||||||
|
|
||||||
void set_client(PeerConnectionClient* client) { client_ = client; }
|
|
||||||
void set_conductor(Conductor* conductor) { conductor_ = conductor; }
|
|
||||||
|
|
||||||
// Override so that we can also pump the GTK message loop.
|
|
||||||
virtual bool Wait(int cms, bool process_io) {
|
|
||||||
// Pump GTK events.
|
|
||||||
// TODO(tommi): We really should move either the socket server or UI to a
|
|
||||||
// different thread. Alternatively we could look at merging the two loops
|
|
||||||
// by implementing a dispatcher for the socket server and/or use
|
|
||||||
// g_main_context_set_poll_func.
|
|
||||||
while (gtk_events_pending())
|
|
||||||
gtk_main_iteration();
|
|
||||||
|
|
||||||
if (!wnd_->IsWindow() && !conductor_->connection_active() &&
|
|
||||||
client_ != NULL && !client_->is_connected()) {
|
|
||||||
thread_->Quit();
|
|
||||||
}
|
|
||||||
return talk_base::PhysicalSocketServer::Wait(0/*cms == -1 ? 1 : cms*/,
|
|
||||||
process_io);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
talk_base::Thread* thread_;
|
|
||||||
GtkMainWnd* wnd_;
|
|
||||||
Conductor* conductor_;
|
|
||||||
PeerConnectionClient* client_;
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
gtk_init(&argc, &argv);
|
|
||||||
g_type_init();
|
|
||||||
g_thread_init(NULL);
|
|
||||||
|
|
||||||
GtkMainWnd wnd;
|
|
||||||
wnd.Create();
|
|
||||||
|
|
||||||
talk_base::AutoThread auto_thread;
|
|
||||||
talk_base::Thread* thread = talk_base::Thread::Current();
|
|
||||||
CustomSocketServer socket_server(thread, &wnd);
|
|
||||||
thread->set_socketserver(&socket_server);
|
|
||||||
|
|
||||||
// Must be constructed after we set the socketserver.
|
|
||||||
PeerConnectionClient client;
|
|
||||||
Conductor conductor(&client, &wnd);
|
|
||||||
socket_server.set_client(&client);
|
|
||||||
socket_server.set_conductor(&conductor);
|
|
||||||
|
|
||||||
thread->Run();
|
|
||||||
|
|
||||||
// gtk_main();
|
|
||||||
wnd.Destroy();
|
|
||||||
|
|
||||||
thread->set_socketserver(NULL);
|
|
||||||
// TODO(tommi): Run the Gtk main loop to tear down the connection.
|
|
||||||
//while (gtk_events_pending()) {
|
|
||||||
// gtk_main_iteration();
|
|
||||||
//}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,458 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/linux/main_wnd.h"
|
|
||||||
|
|
||||||
#include <gdk/gdkkeysyms.h>
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/defaults.h"
|
|
||||||
#include "talk/base/common.h"
|
|
||||||
#include "talk/base/logging.h"
|
|
||||||
#include "talk/base/stringutils.h"
|
|
||||||
|
|
||||||
using talk_base::sprintfn;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
//
|
|
||||||
// Simple static functions that simply forward the callback to the
|
|
||||||
// GtkMainWnd instance.
|
|
||||||
//
|
|
||||||
|
|
||||||
gboolean OnDestroyedCallback(GtkWidget* widget, GdkEvent* event,
|
|
||||||
gpointer data) {
|
|
||||||
reinterpret_cast<GtkMainWnd*>(data)->OnDestroyed(widget, event);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnClickedCallback(GtkWidget* widget, gpointer data) {
|
|
||||||
reinterpret_cast<GtkMainWnd*>(data)->OnClicked(widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean OnKeyPressCallback(GtkWidget* widget, GdkEventKey* key,
|
|
||||||
gpointer data) {
|
|
||||||
reinterpret_cast<GtkMainWnd*>(data)->OnKeyPress(widget, key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnRowActivatedCallback(GtkTreeView* tree_view, GtkTreePath* path,
|
|
||||||
GtkTreeViewColumn* column, gpointer data) {
|
|
||||||
reinterpret_cast<GtkMainWnd*>(data)->OnRowActivated(tree_view, path, column);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a tree view, that we use to display the list of peers.
|
|
||||||
void InitializeList(GtkWidget* list) {
|
|
||||||
GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
|
|
||||||
GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(
|
|
||||||
"List Items", renderer, "text", 0, NULL);
|
|
||||||
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
|
|
||||||
GtkListStore* store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
|
|
||||||
gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store));
|
|
||||||
g_object_unref(store);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds an entry to a tree view.
|
|
||||||
void AddToList(GtkWidget* list, const gchar* str, int value) {
|
|
||||||
GtkListStore* store = GTK_LIST_STORE(
|
|
||||||
gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
|
|
||||||
|
|
||||||
GtkTreeIter iter;
|
|
||||||
gtk_list_store_append(store, &iter);
|
|
||||||
gtk_list_store_set(store, &iter, 0, str, 1, value, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct UIThreadCallbackData {
|
|
||||||
explicit UIThreadCallbackData(MainWndCallback* cb, int id, void* d)
|
|
||||||
: callback(cb), msg_id(id), data(d) {}
|
|
||||||
MainWndCallback* callback;
|
|
||||||
int msg_id;
|
|
||||||
void* data;
|
|
||||||
};
|
|
||||||
|
|
||||||
gboolean HandleUIThreadCallback(gpointer data) {
|
|
||||||
UIThreadCallbackData* cb_data = reinterpret_cast<UIThreadCallbackData*>(data);
|
|
||||||
cb_data->callback->UIThreadCallback(cb_data->msg_id, cb_data->data);
|
|
||||||
delete cb_data;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean Redraw(gpointer data) {
|
|
||||||
GtkMainWnd* wnd = reinterpret_cast<GtkMainWnd*>(data);
|
|
||||||
wnd->OnRedraw();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} // end anonymous
|
|
||||||
|
|
||||||
//
|
|
||||||
// GtkMainWnd implementation.
|
|
||||||
//
|
|
||||||
|
|
||||||
GtkMainWnd::GtkMainWnd()
|
|
||||||
: window_(NULL), draw_area_(NULL), vbox_(NULL), server_edit_(NULL),
|
|
||||||
port_edit_(NULL), peer_list_(NULL), callback_(NULL),
|
|
||||||
server_("localhost") {
|
|
||||||
char buffer[10];
|
|
||||||
sprintfn(buffer, sizeof(buffer), "%i", kDefaultServerPort);
|
|
||||||
port_ = buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkMainWnd::~GtkMainWnd() {
|
|
||||||
ASSERT(!IsWindow());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::RegisterObserver(MainWndCallback* callback) {
|
|
||||||
callback_ = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GtkMainWnd::IsWindow() {
|
|
||||||
return window_ != NULL && GTK_IS_WINDOW(window_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::MessageBox(const char* caption, const char* text,
|
|
||||||
bool is_error) {
|
|
||||||
GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(window_),
|
|
||||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
||||||
is_error ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO,
|
|
||||||
GTK_BUTTONS_CLOSE, "%s", text);
|
|
||||||
gtk_window_set_title(GTK_WINDOW(dialog), caption);
|
|
||||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
|
||||||
gtk_widget_destroy(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow::UI GtkMainWnd::current_ui() {
|
|
||||||
if (vbox_)
|
|
||||||
return CONNECT_TO_SERVER;
|
|
||||||
|
|
||||||
if (peer_list_)
|
|
||||||
return LIST_PEERS;
|
|
||||||
|
|
||||||
return STREAMING;
|
|
||||||
}
|
|
||||||
|
|
||||||
cricket::VideoRenderer* GtkMainWnd::local_renderer() {
|
|
||||||
if (!local_renderer_.get())
|
|
||||||
local_renderer_.reset(new VideoRenderer(this));
|
|
||||||
return local_renderer_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
cricket::VideoRenderer* GtkMainWnd::remote_renderer() {
|
|
||||||
if (!remote_renderer_.get())
|
|
||||||
remote_renderer_.reset(new VideoRenderer(this));
|
|
||||||
return remote_renderer_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::QueueUIThreadCallback(int msg_id, void* data) {
|
|
||||||
g_idle_add(HandleUIThreadCallback,
|
|
||||||
new UIThreadCallbackData(callback_, msg_id, data));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GtkMainWnd::Create() {
|
|
||||||
ASSERT(window_ == NULL);
|
|
||||||
|
|
||||||
window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
||||||
if (window_) {
|
|
||||||
gtk_window_set_position(GTK_WINDOW(window_), GTK_WIN_POS_CENTER);
|
|
||||||
gtk_window_set_default_size(GTK_WINDOW(window_), 640, 480);
|
|
||||||
gtk_window_set_title(GTK_WINDOW(window_), "PeerConnection client");
|
|
||||||
g_signal_connect(G_OBJECT(window_), "delete-event",
|
|
||||||
G_CALLBACK(&OnDestroyedCallback), this);
|
|
||||||
g_signal_connect(window_, "key-press-event", G_CALLBACK(OnKeyPressCallback),
|
|
||||||
this);
|
|
||||||
|
|
||||||
SwitchToConnectUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
return window_ != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GtkMainWnd::Destroy() {
|
|
||||||
if (!IsWindow())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
gtk_widget_destroy(window_);
|
|
||||||
window_ = NULL;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::SwitchToConnectUI() {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
|
|
||||||
ASSERT(IsWindow());
|
|
||||||
ASSERT(vbox_ == NULL);
|
|
||||||
|
|
||||||
gtk_container_set_border_width(GTK_CONTAINER(window_), 10);
|
|
||||||
|
|
||||||
if (peer_list_) {
|
|
||||||
gtk_widget_destroy(peer_list_);
|
|
||||||
peer_list_ = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
vbox_ = gtk_vbox_new(FALSE, 5);
|
|
||||||
GtkWidget* valign = gtk_alignment_new(0, 1, 0, 0);
|
|
||||||
gtk_container_add(GTK_CONTAINER(vbox_), valign);
|
|
||||||
gtk_container_add(GTK_CONTAINER(window_), vbox_);
|
|
||||||
|
|
||||||
GtkWidget* hbox = gtk_hbox_new(FALSE, 5);
|
|
||||||
|
|
||||||
GtkWidget* label = gtk_label_new("Server");
|
|
||||||
gtk_container_add(GTK_CONTAINER(hbox), label);
|
|
||||||
|
|
||||||
server_edit_ = gtk_entry_new();
|
|
||||||
gtk_entry_set_text(GTK_ENTRY(server_edit_), server_.c_str());
|
|
||||||
gtk_widget_set_size_request(server_edit_, 400, 30);
|
|
||||||
gtk_container_add(GTK_CONTAINER(hbox), server_edit_);
|
|
||||||
|
|
||||||
port_edit_ = gtk_entry_new();
|
|
||||||
gtk_entry_set_text(GTK_ENTRY(port_edit_), port_.c_str());
|
|
||||||
gtk_widget_set_size_request(port_edit_, 70, 30);
|
|
||||||
gtk_container_add(GTK_CONTAINER(hbox), port_edit_);
|
|
||||||
|
|
||||||
GtkWidget* button = gtk_button_new_with_label("Connect");
|
|
||||||
gtk_widget_set_size_request(button, 70, 30);
|
|
||||||
g_signal_connect(button, "clicked", G_CALLBACK(OnClickedCallback), this);
|
|
||||||
gtk_container_add(GTK_CONTAINER(hbox), button);
|
|
||||||
|
|
||||||
GtkWidget* halign = gtk_alignment_new(1, 0, 0, 0);
|
|
||||||
gtk_container_add(GTK_CONTAINER(halign), hbox);
|
|
||||||
gtk_box_pack_start(GTK_BOX(vbox_), halign, FALSE, FALSE, 0);
|
|
||||||
|
|
||||||
gtk_widget_show_all(window_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::SwitchToPeerList(const Peers& peers) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
|
|
||||||
// Clean up buffers from a potential previous session.
|
|
||||||
local_renderer_.reset();
|
|
||||||
remote_renderer_.reset();
|
|
||||||
|
|
||||||
if (!peer_list_) {
|
|
||||||
gtk_container_set_border_width(GTK_CONTAINER(window_), 0);
|
|
||||||
if (vbox_) {
|
|
||||||
gtk_widget_destroy(vbox_);
|
|
||||||
vbox_ = NULL;
|
|
||||||
server_edit_ = NULL;
|
|
||||||
port_edit_ = NULL;
|
|
||||||
} else if (draw_area_) {
|
|
||||||
gtk_widget_destroy(draw_area_);
|
|
||||||
draw_area_ = NULL;
|
|
||||||
draw_buffer_.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
peer_list_ = gtk_tree_view_new();
|
|
||||||
g_signal_connect(peer_list_, "row-activated",
|
|
||||||
G_CALLBACK(OnRowActivatedCallback), this);
|
|
||||||
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(peer_list_), FALSE);
|
|
||||||
InitializeList(peer_list_);
|
|
||||||
gtk_container_add(GTK_CONTAINER(window_), peer_list_);
|
|
||||||
gtk_widget_show_all(window_);
|
|
||||||
} else {
|
|
||||||
GtkListStore* store =
|
|
||||||
GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(peer_list_)));
|
|
||||||
gtk_list_store_clear(store);
|
|
||||||
}
|
|
||||||
|
|
||||||
AddToList(peer_list_, "List of currently connected peers:", -1);
|
|
||||||
for (Peers::const_iterator i = peers.begin(); i != peers.end(); ++i)
|
|
||||||
AddToList(peer_list_, i->second.c_str(), i->first);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::SwitchToStreamingUI() {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
|
|
||||||
ASSERT(draw_area_ == NULL);
|
|
||||||
|
|
||||||
gtk_container_set_border_width(GTK_CONTAINER(window_), 0);
|
|
||||||
if (peer_list_) {
|
|
||||||
gtk_widget_destroy(peer_list_);
|
|
||||||
peer_list_ = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_area_ = gtk_drawing_area_new();
|
|
||||||
gtk_container_add(GTK_CONTAINER(window_), draw_area_);
|
|
||||||
|
|
||||||
gtk_widget_show_all(window_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::OnDestroyed(GtkWidget* widget, GdkEvent* event) {
|
|
||||||
callback_->Close();
|
|
||||||
window_ = NULL;
|
|
||||||
draw_area_ = NULL;
|
|
||||||
vbox_ = NULL;
|
|
||||||
server_edit_ = NULL;
|
|
||||||
port_edit_ = NULL;
|
|
||||||
peer_list_ = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::OnClicked(GtkWidget* widget) {
|
|
||||||
server_ = gtk_entry_get_text(GTK_ENTRY(server_edit_));
|
|
||||||
port_ = gtk_entry_get_text(GTK_ENTRY(port_edit_));
|
|
||||||
int port = port_.length() ? atoi(port_.c_str()) : 0;
|
|
||||||
callback_->StartLogin(server_, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::OnKeyPress(GtkWidget* widget, GdkEventKey* key) {
|
|
||||||
if (key->type == GDK_KEY_PRESS) {
|
|
||||||
switch (key->keyval) {
|
|
||||||
case GDK_Escape:
|
|
||||||
if (draw_area_) {
|
|
||||||
callback_->DisconnectFromCurrentPeer();
|
|
||||||
} else if (peer_list_) {
|
|
||||||
callback_->DisconnectFromServer();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GDK_KP_Enter:
|
|
||||||
case GDK_Return:
|
|
||||||
if (vbox_) {
|
|
||||||
OnClicked(NULL);
|
|
||||||
} else if (peer_list_) {
|
|
||||||
// OnRowActivated will be called automatically when the user
|
|
||||||
// presses enter.
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
|
|
||||||
GtkTreeViewColumn* column) {
|
|
||||||
ASSERT(peer_list_ != NULL);
|
|
||||||
GtkTreeIter iter;
|
|
||||||
GtkTreeModel* model;
|
|
||||||
GtkTreeSelection* selection =
|
|
||||||
gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
|
|
||||||
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
|
||||||
char* text;
|
|
||||||
int id = -1;
|
|
||||||
gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1);
|
|
||||||
if (id != -1)
|
|
||||||
callback_->ConnectToPeer(id);
|
|
||||||
g_free(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GtkMainWnd::OnRedraw() {
|
|
||||||
gdk_threads_enter();
|
|
||||||
|
|
||||||
if (remote_renderer_.get() && remote_renderer_->image() != NULL &&
|
|
||||||
draw_area_ != NULL) {
|
|
||||||
int width = remote_renderer_->width();
|
|
||||||
int height = remote_renderer_->height();
|
|
||||||
|
|
||||||
if (!draw_buffer_.get()) {
|
|
||||||
draw_buffer_size_ = (width * height * 4) * 4;
|
|
||||||
draw_buffer_.reset(new uint8[draw_buffer_size_]);
|
|
||||||
gtk_widget_set_size_request(draw_area_, width * 2, height * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32* image = reinterpret_cast<const uint32*>(
|
|
||||||
remote_renderer_->image());
|
|
||||||
uint32* scaled = reinterpret_cast<uint32*>(draw_buffer_.get());
|
|
||||||
for (int r = 0; r < height; ++r) {
|
|
||||||
for (int c = 0; c < width; ++c) {
|
|
||||||
int x = c * 2;
|
|
||||||
scaled[x] = scaled[x + 1] = image[c];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32* prev_line = scaled;
|
|
||||||
scaled += width * 2;
|
|
||||||
memcpy(scaled, prev_line, (width * 2) * 4);
|
|
||||||
|
|
||||||
image += width;
|
|
||||||
scaled += width * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (local_renderer_.get() && local_renderer_->image()) {
|
|
||||||
image = reinterpret_cast<const uint32*>(local_renderer_->image());
|
|
||||||
scaled = reinterpret_cast<uint32*>(draw_buffer_.get());
|
|
||||||
// Position the local preview on the right side.
|
|
||||||
scaled += (width * 2) - (local_renderer_->width() / 2);
|
|
||||||
// right margin...
|
|
||||||
scaled -= 10;
|
|
||||||
// ... towards the bottom.
|
|
||||||
scaled += (height * width * 4) -
|
|
||||||
((local_renderer_->height() / 2) *
|
|
||||||
(local_renderer_->width() / 2) * 4);
|
|
||||||
// bottom margin...
|
|
||||||
scaled -= (width * 2) * 5;
|
|
||||||
for (int r = 0; r < local_renderer_->height(); r += 2) {
|
|
||||||
for (int c = 0; c < local_renderer_->width(); c += 2) {
|
|
||||||
scaled[c / 2] = image[c + r * local_renderer_->width()];
|
|
||||||
}
|
|
||||||
scaled += width * 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gdk_draw_rgb_32_image(draw_area_->window,
|
|
||||||
draw_area_->style->fg_gc[GTK_STATE_NORMAL],
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
width * 2,
|
|
||||||
height * 2,
|
|
||||||
GDK_RGB_DITHER_MAX,
|
|
||||||
draw_buffer_.get(),
|
|
||||||
(width * 2) * 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
gdk_threads_leave();
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkMainWnd::VideoRenderer::VideoRenderer(GtkMainWnd* main_wnd)
|
|
||||||
: width_(0), height_(0), main_wnd_(main_wnd) {
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkMainWnd::VideoRenderer::~VideoRenderer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GtkMainWnd::VideoRenderer::SetSize(int width, int height, int reserved) {
|
|
||||||
gdk_threads_enter();
|
|
||||||
width_ = width;
|
|
||||||
height_ = height;
|
|
||||||
image_.reset(new uint8[width * height * 4]);
|
|
||||||
gdk_threads_leave();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GtkMainWnd::VideoRenderer::RenderFrame(const cricket::VideoFrame* frame) {
|
|
||||||
gdk_threads_enter();
|
|
||||||
|
|
||||||
int size = width_ * height_ * 4;
|
|
||||||
frame->ConvertToRgbBuffer(cricket::FOURCC_ARGB,
|
|
||||||
image_.get(),
|
|
||||||
size,
|
|
||||||
width_ * 4);
|
|
||||||
// Convert the B,G,R,A frame to R,G,B,A, which is accepted by GTK.
|
|
||||||
// The 'A' is just padding for GTK, so we can use it as temp.
|
|
||||||
uint8* pix = image_.get();
|
|
||||||
uint8* end = image_.get() + size;
|
|
||||||
while (pix < end) {
|
|
||||||
pix[3] = pix[0]; // Save B to A.
|
|
||||||
pix[0] = pix[2]; // Set Red.
|
|
||||||
pix[2] = pix[3]; // Set Blue.
|
|
||||||
pix[3] = 0xFF; // Fixed Alpha.
|
|
||||||
pix += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
gdk_threads_leave();
|
|
||||||
|
|
||||||
g_idle_add(Redraw, main_wnd_);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_LINUX_MAIN_WND_H_
|
|
||||||
#define PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/main_wnd.h"
|
|
||||||
#include "peerconnection/samples/client/peer_connection_client.h"
|
|
||||||
|
|
||||||
// Forward declarations.
|
|
||||||
typedef struct _GtkWidget GtkWidget;
|
|
||||||
typedef union _GdkEvent GdkEvent;
|
|
||||||
typedef struct _GdkEventKey GdkEventKey;
|
|
||||||
typedef struct _GtkTreeView GtkTreeView;
|
|
||||||
typedef struct _GtkTreePath GtkTreePath;
|
|
||||||
typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
|
|
||||||
|
|
||||||
// Implements the main UI of the peer connection client.
|
|
||||||
// This is functionally equivalent to the MainWnd class in the Windows
|
|
||||||
// implementation.
|
|
||||||
class GtkMainWnd : public MainWindow {
|
|
||||||
public:
|
|
||||||
GtkMainWnd();
|
|
||||||
~GtkMainWnd();
|
|
||||||
|
|
||||||
virtual void RegisterObserver(MainWndCallback* callback);
|
|
||||||
virtual bool IsWindow();
|
|
||||||
virtual void SwitchToConnectUI();
|
|
||||||
virtual void SwitchToPeerList(const Peers& peers);
|
|
||||||
virtual void SwitchToStreamingUI();
|
|
||||||
virtual void MessageBox(const char* caption, const char* text,
|
|
||||||
bool is_error);
|
|
||||||
virtual MainWindow::UI current_ui();
|
|
||||||
virtual cricket::VideoRenderer* local_renderer();
|
|
||||||
virtual cricket::VideoRenderer* remote_renderer();
|
|
||||||
virtual void QueueUIThreadCallback(int msg_id, void* data);
|
|
||||||
|
|
||||||
// Creates and shows the main window with the |Connect UI| enabled.
|
|
||||||
bool Create();
|
|
||||||
|
|
||||||
// Destroys the window. When the window is destroyed, it ends the
|
|
||||||
// main message loop.
|
|
||||||
bool Destroy();
|
|
||||||
|
|
||||||
// Callback for when the main window is destroyed.
|
|
||||||
void OnDestroyed(GtkWidget* widget, GdkEvent* event);
|
|
||||||
|
|
||||||
// Callback for when the user clicks the "Connect" button.
|
|
||||||
void OnClicked(GtkWidget* widget);
|
|
||||||
|
|
||||||
// Callback for keystrokes. Used to capture Esc and Return.
|
|
||||||
void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
|
|
||||||
|
|
||||||
// Callback when the user double clicks a peer in order to initiate a
|
|
||||||
// connection.
|
|
||||||
void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
|
|
||||||
GtkTreeViewColumn* column);
|
|
||||||
|
|
||||||
void OnRedraw();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
class VideoRenderer : public cricket::VideoRenderer {
|
|
||||||
public:
|
|
||||||
VideoRenderer(GtkMainWnd* main_wnd);
|
|
||||||
virtual ~VideoRenderer();
|
|
||||||
|
|
||||||
virtual bool SetSize(int width, int height, int reserved);
|
|
||||||
|
|
||||||
virtual bool RenderFrame(const cricket::VideoFrame* frame);
|
|
||||||
|
|
||||||
const uint8* image() const {
|
|
||||||
return image_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
int width() const {
|
|
||||||
return width_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int height() const {
|
|
||||||
return height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
talk_base::scoped_array<uint8> image_;
|
|
||||||
int width_;
|
|
||||||
int height_;
|
|
||||||
GtkMainWnd* main_wnd_;
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
|
||||||
GtkWidget* window_; // Our main window.
|
|
||||||
GtkWidget* draw_area_; // The drawing surface for rendering video streams.
|
|
||||||
GtkWidget* vbox_; // Container for the Connect UI.
|
|
||||||
GtkWidget* server_edit_;
|
|
||||||
GtkWidget* port_edit_;
|
|
||||||
GtkWidget* peer_list_; // The list of peers.
|
|
||||||
MainWndCallback* callback_;
|
|
||||||
std::string server_;
|
|
||||||
std::string port_;
|
|
||||||
talk_base::scoped_ptr<VideoRenderer> local_renderer_;
|
|
||||||
talk_base::scoped_ptr<VideoRenderer> remote_renderer_;
|
|
||||||
talk_base::scoped_ptr<uint8> draw_buffer_;
|
|
||||||
int draw_buffer_size_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/conductor.h"
|
|
||||||
#include "peerconnection/samples/client/main_wnd.h"
|
|
||||||
#include "peerconnection/samples/client/peer_connection_client.h"
|
|
||||||
#include "system_wrappers/source/trace_impl.h"
|
|
||||||
#include "talk/base/win32socketinit.h"
|
|
||||||
|
|
||||||
|
|
||||||
int PASCAL wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
|
|
||||||
wchar_t* cmd_line, int cmd_show) {
|
|
||||||
talk_base::EnsureWinsockInit();
|
|
||||||
|
|
||||||
webrtc::Trace::CreateTrace();
|
|
||||||
webrtc::Trace::SetTraceFile("peerconnection_client.log");
|
|
||||||
webrtc::Trace::SetLevelFilter(webrtc::kTraceWarning);
|
|
||||||
|
|
||||||
MainWnd wnd;
|
|
||||||
if (!wnd.Create()) {
|
|
||||||
ASSERT(false);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
PeerConnectionClient client;
|
|
||||||
Conductor conductor(&client, &wnd);
|
|
||||||
|
|
||||||
// Main loop.
|
|
||||||
MSG msg;
|
|
||||||
BOOL gm;
|
|
||||||
while ((gm = ::GetMessage(&msg, NULL, 0, 0)) && gm != -1) {
|
|
||||||
if (!wnd.PreTranslateMessage(&msg)) {
|
|
||||||
::TranslateMessage(&msg);
|
|
||||||
::DispatchMessage(&msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conductor.connection_active() || client.is_connected()) {
|
|
||||||
while ((conductor.connection_active() || client.is_connected()) &&
|
|
||||||
(gm = ::GetMessage(&msg, NULL, 0, 0)) && gm != -1) {
|
|
||||||
if (!wnd.PreTranslateMessage(&msg)) {
|
|
||||||
::TranslateMessage(&msg);
|
|
||||||
::DispatchMessage(&msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,606 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/main_wnd.h"
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "talk/base/common.h"
|
|
||||||
#include "talk/base/logging.h"
|
|
||||||
#include "talk/base/stringutils.h"
|
|
||||||
|
|
||||||
ATOM MainWnd::wnd_class_ = 0;
|
|
||||||
const wchar_t MainWnd::kClassName[] = L"WebRTC_MainWnd";
|
|
||||||
|
|
||||||
// TODO(tommi): declare in header:
|
|
||||||
std::string GetDefaultServerName();
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
const char kConnecting[] = "Connecting... ";
|
|
||||||
const char kNoVideoStreams[] = "(no video streams either way)";
|
|
||||||
const char kNoIncomingStream[] = "(no incoming video)";
|
|
||||||
|
|
||||||
void CalculateWindowSizeForText(HWND wnd, const wchar_t* text,
|
|
||||||
size_t* width, size_t* height) {
|
|
||||||
HDC dc = ::GetDC(wnd);
|
|
||||||
RECT text_rc = {0};
|
|
||||||
::DrawText(dc, text, -1, &text_rc, DT_CALCRECT | DT_SINGLELINE);
|
|
||||||
::ReleaseDC(wnd, dc);
|
|
||||||
RECT client, window;
|
|
||||||
::GetClientRect(wnd, &client);
|
|
||||||
::GetWindowRect(wnd, &window);
|
|
||||||
|
|
||||||
*width = text_rc.right - text_rc.left;
|
|
||||||
*width += (window.right - window.left) -
|
|
||||||
(client.right - client.left);
|
|
||||||
*height = text_rc.bottom - text_rc.top;
|
|
||||||
*height += (window.bottom - window.top) -
|
|
||||||
(client.bottom - client.top);
|
|
||||||
}
|
|
||||||
|
|
||||||
HFONT GetDefaultFont() {
|
|
||||||
static HFONT font = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetWindowText(HWND wnd) {
|
|
||||||
char text[MAX_PATH] = {0};
|
|
||||||
::GetWindowTextA(wnd, &text[0], ARRAYSIZE(text));
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddListBoxItem(HWND listbox, const std::string& str, LPARAM item_data) {
|
|
||||||
LRESULT index = ::SendMessageA(listbox, LB_ADDSTRING, 0,
|
|
||||||
reinterpret_cast<LPARAM>(str.c_str()));
|
|
||||||
::SendMessageA(listbox, LB_SETITEMDATA, index, item_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawWhiteText(HDC dc, const RECT& rect, const char* text, int flags) {
|
|
||||||
HGDIOBJ old_font = ::SelectObject(dc, GetDefaultFont());
|
|
||||||
::SetTextColor(dc, RGB(0xff, 0xff, 0xff));
|
|
||||||
::SetBkMode(dc, TRANSPARENT);
|
|
||||||
RECT rc = rect;
|
|
||||||
::DrawTextA(dc, text, -1, &rc, flags);
|
|
||||||
::SelectObject(dc, old_font);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
MainWnd::MainWnd()
|
|
||||||
: ui_(CONNECT_TO_SERVER), wnd_(NULL), edit1_(NULL), edit2_(NULL),
|
|
||||||
label1_(NULL), label2_(NULL), button_(NULL), listbox_(NULL),
|
|
||||||
destroyed_(false), callback_(NULL), nested_msg_(NULL) {
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWnd::~MainWnd() {
|
|
||||||
ASSERT(!IsWindow());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWnd::Create() {
|
|
||||||
ASSERT(wnd_ == NULL);
|
|
||||||
if (!RegisterWindowClass())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ui_thread_id_ = ::GetCurrentThreadId();
|
|
||||||
wnd_ = ::CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, kClassName, L"WebRTC",
|
|
||||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
|
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
||||||
NULL, NULL, GetModuleHandle(NULL), this);
|
|
||||||
|
|
||||||
::SendMessage(wnd_, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()),
|
|
||||||
TRUE);
|
|
||||||
|
|
||||||
CreateChildWindows();
|
|
||||||
SwitchToConnectUI();
|
|
||||||
|
|
||||||
return wnd_ != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWnd::Destroy() {
|
|
||||||
BOOL ret = FALSE;
|
|
||||||
if (IsWindow()) {
|
|
||||||
ret = ::DestroyWindow(wnd_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret != FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::RegisterObserver(MainWndCallback* callback) {
|
|
||||||
callback_ = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWnd::IsWindow() {
|
|
||||||
return wnd_ && ::IsWindow(wnd_) != FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWnd::PreTranslateMessage(MSG* msg) {
|
|
||||||
bool ret = false;
|
|
||||||
if (msg->message == WM_CHAR) {
|
|
||||||
if (msg->wParam == VK_TAB) {
|
|
||||||
HandleTabbing();
|
|
||||||
ret = true;
|
|
||||||
} else if (msg->wParam == VK_RETURN) {
|
|
||||||
OnDefaultAction();
|
|
||||||
ret = true;
|
|
||||||
} else if (msg->wParam == VK_ESCAPE) {
|
|
||||||
if (callback_) {
|
|
||||||
if (ui_ == STREAMING) {
|
|
||||||
callback_->DisconnectFromCurrentPeer();
|
|
||||||
} else {
|
|
||||||
callback_->DisconnectFromServer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (msg->hwnd == NULL && msg->message == UI_THREAD_CALLBACK) {
|
|
||||||
callback_->UIThreadCallback(static_cast<int>(msg->wParam),
|
|
||||||
reinterpret_cast<void*>(msg->lParam));
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::SwitchToConnectUI() {
|
|
||||||
ASSERT(IsWindow());
|
|
||||||
LayoutPeerListUI(false);
|
|
||||||
ui_ = CONNECT_TO_SERVER;
|
|
||||||
LayoutConnectUI(true);
|
|
||||||
::SetFocus(edit1_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::SwitchToPeerList(const Peers& peers) {
|
|
||||||
remote_video_.reset();
|
|
||||||
local_video_.reset();
|
|
||||||
|
|
||||||
LayoutConnectUI(false);
|
|
||||||
|
|
||||||
::SendMessage(listbox_, LB_RESETCONTENT, 0, 0);
|
|
||||||
|
|
||||||
AddListBoxItem(listbox_, "List of currently connected peers:", -1);
|
|
||||||
Peers::const_iterator i = peers.begin();
|
|
||||||
for (; i != peers.end(); ++i)
|
|
||||||
AddListBoxItem(listbox_, i->second.c_str(), i->first);
|
|
||||||
|
|
||||||
ui_ = LIST_PEERS;
|
|
||||||
LayoutPeerListUI(true);
|
|
||||||
::SetFocus(listbox_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::SwitchToStreamingUI() {
|
|
||||||
LayoutConnectUI(false);
|
|
||||||
LayoutPeerListUI(false);
|
|
||||||
ui_ = STREAMING;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::MessageBox(const char* caption, const char* text, bool is_error) {
|
|
||||||
DWORD flags = MB_OK;
|
|
||||||
if (is_error)
|
|
||||||
flags |= MB_ICONERROR;
|
|
||||||
|
|
||||||
::MessageBoxA(handle(), text, caption, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
cricket::VideoRenderer* MainWnd::local_renderer() {
|
|
||||||
if (!local_video_.get())
|
|
||||||
local_video_.reset(new VideoRenderer(handle(), 1, 1));
|
|
||||||
return local_video_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
cricket::VideoRenderer* MainWnd::remote_renderer() {
|
|
||||||
if (!remote_video_.get())
|
|
||||||
remote_video_.reset(new VideoRenderer(handle(), 1, 1));
|
|
||||||
return remote_video_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::QueueUIThreadCallback(int msg_id, void* data) {
|
|
||||||
::PostThreadMessage(ui_thread_id_, UI_THREAD_CALLBACK,
|
|
||||||
static_cast<WPARAM>(msg_id), reinterpret_cast<LPARAM>(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::OnPaint() {
|
|
||||||
PAINTSTRUCT ps;
|
|
||||||
::BeginPaint(handle(), &ps);
|
|
||||||
|
|
||||||
RECT rc;
|
|
||||||
::GetClientRect(handle(), &rc);
|
|
||||||
|
|
||||||
if (ui_ == STREAMING && remote_video_.get() && local_video_.get()) {
|
|
||||||
AutoLock<VideoRenderer> local_lock(local_video_.get());
|
|
||||||
AutoLock<VideoRenderer> remote_lock(remote_video_.get());
|
|
||||||
|
|
||||||
const BITMAPINFO& bmi = remote_video_->bmi();
|
|
||||||
int height = abs(bmi.bmiHeader.biHeight);
|
|
||||||
int width = bmi.bmiHeader.biWidth;
|
|
||||||
|
|
||||||
const uint8* image = remote_video_->image();
|
|
||||||
if (image != NULL) {
|
|
||||||
HDC dc_mem = ::CreateCompatibleDC(ps.hdc);
|
|
||||||
::SetStretchBltMode(dc_mem, HALFTONE);
|
|
||||||
|
|
||||||
// Set the map mode so that the ratio will be maintained for us.
|
|
||||||
HDC all_dc[] = { ps.hdc, dc_mem };
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(all_dc); ++i) {
|
|
||||||
SetMapMode(all_dc[i], MM_ISOTROPIC);
|
|
||||||
SetWindowExtEx(all_dc[i], width, height, NULL);
|
|
||||||
SetViewportExtEx(all_dc[i], rc.right, rc.bottom, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
HBITMAP bmp_mem = ::CreateCompatibleBitmap(ps.hdc, rc.right, rc.bottom);
|
|
||||||
HGDIOBJ bmp_old = ::SelectObject(dc_mem, bmp_mem);
|
|
||||||
|
|
||||||
POINT logical_area = { rc.right, rc.bottom };
|
|
||||||
DPtoLP(ps.hdc, &logical_area, 1);
|
|
||||||
|
|
||||||
HBRUSH brush = ::CreateSolidBrush(RGB(0, 0, 0));
|
|
||||||
RECT logical_rect = {0, 0, logical_area.x, logical_area.y };
|
|
||||||
::FillRect(dc_mem, &logical_rect, brush);
|
|
||||||
::DeleteObject(brush);
|
|
||||||
|
|
||||||
int max_unit = std::max(width, height);
|
|
||||||
int x = (logical_area.x / 2) - (width / 2);
|
|
||||||
int y = (logical_area.y / 2) - (height / 2);
|
|
||||||
|
|
||||||
StretchDIBits(dc_mem, x, y, width, height,
|
|
||||||
0, 0, width, height, image, &bmi, DIB_RGB_COLORS, SRCCOPY);
|
|
||||||
|
|
||||||
if ((rc.right - rc.left) > 200 && (rc.bottom - rc.top) > 200) {
|
|
||||||
const BITMAPINFO& bmi = local_video_->bmi();
|
|
||||||
image = local_video_->image();
|
|
||||||
int thumb_width = bmi.bmiHeader.biWidth / 4;
|
|
||||||
int thumb_height = abs(bmi.bmiHeader.biHeight) / 4;
|
|
||||||
StretchDIBits(dc_mem,
|
|
||||||
logical_area.x - thumb_width - 10,
|
|
||||||
logical_area.y - thumb_height - 10,
|
|
||||||
thumb_width, thumb_height,
|
|
||||||
0, 0, bmi.bmiHeader.biWidth, -bmi.bmiHeader.biHeight,
|
|
||||||
image, &bmi, DIB_RGB_COLORS, SRCCOPY);
|
|
||||||
}
|
|
||||||
|
|
||||||
BitBlt(ps.hdc, 0, 0, logical_area.x, logical_area.y,
|
|
||||||
dc_mem, 0, 0, SRCCOPY);
|
|
||||||
|
|
||||||
// Print the resolutions.
|
|
||||||
char buffer[1024];
|
|
||||||
talk_base::sprintfn(buffer, sizeof(buffer),
|
|
||||||
"Remote: %u x %u. Local: %u x %u.",
|
|
||||||
remote_video_->frame_height(),
|
|
||||||
remote_video_->frame_width(),
|
|
||||||
local_video_->frame_height(),
|
|
||||||
local_video_->frame_width());
|
|
||||||
|
|
||||||
SetMapMode(ps.hdc, MM_TEXT);
|
|
||||||
DrawWhiteText(ps.hdc, rc, buffer, DT_SINGLELINE);
|
|
||||||
|
|
||||||
// Cleanup.
|
|
||||||
::SelectObject(dc_mem, bmp_old);
|
|
||||||
::DeleteObject(bmp_mem);
|
|
||||||
::DeleteDC(dc_mem);
|
|
||||||
} else {
|
|
||||||
// We're still waiting for the video stream to be initialized.
|
|
||||||
HBRUSH brush = ::CreateSolidBrush(RGB(0, 0, 0));
|
|
||||||
::FillRect(ps.hdc, &rc, brush);
|
|
||||||
::DeleteObject(brush);
|
|
||||||
|
|
||||||
std::string text(kConnecting);
|
|
||||||
if (!local_video_->image()) {
|
|
||||||
text += kNoVideoStreams;
|
|
||||||
} else {
|
|
||||||
text += kNoIncomingStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawWhiteText(ps.hdc, rc, text.c_str(),
|
|
||||||
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
HBRUSH brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
|
|
||||||
::FillRect(ps.hdc, &rc, brush);
|
|
||||||
::DeleteObject(brush);
|
|
||||||
}
|
|
||||||
|
|
||||||
::EndPaint(handle(), &ps);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::OnDestroyed() {
|
|
||||||
PostQuitMessage(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::OnDefaultAction() {
|
|
||||||
if (!callback_)
|
|
||||||
return;
|
|
||||||
if (ui_ == CONNECT_TO_SERVER) {
|
|
||||||
std::string server(GetWindowText(edit1_));
|
|
||||||
std::string port_str(GetWindowText(edit2_));
|
|
||||||
int port = port_str.length() ? atoi(port_str.c_str()) : 0;
|
|
||||||
callback_->StartLogin(server, port);
|
|
||||||
} else if (ui_ == LIST_PEERS) {
|
|
||||||
LRESULT sel = ::SendMessage(listbox_, LB_GETCURSEL, 0, 0);
|
|
||||||
if (sel != LB_ERR) {
|
|
||||||
LRESULT peer_id = ::SendMessage(listbox_, LB_GETITEMDATA, sel, 0);
|
|
||||||
if (peer_id != -1 && callback_) {
|
|
||||||
callback_->ConnectToPeer(peer_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MessageBoxA(wnd_, "OK!", "Yeah", MB_OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWnd::OnMessage(UINT msg, WPARAM wp, LPARAM lp, LRESULT* result) {
|
|
||||||
switch (msg) {
|
|
||||||
case WM_ERASEBKGND:
|
|
||||||
*result = TRUE;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case WM_PAINT:
|
|
||||||
OnPaint();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case WM_SETFOCUS:
|
|
||||||
if (ui_ == CONNECT_TO_SERVER) {
|
|
||||||
SetFocus(edit1_);
|
|
||||||
} else if (ui_ == LIST_PEERS) {
|
|
||||||
SetFocus(listbox_);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case WM_SIZE:
|
|
||||||
if (ui_ == CONNECT_TO_SERVER) {
|
|
||||||
LayoutConnectUI(true);
|
|
||||||
} else if (ui_ == LIST_PEERS) {
|
|
||||||
LayoutPeerListUI(true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_CTLCOLORSTATIC:
|
|
||||||
*result = reinterpret_cast<LRESULT>(GetSysColorBrush(COLOR_WINDOW));
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case WM_COMMAND:
|
|
||||||
if (button_ == reinterpret_cast<HWND>(lp)) {
|
|
||||||
if (BN_CLICKED == HIWORD(wp))
|
|
||||||
OnDefaultAction();
|
|
||||||
} else if (listbox_ == reinterpret_cast<HWND>(lp)) {
|
|
||||||
if (LBN_DBLCLK == HIWORD(wp)) {
|
|
||||||
OnDefaultAction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case WM_CLOSE:
|
|
||||||
if (callback_)
|
|
||||||
callback_->Close();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
LRESULT CALLBACK MainWnd::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
|
|
||||||
MainWnd* me = reinterpret_cast<MainWnd*>(
|
|
||||||
::GetWindowLongPtr(hwnd, GWL_USERDATA));
|
|
||||||
if (!me && WM_CREATE == msg) {
|
|
||||||
CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lp);
|
|
||||||
me = reinterpret_cast<MainWnd*>(cs->lpCreateParams);
|
|
||||||
me->wnd_ = hwnd;
|
|
||||||
::SetWindowLongPtr(hwnd, GWL_USERDATA, reinterpret_cast<LONG_PTR>(me));
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT result = 0;
|
|
||||||
if (me) {
|
|
||||||
void* prev_nested_msg = me->nested_msg_;
|
|
||||||
me->nested_msg_ = &msg;
|
|
||||||
|
|
||||||
bool handled = me->OnMessage(msg, wp, lp, &result);
|
|
||||||
if (WM_NCDESTROY == msg) {
|
|
||||||
me->destroyed_ = true;
|
|
||||||
} else if (!handled) {
|
|
||||||
result = ::DefWindowProc(hwnd, msg, wp, lp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (me->destroyed_ && prev_nested_msg == NULL) {
|
|
||||||
me->OnDestroyed();
|
|
||||||
me->wnd_ = NULL;
|
|
||||||
me->destroyed_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
me->nested_msg_ = prev_nested_msg;
|
|
||||||
} else {
|
|
||||||
result = ::DefWindowProc(hwnd, msg, wp, lp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
bool MainWnd::RegisterWindowClass() {
|
|
||||||
if (wnd_class_)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
|
|
||||||
wcex.style = CS_DBLCLKS;
|
|
||||||
wcex.hInstance = GetModuleHandle(NULL);
|
|
||||||
wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
|
|
||||||
wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
|
|
||||||
wcex.lpfnWndProc = &WndProc;
|
|
||||||
wcex.lpszClassName = kClassName;
|
|
||||||
wnd_class_ = ::RegisterClassEx(&wcex);
|
|
||||||
ASSERT(wnd_class_ != 0);
|
|
||||||
return wnd_class_ != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::CreateChildWindow(HWND* wnd, MainWnd::ChildWindowID id,
|
|
||||||
const wchar_t* class_name, DWORD control_style,
|
|
||||||
DWORD ex_style) {
|
|
||||||
if (::IsWindow(*wnd))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Child windows are invisible at first, and shown after being resized.
|
|
||||||
DWORD style = WS_CHILD | control_style;
|
|
||||||
*wnd = ::CreateWindowEx(ex_style, class_name, L"", style,
|
|
||||||
100, 100, 100, 100, wnd_,
|
|
||||||
reinterpret_cast<HMENU>(id),
|
|
||||||
GetModuleHandle(NULL), NULL);
|
|
||||||
ASSERT(::IsWindow(*wnd) != FALSE);
|
|
||||||
::SendMessage(*wnd, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()),
|
|
||||||
TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::CreateChildWindows() {
|
|
||||||
// Create the child windows in tab order.
|
|
||||||
CreateChildWindow(&label1_, LABEL1_ID, L"Static", ES_CENTER | ES_READONLY, 0);
|
|
||||||
CreateChildWindow(&edit1_, EDIT_ID, L"Edit",
|
|
||||||
ES_LEFT | ES_NOHIDESEL | WS_TABSTOP, WS_EX_CLIENTEDGE);
|
|
||||||
CreateChildWindow(&label2_, LABEL2_ID, L"Static", ES_CENTER | ES_READONLY, 0);
|
|
||||||
CreateChildWindow(&edit2_, EDIT_ID, L"Edit",
|
|
||||||
ES_LEFT | ES_NOHIDESEL | WS_TABSTOP, WS_EX_CLIENTEDGE);
|
|
||||||
CreateChildWindow(&button_, BUTTON_ID, L"Button", BS_CENTER | WS_TABSTOP, 0);
|
|
||||||
|
|
||||||
CreateChildWindow(&listbox_, LISTBOX_ID, L"ListBox",
|
|
||||||
LBS_HASSTRINGS | LBS_NOTIFY, WS_EX_CLIENTEDGE);
|
|
||||||
|
|
||||||
::SetWindowTextA(edit1_, GetDefaultServerName().c_str());
|
|
||||||
::SetWindowTextA(edit2_, "8888");
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::LayoutConnectUI(bool show) {
|
|
||||||
struct Windows {
|
|
||||||
HWND wnd;
|
|
||||||
const wchar_t* text;
|
|
||||||
size_t width;
|
|
||||||
size_t height;
|
|
||||||
} windows[] = {
|
|
||||||
{ label1_, L"Server" },
|
|
||||||
{ edit1_, L"XXXyyyYYYgggXXXyyyYYYggg" },
|
|
||||||
{ label2_, L":" },
|
|
||||||
{ edit2_, L"XyXyX" },
|
|
||||||
{ button_, L"Connect" },
|
|
||||||
};
|
|
||||||
|
|
||||||
if (show) {
|
|
||||||
const size_t kSeparator = 5;
|
|
||||||
size_t total_width = (ARRAYSIZE(windows) - 1) * kSeparator;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < ARRAYSIZE(windows); ++i) {
|
|
||||||
CalculateWindowSizeForText(windows[i].wnd, windows[i].text,
|
|
||||||
&windows[i].width, &windows[i].height);
|
|
||||||
total_width += windows[i].width;
|
|
||||||
}
|
|
||||||
|
|
||||||
RECT rc;
|
|
||||||
::GetClientRect(wnd_, &rc);
|
|
||||||
size_t x = (rc.right / 2) - (total_width / 2);
|
|
||||||
size_t y = rc.bottom / 2;
|
|
||||||
for (size_t i = 0; i < ARRAYSIZE(windows); ++i) {
|
|
||||||
size_t top = y - (windows[i].height / 2);
|
|
||||||
::MoveWindow(windows[i].wnd, x, top, windows[i].width, windows[i].height,
|
|
||||||
TRUE);
|
|
||||||
x += kSeparator + windows[i].width;
|
|
||||||
if (windows[i].text[0] != 'X')
|
|
||||||
::SetWindowText(windows[i].wnd, windows[i].text);
|
|
||||||
::ShowWindow(windows[i].wnd, SW_SHOWNA);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (size_t i = 0; i < ARRAYSIZE(windows); ++i) {
|
|
||||||
::ShowWindow(windows[i].wnd, SW_HIDE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::LayoutPeerListUI(bool show) {
|
|
||||||
if (show) {
|
|
||||||
RECT rc;
|
|
||||||
::GetClientRect(wnd_, &rc);
|
|
||||||
::MoveWindow(listbox_, 0, 0, rc.right, rc.bottom, TRUE);
|
|
||||||
::ShowWindow(listbox_, SW_SHOWNA);
|
|
||||||
} else {
|
|
||||||
::ShowWindow(listbox_, SW_HIDE);
|
|
||||||
InvalidateRect(wnd_, NULL, TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWnd::HandleTabbing() {
|
|
||||||
bool shift = ((::GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0);
|
|
||||||
UINT next_cmd = shift ? GW_HWNDPREV : GW_HWNDNEXT;
|
|
||||||
UINT loop_around_cmd = shift ? GW_HWNDLAST : GW_HWNDFIRST;
|
|
||||||
HWND focus = GetFocus(), next;
|
|
||||||
do {
|
|
||||||
next = ::GetWindow(focus, next_cmd);
|
|
||||||
if (IsWindowVisible(next) &&
|
|
||||||
(GetWindowLong(next, GWL_STYLE) & WS_TABSTOP)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!next) {
|
|
||||||
next = ::GetWindow(focus, loop_around_cmd);
|
|
||||||
if (IsWindowVisible(next) &&
|
|
||||||
(GetWindowLong(next, GWL_STYLE) & WS_TABSTOP)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
focus = next;
|
|
||||||
} while (true);
|
|
||||||
::SetFocus(next);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// MainWnd::VideoRenderer
|
|
||||||
//
|
|
||||||
|
|
||||||
MainWnd::VideoRenderer::VideoRenderer(HWND wnd, int width, int height)
|
|
||||||
: wnd_(wnd), frame_width_(0), frame_height_(0) {
|
|
||||||
::InitializeCriticalSection(&buffer_lock_);
|
|
||||||
ZeroMemory(&bmi_, sizeof(bmi_));
|
|
||||||
bmi_.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
||||||
bmi_.bmiHeader.biPlanes = 1;
|
|
||||||
bmi_.bmiHeader.biBitCount = 32;
|
|
||||||
bmi_.bmiHeader.biCompression = BI_RGB;
|
|
||||||
bmi_.bmiHeader.biWidth = width;
|
|
||||||
bmi_.bmiHeader.biHeight = -height;
|
|
||||||
bmi_.bmiHeader.biSizeImage = width * height *
|
|
||||||
(bmi_.bmiHeader.biBitCount >> 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWnd::VideoRenderer::~VideoRenderer() {
|
|
||||||
::DeleteCriticalSection(&buffer_lock_);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWnd::VideoRenderer::SetSize(int width, int height, int reserved) {
|
|
||||||
AutoLock<VideoRenderer> lock(this);
|
|
||||||
|
|
||||||
bmi_.bmiHeader.biWidth = width;
|
|
||||||
bmi_.bmiHeader.biHeight = -height;
|
|
||||||
bmi_.bmiHeader.biSizeImage = width * height *
|
|
||||||
(bmi_.bmiHeader.biBitCount >> 3);
|
|
||||||
image_.reset(new uint8[bmi_.bmiHeader.biSizeImage]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MainWnd::VideoRenderer::RenderFrame(const cricket::VideoFrame* frame) {
|
|
||||||
if (!frame)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
{
|
|
||||||
AutoLock<VideoRenderer> lock(this);
|
|
||||||
|
|
||||||
frame_height_ = frame->GetHeight();
|
|
||||||
frame_width_ = frame->GetWidth();
|
|
||||||
|
|
||||||
ASSERT(image_.get() != NULL);
|
|
||||||
frame->ConvertToRgbBuffer(cricket::FOURCC_ARGB, image_.get(),
|
|
||||||
bmi_.bmiHeader.biSizeImage,
|
|
||||||
bmi_.bmiHeader.biWidth *
|
|
||||||
(bmi_.bmiHeader.biBitCount >> 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
InvalidateRect(wnd_, NULL, TRUE);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -1,195 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_MAIN_WND_H_
|
|
||||||
#define PEERCONNECTION_SAMPLES_CLIENT_MAIN_WND_H_
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/peer_connection_client.h"
|
|
||||||
#include "talk/base/win32.h"
|
|
||||||
#include "talk/session/phone/mediachannel.h"
|
|
||||||
#include "talk/session/phone/videocommon.h"
|
|
||||||
#include "talk/session/phone/videoframe.h"
|
|
||||||
#include "talk/session/phone/videorenderer.h"
|
|
||||||
|
|
||||||
class MainWndCallback {
|
|
||||||
public:
|
|
||||||
virtual bool StartLogin(const std::string& server, int port) = 0;
|
|
||||||
virtual void DisconnectFromServer() = 0;
|
|
||||||
virtual void ConnectToPeer(int peer_id) = 0;
|
|
||||||
virtual void DisconnectFromCurrentPeer() = 0;
|
|
||||||
virtual void UIThreadCallback(int msg_id, void* data) = 0;
|
|
||||||
virtual void Close() = 0;
|
|
||||||
protected:
|
|
||||||
virtual ~MainWndCallback() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Pure virtual interface for the main window.
|
|
||||||
class MainWindow {
|
|
||||||
public:
|
|
||||||
virtual ~MainWindow() {}
|
|
||||||
|
|
||||||
enum UI {
|
|
||||||
CONNECT_TO_SERVER,
|
|
||||||
LIST_PEERS,
|
|
||||||
STREAMING,
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual void RegisterObserver(MainWndCallback* callback) = 0;
|
|
||||||
|
|
||||||
virtual bool IsWindow() = 0;
|
|
||||||
virtual void MessageBox(const char* caption, const char* text,
|
|
||||||
bool is_error) = 0;
|
|
||||||
|
|
||||||
virtual UI current_ui() = 0;
|
|
||||||
|
|
||||||
virtual void SwitchToConnectUI() = 0;
|
|
||||||
virtual void SwitchToPeerList(const Peers& peers) = 0;
|
|
||||||
virtual void SwitchToStreamingUI() = 0;
|
|
||||||
|
|
||||||
virtual cricket::VideoRenderer* local_renderer() = 0;
|
|
||||||
virtual cricket::VideoRenderer* remote_renderer() = 0;
|
|
||||||
|
|
||||||
virtual void QueueUIThreadCallback(int msg_id, void* data) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
|
|
||||||
class MainWnd : public MainWindow {
|
|
||||||
public:
|
|
||||||
static const wchar_t kClassName[];
|
|
||||||
|
|
||||||
enum WindowMessages {
|
|
||||||
UI_THREAD_CALLBACK = WM_APP + 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
MainWnd();
|
|
||||||
~MainWnd();
|
|
||||||
|
|
||||||
bool Create();
|
|
||||||
bool Destroy();
|
|
||||||
bool PreTranslateMessage(MSG* msg);
|
|
||||||
|
|
||||||
virtual void RegisterObserver(MainWndCallback* callback);
|
|
||||||
virtual bool IsWindow();
|
|
||||||
virtual void SwitchToConnectUI();
|
|
||||||
virtual void SwitchToPeerList(const Peers& peers);
|
|
||||||
virtual void SwitchToStreamingUI();
|
|
||||||
virtual void MessageBox(const char* caption, const char* text,
|
|
||||||
bool is_error);
|
|
||||||
virtual UI current_ui() { return ui_; }
|
|
||||||
|
|
||||||
virtual cricket::VideoRenderer* local_renderer();
|
|
||||||
virtual cricket::VideoRenderer* remote_renderer();
|
|
||||||
|
|
||||||
virtual void QueueUIThreadCallback(int msg_id, void* data);
|
|
||||||
|
|
||||||
HWND handle() const { return wnd_; }
|
|
||||||
|
|
||||||
class VideoRenderer : public cricket::VideoRenderer {
|
|
||||||
public:
|
|
||||||
VideoRenderer(HWND wnd, int width, int height);
|
|
||||||
virtual ~VideoRenderer();
|
|
||||||
|
|
||||||
void Lock() {
|
|
||||||
::EnterCriticalSection(&buffer_lock_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Unlock() {
|
|
||||||
::LeaveCriticalSection(&buffer_lock_);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool SetSize(int width, int height, int reserved);
|
|
||||||
|
|
||||||
// Called when a new frame is available for display.
|
|
||||||
virtual bool RenderFrame(const cricket::VideoFrame* frame);
|
|
||||||
|
|
||||||
const BITMAPINFO& bmi() const { return bmi_; }
|
|
||||||
const uint8* image() const { return image_.get(); }
|
|
||||||
|
|
||||||
size_t frame_width() const { return frame_width_; }
|
|
||||||
size_t frame_height() const { return frame_height_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
enum {
|
|
||||||
SET_SIZE,
|
|
||||||
RENDER_FRAME,
|
|
||||||
};
|
|
||||||
|
|
||||||
HWND wnd_;
|
|
||||||
BITMAPINFO bmi_;
|
|
||||||
size_t frame_width_;
|
|
||||||
size_t frame_height_;
|
|
||||||
talk_base::scoped_array<uint8> image_;
|
|
||||||
CRITICAL_SECTION buffer_lock_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// A little helper class to make sure we always to proper locking and
|
|
||||||
// unlocking when working with VideoRenderer buffers.
|
|
||||||
template <typename T>
|
|
||||||
class AutoLock {
|
|
||||||
public:
|
|
||||||
explicit AutoLock(T* obj) : obj_(obj) { obj_->Lock(); }
|
|
||||||
~AutoLock() { obj_->Unlock(); }
|
|
||||||
protected:
|
|
||||||
T* obj_;
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
|
||||||
enum ChildWindowID {
|
|
||||||
EDIT_ID = 1,
|
|
||||||
BUTTON_ID,
|
|
||||||
LABEL1_ID,
|
|
||||||
LABEL2_ID,
|
|
||||||
LISTBOX_ID,
|
|
||||||
};
|
|
||||||
|
|
||||||
void OnPaint();
|
|
||||||
void OnDestroyed();
|
|
||||||
|
|
||||||
void OnDefaultAction();
|
|
||||||
|
|
||||||
bool OnMessage(UINT msg, WPARAM wp, LPARAM lp, LRESULT* result);
|
|
||||||
|
|
||||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
|
|
||||||
static bool RegisterWindowClass();
|
|
||||||
|
|
||||||
void CreateChildWindow(HWND* wnd, ChildWindowID id, const wchar_t* class_name,
|
|
||||||
DWORD control_style, DWORD ex_style);
|
|
||||||
void CreateChildWindows();
|
|
||||||
|
|
||||||
void LayoutConnectUI(bool show);
|
|
||||||
void LayoutPeerListUI(bool show);
|
|
||||||
|
|
||||||
void HandleTabbing();
|
|
||||||
|
|
||||||
private:
|
|
||||||
talk_base::scoped_ptr<VideoRenderer> remote_video_;
|
|
||||||
talk_base::scoped_ptr<VideoRenderer> local_video_;
|
|
||||||
UI ui_;
|
|
||||||
HWND wnd_;
|
|
||||||
DWORD ui_thread_id_;
|
|
||||||
HWND edit1_;
|
|
||||||
HWND edit2_;
|
|
||||||
HWND label1_;
|
|
||||||
HWND label2_;
|
|
||||||
HWND button_;
|
|
||||||
HWND listbox_;
|
|
||||||
bool destroyed_;
|
|
||||||
void* nested_msg_;
|
|
||||||
MainWndCallback* callback_;
|
|
||||||
static ATOM wnd_class_;
|
|
||||||
};
|
|
||||||
#endif // WIN32
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_CLIENT_MAIN_WND_H_
|
|
@ -1,482 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/peer_connection_client.h"
|
|
||||||
|
|
||||||
#include "peerconnection/samples/client/defaults.h"
|
|
||||||
#include "talk/base/common.h"
|
|
||||||
#include "talk/base/nethelpers.h"
|
|
||||||
#include "talk/base/logging.h"
|
|
||||||
#include "talk/base/stringutils.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include "talk/base/win32socketserver.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using talk_base::sprintfn;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// This is our magical hangup signal.
|
|
||||||
const char kByeMessage[] = "BYE";
|
|
||||||
|
|
||||||
talk_base::AsyncSocket* CreateClientSocket() {
|
|
||||||
#ifdef WIN32
|
|
||||||
return new talk_base::Win32Socket();
|
|
||||||
#elif defined(POSIX)
|
|
||||||
talk_base::Thread* thread = talk_base::Thread::Current();
|
|
||||||
ASSERT(thread != NULL);
|
|
||||||
return thread->socketserver()->CreateAsyncSocket(SOCK_STREAM);
|
|
||||||
#else
|
|
||||||
#error Platform not supported.
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PeerConnectionClient::PeerConnectionClient()
|
|
||||||
: callback_(NULL),
|
|
||||||
control_socket_(CreateClientSocket()),
|
|
||||||
hanging_get_(CreateClientSocket()),
|
|
||||||
state_(NOT_CONNECTED),
|
|
||||||
my_id_(-1) {
|
|
||||||
control_socket_->SignalCloseEvent.connect(this,
|
|
||||||
&PeerConnectionClient::OnClose);
|
|
||||||
hanging_get_->SignalCloseEvent.connect(this,
|
|
||||||
&PeerConnectionClient::OnClose);
|
|
||||||
control_socket_->SignalConnectEvent.connect(this,
|
|
||||||
&PeerConnectionClient::OnConnect);
|
|
||||||
hanging_get_->SignalConnectEvent.connect(this,
|
|
||||||
&PeerConnectionClient::OnHangingGetConnect);
|
|
||||||
control_socket_->SignalReadEvent.connect(this,
|
|
||||||
&PeerConnectionClient::OnRead);
|
|
||||||
hanging_get_->SignalReadEvent.connect(this,
|
|
||||||
&PeerConnectionClient::OnHangingGetRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
PeerConnectionClient::~PeerConnectionClient() {
|
|
||||||
}
|
|
||||||
|
|
||||||
int PeerConnectionClient::id() const {
|
|
||||||
return my_id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::is_connected() const {
|
|
||||||
return my_id_ != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Peers& PeerConnectionClient::peers() const {
|
|
||||||
return peers_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::RegisterObserver(
|
|
||||||
PeerConnectionClientObserver* callback) {
|
|
||||||
ASSERT(!callback_);
|
|
||||||
callback_ = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::Connect(const std::string& server, int port,
|
|
||||||
const std::string& client_name) {
|
|
||||||
ASSERT(!server.empty());
|
|
||||||
ASSERT(!client_name.empty());
|
|
||||||
|
|
||||||
if (state_ != NOT_CONNECTED) {
|
|
||||||
LOG(WARNING)
|
|
||||||
<< "The client must not be connected before you can call Connect()";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (server.empty() || client_name.empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (port <= 0)
|
|
||||||
port = kDefaultServerPort;
|
|
||||||
|
|
||||||
server_address_.SetIP(server);
|
|
||||||
server_address_.SetPort(port);
|
|
||||||
|
|
||||||
if (server_address_.IsUnresolved()) {
|
|
||||||
int errcode = 0;
|
|
||||||
hostent* h = talk_base::SafeGetHostByName(
|
|
||||||
server_address_.IPAsString().c_str(), &errcode);
|
|
||||||
if (!h) {
|
|
||||||
LOG(LS_ERROR) << "Failed to resolve host name: "
|
|
||||||
<< server_address_.IPAsString();
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
server_address_.SetResolvedIP(
|
|
||||||
ntohl(*reinterpret_cast<uint32*>(h->h_addr_list[0])));
|
|
||||||
talk_base::FreeHostEnt(h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[1024];
|
|
||||||
sprintfn(buffer, sizeof(buffer),
|
|
||||||
"GET /sign_in?%s HTTP/1.0\r\n\r\n", client_name.c_str());
|
|
||||||
onconnect_data_ = buffer;
|
|
||||||
|
|
||||||
bool ret = ConnectControlSocket();
|
|
||||||
if (ret)
|
|
||||||
state_ = SIGNING_IN;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::SendToPeer(int peer_id, const std::string& message) {
|
|
||||||
if (state_ != CONNECTED)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ASSERT(is_connected());
|
|
||||||
ASSERT(control_socket_->GetState() == talk_base::Socket::CS_CLOSED);
|
|
||||||
if (!is_connected() || peer_id == -1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char headers[1024];
|
|
||||||
sprintfn(headers, sizeof(headers),
|
|
||||||
"POST /message?peer_id=%i&to=%i HTTP/1.0\r\n"
|
|
||||||
"Content-Length: %i\r\n"
|
|
||||||
"Content-Type: text/plain\r\n"
|
|
||||||
"\r\n",
|
|
||||||
my_id_, peer_id, message.length());
|
|
||||||
onconnect_data_ = headers;
|
|
||||||
onconnect_data_ += message;
|
|
||||||
return ConnectControlSocket();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::SendHangUp(int peer_id) {
|
|
||||||
return SendToPeer(peer_id, kByeMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::IsSendingMessage() {
|
|
||||||
return state_ == CONNECTED &&
|
|
||||||
control_socket_->GetState() != talk_base::Socket::CS_CLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::SignOut() {
|
|
||||||
if (state_ == NOT_CONNECTED || state_ == SIGNING_OUT)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (hanging_get_->GetState() != talk_base::Socket::CS_CLOSED)
|
|
||||||
hanging_get_->Close();
|
|
||||||
|
|
||||||
if (control_socket_->GetState() == talk_base::Socket::CS_CLOSED) {
|
|
||||||
state_ = SIGNING_OUT;
|
|
||||||
|
|
||||||
if (my_id_ != -1) {
|
|
||||||
char buffer[1024];
|
|
||||||
sprintfn(buffer, sizeof(buffer),
|
|
||||||
"GET /sign_out?peer_id=%i HTTP/1.0\r\n\r\n", my_id_);
|
|
||||||
onconnect_data_ = buffer;
|
|
||||||
return ConnectControlSocket();
|
|
||||||
} else {
|
|
||||||
// Can occur if the app is closed before we finish connecting.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
state_ = SIGNING_OUT_WAITING;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::Close() {
|
|
||||||
control_socket_->Close();
|
|
||||||
hanging_get_->Close();
|
|
||||||
onconnect_data_.clear();
|
|
||||||
peers_.clear();
|
|
||||||
my_id_ = -1;
|
|
||||||
state_ = NOT_CONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::ConnectControlSocket() {
|
|
||||||
ASSERT(control_socket_->GetState() == talk_base::Socket::CS_CLOSED);
|
|
||||||
int err = control_socket_->Connect(server_address_);
|
|
||||||
if (err == SOCKET_ERROR) {
|
|
||||||
Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::OnConnect(talk_base::AsyncSocket* socket) {
|
|
||||||
ASSERT(!onconnect_data_.empty());
|
|
||||||
size_t sent = socket->Send(onconnect_data_.c_str(), onconnect_data_.length());
|
|
||||||
ASSERT(sent == onconnect_data_.length());
|
|
||||||
UNUSED(sent);
|
|
||||||
onconnect_data_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::OnHangingGetConnect(talk_base::AsyncSocket* socket) {
|
|
||||||
char buffer[1024];
|
|
||||||
sprintfn(buffer, sizeof(buffer),
|
|
||||||
"GET /wait?peer_id=%i HTTP/1.0\r\n\r\n", my_id_);
|
|
||||||
int len = strlen(buffer);
|
|
||||||
int sent = socket->Send(buffer, len);
|
|
||||||
ASSERT(sent == len);
|
|
||||||
UNUSED2(sent, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::OnMessageFromPeer(int peer_id,
|
|
||||||
const std::string& message) {
|
|
||||||
if (message.length() == (sizeof(kByeMessage) - 1) &&
|
|
||||||
message.compare(kByeMessage) == 0) {
|
|
||||||
callback_->OnPeerDisconnected(peer_id);
|
|
||||||
} else {
|
|
||||||
callback_->OnMessageFromPeer(peer_id, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::GetHeaderValue(const std::string& data,
|
|
||||||
size_t eoh,
|
|
||||||
const char* header_pattern,
|
|
||||||
size_t* value) {
|
|
||||||
ASSERT(value != NULL);
|
|
||||||
size_t found = data.find(header_pattern);
|
|
||||||
if (found != std::string::npos && found < eoh) {
|
|
||||||
*value = atoi(&data[found + strlen(header_pattern)]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::GetHeaderValue(const std::string& data, size_t eoh,
|
|
||||||
const char* header_pattern,
|
|
||||||
std::string* value) {
|
|
||||||
ASSERT(value != NULL);
|
|
||||||
size_t found = data.find(header_pattern);
|
|
||||||
if (found != std::string::npos && found < eoh) {
|
|
||||||
size_t begin = found + strlen(header_pattern);
|
|
||||||
size_t end = data.find("\r\n", begin);
|
|
||||||
if (end == std::string::npos)
|
|
||||||
end = eoh;
|
|
||||||
value->assign(data.substr(begin, end - begin));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::ReadIntoBuffer(talk_base::AsyncSocket* socket,
|
|
||||||
std::string* data,
|
|
||||||
size_t* content_length) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
|
|
||||||
char buffer[0xffff];
|
|
||||||
do {
|
|
||||||
int bytes = socket->Recv(buffer, sizeof(buffer));
|
|
||||||
if (bytes <= 0)
|
|
||||||
break;
|
|
||||||
data->append(buffer, bytes);
|
|
||||||
} while (true);
|
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
size_t i = data->find("\r\n\r\n");
|
|
||||||
if (i != std::string::npos) {
|
|
||||||
LOG(INFO) << "Headers received";
|
|
||||||
if (GetHeaderValue(*data, i, "\r\nContent-Length: ", content_length)) {
|
|
||||||
LOG(INFO) << "Expecting " << *content_length << " bytes.";
|
|
||||||
size_t total_response_size = (i + 4) + *content_length;
|
|
||||||
if (data->length() >= total_response_size) {
|
|
||||||
ret = true;
|
|
||||||
std::string should_close;
|
|
||||||
const char kConnection[] = "\r\nConnection: ";
|
|
||||||
if (GetHeaderValue(*data, i, kConnection, &should_close) &&
|
|
||||||
should_close.compare("close") == 0) {
|
|
||||||
socket->Close();
|
|
||||||
// Since we closed the socket, there was no notification delivered
|
|
||||||
// to us. Compensate by letting ourselves know.
|
|
||||||
OnClose(socket, 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// We haven't received everything. Just continue to accept data.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG(LS_ERROR) << "No content length field specified by the server.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::OnRead(talk_base::AsyncSocket* socket) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
size_t content_length = 0;
|
|
||||||
if (ReadIntoBuffer(socket, &control_data_, &content_length)) {
|
|
||||||
size_t peer_id = 0, eoh = 0;
|
|
||||||
bool ok = ParseServerResponse(control_data_, content_length, &peer_id,
|
|
||||||
&eoh);
|
|
||||||
if (ok) {
|
|
||||||
if (my_id_ == -1) {
|
|
||||||
// First response. Let's store our server assigned ID.
|
|
||||||
ASSERT(state_ == SIGNING_IN);
|
|
||||||
my_id_ = peer_id;
|
|
||||||
ASSERT(my_id_ != -1);
|
|
||||||
|
|
||||||
// The body of the response will be a list of already connected peers.
|
|
||||||
if (content_length) {
|
|
||||||
size_t pos = eoh + 4;
|
|
||||||
while (pos < control_data_.size()) {
|
|
||||||
size_t eol = control_data_.find('\n', pos);
|
|
||||||
if (eol == std::string::npos)
|
|
||||||
break;
|
|
||||||
int id = 0;
|
|
||||||
std::string name;
|
|
||||||
bool connected;
|
|
||||||
if (ParseEntry(control_data_.substr(pos, eol - pos), &name, &id,
|
|
||||||
&connected) && id != my_id_) {
|
|
||||||
peers_[id] = name;
|
|
||||||
callback_->OnPeerConnected(id, name);
|
|
||||||
}
|
|
||||||
pos = eol + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ASSERT(is_connected());
|
|
||||||
callback_->OnSignedIn();
|
|
||||||
} else if (state_ == SIGNING_OUT) {
|
|
||||||
Close();
|
|
||||||
callback_->OnDisconnected();
|
|
||||||
} else if (state_ == SIGNING_OUT_WAITING) {
|
|
||||||
SignOut();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
control_data_.clear();
|
|
||||||
|
|
||||||
if (state_ == SIGNING_IN) {
|
|
||||||
ASSERT(hanging_get_->GetState() == talk_base::Socket::CS_CLOSED);
|
|
||||||
state_ = CONNECTED;
|
|
||||||
hanging_get_->Connect(server_address_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::OnHangingGetRead(talk_base::AsyncSocket* socket) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
size_t content_length = 0;
|
|
||||||
if (ReadIntoBuffer(socket, ¬ification_data_, &content_length)) {
|
|
||||||
size_t peer_id = 0, eoh = 0;
|
|
||||||
bool ok = ParseServerResponse(notification_data_, content_length,
|
|
||||||
&peer_id, &eoh);
|
|
||||||
|
|
||||||
if (ok) {
|
|
||||||
// Store the position where the body begins.
|
|
||||||
size_t pos = eoh + 4;
|
|
||||||
|
|
||||||
if (my_id_ == static_cast<int>(peer_id)) {
|
|
||||||
// A notification about a new member or a member that just
|
|
||||||
// disconnected.
|
|
||||||
int id = 0;
|
|
||||||
std::string name;
|
|
||||||
bool connected = false;
|
|
||||||
if (ParseEntry(notification_data_.substr(pos), &name, &id,
|
|
||||||
&connected)) {
|
|
||||||
if (connected) {
|
|
||||||
peers_[id] = name;
|
|
||||||
callback_->OnPeerConnected(id, name);
|
|
||||||
} else {
|
|
||||||
peers_.erase(id);
|
|
||||||
callback_->OnPeerDisconnected(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
OnMessageFromPeer(peer_id, notification_data_.substr(pos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notification_data_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hanging_get_->GetState() == talk_base::Socket::CS_CLOSED &&
|
|
||||||
state_ == CONNECTED) {
|
|
||||||
hanging_get_->Connect(server_address_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::ParseEntry(const std::string& entry,
|
|
||||||
std::string* name,
|
|
||||||
int* id,
|
|
||||||
bool* connected) {
|
|
||||||
ASSERT(name != NULL);
|
|
||||||
ASSERT(id != NULL);
|
|
||||||
ASSERT(connected != NULL);
|
|
||||||
ASSERT(!entry.empty());
|
|
||||||
|
|
||||||
*connected = false;
|
|
||||||
size_t separator = entry.find(',');
|
|
||||||
if (separator != std::string::npos) {
|
|
||||||
*id = atoi(&entry[separator + 1]);
|
|
||||||
name->assign(entry.substr(0, separator));
|
|
||||||
separator = entry.find(',', separator + 1);
|
|
||||||
if (separator != std::string::npos) {
|
|
||||||
*connected = atoi(&entry[separator + 1]) ? true : false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !name->empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
int PeerConnectionClient::GetResponseStatus(const std::string& response) {
|
|
||||||
int status = -1;
|
|
||||||
size_t pos = response.find(' ');
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
status = atoi(&response[pos + 1]);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerConnectionClient::ParseServerResponse(const std::string& response,
|
|
||||||
size_t content_length,
|
|
||||||
size_t* peer_id,
|
|
||||||
size_t* eoh) {
|
|
||||||
LOG(INFO) << response;
|
|
||||||
|
|
||||||
int status = GetResponseStatus(response.c_str());
|
|
||||||
if (status != 200) {
|
|
||||||
LOG(LS_ERROR) << "Received error from server";
|
|
||||||
Close();
|
|
||||||
callback_->OnDisconnected();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*eoh = response.find("\r\n\r\n");
|
|
||||||
ASSERT(*eoh != std::string::npos);
|
|
||||||
if (*eoh == std::string::npos)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
*peer_id = -1;
|
|
||||||
|
|
||||||
// See comment in peer_channel.cc for why we use the Pragma header and
|
|
||||||
// not e.g. "X-Peer-Id".
|
|
||||||
GetHeaderValue(response, *eoh, "\r\nPragma: ", peer_id);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerConnectionClient::OnClose(talk_base::AsyncSocket* socket, int err) {
|
|
||||||
LOG(INFO) << __FUNCTION__;
|
|
||||||
|
|
||||||
socket->Close();
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
if (err != WSAECONNREFUSED) {
|
|
||||||
#else
|
|
||||||
if (err != ECONNREFUSED) {
|
|
||||||
#endif
|
|
||||||
if (socket == hanging_get_.get()) {
|
|
||||||
if (state_ == CONNECTED) {
|
|
||||||
LOG(INFO) << "Issuing a new hanging get";
|
|
||||||
hanging_get_->Close();
|
|
||||||
hanging_get_->Connect(server_address_);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
callback_->OnMessageSent(err);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG(WARNING) << "Failed to connect to the server";
|
|
||||||
Close();
|
|
||||||
callback_->OnDisconnected();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_PEER_CONNECTION_CLIENT_H_
|
|
||||||
#define PEERCONNECTION_SAMPLES_CLIENT_PEER_CONNECTION_CLIENT_H_
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "talk/base/sigslot.h"
|
|
||||||
#include "talk/base/physicalsocketserver.h"
|
|
||||||
#include "talk/base/scoped_ptr.h"
|
|
||||||
|
|
||||||
typedef std::map<int, std::string> Peers;
|
|
||||||
|
|
||||||
struct PeerConnectionClientObserver {
|
|
||||||
virtual void OnSignedIn() = 0; // Called when we're logged on.
|
|
||||||
virtual void OnDisconnected() = 0;
|
|
||||||
virtual void OnPeerConnected(int id, const std::string& name) = 0;
|
|
||||||
virtual void OnPeerDisconnected(int peer_id) = 0;
|
|
||||||
virtual void OnMessageFromPeer(int peer_id, const std::string& message) = 0;
|
|
||||||
virtual void OnMessageSent(int err) = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~PeerConnectionClientObserver() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class PeerConnectionClient : public sigslot::has_slots<> {
|
|
||||||
public:
|
|
||||||
enum State {
|
|
||||||
NOT_CONNECTED,
|
|
||||||
SIGNING_IN,
|
|
||||||
CONNECTED,
|
|
||||||
SIGNING_OUT_WAITING,
|
|
||||||
SIGNING_OUT,
|
|
||||||
};
|
|
||||||
|
|
||||||
PeerConnectionClient();
|
|
||||||
~PeerConnectionClient();
|
|
||||||
|
|
||||||
int id() const;
|
|
||||||
bool is_connected() const;
|
|
||||||
const Peers& peers() const;
|
|
||||||
|
|
||||||
void RegisterObserver(PeerConnectionClientObserver* callback);
|
|
||||||
|
|
||||||
bool Connect(const std::string& server, int port,
|
|
||||||
const std::string& client_name);
|
|
||||||
|
|
||||||
bool SendToPeer(int peer_id, const std::string& message);
|
|
||||||
bool SendHangUp(int peer_id);
|
|
||||||
bool IsSendingMessage();
|
|
||||||
|
|
||||||
bool SignOut();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void Close();
|
|
||||||
bool ConnectControlSocket();
|
|
||||||
void OnConnect(talk_base::AsyncSocket* socket);
|
|
||||||
void OnHangingGetConnect(talk_base::AsyncSocket* socket);
|
|
||||||
void OnMessageFromPeer(int peer_id, const std::string& message);
|
|
||||||
|
|
||||||
// Quick and dirty support for parsing HTTP header values.
|
|
||||||
bool GetHeaderValue(const std::string& data, size_t eoh,
|
|
||||||
const char* header_pattern, size_t* value);
|
|
||||||
|
|
||||||
bool GetHeaderValue(const std::string& data, size_t eoh,
|
|
||||||
const char* header_pattern, std::string* value);
|
|
||||||
|
|
||||||
// Returns true if the whole response has been read.
|
|
||||||
bool ReadIntoBuffer(talk_base::AsyncSocket* socket, std::string* data,
|
|
||||||
size_t* content_length);
|
|
||||||
|
|
||||||
void OnRead(talk_base::AsyncSocket* socket);
|
|
||||||
|
|
||||||
void OnHangingGetRead(talk_base::AsyncSocket* socket);
|
|
||||||
|
|
||||||
// Parses a single line entry in the form "<name>,<id>,<connected>"
|
|
||||||
bool ParseEntry(const std::string& entry, std::string* name, int* id,
|
|
||||||
bool* connected);
|
|
||||||
|
|
||||||
int GetResponseStatus(const std::string& response);
|
|
||||||
|
|
||||||
bool ParseServerResponse(const std::string& response, size_t content_length,
|
|
||||||
size_t* peer_id, size_t* eoh);
|
|
||||||
|
|
||||||
void OnClose(talk_base::AsyncSocket* socket, int err);
|
|
||||||
|
|
||||||
PeerConnectionClientObserver* callback_;
|
|
||||||
talk_base::SocketAddress server_address_;
|
|
||||||
talk_base::scoped_ptr<talk_base::AsyncSocket> control_socket_;
|
|
||||||
talk_base::scoped_ptr<talk_base::AsyncSocket> hanging_get_;
|
|
||||||
std::string onconnect_data_;
|
|
||||||
std::string control_data_;
|
|
||||||
std::string notification_data_;
|
|
||||||
Peers peers_;
|
|
||||||
State state_;
|
|
||||||
int my_id_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_CLIENT_PEER_CONNECTION_CLIENT_H_
|
|
@ -1,287 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "peerconnection/samples/server/data_socket.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/server/utils.h"
|
|
||||||
|
|
||||||
static const char kHeaderTerminator[] = "\r\n\r\n";
|
|
||||||
static const int kHeaderTerminatorLength = sizeof(kHeaderTerminator) - 1;
|
|
||||||
|
|
||||||
// static
|
|
||||||
const char DataSocket::kCrossOriginAllowHeaders[] =
|
|
||||||
"Access-Control-Allow-Origin: *\r\n"
|
|
||||||
"Access-Control-Allow-Credentials: true\r\n"
|
|
||||||
"Access-Control-Allow-Methods: POST, GET, OPTIONS\r\n"
|
|
||||||
"Access-Control-Allow-Headers: Content-Type, "
|
|
||||||
"Content-Length, Connection, Cache-Control\r\n"
|
|
||||||
"Access-Control-Expose-Headers: Content-Length, X-Peer-Id\r\n";
|
|
||||||
|
|
||||||
#if defined(WIN32)
|
|
||||||
class WinsockInitializer {
|
|
||||||
static WinsockInitializer singleton;
|
|
||||||
|
|
||||||
WinsockInitializer() {
|
|
||||||
WSADATA data;
|
|
||||||
WSAStartup(MAKEWORD(1, 0), &data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
~WinsockInitializer() { WSACleanup(); }
|
|
||||||
};
|
|
||||||
WinsockInitializer WinsockInitializer::singleton;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
|
||||||
// SocketBase
|
|
||||||
//
|
|
||||||
|
|
||||||
bool SocketBase::Create() {
|
|
||||||
assert(!valid());
|
|
||||||
socket_ = ::socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
return valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SocketBase::Close() {
|
|
||||||
if (socket_ != INVALID_SOCKET) {
|
|
||||||
closesocket(socket_);
|
|
||||||
socket_ = INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DataSocket
|
|
||||||
//
|
|
||||||
|
|
||||||
std::string DataSocket::request_arguments() const {
|
|
||||||
size_t args = request_path_.find('?');
|
|
||||||
if (args != std::string::npos)
|
|
||||||
return request_path_.substr(args + 1);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataSocket::PathEquals(const char* path) const {
|
|
||||||
assert(path);
|
|
||||||
size_t args = request_path_.find('?');
|
|
||||||
if (args != std::string::npos)
|
|
||||||
return request_path_.substr(0, args).compare(path) == 0;
|
|
||||||
return request_path_.compare(path) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataSocket::OnDataAvailable(bool* close_socket) {
|
|
||||||
assert(valid());
|
|
||||||
char buffer[0xfff] = {0};
|
|
||||||
int bytes = recv(socket_, buffer, sizeof(buffer), 0);
|
|
||||||
if (bytes == SOCKET_ERROR || bytes == 0) {
|
|
||||||
*close_socket = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*close_socket = false;
|
|
||||||
|
|
||||||
bool ret = true;
|
|
||||||
if (headers_received()) {
|
|
||||||
if (method_ != POST) {
|
|
||||||
// unexpectedly received data.
|
|
||||||
ret = false;
|
|
||||||
} else {
|
|
||||||
data_.append(buffer, bytes);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
request_headers_.append(buffer, bytes);
|
|
||||||
size_t found = request_headers_.find(kHeaderTerminator);
|
|
||||||
if (found != std::string::npos) {
|
|
||||||
data_ = request_headers_.substr(found + kHeaderTerminatorLength);
|
|
||||||
request_headers_.resize(found + kHeaderTerminatorLength);
|
|
||||||
ret = ParseHeaders();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataSocket::Send(const std::string& data) const {
|
|
||||||
return send(socket_, data.data(), data.length(), 0) != SOCKET_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataSocket::Send(const std::string& status, bool connection_close,
|
|
||||||
const std::string& content_type,
|
|
||||||
const std::string& extra_headers,
|
|
||||||
const std::string& data) const {
|
|
||||||
assert(valid());
|
|
||||||
assert(!status.empty());
|
|
||||||
std::string buffer("HTTP/1.1 " + status + "\r\n");
|
|
||||||
|
|
||||||
buffer += "Server: PeerConnectionTestServer/0.1\r\n"
|
|
||||||
"Cache-Control: no-cache\r\n";
|
|
||||||
|
|
||||||
if (connection_close)
|
|
||||||
buffer += "Connection: close\r\n";
|
|
||||||
|
|
||||||
if (!content_type.empty())
|
|
||||||
buffer += "Content-Type: " + content_type + "\r\n";
|
|
||||||
|
|
||||||
buffer += "Content-Length: " + int2str(data.size()) + "\r\n";
|
|
||||||
|
|
||||||
if (!extra_headers.empty()) {
|
|
||||||
buffer += extra_headers;
|
|
||||||
// Extra headers are assumed to have a separator per header.
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += kCrossOriginAllowHeaders;
|
|
||||||
|
|
||||||
buffer += "\r\n";
|
|
||||||
buffer += data;
|
|
||||||
|
|
||||||
return Send(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataSocket::Clear() {
|
|
||||||
method_ = INVALID;
|
|
||||||
content_length_ = 0;
|
|
||||||
content_type_.clear();
|
|
||||||
request_path_.clear();
|
|
||||||
request_headers_.clear();
|
|
||||||
data_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataSocket::ParseHeaders() {
|
|
||||||
assert(!request_headers_.empty());
|
|
||||||
assert(method_ == INVALID);
|
|
||||||
size_t i = request_headers_.find("\r\n");
|
|
||||||
if (i == std::string::npos)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!ParseMethodAndPath(request_headers_.data(), i))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
assert(method_ != INVALID);
|
|
||||||
assert(!request_path_.empty());
|
|
||||||
|
|
||||||
if (method_ == POST) {
|
|
||||||
const char* headers = request_headers_.data() + i + 2;
|
|
||||||
size_t len = request_headers_.length() - i - 2;
|
|
||||||
if (!ParseContentLengthAndType(headers, len))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataSocket::ParseMethodAndPath(const char* begin, size_t len) {
|
|
||||||
struct {
|
|
||||||
const char* method_name;
|
|
||||||
size_t method_name_len;
|
|
||||||
RequestMethod id;
|
|
||||||
} supported_methods[] = {
|
|
||||||
{ "GET", 3, GET },
|
|
||||||
{ "POST", 4, POST },
|
|
||||||
{ "OPTIONS", 7, OPTIONS },
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* path = NULL;
|
|
||||||
for (size_t i = 0; i < ARRAYSIZE(supported_methods); ++i) {
|
|
||||||
if (len > supported_methods[i].method_name_len &&
|
|
||||||
isspace(begin[supported_methods[i].method_name_len]) &&
|
|
||||||
strncmp(begin, supported_methods[i].method_name,
|
|
||||||
supported_methods[i].method_name_len) == 0) {
|
|
||||||
method_ = supported_methods[i].id;
|
|
||||||
path = begin + supported_methods[i].method_name_len;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* end = begin + len;
|
|
||||||
if (!path || path >= end)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
++path;
|
|
||||||
begin = path;
|
|
||||||
while (!isspace(*path) && path < end)
|
|
||||||
++path;
|
|
||||||
|
|
||||||
request_path_.assign(begin, path - begin);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataSocket::ParseContentLengthAndType(const char* headers, size_t length) {
|
|
||||||
assert(content_length_ == 0);
|
|
||||||
assert(content_type_.empty());
|
|
||||||
|
|
||||||
const char* end = headers + length;
|
|
||||||
while (headers && headers < end) {
|
|
||||||
if (!isspace(headers[0])) {
|
|
||||||
static const char kContentLength[] = "Content-Length:";
|
|
||||||
static const char kContentType[] = "Content-Type:";
|
|
||||||
if ((headers + ARRAYSIZE(kContentLength)) < end &&
|
|
||||||
strncmp(headers, kContentLength,
|
|
||||||
ARRAYSIZE(kContentLength) - 1) == 0) {
|
|
||||||
headers += ARRAYSIZE(kContentLength) - 1;
|
|
||||||
while (headers[0] == ' ')
|
|
||||||
++headers;
|
|
||||||
content_length_ = atoi(headers);
|
|
||||||
} else if ((headers + ARRAYSIZE(kContentType)) < end &&
|
|
||||||
strncmp(headers, kContentType,
|
|
||||||
ARRAYSIZE(kContentType) - 1) == 0) {
|
|
||||||
headers += ARRAYSIZE(kContentType) - 1;
|
|
||||||
while (headers[0] == ' ')
|
|
||||||
++headers;
|
|
||||||
const char* type_end = strstr(headers, "\r\n");
|
|
||||||
if (type_end == NULL)
|
|
||||||
type_end = end;
|
|
||||||
content_type_.assign(headers, type_end);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
++headers;
|
|
||||||
}
|
|
||||||
headers = strstr(headers, "\r\n");
|
|
||||||
if (headers)
|
|
||||||
headers += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !content_type_.empty() && content_length_ != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// ListeningSocket
|
|
||||||
//
|
|
||||||
|
|
||||||
bool ListeningSocket::Listen(unsigned short port) {
|
|
||||||
assert(valid());
|
|
||||||
int enabled = 1;
|
|
||||||
setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
|
|
||||||
reinterpret_cast<const char*>(&enabled), sizeof(enabled));
|
|
||||||
struct sockaddr_in addr = {0};
|
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
||||||
addr.sin_port = htons(port);
|
|
||||||
if (bind(socket_, reinterpret_cast<const sockaddr*>(&addr),
|
|
||||||
sizeof(addr)) == SOCKET_ERROR) {
|
|
||||||
printf("bind failed\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return listen(socket_, 5) != SOCKET_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataSocket* ListeningSocket::Accept() const {
|
|
||||||
assert(valid());
|
|
||||||
struct sockaddr_in addr = {0};
|
|
||||||
socklen_t size = sizeof(addr);
|
|
||||||
int client = accept(socket_, reinterpret_cast<sockaddr*>(&addr), &size);
|
|
||||||
if (client == INVALID_SOCKET)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return new DataSocket(client);
|
|
||||||
}
|
|
||||||
|
|
@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_SERVER_DATA_SOCKET_H_
|
|
||||||
#define PEERCONNECTION_SAMPLES_SERVER_DATA_SOCKET_H_
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <winsock2.h>
|
|
||||||
typedef int socklen_t;
|
|
||||||
#else
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#define closesocket close
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifndef SOCKET_ERROR
|
|
||||||
#define SOCKET_ERROR (-1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef INVALID_SOCKET
|
|
||||||
#define INVALID_SOCKET static_cast<int>(~0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class SocketBase {
|
|
||||||
public:
|
|
||||||
SocketBase() : socket_(INVALID_SOCKET) { }
|
|
||||||
explicit SocketBase(int socket) : socket_(socket) { }
|
|
||||||
~SocketBase() { Close(); }
|
|
||||||
|
|
||||||
int socket() const { return socket_; }
|
|
||||||
bool valid() const { return socket_ != INVALID_SOCKET; }
|
|
||||||
|
|
||||||
bool Create();
|
|
||||||
void Close();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int socket_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Represents an HTTP server socket.
|
|
||||||
class DataSocket : public SocketBase {
|
|
||||||
public:
|
|
||||||
enum RequestMethod {
|
|
||||||
INVALID,
|
|
||||||
GET,
|
|
||||||
POST,
|
|
||||||
OPTIONS,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit DataSocket(int socket)
|
|
||||||
: SocketBase(socket),
|
|
||||||
method_(INVALID),
|
|
||||||
content_length_(0) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~DataSocket() {
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char kCrossOriginAllowHeaders[];
|
|
||||||
|
|
||||||
bool headers_received() const { return method_ != INVALID; }
|
|
||||||
|
|
||||||
RequestMethod method() const { return method_; }
|
|
||||||
|
|
||||||
const std::string& request_path() const { return request_path_; }
|
|
||||||
std::string request_arguments() const;
|
|
||||||
|
|
||||||
const std::string& data() const { return data_; }
|
|
||||||
|
|
||||||
const std::string& content_type() const { return content_type_; }
|
|
||||||
|
|
||||||
size_t content_length() const { return content_length_; }
|
|
||||||
|
|
||||||
bool request_received() const {
|
|
||||||
return headers_received() && (method_ != POST || data_received());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool data_received() const {
|
|
||||||
return method_ != POST || data_.length() >= content_length_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks if the request path (minus arguments) matches a given path.
|
|
||||||
bool PathEquals(const char* path) const;
|
|
||||||
|
|
||||||
// Called when we have received some data from clients.
|
|
||||||
// Returns false if an error occurred.
|
|
||||||
bool OnDataAvailable(bool* close_socket);
|
|
||||||
|
|
||||||
// Send a raw buffer of bytes.
|
|
||||||
bool Send(const std::string& data) const;
|
|
||||||
|
|
||||||
// Send an HTTP response. The |status| should start with a valid HTTP
|
|
||||||
// response code, followed by a string. E.g. "200 OK".
|
|
||||||
// If |connection_close| is set to true, an extra "Connection: close" HTTP
|
|
||||||
// header will be included. |content_type| is the mime content type, not
|
|
||||||
// including the "Content-Type: " string.
|
|
||||||
// |extra_headers| should be either empty or a list of headers where each
|
|
||||||
// header terminates with "\r\n".
|
|
||||||
// |data| is the body of the message. It's length will be specified via
|
|
||||||
// a "Content-Length" header.
|
|
||||||
bool Send(const std::string& status, bool connection_close,
|
|
||||||
const std::string& content_type,
|
|
||||||
const std::string& extra_headers, const std::string& data) const;
|
|
||||||
|
|
||||||
// Clears all held state and prepares the socket for receiving a new request.
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// A fairly relaxed HTTP header parser. Parses the method, path and
|
|
||||||
// content length (POST only) of a request.
|
|
||||||
// Returns true if a valid request was received and no errors occurred.
|
|
||||||
bool ParseHeaders();
|
|
||||||
|
|
||||||
// Figures out whether the request is a GET or POST and what path is
|
|
||||||
// being requested.
|
|
||||||
bool ParseMethodAndPath(const char* begin, size_t len);
|
|
||||||
|
|
||||||
// Determines the length of the body and it's mime type.
|
|
||||||
bool ParseContentLengthAndType(const char* headers, size_t length);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
RequestMethod method_;
|
|
||||||
size_t content_length_;
|
|
||||||
std::string content_type_;
|
|
||||||
std::string request_path_;
|
|
||||||
std::string request_headers_;
|
|
||||||
std::string data_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// The server socket. Accepts connections and generates DataSocket instances
|
|
||||||
// for each new connection.
|
|
||||||
class ListeningSocket : public SocketBase {
|
|
||||||
public:
|
|
||||||
ListeningSocket() {}
|
|
||||||
|
|
||||||
bool Listen(unsigned short port);
|
|
||||||
DataSocket* Accept() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_SERVER_DATA_SOCKET_H_
|
|
@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/server/data_socket.h"
|
|
||||||
#include "peerconnection/samples/server/peer_channel.h"
|
|
||||||
#include "peerconnection/samples/server/utils.h"
|
|
||||||
|
|
||||||
static const size_t kMaxConnections = (FD_SETSIZE - 2);
|
|
||||||
|
|
||||||
void HandleBrowserRequest(DataSocket* ds, bool* quit) {
|
|
||||||
assert(ds && ds->valid());
|
|
||||||
assert(quit);
|
|
||||||
|
|
||||||
const std::string& path = ds->request_path();
|
|
||||||
|
|
||||||
*quit = (path.compare("/quit") == 0);
|
|
||||||
|
|
||||||
if (*quit) {
|
|
||||||
ds->Send("200 OK", true, "text/html", "",
|
|
||||||
"<html><body>Quitting...</body></html>");
|
|
||||||
} else if (ds->method() == DataSocket::OPTIONS) {
|
|
||||||
// We'll get this when a browsers do cross-resource-sharing requests.
|
|
||||||
// The headers to allow cross-origin script support will be set inside
|
|
||||||
// Send.
|
|
||||||
ds->Send("200 OK", true, "", "", "");
|
|
||||||
} else {
|
|
||||||
// Here we could write some useful output back to the browser depending on
|
|
||||||
// the path.
|
|
||||||
printf("Received an invalid request: %s\n", ds->request_path().c_str());
|
|
||||||
ds->Send("500 Sorry", true, "text/html", "",
|
|
||||||
"<html><body>Sorry, not yet implemented</body></html>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
// TODO(tommi): make configurable.
|
|
||||||
static const unsigned short port = 8888;
|
|
||||||
|
|
||||||
ListeningSocket listener;
|
|
||||||
if (!listener.Create()) {
|
|
||||||
printf("Failed to create server socket\n");
|
|
||||||
return -1;
|
|
||||||
} else if (!listener.Listen(port)) {
|
|
||||||
printf("Failed to listen on server socket\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Server listening on port %i\n", port);
|
|
||||||
|
|
||||||
PeerChannel clients;
|
|
||||||
typedef std::vector<DataSocket*> SocketArray;
|
|
||||||
SocketArray sockets;
|
|
||||||
bool quit = false;
|
|
||||||
while (!quit) {
|
|
||||||
fd_set socket_set;
|
|
||||||
FD_ZERO(&socket_set);
|
|
||||||
if (listener.valid())
|
|
||||||
FD_SET(listener.socket(), &socket_set);
|
|
||||||
|
|
||||||
for (SocketArray::iterator i = sockets.begin(); i != sockets.end(); ++i)
|
|
||||||
FD_SET((*i)->socket(), &socket_set);
|
|
||||||
|
|
||||||
struct timeval timeout = { 10, 0 };
|
|
||||||
if (select(FD_SETSIZE, &socket_set, NULL, NULL, &timeout) == SOCKET_ERROR) {
|
|
||||||
printf("select failed\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (SocketArray::iterator i = sockets.begin(); i != sockets.end(); ++i) {
|
|
||||||
DataSocket* s = *i;
|
|
||||||
bool socket_done = true;
|
|
||||||
if (FD_ISSET(s->socket(), &socket_set)) {
|
|
||||||
if (s->OnDataAvailable(&socket_done) && s->request_received()) {
|
|
||||||
ChannelMember* member = clients.Lookup(s);
|
|
||||||
if (member || PeerChannel::IsPeerConnection(s)) {
|
|
||||||
if (!member) {
|
|
||||||
if (s->PathEquals("/sign_in")) {
|
|
||||||
clients.AddMember(s);
|
|
||||||
} else {
|
|
||||||
printf("No member found for: %s\n",
|
|
||||||
s->request_path().c_str());
|
|
||||||
s->Send("500 Error", true, "text/plain", "",
|
|
||||||
"Peer most likely gone.");
|
|
||||||
}
|
|
||||||
} else if (member->is_wait_request(s)) {
|
|
||||||
// no need to do anything.
|
|
||||||
socket_done = false;
|
|
||||||
} else {
|
|
||||||
ChannelMember* target = clients.IsTargetedRequest(s);
|
|
||||||
if (target) {
|
|
||||||
member->ForwardRequestToPeer(s, target);
|
|
||||||
} else if (s->PathEquals("/sign_out")) {
|
|
||||||
s->Send("200 OK", true, "text/plain", "", "");
|
|
||||||
} else {
|
|
||||||
printf("Couldn't find target for request: %s\n",
|
|
||||||
s->request_path().c_str());
|
|
||||||
s->Send("500 Error", true, "text/plain", "",
|
|
||||||
"Peer most likely gone.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
HandleBrowserRequest(s, &quit);
|
|
||||||
if (quit) {
|
|
||||||
printf("Quitting...\n");
|
|
||||||
FD_CLR(listener.socket(), &socket_set);
|
|
||||||
listener.Close();
|
|
||||||
clients.CloseAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
socket_done = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (socket_done) {
|
|
||||||
printf("Disconnecting socket\n");
|
|
||||||
clients.OnClosing(s);
|
|
||||||
assert(s->valid()); // Close must not have been called yet.
|
|
||||||
FD_CLR(s->socket(), &socket_set);
|
|
||||||
delete (*i);
|
|
||||||
i = sockets.erase(i);
|
|
||||||
if (i == sockets.end())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clients.CheckForTimeout();
|
|
||||||
|
|
||||||
if (FD_ISSET(listener.socket(), &socket_set)) {
|
|
||||||
DataSocket* s = listener.Accept();
|
|
||||||
if (sockets.size() >= kMaxConnections) {
|
|
||||||
delete s; // sorry, that's all we can take.
|
|
||||||
printf("Connection limit reached\n");
|
|
||||||
} else {
|
|
||||||
sockets.push_back(s);
|
|
||||||
printf("New connection...\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (SocketArray::iterator i = sockets.begin(); i != sockets.end(); ++i)
|
|
||||||
delete (*i);
|
|
||||||
sockets.clear();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,352 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "peerconnection/samples/server/peer_channel.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "peerconnection/samples/server/data_socket.h"
|
|
||||||
#include "peerconnection/samples/server/utils.h"
|
|
||||||
|
|
||||||
// Set to the peer id of the originator when messages are being
|
|
||||||
// exchanged between peers, but set to the id of the receiving peer
|
|
||||||
// itself when notifications are sent from the server about the state
|
|
||||||
// of other peers.
|
|
||||||
//
|
|
||||||
// WORKAROUND: Since support for CORS varies greatly from one browser to the
|
|
||||||
// next, we don't use a custom name for our peer-id header (originally it was
|
|
||||||
// "X-Peer-Id: "). Instead, we use a "simple header", "Pragma" which should
|
|
||||||
// always be exposed to CORS requests. There is a special CORS header devoted
|
|
||||||
// to exposing proprietary headers (Access-Control-Expose-Headers), however
|
|
||||||
// at this point it is not working correctly in some popular browsers.
|
|
||||||
static const char kPeerIdHeader[] = "Pragma: ";
|
|
||||||
|
|
||||||
static const char* kRequestPaths[] = {
|
|
||||||
"/wait", "/sign_out", "/message",
|
|
||||||
};
|
|
||||||
|
|
||||||
enum RequestPathIndex {
|
|
||||||
kWait,
|
|
||||||
kSignOut,
|
|
||||||
kMessage,
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// ChannelMember
|
|
||||||
//
|
|
||||||
|
|
||||||
int ChannelMember::s_member_id_ = 0;
|
|
||||||
|
|
||||||
ChannelMember::ChannelMember(DataSocket* socket)
|
|
||||||
: waiting_socket_(NULL), id_(++s_member_id_),
|
|
||||||
connected_(true), timestamp_(time(NULL)) {
|
|
||||||
assert(socket);
|
|
||||||
assert(socket->method() == DataSocket::GET);
|
|
||||||
assert(socket->PathEquals("/sign_in"));
|
|
||||||
name_ = socket->request_arguments(); // TODO(tommi): urldecode
|
|
||||||
if (!name_.length())
|
|
||||||
name_ = "peer_" + int2str(id_);
|
|
||||||
std::replace(name_.begin(), name_.end(), ',', '_');
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelMember::~ChannelMember() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChannelMember::is_wait_request(DataSocket* ds) const {
|
|
||||||
return ds && ds->PathEquals(kRequestPaths[kWait]);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChannelMember::TimedOut() {
|
|
||||||
return waiting_socket_ == NULL && (time(NULL) - timestamp_) > 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ChannelMember::GetPeerIdHeader() const {
|
|
||||||
std::string ret(kPeerIdHeader + int2str(id_) + "\r\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChannelMember::NotifyOfOtherMember(const ChannelMember& other) {
|
|
||||||
assert(&other != this);
|
|
||||||
QueueResponse("200 OK", "text/plain", GetPeerIdHeader(),
|
|
||||||
other.GetEntry());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a string in the form "name,id\n".
|
|
||||||
std::string ChannelMember::GetEntry() const {
|
|
||||||
char entry[1024] = {0};
|
|
||||||
sprintf(entry, "%s,%i,%i\n", name_.c_str(), id_, connected_); // NOLINT
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelMember::ForwardRequestToPeer(DataSocket* ds, ChannelMember* peer) {
|
|
||||||
assert(peer);
|
|
||||||
assert(ds);
|
|
||||||
|
|
||||||
std::string extra_headers(GetPeerIdHeader());
|
|
||||||
|
|
||||||
if (peer == this) {
|
|
||||||
ds->Send("200 OK", true, ds->content_type(), extra_headers,
|
|
||||||
ds->data());
|
|
||||||
} else {
|
|
||||||
printf("Client %s sending to %s\n",
|
|
||||||
name_.c_str(), peer->name().c_str());
|
|
||||||
peer->QueueResponse("200 OK", ds->content_type(), extra_headers,
|
|
||||||
ds->data());
|
|
||||||
ds->Send("200 OK", true, "text/plain", "", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelMember::OnClosing(DataSocket* ds) {
|
|
||||||
if (ds == waiting_socket_) {
|
|
||||||
waiting_socket_ = NULL;
|
|
||||||
timestamp_ = time(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelMember::QueueResponse(const std::string& status,
|
|
||||||
const std::string& content_type,
|
|
||||||
const std::string& extra_headers,
|
|
||||||
const std::string& data) {
|
|
||||||
if (waiting_socket_) {
|
|
||||||
assert(queue_.size() == 0);
|
|
||||||
assert(waiting_socket_->method() == DataSocket::GET);
|
|
||||||
bool ok = waiting_socket_->Send(status, true, content_type, extra_headers,
|
|
||||||
data);
|
|
||||||
if (!ok) {
|
|
||||||
printf("Failed to deliver data to waiting socket\n");
|
|
||||||
}
|
|
||||||
waiting_socket_ = NULL;
|
|
||||||
timestamp_ = time(NULL);
|
|
||||||
} else {
|
|
||||||
QueuedResponse qr;
|
|
||||||
qr.status = status;
|
|
||||||
qr.content_type = content_type;
|
|
||||||
qr.extra_headers = extra_headers;
|
|
||||||
qr.data = data;
|
|
||||||
queue_.push(qr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelMember::SetWaitingSocket(DataSocket* ds) {
|
|
||||||
assert(ds->method() == DataSocket::GET);
|
|
||||||
if (ds && !queue_.empty()) {
|
|
||||||
assert(waiting_socket_ == NULL);
|
|
||||||
const QueuedResponse& response = queue_.back();
|
|
||||||
ds->Send(response.status, true, response.content_type,
|
|
||||||
response.extra_headers, response.data);
|
|
||||||
queue_.pop();
|
|
||||||
} else {
|
|
||||||
waiting_socket_ = ds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// PeerChannel
|
|
||||||
//
|
|
||||||
|
|
||||||
// static
|
|
||||||
bool PeerChannel::IsPeerConnection(const DataSocket* ds) {
|
|
||||||
assert(ds);
|
|
||||||
return (ds->method() == DataSocket::POST && ds->content_length() > 0) ||
|
|
||||||
(ds->method() == DataSocket::GET && ds->PathEquals("/sign_in"));
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelMember* PeerChannel::Lookup(DataSocket* ds) const {
|
|
||||||
assert(ds);
|
|
||||||
|
|
||||||
if (ds->method() != DataSocket::GET && ds->method() != DataSocket::POST)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
size_t i = 0;
|
|
||||||
for (; i < ARRAYSIZE(kRequestPaths); ++i) {
|
|
||||||
if (ds->PathEquals(kRequestPaths[i]))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == ARRAYSIZE(kRequestPaths))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
std::string args(ds->request_arguments());
|
|
||||||
static const char kPeerId[] = "peer_id=";
|
|
||||||
size_t found = args.find(kPeerId);
|
|
||||||
if (found == std::string::npos)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
int id = atoi(&args[found + ARRAYSIZE(kPeerId) - 1]);
|
|
||||||
Members::const_iterator iter = members_.begin();
|
|
||||||
for (; iter != members_.end(); ++iter) {
|
|
||||||
if (id == (*iter)->id()) {
|
|
||||||
if (i == kWait)
|
|
||||||
(*iter)->SetWaitingSocket(ds);
|
|
||||||
if (i == kSignOut)
|
|
||||||
(*iter)->set_disconnected();
|
|
||||||
return *iter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelMember* PeerChannel::IsTargetedRequest(const DataSocket* ds) const {
|
|
||||||
assert(ds);
|
|
||||||
// Regardless of GET or POST, we look for the peer_id parameter
|
|
||||||
// only in the request_path.
|
|
||||||
const std::string& path = ds->request_path();
|
|
||||||
size_t args = path.find('?');
|
|
||||||
if (args == std::string::npos)
|
|
||||||
return NULL;
|
|
||||||
size_t found;
|
|
||||||
const char kTargetPeerIdParam[] = "to=";
|
|
||||||
do {
|
|
||||||
found = path.find(kTargetPeerIdParam, args);
|
|
||||||
if (found == std::string::npos)
|
|
||||||
return NULL;
|
|
||||||
if (found == (args + 1) || path[found - 1] == '&') {
|
|
||||||
found += ARRAYSIZE(kTargetPeerIdParam) - 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
args = found + ARRAYSIZE(kTargetPeerIdParam) - 1;
|
|
||||||
} while (true);
|
|
||||||
int id = atoi(&path[found]);
|
|
||||||
Members::const_iterator i = members_.begin();
|
|
||||||
for (; i != members_.end(); ++i) {
|
|
||||||
if ((*i)->id() == id) {
|
|
||||||
return *i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerChannel::AddMember(DataSocket* ds) {
|
|
||||||
assert(IsPeerConnection(ds));
|
|
||||||
ChannelMember* new_guy = new ChannelMember(ds);
|
|
||||||
Members failures;
|
|
||||||
BroadcastChangedState(*new_guy, &failures);
|
|
||||||
HandleDeliveryFailures(&failures);
|
|
||||||
members_.push_back(new_guy);
|
|
||||||
|
|
||||||
printf("New member added (total=%s): %s\n",
|
|
||||||
size_t2str(members_.size()).c_str(), new_guy->name().c_str());
|
|
||||||
|
|
||||||
// Let the newly connected peer know about other members of the channel.
|
|
||||||
std::string content_type;
|
|
||||||
std::string response = BuildResponseForNewMember(*new_guy, &content_type);
|
|
||||||
ds->Send("200 Added", true, content_type, new_guy->GetPeerIdHeader(),
|
|
||||||
response);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerChannel::CloseAll() {
|
|
||||||
Members::const_iterator i = members_.begin();
|
|
||||||
for (; i != members_.end(); ++i) {
|
|
||||||
(*i)->QueueResponse("200 OK", "text/plain", "", "Server shutting down");
|
|
||||||
}
|
|
||||||
DeleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerChannel::OnClosing(DataSocket* ds) {
|
|
||||||
for (Members::iterator i = members_.begin(); i != members_.end(); ++i) {
|
|
||||||
ChannelMember* m = (*i);
|
|
||||||
m->OnClosing(ds);
|
|
||||||
if (!m->connected()) {
|
|
||||||
i = members_.erase(i);
|
|
||||||
Members failures;
|
|
||||||
BroadcastChangedState(*m, &failures);
|
|
||||||
HandleDeliveryFailures(&failures);
|
|
||||||
delete m;
|
|
||||||
if (i == members_.end())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("Total connected: %s\n", size_t2str(members_.size()).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerChannel::CheckForTimeout() {
|
|
||||||
for (Members::iterator i = members_.begin(); i != members_.end(); ++i) {
|
|
||||||
ChannelMember* m = (*i);
|
|
||||||
if (m->TimedOut()) {
|
|
||||||
printf("Timeout: %s\n", m->name().c_str());
|
|
||||||
m->set_disconnected();
|
|
||||||
i = members_.erase(i);
|
|
||||||
Members failures;
|
|
||||||
BroadcastChangedState(*m, &failures);
|
|
||||||
HandleDeliveryFailures(&failures);
|
|
||||||
delete m;
|
|
||||||
if (i == members_.end())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerChannel::DeleteAll() {
|
|
||||||
for (Members::iterator i = members_.begin(); i != members_.end(); ++i)
|
|
||||||
delete (*i);
|
|
||||||
members_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerChannel::BroadcastChangedState(const ChannelMember& member,
|
|
||||||
Members* delivery_failures) {
|
|
||||||
// This function should be called prior to DataSocket::Close().
|
|
||||||
assert(delivery_failures);
|
|
||||||
|
|
||||||
if (!member.connected()) {
|
|
||||||
printf("Member disconnected: %s\n", member.name().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
Members::iterator i = members_.begin();
|
|
||||||
for (; i != members_.end(); ++i) {
|
|
||||||
if (&member != (*i)) {
|
|
||||||
if (!(*i)->NotifyOfOtherMember(member)) {
|
|
||||||
(*i)->set_disconnected();
|
|
||||||
delivery_failures->push_back(*i);
|
|
||||||
i = members_.erase(i);
|
|
||||||
if (i == members_.end())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerChannel::HandleDeliveryFailures(Members* failures) {
|
|
||||||
assert(failures);
|
|
||||||
|
|
||||||
while (!failures->empty()) {
|
|
||||||
Members::iterator i = failures->begin();
|
|
||||||
ChannelMember* member = *i;
|
|
||||||
assert(!member->connected());
|
|
||||||
failures->erase(i);
|
|
||||||
BroadcastChangedState(*member, failures);
|
|
||||||
delete member;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builds a simple list of "name,id\n" entries for each member.
|
|
||||||
std::string PeerChannel::BuildResponseForNewMember(const ChannelMember& member,
|
|
||||||
std::string* content_type) {
|
|
||||||
assert(content_type);
|
|
||||||
|
|
||||||
*content_type = "text/plain";
|
|
||||||
// The peer itself will always be the first entry.
|
|
||||||
std::string response(member.GetEntry());
|
|
||||||
for (Members::iterator i = members_.begin(); i != members_.end(); ++i) {
|
|
||||||
if (member.id() != (*i)->id()) {
|
|
||||||
assert((*i)->connected());
|
|
||||||
response += (*i)->GetEntry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_SERVER_PEER_CHANNEL_H_
|
|
||||||
#define PEERCONNECTION_SAMPLES_SERVER_PEER_CHANNEL_H_
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <queue>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class DataSocket;
|
|
||||||
|
|
||||||
// Represents a single peer connected to the server.
|
|
||||||
class ChannelMember {
|
|
||||||
public:
|
|
||||||
explicit ChannelMember(DataSocket* socket);
|
|
||||||
~ChannelMember();
|
|
||||||
|
|
||||||
bool connected() const { return connected_; }
|
|
||||||
int id() const { return id_; }
|
|
||||||
void set_disconnected() { connected_ = false; }
|
|
||||||
bool is_wait_request(DataSocket* ds) const;
|
|
||||||
const std::string& name() const { return name_; }
|
|
||||||
|
|
||||||
bool TimedOut();
|
|
||||||
|
|
||||||
std::string GetPeerIdHeader() const;
|
|
||||||
|
|
||||||
bool NotifyOfOtherMember(const ChannelMember& other);
|
|
||||||
|
|
||||||
// Returns a string in the form "name,id\n".
|
|
||||||
std::string GetEntry() const;
|
|
||||||
|
|
||||||
void ForwardRequestToPeer(DataSocket* ds, ChannelMember* peer);
|
|
||||||
|
|
||||||
void OnClosing(DataSocket* ds);
|
|
||||||
|
|
||||||
void QueueResponse(const std::string& status, const std::string& content_type,
|
|
||||||
const std::string& extra_headers, const std::string& data);
|
|
||||||
|
|
||||||
void SetWaitingSocket(DataSocket* ds);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
struct QueuedResponse {
|
|
||||||
std::string status, content_type, extra_headers, data;
|
|
||||||
};
|
|
||||||
|
|
||||||
DataSocket* waiting_socket_;
|
|
||||||
int id_;
|
|
||||||
bool connected_;
|
|
||||||
time_t timestamp_;
|
|
||||||
std::string name_;
|
|
||||||
std::queue<QueuedResponse> queue_;
|
|
||||||
static int s_member_id_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Manages all currently connected peers.
|
|
||||||
class PeerChannel {
|
|
||||||
public:
|
|
||||||
typedef std::vector<ChannelMember*> Members;
|
|
||||||
|
|
||||||
PeerChannel() {
|
|
||||||
}
|
|
||||||
|
|
||||||
~PeerChannel() {
|
|
||||||
DeleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
const Members& members() const { return members_; }
|
|
||||||
|
|
||||||
// Returns true if the request should be treated as a new ChannelMember
|
|
||||||
// request. Otherwise the request is not peerconnection related.
|
|
||||||
static bool IsPeerConnection(const DataSocket* ds);
|
|
||||||
|
|
||||||
// Finds a connected peer that's associated with the |ds| socket.
|
|
||||||
ChannelMember* Lookup(DataSocket* ds) const;
|
|
||||||
|
|
||||||
// Checks if the request has a "peer_id" parameter and if so, looks up the
|
|
||||||
// peer for which the request is targeted at.
|
|
||||||
ChannelMember* IsTargetedRequest(const DataSocket* ds) const;
|
|
||||||
|
|
||||||
// Adds a new ChannelMember instance to the list of connected peers and
|
|
||||||
// associates it with the socket.
|
|
||||||
bool AddMember(DataSocket* ds);
|
|
||||||
|
|
||||||
// Closes all connections and sends a "shutting down" message to all
|
|
||||||
// connected peers.
|
|
||||||
void CloseAll();
|
|
||||||
|
|
||||||
// Called when a socket was determined to be closing by the peer (or if the
|
|
||||||
// connection went dead).
|
|
||||||
void OnClosing(DataSocket* ds);
|
|
||||||
|
|
||||||
void CheckForTimeout();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void DeleteAll();
|
|
||||||
void BroadcastChangedState(const ChannelMember& member,
|
|
||||||
Members* delivery_failures);
|
|
||||||
void HandleDeliveryFailures(Members* failures);
|
|
||||||
|
|
||||||
// Builds a simple list of "name,id\n" entries for each member.
|
|
||||||
std::string BuildResponseForNewMember(const ChannelMember& member,
|
|
||||||
std::string* content_type);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Members members_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_SERVER_PEER_CHANNEL_H_
|
|
@ -1,228 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>PeerConnection server test page</title>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var request = null;
|
|
||||||
var hangingGet = null;
|
|
||||||
var localName;
|
|
||||||
var server;
|
|
||||||
var my_id = -1;
|
|
||||||
var other_peers = {};
|
|
||||||
var message_counter = 0;
|
|
||||||
|
|
||||||
function trace(txt) {
|
|
||||||
var elem = document.getElementById("debug");
|
|
||||||
elem.innerHTML += txt + "<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleServerNotification(data) {
|
|
||||||
trace("Server notification: " + data);
|
|
||||||
var parsed = data.split(',');
|
|
||||||
if (parseInt(parsed[2]) != 0)
|
|
||||||
other_peers[parseInt(parsed[1])] = parsed[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePeerMessage(peer_id, data) {
|
|
||||||
++message_counter;
|
|
||||||
var str = "Message from '" + other_peers[peer_id] + "' ";
|
|
||||||
str += "<span id='toggle_" + message_counter + "' onclick='toggleMe(this);' ";
|
|
||||||
str += "style='cursor: pointer'>+</span><br>";
|
|
||||||
str += "<blockquote id='msg_" + message_counter + "' style='display:none'>";
|
|
||||||
str += data + "</blockquote>";
|
|
||||||
trace(str);
|
|
||||||
if (document.getElementById("loopback").checked)
|
|
||||||
sendToPeer(peer_id, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetIntHeader(r, name) {
|
|
||||||
var val = r.getResponseHeader(name);
|
|
||||||
return val != null && val.length ? parseInt(val) : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hangingGetCallback() {
|
|
||||||
try {
|
|
||||||
if (hangingGet.readyState != 4)
|
|
||||||
return;
|
|
||||||
if (hangingGet.status != 200) {
|
|
||||||
trace("server error: " + hangingGet.statusText);
|
|
||||||
disconnect();
|
|
||||||
} else {
|
|
||||||
var peer_id = GetIntHeader(hangingGet, "Pragma");
|
|
||||||
if (peer_id == my_id) {
|
|
||||||
handleServerNotification(hangingGet.responseText);
|
|
||||||
} else {
|
|
||||||
handlePeerMessage(peer_id, hangingGet.responseText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hangingGet) {
|
|
||||||
hangingGet.abort();
|
|
||||||
hangingGet = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (my_id != -1)
|
|
||||||
window.setTimeout(startHangingGet, 0);
|
|
||||||
} catch (e) {
|
|
||||||
trace("Hanging get error: " + e.description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function startHangingGet() {
|
|
||||||
try {
|
|
||||||
hangingGet = new XMLHttpRequest();
|
|
||||||
hangingGet.onreadystatechange = hangingGetCallback;
|
|
||||||
hangingGet.ontimeout = onHangingGetTimeout;
|
|
||||||
hangingGet.open("GET", server + "/wait?peer_id=" + my_id, true);
|
|
||||||
hangingGet.send();
|
|
||||||
} catch (e) {
|
|
||||||
trace("error" + e.description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onHangingGetTimeout() {
|
|
||||||
trace("hanging get timeout. issuing again.");
|
|
||||||
hangingGet.abort();
|
|
||||||
hangingGet = null;
|
|
||||||
if (my_id != -1)
|
|
||||||
window.setTimeout(startHangingGet, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function signInCallback() {
|
|
||||||
try {
|
|
||||||
if (request.readyState == 4) {
|
|
||||||
if (request.status == 200) {
|
|
||||||
var peers = request.responseText.split("\n");
|
|
||||||
my_id = parseInt(peers[0].split(',')[1]);
|
|
||||||
trace("My id: " + my_id);
|
|
||||||
for (var i = 1; i < peers.length; ++i) {
|
|
||||||
if (peers[i].length > 0) {
|
|
||||||
trace("Peer " + i + ": " + peers[i]);
|
|
||||||
var parsed = peers[i].split(',');
|
|
||||||
other_peers[parseInt(parsed[1])] = parsed[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
startHangingGet();
|
|
||||||
request = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
trace("error: " + e.description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function signIn() {
|
|
||||||
try {
|
|
||||||
request = new XMLHttpRequest();
|
|
||||||
request.onreadystatechange = signInCallback;
|
|
||||||
request.open("GET", server + "/sign_in?" + localName, true);
|
|
||||||
request.send();
|
|
||||||
} catch (e) {
|
|
||||||
trace("error: " + e.description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendToPeer(peer_id, data) {
|
|
||||||
if (my_id == -1) {
|
|
||||||
alert("Not connected");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (peer_id == my_id) {
|
|
||||||
alert("Can't send a message to oneself :)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var r = new XMLHttpRequest();
|
|
||||||
r.open("POST", server + "/message?peer_id=" + my_id + "&to=" + peer_id,
|
|
||||||
false);
|
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.send(data);
|
|
||||||
r = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function connect() {
|
|
||||||
localName = document.getElementById("local").value.toLowerCase();
|
|
||||||
server = document.getElementById("server").value.toLowerCase();
|
|
||||||
if (localName.length == 0) {
|
|
||||||
alert("I need a name please.");
|
|
||||||
document.getElementById("local").focus();
|
|
||||||
} else {
|
|
||||||
document.getElementById("connect").disabled = true;
|
|
||||||
document.getElementById("disconnect").disabled = false;
|
|
||||||
document.getElementById("send").disabled = false;
|
|
||||||
signIn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function disconnect() {
|
|
||||||
if (request) {
|
|
||||||
request.abort();
|
|
||||||
request = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hangingGet) {
|
|
||||||
hangingGet.abort();
|
|
||||||
hangingGet = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (my_id != -1) {
|
|
||||||
request = new XMLHttpRequest();
|
|
||||||
request.open("GET", server + "/sign_out?peer_id=" + my_id, false);
|
|
||||||
request.send();
|
|
||||||
request = null;
|
|
||||||
my_id = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("connect").disabled = false;
|
|
||||||
document.getElementById("disconnect").disabled = true;
|
|
||||||
document.getElementById("send").disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.onbeforeunload = disconnect;
|
|
||||||
|
|
||||||
function send() {
|
|
||||||
var text = document.getElementById("message").value;
|
|
||||||
var peer_id = parseInt(document.getElementById("peer_id").value);
|
|
||||||
if (!text.length || peer_id == 0) {
|
|
||||||
alert("No text supplied or invalid peer id");
|
|
||||||
} else {
|
|
||||||
sendToPeer(peer_id, text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleMe(obj) {
|
|
||||||
var id = obj.id.replace("toggle", "msg");
|
|
||||||
var t = document.getElementById(id);
|
|
||||||
if (obj.innerText == "+") {
|
|
||||||
obj.innerText = "-";
|
|
||||||
t.style.display = "block";
|
|
||||||
} else {
|
|
||||||
obj.innerText = "+";
|
|
||||||
t.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Server: <input type="text" id="server" value="http://localhost:8888" /><br>
|
|
||||||
<input type="checkbox" id="loopback" checked="checked"/> Loopback (just send
|
|
||||||
received messages right back)<br>
|
|
||||||
Your name: <input type="text" id="local" value="my_name"/>
|
|
||||||
<button id="connect" onclick="connect();">Connect</button>
|
|
||||||
<button disabled="true" id="disconnect"
|
|
||||||
onclick="disconnect();">Disconnect</button>
|
|
||||||
<br>
|
|
||||||
<table><tr><td>
|
|
||||||
Target peer id: <input type="text" id="peer_id" size="3"/></td><td>
|
|
||||||
Message: <input type="text" id="message"/></td><td>
|
|
||||||
<button disabled="true" id="send" onclick="send();">Send</button>
|
|
||||||
</td></tr></table>
|
|
||||||
<button onclick="document.getElementById('debug').innerHTML='';">
|
|
||||||
Clear log</button>
|
|
||||||
|
|
||||||
<pre id="debug">
|
|
||||||
</pre>
|
|
||||||
<br><hr>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "peerconnection/samples/server/utils.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
std::string int2str(int i) {
|
|
||||||
char buffer[11] = {0};
|
|
||||||
sprintf(buffer, "%d", i); // NOLINT
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string size_t2str(size_t i) {
|
|
||||||
char buffer[32] = {0};
|
|
||||||
#ifdef WIN32
|
|
||||||
// %zu isn't supported on Windows.
|
|
||||||
sprintf(buffer, "%Iu", i); // NOLINT
|
|
||||||
#else
|
|
||||||
sprintf(buffer, "%zu", i); // NOLINT
|
|
||||||
#endif
|
|
||||||
return buffer;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_SERVER_UTILS_H_
|
|
||||||
#define PEERCONNECTION_SAMPLES_SERVER_UTILS_H_
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef assert
|
|
||||||
#ifndef WIN32
|
|
||||||
#include <assert.h>
|
|
||||||
#else
|
|
||||||
#ifndef NDEBUG
|
|
||||||
#define assert(expr) ((void)((expr) ? true : __debugbreak()))
|
|
||||||
#else
|
|
||||||
#define assert(expr) ((void)0)
|
|
||||||
#endif // NDEBUG
|
|
||||||
#endif // WIN32
|
|
||||||
#endif // assert
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifndef ARRAYSIZE
|
|
||||||
#define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0]))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string int2str(int i);
|
|
||||||
std::string size_t2str(size_t i);
|
|
||||||
|
|
||||||
#endif // PEERCONNECTION_SAMPLES_SERVER_UTILS_H_
|
|
@ -1,5 +0,0 @@
|
|||||||
henrike@webrtc.org
|
|
||||||
mallinath@webrtc.org
|
|
||||||
perkj@webrtc.org
|
|
||||||
wu@webrtc.org
|
|
||||||
tommi@webrtc.org
|
|
@ -1,696 +0,0 @@
|
|||||||
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
|
||||||
# found in the LICENSE file.
|
|
||||||
|
|
||||||
{
|
|
||||||
'variables': {
|
|
||||||
'no_libjingle_logging%': 0,
|
|
||||||
'libjingle_orig': '../../third_party/libjingle',
|
|
||||||
'libjingle_mods': '../../third_party_mods/libjingle',
|
|
||||||
'conditions': [
|
|
||||||
['inside_chromium_build==1', {
|
|
||||||
'overrides': '<(libjingle_orig)/overrides',
|
|
||||||
},{
|
|
||||||
'overrides': '<(libjingle_orig)/source',
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
'jsoncpp': '../../third_party/jsoncpp',
|
|
||||||
},
|
|
||||||
'target_defaults': {
|
|
||||||
'defines': [
|
|
||||||
'FEATURE_ENABLE_SSL',
|
|
||||||
'FEATURE_ENABLE_VOICEMAIL', # TODO(ncarter): Do we really need this?
|
|
||||||
'_USE_32BIT_TIME_T',
|
|
||||||
'SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS',
|
|
||||||
'EXPAT_RELATIVE_PATH',
|
|
||||||
'JSONCPP_RELATIVE_PATH',
|
|
||||||
'WEBRTC_RELATIVE_PATH',
|
|
||||||
'HAVE_WEBRTC',
|
|
||||||
'HAVE_WEBRTC_VIDEO',
|
|
||||||
'HAVE_WEBRTC_VOICE',
|
|
||||||
],
|
|
||||||
'configurations': {
|
|
||||||
'Debug': {
|
|
||||||
'defines': [
|
|
||||||
# TODO(sergeyu): Fix libjingle to use NDEBUG instead of
|
|
||||||
# _DEBUG and remove this define. See below as well.
|
|
||||||
'_DEBUG',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'dependencies': [
|
|
||||||
'<(libjingle_orig)/../expat/expat.gyp:expat',
|
|
||||||
],
|
|
||||||
'export_dependent_settings': [
|
|
||||||
'<(libjingle_orig)/../expat/expat.gyp:expat',
|
|
||||||
],
|
|
||||||
'include_dirs': [
|
|
||||||
'../../third_party/libyuv/include/',
|
|
||||||
],
|
|
||||||
'direct_dependent_settings': {
|
|
||||||
'defines': [
|
|
||||||
'FEATURE_ENABLE_SSL',
|
|
||||||
'FEATURE_ENABLE_VOICEMAIL',
|
|
||||||
'EXPAT_RELATIVE_PATH',
|
|
||||||
'WEBRTC_RELATIVE_PATH',
|
|
||||||
],
|
|
||||||
'conditions': [
|
|
||||||
['OS=="win"', {
|
|
||||||
'link_settings': {
|
|
||||||
'libraries': [
|
|
||||||
'-lsecur32.lib',
|
|
||||||
'-lcrypt32.lib',
|
|
||||||
'-liphlpapi.lib',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
['OS=="win"', {
|
|
||||||
'include_dirs': [
|
|
||||||
'../third_party/platformsdk_win7/files/Include',
|
|
||||||
],
|
|
||||||
'defines': [
|
|
||||||
'_CRT_SECURE_NO_WARNINGS', # Suppres warnings about _vsnprinf
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="linux"', {
|
|
||||||
'defines': [
|
|
||||||
'LINUX',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="mac"', {
|
|
||||||
'defines': [
|
|
||||||
'OSX',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['os_posix == 1', {
|
|
||||||
'defines': [
|
|
||||||
'POSIX',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="openbsd" or OS=="freebsd"', {
|
|
||||||
'defines': [
|
|
||||||
'BSD',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['no_libjingle_logging==1', {
|
|
||||||
'defines': [
|
|
||||||
'NO_LIBJINGLE_LOGGING',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'all_dependent_settings': {
|
|
||||||
'configurations': {
|
|
||||||
'Debug': {
|
|
||||||
'defines': [
|
|
||||||
# TODO(sergeyu): Fix libjingle to use NDEBUG instead of
|
|
||||||
# _DEBUG and remove this define. See above as well.
|
|
||||||
'_DEBUG',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'conditions': [
|
|
||||||
['inside_chromium_build==1', {
|
|
||||||
'defines': [
|
|
||||||
'NO_SOUND_SYSTEM',
|
|
||||||
],
|
|
||||||
'include_dirs': [
|
|
||||||
'<(overrides)',
|
|
||||||
'<(libjingle_orig)/source',
|
|
||||||
'../..', # the third_party folder for webrtc includes
|
|
||||||
'../../third_party/expat/files',
|
|
||||||
],
|
|
||||||
'direct_dependent_settings': {
|
|
||||||
'defines': [
|
|
||||||
'NO_SOUND_SYSTEM',
|
|
||||||
],
|
|
||||||
'include_dirs': [
|
|
||||||
'<(overrides)',
|
|
||||||
'<(libjingle_orig)/source',
|
|
||||||
'../../third_party/expat/files'
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'dependencies': [
|
|
||||||
'../../base/base.gyp:base',
|
|
||||||
'../../net/net.gyp:net',
|
|
||||||
],
|
|
||||||
},{
|
|
||||||
'include_dirs': [
|
|
||||||
# the third_party folder for webrtc/ includes (non-chromium).
|
|
||||||
'../../src',
|
|
||||||
'<(libjingle_orig)/source',
|
|
||||||
'../../third_party/expat/files',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="win"', {
|
|
||||||
'include_dirs': [
|
|
||||||
'../third_party/platformsdk_win7/files/Include',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="linux"', {
|
|
||||||
'defines': [
|
|
||||||
'LINUX',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="mac"', {
|
|
||||||
'defines': [
|
|
||||||
'OSX',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['os_posix == 1', {
|
|
||||||
'defines': [
|
|
||||||
'POSIX',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="openbsd" or OS=="freebsd"', {
|
|
||||||
'defines': [
|
|
||||||
'BSD',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'targets': [
|
|
||||||
#TODO(ronghuawu): move jsoncpp target to its own gyp
|
|
||||||
{
|
|
||||||
'target_name': 'jsoncpp',
|
|
||||||
'type': '<(library)',
|
|
||||||
'defines': [
|
|
||||||
'JSON_USE_EXCEPTION=0',
|
|
||||||
],
|
|
||||||
'sources': [
|
|
||||||
'<(jsoncpp)/include/json/assertions.h',
|
|
||||||
'<(jsoncpp)/include/json/autolink.h',
|
|
||||||
'<(jsoncpp)/include/json/config.h',
|
|
||||||
'<(jsoncpp)/include/json/features.h',
|
|
||||||
'<(jsoncpp)/include/json/forwards.h',
|
|
||||||
'<(jsoncpp)/include/json/json.h',
|
|
||||||
'<(jsoncpp)/include/json/reader.h',
|
|
||||||
'<(jsoncpp)/include/json/value.h',
|
|
||||||
'<(jsoncpp)/include/json/writer.h',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_batchallocator.h',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_internalarray.inl',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_internalmap.inl',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_reader.cpp',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_tool.h',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_value.cpp',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_valueiterator.inl',
|
|
||||||
'<(jsoncpp)/src/lib_json/json_writer.cpp',
|
|
||||||
],
|
|
||||||
'include_dirs': [
|
|
||||||
'<(jsoncpp)/include/',
|
|
||||||
],
|
|
||||||
'direct_dependent_settings': {
|
|
||||||
'include_dirs': [
|
|
||||||
'<(jsoncpp)/include/',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'target_name': 'libjingle',
|
|
||||||
'type': 'static_library',
|
|
||||||
'sources': [
|
|
||||||
'<(overrides)/talk/base/basictypes.h',
|
|
||||||
'<(overrides)/talk/base/constructormagic.h',
|
|
||||||
|
|
||||||
# Need to override logging.h because we need
|
|
||||||
# SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS to work.
|
|
||||||
# TODO(sergeyu): push SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS to
|
|
||||||
# libjingle and remove this override.
|
|
||||||
'<(overrides)/talk/base/logging.h',
|
|
||||||
|
|
||||||
'<(overrides)/talk/base/scoped_ptr.h',
|
|
||||||
|
|
||||||
# Libjingle's QName is not threadsafe, so we need to use our own version
|
|
||||||
# here.
|
|
||||||
# TODO(sergeyu): Fix QName in Libjingle.
|
|
||||||
'<(overrides)/talk/xmllite/qname.cc',
|
|
||||||
'<(overrides)/talk/xmllite/qname.h',
|
|
||||||
|
|
||||||
'<(libjingle_orig)/source/talk/base/Equifax_Secure_Global_eBusiness_CA-1.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asyncfile.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asyncfile.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asynchttprequest.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asynchttprequest.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asyncpacketsocket.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asyncsocket.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asyncsocket.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asynctcpsocket.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asynctcpsocket.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asyncudpsocket.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/asyncudpsocket.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/autodetectproxy.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/autodetectproxy.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/base64.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/base64.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/basicdefs.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/basicpacketsocketfactory.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/basicpacketsocketfactory.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/bytebuffer.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/bytebuffer.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/byteorder.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/checks.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/checks.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/common.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/common.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/criticalsection.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/cryptstring.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/diskcache.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/diskcache.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/event.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/event.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/fileutils.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/fileutils.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/firewallsocketserver.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/firewallsocketserver.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/flags.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/flags.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/helpers.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/helpers.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/host.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/host.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httpbase.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httpbase.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httpclient.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httpclient.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httpcommon-inl.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httpcommon.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httpcommon.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httprequest.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/httprequest.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/ipaddress.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/ipaddress.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/json.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/json.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/linked_ptr.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/logging.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/md5.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/md5c.c',
|
|
||||||
'<(libjingle_orig)/source/talk/base/messagehandler.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/messagehandler.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/messagequeue.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/messagequeue.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/nethelpers.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/nethelpers.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/network.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/network.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/pathutils.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/pathutils.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/physicalsocketserver.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/physicalsocketserver.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/proxydetect.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/proxydetect.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/proxyinfo.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/proxyinfo.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/ratetracker.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/ratetracker.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/sec_buffer.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/signalthread.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/signalthread.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/sigslot.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/sigslotrepeater.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socket.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketadapters.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketadapters.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketaddress.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketaddress.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketaddresspair.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketaddresspair.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketfactory.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketpool.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketpool.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketserver.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketstream.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/socketstream.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/ssladapter.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/ssladapter.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/sslsocketfactory.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/sslsocketfactory.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stream.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stream.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stringdigest.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stringdigest.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stringencode.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stringencode.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stringutils.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/stringutils.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/task.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/task.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/taskparent.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/taskparent.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/taskrunner.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/taskrunner.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/thread.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/thread.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/time.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/time.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/urlencode.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/urlencode.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/worker.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/worker.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlbuilder.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlbuilder.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlconstants.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlconstants.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlelement.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlelement.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlnsstack.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlnsstack.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlparser.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlparser.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlprinter.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmllite/xmlprinter.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/asyncsocket.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/constants.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/constants.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/jid.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/jid.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/plainsaslhandler.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/prexmppauth.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/ratelimitmanager.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/ratelimitmanager.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/saslcookiemechanism.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/saslhandler.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/saslmechanism.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/saslmechanism.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/saslplainmechanism.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppclient.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppclient.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppclientsettings.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppengine.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppengineimpl.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppengineimpl.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppengineimpl_iq.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmpplogintask.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmpplogintask.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppstanzaparser.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmppstanzaparser.h',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmpptask.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/xmpp/xmpptask.h',
|
|
||||||
],
|
|
||||||
'conditions': [
|
|
||||||
['inside_chromium_build==0', {
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/sound/automaticallychosensoundsystem.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/platformsoundsystem.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/platformsoundsystem.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/platformsoundsystemfactory.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/platformsoundsystemfactory.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/sounddevicelocator.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/soundinputstreaminterface.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/soundoutputstreaminterface.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/soundsystemfactory.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/soundsysteminterface.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/soundsysteminterface.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/soundsystemproxy.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/soundsystemproxy.h',
|
|
||||||
],
|
|
||||||
'conditions' : [
|
|
||||||
['OS=="linux"', {
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/sound/alsasoundsystem.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/alsasoundsystem.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/alsasymboltable.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/alsasymboltable.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/linuxsoundsystem.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/linuxsoundsystem.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/pulseaudiosoundsystem.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/pulseaudiosoundsystem.h',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/pulseaudiosymboltable.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/sound/pulseaudiosymboltable.h',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="win"', {
|
|
||||||
'sources': [
|
|
||||||
'<(overrides)/talk/base/win32socketinit.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/schanneladapter.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/schanneladapter.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/win32.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/win32.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/win32filesystem.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/win32filesystem.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/win32window.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/win32window.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/win32securityerrors.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/winfirewall.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/winfirewall.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/winping.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/winping.h',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['os_posix == 1', {
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/base/latebindingsymboltable.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/latebindingsymboltable.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/sslstreamadapter.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/sslstreamadapter.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/unixfilesystem.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/unixfilesystem.h',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="linux"', {
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/base/linux.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/linux.h',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="mac"', {
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/base/macconversion.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/macconversion.h',
|
|
||||||
'<(libjingle_orig)/source/talk/base/macutils.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/base/macutils.h',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
'dependencies': [
|
|
||||||
'jsoncpp',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
# This has to be is a separate project due to a bug in MSVS:
|
|
||||||
# https://connect.microsoft.com/VisualStudio/feedback/details/368272/duplicate-cpp-filename-in-c-project-visual-studio-2008
|
|
||||||
# We have two files named "constants.cc" and MSVS doesn't handle this
|
|
||||||
# properly.
|
|
||||||
{
|
|
||||||
'target_name': 'libjingle_p2p',
|
|
||||||
'type': 'static_library',
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/candidate.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/common.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/constants.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/constants.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/p2ptransport.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/p2ptransport.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/p2ptransportchannel.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/p2ptransportchannel.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/port.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/port.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/portallocator.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/pseudotcp.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/pseudotcp.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/rawtransport.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/rawtransport.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/rawtransportchannel.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/rawtransportchannel.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/relayport.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/relayport.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/session.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/session.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessionclient.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessiondescription.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessiondescription.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessionid.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessionmanager.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessionmanager.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessionmessages.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/sessionmessages.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/parsing.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/parsing.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/stun.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/stun.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/stunport.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/stunport.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/stunrequest.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/stunrequest.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/tcpport.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/tcpport.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/transport.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/transport.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/transportchannel.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/transportchannel.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/transportchannelimpl.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/transportchannelproxy.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/transportchannelproxy.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/udpport.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/base/udpport.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/basicportallocator.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/basicportallocator.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/httpportallocator.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/httpportallocator.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/sessionmanagertask.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/sessionsendtask.h',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/socketmonitor.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/p2p/client/socketmonitor.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/audiomonitor.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/audiomonitor.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/call.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/call.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/channel.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/channel.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/channelmanager.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/channelmanager.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/codec.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/codec.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/cryptoparams.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/currentspeakermonitor.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/currentspeakermonitor.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/devicemanager.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/devicemanager.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/filemediaengine.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/filemediaengine.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediachannel.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediaengine.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediaengine.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediamessages.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediamessages.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediamonitor.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediamonitor.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediasession.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediasession.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediasessionclient.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediasessionclient.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/mediasink.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/rtcpmuxfilter.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/rtcpmuxfilter.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/rtpdump.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/rtpdump.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/rtputils.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/rtputils.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/soundclip.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/soundclip.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/srtpfilter.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/srtpfilter.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/ssrcmuxfilter.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/ssrcmuxfilter.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/videocapturer.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/videocapturer.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/videocommon.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/videocommon.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/videoframe.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/videoframe.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/voicechannel.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcpassthroughrender.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtccommon.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvideocapturer.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvideocapturer.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvideoengine.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvideoengine.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvideoframe.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvideoframe.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvie.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvoe.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvoiceengine.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/webrtcvoiceengine.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/tunnel/pseudotcpchannel.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/tunnel/pseudotcpchannel.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/tunnel/tunnelsessionclient.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/tunnel/tunnelsessionclient.h',
|
|
||||||
],
|
|
||||||
'conditions': [
|
|
||||||
['OS=="win"', {
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/gdivideorenderer.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/gdivideorenderer.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/win32devicemanager.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/win32devicemanager.h',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['OS=="linux"', {
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/gtkvideorenderer.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/gtkvideorenderer.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/gtkvideorenderer.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/libudevsymboltable.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/libudevsymboltable.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/linuxdevicemanager.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/linuxdevicemanager.h',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/v4llookup.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/session/phone/v4llookup.h',
|
|
||||||
],
|
|
||||||
'include_dirs': [
|
|
||||||
'<(libjingle_orig)/source/talk/third_party/libudev',
|
|
||||||
],
|
|
||||||
'cflags': [
|
|
||||||
'<!@(pkg-config --cflags gtk+-2.0)',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
['inside_chromium_build==1', {
|
|
||||||
'dependencies': [
|
|
||||||
'../../third_party/webrtc/modules/modules.gyp:audio_device',
|
|
||||||
'../../third_party/webrtc/modules/modules.gyp:video_capture_module',
|
|
||||||
'../../third_party/webrtc/modules/modules.gyp:video_render_module',
|
|
||||||
'../../third_party/webrtc/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
|
||||||
'../../third_party/webrtc/video_engine/video_engine.gyp:video_engine_core',
|
|
||||||
'../../third_party/webrtc/voice_engine/voice_engine.gyp:voice_engine_core',
|
|
||||||
'libjingle',
|
|
||||||
],
|
|
||||||
}, {
|
|
||||||
'dependencies': [
|
|
||||||
'../../src/modules/modules.gyp:audio_device',
|
|
||||||
'../../src/modules/modules.gyp:video_capture_module',
|
|
||||||
'../../src/modules/modules.gyp:video_render_module',
|
|
||||||
'../../src/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
|
||||||
'../../src/video_engine/video_engine.gyp:video_engine_core',
|
|
||||||
'../../src/voice_engine/voice_engine.gyp:voice_engine_core',
|
|
||||||
'libjingle',
|
|
||||||
],
|
|
||||||
} ], # inside_chromium_build
|
|
||||||
], # conditions
|
|
||||||
},
|
|
||||||
# seperate project for app
|
|
||||||
{
|
|
||||||
'target_name': 'libjingle_app',
|
|
||||||
'type': '<(library)',
|
|
||||||
'sources': [
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/peerconnection.h',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/peerconnectionfactory.h',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/peerconnectionfactory.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/peerconnectionimpl.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/peerconnectionimpl.h',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/peerconnectionproxy.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/peerconnectionproxy.h',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/webrtcsession.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/webrtcsession.h',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/webrtcjson.cc',
|
|
||||||
'<(libjingle_orig)/source/talk/app/webrtc/webrtcjson.h',
|
|
||||||
],
|
|
||||||
'dependencies': [
|
|
||||||
'<(DEPTH)/third_party/libsrtp/libsrtp.gyp:libsrtp',
|
|
||||||
'jsoncpp',
|
|
||||||
],
|
|
||||||
'conditions': [
|
|
||||||
['inside_chromium_build==1', {
|
|
||||||
'dependencies': [
|
|
||||||
'../../third_party/webrtc/modules/modules.gyp:video_capture_module',
|
|
||||||
'../../third_party/webrtc/modules/modules.gyp:video_render_module',
|
|
||||||
'../../third_party/webrtc/video_engine/video_engine.gyp:video_engine_core',
|
|
||||||
'../../third_party/webrtc/voice_engine/voice_engine.gyp:voice_engine_core',
|
|
||||||
'../../third_party/webrtc/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
|
||||||
'libjingle_p2p',
|
|
||||||
],
|
|
||||||
}, {
|
|
||||||
'dependencies': [
|
|
||||||
'../../src/modules/modules.gyp:video_capture_module',
|
|
||||||
'../../src/modules/modules.gyp:video_render_module',
|
|
||||||
'../../src/video_engine/video_engine.gyp:video_engine_core',
|
|
||||||
'../../src/voice_engine/voice_engine.gyp:voice_engine_core',
|
|
||||||
'../../src/system_wrappers/source/system_wrappers.gyp:system_wrappers',
|
|
||||||
'libjingle_p2p',
|
|
||||||
],
|
|
||||||
} ], # inside_chromium_build
|
|
||||||
], # conditions
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
@ -13,7 +13,6 @@
|
|||||||
'target_name': 'All',
|
'target_name': 'All',
|
||||||
'type': 'none',
|
'type': 'none',
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'peerconnection/peerconnection.gyp:*',
|
|
||||||
'src/common_audio/common_audio.gyp:*',
|
'src/common_audio/common_audio.gyp:*',
|
||||||
'src/common_video/common_video.gyp:*',
|
'src/common_video/common_video.gyp:*',
|
||||||
'src/modules/modules.gyp:*',
|
'src/modules/modules.gyp:*',
|
||||||
|
Reference in New Issue
Block a user