I recently synced to the new version of webrtc native and I am now unable to get the OnSuccess callback from the CreateSessionDescriptionObserver implementation when CreateOffer is called.
What is the simplest way to get an "OnSuccess"?
Below is the code I am using. OnSuccess is triggered with my old copy of webrtc, but not the most current version.
Thanks
--------------------------------------------------------------------------------------------------------------------------
#include "main.h"
class FakeConstraints : public webrtc::MediaConstraintsInterface {
public:
FakeConstraints() { }
virtual ~FakeConstraints() { }
virtual const Constraints& GetMandatory() const {
return mandatory_;
}
virtual const Constraints& GetOptional() const {
return optional_;
}
template <class T>
void AddMandatory(const std::string& key, const T& value) {
mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
}
template <class T>
void SetMandatory(const std::string& key, const T& value) {
std::string value_str;
if (mandatory_.FindFirst(key, &value_str)) {
for (Constraints::iterator iter = mandatory_.begin();
iter != mandatory_.end(); ++iter) {
if (iter->key == key) {
mandatory_.erase(iter);
break;
}
}
}
mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
}
template <class T>
void AddOptional(const std::string& key, const T& value) {
optional_.push_back(Constraint(key, rtc::ToString<T>(value)));
}
void SetMandatoryMinAspectRatio(double ratio) {
SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
}
void SetMandatoryMinWidth(int width) {
SetMandatory(MediaConstraintsInterface::kMinWidth, width);
}
void SetMandatoryMinHeight(int height) {
SetMandatory(MediaConstraintsInterface::kMinHeight, height);
}
void SetOptionalMaxWidth(int width) {
AddOptional(MediaConstraintsInterface::kMaxWidth, width);
}
void SetMandatoryMaxFrameRate(int frame_rate) {
SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
}
void SetMandatoryReceiveAudio(bool enable) {
SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
}
void SetMandatoryReceiveVideo(bool enable) {
SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
}
void SetMandatoryUseRtpMux(bool enable) {
SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
}
void SetMandatoryIceRestart(bool enable) {
SetMandatory(MediaConstraintsInterface::kIceRestart, enable);
}
void SetAllowRtpDataChannels() {
SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false);
}
void SetOptionalVAD(bool enable) {
AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
}
void SetAllowDtlsSctpDataChannels() {
SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
}
private:
Constraints mandatory_;
Constraints optional_;
};
class Observer
: public webrtc::PeerConnectionObserver,
public webrtc::CreateSessionDescriptionObserver
{
public:
enum State
{
ACTIVE,
PENDING,
INACTIVE,
DELETED
};
Observer() {
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory();
}
~Observer() {}
bool createPeerConnection() {
if (!peer_connection_factory_.get())
{
return false;
}
webrtc::PeerConnectionInterface::IceServers servers;
webrtc::PeerConnectionInterface::IceServer server;
constraints_.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, "true");
constraints_.SetMandatoryReceiveVideo(true);
constraints_.SetMandatoryReceiveAudio(true);
servers.push_back(server);
constraints_.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, "true");
peer_connection_ = peer_connection_factory_->CreatePeerConnection(servers, &constraints_, NULL, NULL, this);
if (!peer_connection_.get())
{
peer_connection_->Release();
}
std::cout << "Observer: Peer Connection Created." << std::endl;
return peer_connection_.get() != NULL;
}
void connectToPeer() {
peer_connection_->CreateOffer(this, NULL);
}
protected:
// PeerConnectionObserver implementation
virtual void OnError() {}
virtual void OnStateChange(webrtc::PeerConnectionObserver::StateType state_changed) {}
virtual void OnAddStream(webrtc::MediaStreamInterface* stream) {}
virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) {}
virtual void OnDataChannel(webrtc::DataChannelInterface* channel) {}
virtual void OnRenegotiationNeeded() {}
virtual void OnIceChange() {}
virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {}
// CreateSessionDescriptionObserver implementation.
virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc) {
std::cout << "ON SUCCESS" << std::endl;
}
virtual void OnFailure(const std::string& error) {
std::cout << "ON FAILURE" << std::endl;
}
public:
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory_;
FakeConstraints constraints_;
std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> >
active_streams_;
};
int main()
{
rtc::EnsureWinsockInit();
rtc::Win32Thread w32_thread;
rtc::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
rtc::InitializeSSL();
rtc::scoped_refptr<Observer> observer(new rtc::RefCountedObject<Observer>());
observer->createPeerConnection();
observer->connectToPeer();
rtc::CleanupSSL();
return 0;
}