Created
March 5, 2018 21:13
-
-
Save ziahamza/a36214d87a3c8165edd3f923e9f49962 to your computer and use it in GitHub Desktop.
Getting WebRTC offers from latest version of Chromium WebRTC library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "webrtc/pc/peerconnectionfactory.h" | |
#include "webrtc/api/mediastreaminterface.h" | |
#include "webrtc/api/datachannelinterface.h" | |
#include "webrtc/api/peerconnectioninterface.h" | |
#include "webrtc/api/test/fakeconstraints.h" | |
using namespace std; | |
class TestConnectionObserver : public webrtc::PeerConnectionObserver | |
{ | |
public: | |
TestConnectionObserver(); | |
~TestConnectionObserver(); | |
void OnError(); | |
void OnStateChange(webrtc::PeerConnectionObserver::StateType state_changed); | |
void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream); | |
void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream); | |
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state); | |
void OnRenegotiationNeeded(); | |
void OnIceChange(); | |
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate); | |
void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel); | |
void OnIceConnectionChange( | |
webrtc::PeerConnectionInterface::IceConnectionState new_state); | |
void OnIceGatheringChange( | |
webrtc::PeerConnectionInterface::IceGatheringState new_state); | |
}; | |
class TestSDObserver : public rtc::RefCountedObject<webrtc::CreateSessionDescriptionObserver> | |
{ | |
public: | |
TestSDObserver(); | |
~TestSDObserver(); | |
void OnSuccess(webrtc::SessionDescriptionInterface* desc); | |
void OnFailure(const std::string& error); | |
}; | |
TestConnectionObserver::TestConnectionObserver() | |
{ | |
cerr << "TestConnectionObserver::TestConnectionObserver" << endl; | |
} | |
void TestConnectionObserver::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) { | |
cerr << "TestConnectionObserver::" << endl; | |
} | |
void TestConnectionObserver::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) { | |
cerr << "OnIceConnectionChange" << endl; | |
} | |
void TestConnectionObserver::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) { | |
cerr << "OnIceConnectionChange" << endl; | |
} | |
TestConnectionObserver::~TestConnectionObserver() | |
{ | |
cerr << "TestConnectionObserver::~TestConnectionObserver" << endl; | |
} | |
void TestConnectionObserver::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel){ | |
} | |
void TestConnectionObserver::OnError() | |
{ | |
cerr << "TestConnectionObserver::OnError" << endl; | |
} | |
void TestConnectionObserver::OnStateChange(webrtc::PeerConnectionObserver::StateType state_changed) | |
{ | |
cerr << "TestConnectionObserver::OnStateChange" << endl; | |
} | |
void TestConnectionObserver::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) | |
{ | |
cerr << "TestConnectionObserver::OnAddStream" << endl; | |
} | |
void TestConnectionObserver::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) | |
{ | |
cerr << "TestConnectionObserver::OnRemoveStream" << endl; | |
} | |
void TestConnectionObserver::OnRenegotiationNeeded() | |
{ | |
cerr << "TestConnectionObserver::OnRenegotiationNeeded" << endl; | |
} | |
void TestConnectionObserver::OnIceChange() | |
{ | |
cerr << "TestConnectionObserver::OnIceChange" << endl; | |
} | |
void TestConnectionObserver::OnIceCandidate(const webrtc::IceCandidateInterface* candidate) | |
{ | |
cerr << "TestConnectionObserver::OnIceCandidate" << endl; | |
} | |
TestSDObserver::TestSDObserver() | |
{ | |
cerr << "TestSDObserver::TestSDObserver" << endl; | |
} | |
TestSDObserver::~TestSDObserver() | |
{ | |
cerr << "TestSDObserver::~TestSDObserver" << endl; | |
} | |
void TestSDObserver::OnSuccess(webrtc::SessionDescriptionInterface* desc) | |
{ | |
cerr << "TestSDObserver::OnSuccess!!!! :D :D :D :D :D" << endl; | |
} | |
void TestSDObserver::OnFailure(const std::string& error) | |
{ | |
cerr << "TestSDObserver::OnFailure" << endl; | |
} | |
int main() { | |
auto factory = webrtc::CreatePeerConnectionFactory(); | |
auto rtcthread = rtc::Thread::Current(); | |
webrtc::PeerConnectionInterface::RTCConfiguration _config; | |
webrtc::FakeConstraints _constraints; | |
TestConnectionObserver* testConnectionObserver = new TestConnectionObserver(); | |
auto peer_connection = factory->CreatePeerConnection(_config, &_constraints, 0, 0, testConnectionObserver); | |
TestSDObserver *testDescriptorObserver = new TestSDObserver(); | |
peer_connection->CreateOffer(testDescriptorObserver, nullptr); | |
while (1) { | |
cout << "processing messages ...." << endl; | |
rtcthread->ProcessMessages(100); | |
usleep(1000 * 1000); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment