A PHP Error was encountered
Severity: 8192
Message: Function create_function() is deprecated
Filename: geshi/geshi.php
Line Number: 4698
Backtrace:
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 624
Function: getPaste
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/system/core/Exceptions.php:271)
Filename: view/download.php
Line Number: 2
Backtrace:
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/themes/geocities/views/view/download.php
Line: 2
Function: header
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 173
Function: include
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 43
Function: _ci_load
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 625
Function: view
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/system/core/Exceptions.php:271)
Filename: view/download.php
Line Number: 3
Backtrace:
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/themes/geocities/views/view/download.php
Line: 3
Function: header
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 173
Function: include
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 43
Function: _ci_load
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 625
Function: view
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once
// PeerConnection.cpp
// AppSharing
//
// Created by Faraz Khan on 4/17/14.
//
//
#include "SHPeerConnection.h"
#include
#include "talk/base/common.h"
#include "talk/base/json.h"
#include "talk/base/logging.h"
#include "talk/base/ssladapter.h"
#include "portable_time.h"
#include "SHPeerConnectionFactory.h"
namespace nexus {
//
// test_client.cpp
// libjingle_examples
//
// Created by Faraz Khan on 4/15/14.
//
//
// Names used for a IceCandidate JSON object.
const char kCandidateSdpMidName[] = "sdpMid";
const char kCandidateSdpMlineIndexName[] = "sdpMLineIndex";
const char kCandidateSdpName[] = "candidate";
// Names used for a SessionDescription JSON object.
const char kSessionDescriptionTypeName[] = "type";
const char kSessionDescriptionSdpName[] = "sdp";
class DummySetSessionDescriptionObserver
: public webrtc::SetSessionDescriptionObserver {
public:
static DummySetSessionDescriptionObserver* Create(ILog * log,std::string sdp) {
return
new talk_base::RefCountedObject(log,sdp);
}
virtual void OnSuccess() {
logger_->OnLog("Successfully set SDP");
}
virtual void OnFailure(const std::string& error)
{
std::stringstream str;
str << "Failure setting SDP : " << sdp_ << " with error " << error;
logger_->OnLog(str.str());
}
protected:
DummySetSessionDescriptionObserver(ILog * logger , std::string sdp) : logger_(logger), sdp_(sdp) { }
~DummySetSessionDescriptionObserver() {}
ILog * logger_;
std::string sdp_;
};
SHPeerConnection::SHPeerConnection(SHPeerConnectionMessageTransport * transport,
SHPeerConnectionDataCallback * callback,
SHPeerConnectionChannelType channel_id,std::string jid,
ILog * logger)
: channel_type_(channel_id), message_transport_(transport),
data_callback_(callback),buddyjid_(jid),local_set_(false),
is_receiver_(false),in_shutdown_(false),logger_(logger),
ice_disconnected_time_ms_(PortableTickCount()),last_renegotiate_time_ms_(PortableTickCount()),
last_process_time_(PortableTickCount()),
did_have_active_connection_(false),started_ts_(PortableTickCount()),is_master_(false),
callback_on_other_thread_(false),yet_another_thread_(NULL)
{
talk_base::LogMessage::LogTimestamps();
talk_base::LogMessage::LogToDebug(talk_base::LS_ERROR);
#ifdef VERBOSE_PEERCONNECTION_DEBUG
talk_base::LogMessage::LogToDebug(talk_base::LS_VERBOSE);
streaminterface_ = new LogStreamInterface();
streaminterface_->SignalLogReceived.connect(this, &SHPeerConnection::Log);
talk_base::LogMessage::LogToStream(streaminterface_, talk_base::LS_INFO);
#endif
thread_ = new talk_base::Thread();
thread_->Release();
thread_->Start();
identity_service_ = new SHIdentityService(logger_,jid);
// server.uri = "stun:stun.l.google.com:19302";
// server.uri = "stun:165.225.139.11:443";
// servers.push_back(server);
webrtc::PeerConnectionInterface::IceServer turnserver;
webrtc::PeerConnectionInterface::IceServer backupstunserver;
turnserver.uri = "turn:165.225.139.11:443";
turnserver.username = "powwie";
turnserver.password = "magic#mobile351";
servers.push_back(turnserver);
#ifndef USE_ONLY_UDP_TURN
turnserver.uri = "turn:165.225.139.11:443?transport=tcp";
servers.push_back(turnserver);
backupstunserver.uri = "stun:stun.l.google.com:19302";
servers.push_back(backupstunserver);
#endif
// server.uri = "turn:165.225.139.11:443?transport=tcp";
// server.username = "powwie";
// server.password = "magic#mobile351";
// servers.push_back(server);
// talk_base::ThreadManager::Instance()->SetCurrentThread(thread_);
process_thread_ = webrtc::ProcessThread::CreateProcessThread();
process_thread_->RegisterModule(this);
process_thread_->Start();
}
void SHPeerConnection::Log(std::string log)
{
if (logger_)
{
logger_->OnLog(log);
}
}
SHPeerConnection::~SHPeerConnection() {
Log("Peerconnection delete");
if (!thread_->IsCurrent())
{
Log("Stopping since thread not current");
thread_->Stop();
}
ASSERT(peer_connection_.get() == NULL);
}
bool SHPeerConnection::connection_active() const
{
return (peer_connection_.get() != NULL &&
(peer_connection_->ice_connection_state() == webrtc::PeerConnectionInterface::kIceConnectionConnected ||
peer_connection_->ice_connection_state() == webrtc::PeerConnectionInterface::kIceConnectionCompleted));
}
void SHPeerConnection::Reconnect()
{
thread_->Post(this,RENEGOTIATE);
}
void SHPeerConnection::Connect()
{
thread_->Post(this, SHPeerConnection::DO_CONNECT);
}
void SHPeerConnection::ReceivedMessageFromPeer(std::string message)
{
// this->OnMessageFromPeer(message);
thread_->Post(this, RECV_MESSAGE_FROM_PEER, new talk_base::TypedMessageData(message));
}
void SHPeerConnection::Shutdown()
{
Log("PeerConnection Shutdown ");
thread_->Post(this,PEER_CONNECTION_CLOSED);
}
bool SHPeerConnection::InitializePeerConnection() {
Log("Initializing Peer Connection");
ASSERT(peer_connection_.get() == NULL);
if (!SHPeerConnectionFactory::GetPeerConnectionFactory().get()) {
// main_wnd_->MessageBox("Error",
// "Failed to initialize PeerConnectionFactory", true);
DeletePeerConnection();
return false;
}
// server.uri = "turn:165.225.139.11:443?transport=tcp";
// servers.push_back(server);
// server.uri = "stun:stun.l.google.com:19302";
webrtc::DataChannelInit dcinit;
constraints.AddMandatory(webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, webrtc::MediaConstraintsInterface::kValueFalse);
constraints.AddMandatory(webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, webrtc::MediaConstraintsInterface::kValueFalse);
constraints.AddMandatory(webrtc::MediaConstraintsInterface::kIceRestart, webrtc::MediaConstraintsInterface::kValueTrue);
if (channel_type_ == SHChannelTypeSCTP)
{
constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, webrtc::MediaConstraintsInterface::kValueTrue);
dcinit.reliable = true;
dcinit.ordered = true;
//dcinit.maxRetransmits = 0;
}
else
{
constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableRtpDataChannels,webrtc::MediaConstraintsInterface::kValueTrue);
constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, webrtc::MediaConstraintsInterface::kValueFalse);
dcinit.reliable = false;
dcinit.ordered = false;
}
peer_connection_ = SHPeerConnectionFactory::GetPeerConnectionFactory()->CreatePeerConnection(servers,
&constraints,
identity_service_,
this);
if (is_master_)
{
if (channel_type_ == SHChannelTypeSCTP)
datachannel_ = peer_connection_->CreateDataChannel("sctp_chan", &dcinit);
else
datachannel_ = peer_connection_->CreateDataChannel("udp_chan", &dcinit);
datachannel_->RegisterObserver(this);
}
if (!peer_connection_.get()) {
DeletePeerConnection();
}
Log("Initialized Peer Connection");
started_ts_ = PortableTickCount();
return peer_connection_.get() != NULL;
}
void SHPeerConnection::DeletePeerConnection() {
Log("Deleting peer connection");
//Quit this thread first, as there maybe be inbound messages that havent been processed yet. Wait for actions
//before you start killing this thread
if (yet_another_thread_ != NULL)
{
if (yet_another_thread_->IsCurrent())
yet_another_thread_->Quit();
else
yet_another_thread_->Stop();
Log("Quit secondary inbound messaging thread");
}
in_shutdown_ = true;
thread_->Quit();
Log("Thread quit complete");
bool neverstarted = (peer_connection_.get() == NULL);
if (neverstarted && data_callback_)
data_callback_->OnConnectionClosed(channel_type_);
if (datachannel_.get())
{
datachannel_->UnregisterObserver();
}
// if (peer_connection_.get())
// peer_connection_->Close();
//
process_thread_->DeRegisterModule(this);
process_thread_->Stop();
webrtc::ProcessThread::DestroyProcessThread(process_thread_);
peer_connection_ = NULL;
Log("Peerconnection = NULL DONE");
data_callback_->OnShutdownComplete(channel_type_);
ResetCallbacks();
}
void SHPeerConnection::OnError() {
Log("PeerConnection error");
thread_->Post(this, PEER_CONNECTION_ERROR);
}
void SHPeerConnection::OnMessage(const webrtc::DataBuffer &buffer)
{
// std::stringstream stream;
// stream << "receving udp size " << buffer.size();
// Log(stream.str());
if (in_shutdown_)
return;
if (data_callback_)
{
if (callback_on_other_thread_)
yet_another_thread_->Post(this,ON_DATA_RECEIVED,new talk_base::TypedMessageData(std::string(buffer.data.data(),buffer.data.length())));
else
data_callback_->OnDataReceived(channel_type_, (uint8_t*)buffer.data.data(), (int)buffer.size());
}
}
void SHPeerConnection::OnStateChange()
{
if (!in_shutdown_)
{
std::stringstream stream;
stream << "Datachannel state changed : " << datachannel_->state();
Log(stream.str());
if (datachannel_->state() == webrtc::DataChannelInterface::kOpen && data_callback_)
{
stream.clear();
stream << "Datachannel opened: " << datachannel_->state();
Log(stream.str());
if (is_receiver_)
thread_->Post(this,ON_INCOMING_CONNECTION);
else
thread_->Post(this,ON_CONNECTION_OPENED);
}
if (datachannel_->state() == webrtc::DataChannelInterface::kClosed && data_callback_)
{
data_callback_->OnConnectionClosed(channel_type_);
}
}
}
void SHPeerConnection::OnIceChange()
{
Log("Ice Status Changed");
}
void SHPeerConnection::OnRenegotiationNeeded()
{
Log("Renegotiation Needed");
}
void SHPeerConnection::OnIceComplete()
{
Log("Ice State Complete");
}
int SHPeerConnection::AddRef()
{
return 0;
}
int SHPeerConnection::Release()
{
return 0;
}
void SHPeerConnection::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state)
{
std::stringstream stream;
stream << "Ice connection state : " << new_state;
Log(stream.str());
switch (new_state) {
case webrtc::PeerConnectionInterface::kIceConnectionDisconnected:
Log("Temporary disconnection, chillout");
ice_disconnected_time_ms_ = PortableTickCount();
last_renegotiate_time_ms_ = PortableTickCount();
break;
case webrtc::PeerConnectionInterface::kIceConnectionFailed:
case webrtc::PeerConnectionInterface::kIceConnectionClosed:
thread_->Post(this,ON_CONNECTION_CLOSED);
break;
case webrtc::PeerConnectionInterface::kIceConnectionCompleted:
case webrtc::PeerConnectionInterface::kIceConnectionConnected:
Log("Ice Connection Established!");
did_have_active_connection_ = true;
break;
default:
break;
}
}
void SHPeerConnection::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state)
{
#ifdef VERBOSE_PEERCONNECTION_DEBUG
std::stringstream stream;
stream << "Ice Gathering state : " << new_state;
Log(stream.str());
#endif
}
void SHPeerConnection::OnStateChange(webrtc::PeerConnectionObserver::StateType state_changed)
{
#ifdef VERBOSE_PEERCONNECTION_DEBUG
std::stringstream stream;
stream << "Peer connection state : " << state_changed;
Log(stream.str());
#endif
}
void SHPeerConnection::OnDataChannel(webrtc::DataChannelInterface* data_channel)
{
datachannel_ = data_channel;
data_channel->AddRef();
datachannel_->RegisterObserver(this);
Log("Incoming Data channel established!");
}
// Called when a remote stream is added
void SHPeerConnection::OnAddStream(webrtc::MediaStreamInterface* stream) {
LOG(LERROR) << __FUNCTION__ << " " << stream->label();
stream->AddRef();
thread_->Post(this, NEW_STREAM_ADDED, new talk_base::TypedMessageData(stream));
}
void SHPeerConnection::OnRemoveStream(webrtc::MediaStreamInterface* stream) {
LOG(LERROR) << __FUNCTION__ << " " << stream->label();
stream->AddRef();
thread_->Post(this, STREAM_REMOVED, new talk_base::TypedMessageData(stream));
}
void SHPeerConnection::OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
Json::StyledWriter writer;
Json::Value jmessage;
jmessage[kCandidateSdpMidName] = candidate->sdp_mid();
jmessage[kCandidateSdpMlineIndexName] = candidate->sdp_mline_index();
std::string sdp;
if (!candidate->ToString(&sdp)) {
Log("Failed to serialize candidate");
return;
}
jmessage[kCandidateSdpName] = sdp;
SendMessage(writer.write(jmessage));
}
void SHPeerConnection::ResetCallbacks()
{
data_callback_ = NULL;
message_transport_ = NULL;
logger_ = NULL;
}
void SHPeerConnection::OnMessageFromPeer(const std::string message) {
if (in_shutdown_)
return;
if (!peer_connection_.get()) {
if (!InitializePeerConnection()) {
Log("Failed to initialize our PeerConnection instance");
return;
}
}
Json::Reader reader;
Json::Value jmessage;
if (!reader.parse(message, jmessage)) {
std::stringstream stream;
stream << "Received unknown message. " << message;
Log(stream.str());
return;
}
#ifdef VERBOSE_PEERCONNECTION_DEBUG
std::stringstream stream;
stream << "Got Msg: " << message.c_str();
Log(stream.str());
#endif
std::string type;
std::string json_object;
GetStringFromJsonObject(jmessage, kSessionDescriptionTypeName, &type);
if (!type.empty()) {
std::string sdp;
if (!GetStringFromJsonObject(jmessage, kSessionDescriptionSdpName, &sdp)) {
Log("Can't parse received session description message.");
return;
}
webrtc::SdpParseError * parseError = NULL;
webrtc::SessionDescriptionInterface* session_description(
webrtc::CreateSessionDescription(type, sdp,parseError));
if (!session_description && !parseError) {
std::stringstream stream;
stream << "Error parsing message :" << parseError->description << " on line :"<line;
Log(stream.str());
if (!did_have_active_connection_)
thread_->Post(this,ON_CONNECTION_CLOSED);
return;
}
std::stringstream stream;
stream << "Received session description :" << message;
Log(stream.str());
peer_connection_->SetRemoteDescription(DummySetSessionDescriptionObserver::Create(logger_,sdp), session_description);
if (!is_master_&& session_description->type() == webrtc::SessionDescriptionInterface::kOffer) {
is_receiver_ = true;
peer_connection_->CreateAnswer(this, &constraints);
}
return;
} else {
local_set_ = true;
if (local_set_)
this->AddIceCandidate(message);
else
pending_messages_.push_back(message);
}
}
void SHPeerConnection::AddIceCandidate(std::string message)
{
Json::Reader reader;
Json::Value jmessage;
if (!reader.parse(message, jmessage)) {
std::stringstream stream;
stream << "Received unknown message. " << message;
Log(stream.str());
return;
}
std::string sdp_mid;
int sdp_mlineindex = 0;
std::string sdp;
if (!GetStringFromJsonObject(jmessage, kCandidateSdpMidName, &sdp_mid) ||
!GetIntFromJsonObject(jmessage, kCandidateSdpMlineIndexName,
&sdp_mlineindex) ||
!GetStringFromJsonObject(jmessage, kCandidateSdpName, &sdp)) {
Log("Can't parse received message.");
return;
}
talk_base::scoped_ptr candidate(
webrtc::CreateIceCandidate(sdp_mid, sdp_mlineindex, sdp));
if (!candidate.get()) {
Log("Can't parse received candidate message.");
return;
}
if (!peer_connection_->AddIceCandidate(candidate.get())) {
Log("Failed to apply the received candidate");
return;
}
std::stringstream stream;
stream << " Received candidate :" << message;
// Log(stream.str());
return;
}
// void SHPeerConnection::AddStreams() {
// if (active_streams_.find(kStreamLabel) != active_streams_.end())
// return; // Already added.
//
// talk_base::scoped_refptr audio_track(
// peer_connection_factory_->CreateAudioTrack(
// kAudioLabel, peer_connection_factory_->CreateAudioSource(NULL)));
//
// talk_base::scoped_refptr video_track(
// peer_connection_factory_->CreateVideoTrack(
// kVideoLabel,
// peer_connection_factory_->CreateVideoSource(OpenVideoCaptureDevice(),
// NULL)));
//// main_wnd_->StartLocalRenderer(video_track);
// talk_base::scoped_refptr stream =
// peer_connection_factory_->CreateLocalMediaStream(kStreamLabel);
//
//
// stream->AddTrack(audio_track);
//
// stream->AddTrack(video_track);
// if (!peer_connection_->AddStream(stream, NULL)) {
// LOG(LS_ERROR) << "Adding stream to PeerConnection failed";
// }
// typedef std::pair >
// MediaStreamPair;
// active_streams_.insert(MediaStreamPair(stream->label(), stream));
// }
int32_t SHPeerConnection::TimeUntilNextProcess()
{
return DEFAULT_PROCESS_TIME - (PortableTickCount() - last_process_time_);
}
int32_t SHPeerConnection::Process()
{
//test for disconnect timeout
last_process_time_ = PortableTickCount();
if (in_shutdown_)
return 0;
if (did_have_active_connection_ && peer_connection_.get() != NULL)
{
bool is_disconnected =
peer_connection_->ice_connection_state() == webrtc::PeerConnectionInterface::kIceConnectionDisconnected ||
peer_connection_->ice_connection_state() == webrtc::PeerConnectionInterface::kIceConnectionClosed ||
peer_connection_->ice_connection_state() == webrtc::PeerConnectionInterface::kIceConnectionFailed ||
peer_connection_->ice_connection_state() == webrtc::PeerConnectionInterface::kIceConnectionChecking;
if (time_delta_32(PortableTickCount(), ice_disconnected_time_ms_) > DEFAULT_DISCONNECT_TIMEOUT
&& is_disconnected)
{
Log("Timeout happened, causing disconnect");
thread_->Post(this,ON_CONNECTION_CLOSED);
}
else if (time_delta_32(PortableTickCount(), last_renegotiate_time_ms_) > RENEGOTIATE_TIMEOUT
&& is_disconnected)
{
Log("Reconnecting....");
last_renegotiate_time_ms_ = PortableTickCount();
this->Reconnect();
}
}
else
{
if (time_delta_32(PortableTickCount(), started_ts_) > CONNECTION_ESTABLISHMENT_TIMEOUT)
{
Log("Unable to establish conneciton, timeout");
thread_->Post(this,ON_CONNECTION_CLOSED);
}
}
return 0;
}
bool SHPeerConnection::QueueDataToSend(uint8_t* data, int len)
{
if (in_shutdown_)
return false;
std::string tosend((const char*)data,len);
thread_->Post(this,SEND_DATA,new talk_base::TypedMessageData(tosend));
return true;
}
bool SHPeerConnection::SendData(uint8_t * data, int len)
{
if (in_shutdown_)
return false;
if (datachannel_ && datachannel_.get() && datachannel_->state() == webrtc::DataChannelInterface::kOpen)
{
return datachannel_->Send(webrtc::DataBuffer(talk_base::Buffer(data,len),false));
}
return false;
}
void SHPeerConnection::OnMessage(talk_base::Message *m)
{
if (in_shutdown_)
return;
switch (m->message_id) {
case RECV_MESSAGE_FROM_PEER:
{
std::string msg;
if (m->pdata != NULL)
msg = ((talk_base::TypedMessageData*)m->pdata)->data();
if (!msg.empty())
{
OnMessageFromPeer(msg);
}
break;
}
case DO_CONNECT:
{
is_master_ = true;
if (InitializePeerConnection())
{
peer_connection_->CreateOffer(this, &constraints);
}
break;
}
case ON_DATA_RECEIVED:
{
std::string msg;
if (m->pdata != NULL)
msg = ((talk_base::TypedMessageData*)m->pdata)->data();
if (!msg.empty() && data_callback_)
{
data_callback_->OnDataReceived(channel_type_, (uint8_t*)msg.data(), (int)msg.length());;
}
break;
}
case SEND_DATA:
{
std::string msg;
if (m->pdata != NULL)
msg = ((talk_base::TypedMessageData*)m->pdata)->data();
if (!msg.empty())
{
webrtc::DataBuffer buf = webrtc::DataBuffer(msg);
datachannel_->Send(buf);
}
break;
}
case RENEGOTIATE:
{
this->Renegotiate();
break;
}
case ON_CONNECTION_CLOSED:
{
if (data_callback_)
data_callback_->OnConnectionClosed(channel_type_);
break;
}
case ON_INCOMING_CONNECTION:
{
if (data_callback_)
data_callback_->OnIncomingConnection(channel_type_);
break;
}
case ON_CONNECTION_OPENED:
{
if (data_callback_)
data_callback_->OnConnectionOpened(channel_type_);
break;
}
case PEER_CONNECTION_CLOSED:
{
Log("PEER_CONNECTION_CLOSED");
DeletePeerConnection();
break;
}
case SEND_MESSAGE_TO_PEER: {
std::string msg;
if (m->pdata != NULL)
msg = ((talk_base::TypedMessageData*)m->pdata)->data();
if (!msg.empty()) {
#ifdef VERBOSE_PEERCONNECTION_DEBUG
std::stringstream stream;
stream << "SEND_MESSAGE_TO_PEER: " << msg.c_str();
Log(stream.str());
#endif
if (message_transport_)
message_transport_->SendMessageToPeer(msg, buddyjid_, channel_type_);
}
break;
}
case PEER_CONNECTION_ERROR:
Log("Peer Conneciton Error");
break;
case NEW_STREAM_ADDED: {
webrtc::MediaStreamInterface * stream =
((talk_base::TypedMessageData*)m->pdata)->data();
webrtc::VideoTrackVector tracks = stream->GetVideoTracks();
// Only render the first track.
if (!tracks.empty()) {
webrtc::VideoTrackInterface* track = tracks[0];
// main_wnd_->StartRemoteRenderer(track);
}
stream->Release();
break;
}
case STREAM_REMOVED: {
// Remote peer stopped sending a stream.
webrtc::MediaStreamInterface * stream =
((talk_base::TypedMessageData*)m->pdata)->data();
stream->Release();
break;
}
default:
ASSERT(false);
break;
}
}
void SHPeerConnection::OnSuccess(webrtc::SessionDescriptionInterface* desc)
{
std::string sdp;
desc->ToString(&sdp);
Json::StyledWriter writer;
Json::Value jmessage;
jmessage[kSessionDescriptionTypeName] = desc->type();
webrtc::SdpParseError parserror;
webrtc::SessionDescriptionInterface * sdpinterface = webrtc::CreateSessionDescription(desc->type(), sdp, &parserror);
if (sdpinterface != NULL)
{
peer_connection_->SetLocalDescription(DummySetSessionDescriptionObserver::Create(logger_,sdp),
sdpinterface);
jmessage[kSessionDescriptionSdpName] = sdp;
SendMessage(writer.write(jmessage));
}
else
{
std::stringstream str;
str << "Failed setting local description, cannot proceed! error " << parserror.description << " line: " << parserror.line;
logger_->OnLog(str.str());
if (!did_have_active_connection_)
thread_->Post(this,ON_CONNECTION_CLOSED);
}
}
void SHPeerConnection::OnFailure(const std::string& error) {
Log(error);
}
void SHPeerConnection::SendMessage(const std::string json_object) {
// message_transport_->SendMessageToPeer(json_object, buddyjid_, channel_type_);
thread_->Post(this, SEND_MESSAGE_TO_PEER, new talk_base::TypedMessageData(json_object));
// main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg);
}
void SHPeerConnection::SetCallbackOnSecondaryThread(bool callback)
{
if (callback && !callback_on_other_thread_)
{
yet_another_thread_ = new talk_base::Thread();
yet_another_thread_->Release();
yet_another_thread_->Start();
}
callback_on_other_thread_ = callback;
}
void SHPeerConnection::Renegotiate()
{
if (peer_connection_.get() && is_master_)
{
peer_connection_->CreateOffer(this, &constraints);
}
}
}