bool PeerConnectionObserver::ConnectToPeer(int peerId, const std::string& peerName) { if(IsConnectionActive()) { std::cerr << __FUNCTION__ << ": Local peer busy..." << std::endl; return false; } if(false == InitPeerConnection()) { std::cerr << __FUNCTION__ << ": InitPeerConnection() failed..." << std::endl; return false; } m_PeerId = peerId; m_PeerName = peerName; m_pPeerConnection->AddStream("voice",false); #if(defined(GOCAST_ENABLE_VIDEO) && !defined(GOCAST_WINDOWS)) if(false == m_bAudioOnly) { m_pPeerConnection->AddStream("video",true); } #endif m_pPeerConnection->Connect(); return true; }
void PeerConnectionObserver::OnMessageFromRemotePeer(int peerId, const std::string& msg) { if(msg == "bye") { if(IsConnectionActive()) { std::cout << m_PeerName << " hung up..." << std::endl; int peerId = m_PeerId; #if(defined(GOCAST_ENABLE_VIDEO) && !defined(GOCAST_WINDOWS)) m_pPeerConnection->SetVideoRenderer("video", NULL); if(NULL != m_pRemoteRenderer) { gRemoteStream = NULL; //iPhone only m_pRemoteRenderer->Deinit(); VideoRenderer::Destroy(m_pRemoteRenderer); m_pRemoteRenderer = NULL; } #endif if(true == m_pPeerConnection->Close()) { DeletePeerConnection(); ParsedMessage cmd; cmd["command"] = "deleteobserver"; cmd["peerid"] = ToString(peerId); m_pMsgQ->PostMessage(cmd); } else { std::cerr << __FUNCTION__ << ": Connection teardown failed..." << std::endl; } } else { std::cerr << __FUNCTION__ << ": Peerconnection already deleted..." << std::endl; } return; } if(false == IsConnectionActive()) { std::cout << m_PeerName << " on the line..." << std::endl; if(false == InitPeerConnection()) { std::cerr << __FUNCTION__ << ": Failed to init peer connection..." << std::endl; return; } } m_pPeerConnection->SignalingMessage(msg); }
bool PeerConnectionObserver::ConnectToPeer(int peerId, const std::string& peerName) { if(IsConnectionActive()) { std::cerr << __FUNCTION__ << ": Local peer busy..." << std::endl; return false; } if(false == InitPeerConnection()) { std::cerr << __FUNCTION__ << ": InitPeerConnection() failed..." << std::endl; return false; } m_PeerId = peerId; m_PeerName = peerName; m_pPeerConnection->AddStream("voice",false); #if(defined(GOCAST_ENABLE_VIDEO) && defined(GOCAST_LINUX)) m_pPeerConnection->AddStream("video",true); m_pRemoteRenderer = VideoRenderer::Create( m_PeerName, GOCAST_DEFAULT_RENDER_WIDTH, GOCAST_DEFAULT_RENDER_HEIGHT ); bool bStatus = m_pRemoteRenderer->Init(); if(false == bStatus) { std::cerr << __FUNCTION__ << ": remote renderer init failed..." << std::endl; return false; } bStatus = m_pPeerConnection->SetVideoRenderer("video", m_pRemoteRenderer); if(false == bStatus) { std::cerr << __FUNCTION__ << ":set remote renderer failed..." << std::endl; return false; } #endif m_pPeerConnection->Connect(); return true; }