Skip to content

Commit c0466de

Browse files
author
Clément Charmet
committed
removed (fake) constraints (deprecated?) + make PC configuration fields optional
1 parent b0e4cb7 commit c0466de

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

src/rtcpeerconnection.cc

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ static const char eUnsupported[] = "The 1st argument provided is an "
8888
"AlgorithmIdentifier with a supported algorithm name, but the parameters "
8989
"are not supported.";
9090

91-
static const char eFailure[] = "Failed to generate the certificate.";
91+
static const char eGenerateCertificateFailure[] =
92+
"Failed to generate the certificate.";
93+
static const char eConstructorFailure[] =
94+
"Failed to construct 'RTCPeerConnection'";
9295

9396
NAN_MODULE_INIT(RTCPeerConnection::Init) {
9497
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(New);
@@ -131,16 +134,15 @@ NAN_MODULE_INIT(RTCPeerConnection::Init) {
131134
}
132135

133136
RTCPeerConnection::RTCPeerConnection(
134-
const webrtc::PeerConnectionInterface::RTCConfiguration& config,
135-
const webrtc::MediaConstraintsInterface& constraints) {
137+
const webrtc::PeerConnectionInterface::RTCConfiguration& config) {
136138

137139
_peerConnectionFactory = webrtc::CreatePeerConnectionFactory(
138140
Globals::GetSignalingThread(), Globals::GetWorkerThread(),
139141
NULL, NULL, NULL);
140142

141143
_peerConnectionObserver = PeerConnectionObserver::Create();
142144
_peerConnection = _peerConnectionFactory->CreatePeerConnection(
143-
config, &constraints, NULL, NULL, _peerConnectionObserver);
145+
config, NULL, NULL, _peerConnectionObserver);
144146
}
145147

146148
RTCPeerConnection::~RTCPeerConnection() {
@@ -158,44 +160,53 @@ NAN_METHOD(RTCPeerConnection::New) {
158160
ASSERT_OBJECT_ARGUMENT(0, config);
159161

160162
DECLARE_OBJECT_PROPERTY(config, kIceServers, iceServersVal);
161-
ASSERT_PROPERTY_ARRAY(kIceServers, iceServersVal, iceServers);
162163

163-
for (unsigned int i = 0; i < iceServers->Length(); i = i + 1) {
164-
Local<Value> iceServerVal = iceServers->Get(i);
165-
ASSERT_PROPERTY_OBJECT(kIceServers, iceServerVal, iceServer);
164+
if (!iceServersVal->IsNull() && !iceServersVal->IsUndefined()) {
165+
ASSERT_PROPERTY_ARRAY(kIceServers, iceServersVal, iceServers);
166166

167-
webrtc::PeerConnectionInterface::IceServer server;
167+
for (unsigned int i = 0; i < iceServers->Length(); i = i + 1) {
168+
Local<Value> iceServerVal = iceServers->Get(i);
169+
ASSERT_PROPERTY_OBJECT(kIceServers, iceServerVal, iceServer);
168170

169-
DECLARE_OBJECT_PROPERTY(iceServer, kIceServerUrls, iceServerUrlsVal);
170-
ASSERT_PROPERTY_ARRAY(kIceServerUrls, iceServerUrlsVal, iceServerUrls);
171+
webrtc::PeerConnectionInterface::IceServer server;
171172

172-
for (unsigned int j = 0; j < iceServerUrls->Length(); j = j + 1) {
173-
Local<Value> iceServerUrlVal = iceServerUrls->Get(j);
174-
ASSERT_PROPERTY_STRING(kIceServerUrls, iceServerUrlVal, iceServerUrl);
175-
server.urls.push_back(*iceServerUrl);
173+
DECLARE_OBJECT_PROPERTY(iceServer, kIceServerUrls, iceServerUrlsVal);
174+
ASSERT_PROPERTY_ARRAY(kIceServerUrls, iceServerUrlsVal, iceServerUrls);
175+
176+
for (unsigned int j = 0; j < iceServerUrls->Length(); j = j + 1) {
177+
Local<Value> iceServerUrlVal = iceServerUrls->Get(j);
178+
// FIXME: validate URL
179+
ASSERT_PROPERTY_STRING(kIceServerUrls, iceServerUrlVal, iceServerUrl);
180+
server.urls.push_back(*iceServerUrl);
181+
// FIXME: add username / password for TURN servers
182+
}
183+
_config.servers.push_back(server);
176184
}
177-
_config.servers.push_back(server);
178185
}
179186

180187
DECLARE_OBJECT_PROPERTY(config, kCertificates, certificatesVal);
181-
ASSERT_PROPERTY_ARRAY(kCertificates, certificatesVal, certificates);
182188

183-
for (unsigned int i = 0; i < certificates->Length(); i = i + 1) {
184-
Local<Value> certificateVal = certificates->Get(i);
185-
ASSERT_PROPERTY_OBJECT(kCertificates, certificateVal, certificate);
186-
// FIXME: validate it's a RTCCertificate object
187-
RTCCertificate* _certificate
188-
= Nan::ObjectWrap::Unwrap<RTCCertificate>(certificate);
189+
if (!certificatesVal->IsNull() && !certificatesVal->IsUndefined()) {
190+
ASSERT_PROPERTY_ARRAY(kCertificates, certificatesVal, certificates);
191+
192+
for (unsigned int i = 0; i < certificates->Length(); i = i + 1) {
193+
Local<Value> certificateVal = certificates->Get(i);
194+
ASSERT_PROPERTY_OBJECT(kCertificates, certificateVal, certificate);
195+
// FIXME: validate it's a RTCCertificate object
196+
RTCCertificate* _certificate
197+
= Nan::ObjectWrap::Unwrap<RTCCertificate>(certificate);
189198

190-
_config.certificates.push_back(_certificate->_certificate);
199+
_config.certificates.push_back(_certificate->_certificate);
200+
}
191201
}
192202
}
193203

194-
constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
195-
"true");
204+
RTCPeerConnection *rtcPeerConnection = new RTCPeerConnection(_config);
205+
206+
if (!rtcPeerConnection->_peerConnection) {
207+
return Nan::ThrowError("Failed to construct 'RTCPeerConnection'");
208+
}
196209

197-
RTCPeerConnection *rtcPeerConnection = new RTCPeerConnection(_config,
198-
constraints);
199210
rtcPeerConnection->Wrap(info.This());
200211

201212
rtcPeerConnection->_peerConnectionObserver->SetEventEmitter(
@@ -519,7 +530,7 @@ void RTCPeerConnection::GenerateCertificateWorker::WorkComplete() {
519530
if (!_certificate.get()) {
520531
std::stringstream errorStream;
521532

522-
errorStream << eFailure;
533+
errorStream << eGenerateCertificateFailure;
523534
resolver->Reject(Nan::TypeError(errorStream.str().c_str()));
524535
} else {
525536
resolver->Resolve(RTCCertificate::Create(_certificate));

src/rtcpeerconnection.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class RTCPeerConnection : public EventEmitter {
3131

3232
private:
3333
explicit RTCPeerConnection(
34-
const webrtc::PeerConnectionInterface::RTCConfiguration& config,
35-
const webrtc::MediaConstraintsInterface& constraints);
34+
const webrtc::PeerConnectionInterface::RTCConfiguration& config);
3635
~RTCPeerConnection();
3736

3837
static NAN_METHOD(New);

0 commit comments

Comments
 (0)