Skip to content

Commit 798dbe3

Browse files
committed
feat: support setting ICE ufrag and pwd, and missing config values
Updates the implementation to match the latest libdatachannel with features for setting ICE ufrag/pwd and reading the remote cert fingerprint. Also adds pass-through for missing config values.
1 parent b0caa62 commit 798dbe3

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/cpp/peer-connection-wrapper.cpp

+57-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
4141
InstanceMethod("setRemoteDescription", &PeerConnectionWrapper::setRemoteDescription),
4242
InstanceMethod("localDescription", &PeerConnectionWrapper::localDescription),
4343
InstanceMethod("remoteDescription", &PeerConnectionWrapper::remoteDescription),
44+
InstanceMethod("remoteFingerprint", &PeerConnectionWrapper::remoteFingerprint),
4445
InstanceMethod("addRemoteCandidate", &PeerConnectionWrapper::addRemoteCandidate),
4546
InstanceMethod("createDataChannel", &PeerConnectionWrapper::createDataChannel),
4647
InstanceMethod("addTrack", &PeerConnectionWrapper::addTrack),
@@ -214,6 +215,10 @@ PeerConnectionWrapper::PeerConnectionWrapper(const Napi::CallbackInfo &info) : N
214215
if (config.Get("disableAutoNegotiation").IsBoolean())
215216
rtcConfig.disableAutoNegotiation = config.Get("disableAutoNegotiation").As<Napi::Boolean>();
216217

218+
// disableAutoGathering option
219+
if (config.Get("disableAutoGathering").IsBoolean())
220+
rtcConfig.disableAutoGathering = config.Get("disableAutoGathering").As<Napi::Boolean>();
221+
217222
// forceMediaTransport option
218223
if (config.Get("forceMediaTransport").IsBoolean())
219224
rtcConfig.forceMediaTransport = config.Get("forceMediaTransport").As<Napi::Boolean>();
@@ -331,6 +336,7 @@ void PeerConnectionWrapper::setLocalDescription(const Napi::CallbackInfo &info)
331336
}
332337

333338
rtc::Description::Type type = rtc::Description::Type::Unspec;
339+
rtc::LocalDescriptionInit init;
334340

335341
// optional
336342
if (length > 0)
@@ -356,7 +362,29 @@ void PeerConnectionWrapper::setLocalDescription(const Napi::CallbackInfo &info)
356362
type = rtc::Description::Type::Rollback;
357363
}
358364

359-
mRtcPeerConnPtr->setLocalDescription(type);
365+
// optional
366+
if (length > 1)
367+
{
368+
PLOG_DEBUG << "setLocalDescription() called with LocalDescriptionInit";
369+
370+
if (info[1].IsObject())
371+
{
372+
PLOG_DEBUG << "setLocalDescription() called with LocalDescriptionInit as object";
373+
Napi::Object obj = info[1].As<Napi::Object>();
374+
375+
if (obj.Get("iceUfrag").IsString()) {
376+
PLOG_DEBUG << "setLocalDescription() has ufrag";
377+
init.iceUfrag = obj.Get("iceUfrag").As<Napi::String>();
378+
}
379+
380+
if (obj.Get("icePwd").IsString()) {
381+
PLOG_DEBUG << "setLocalDescription() has password";
382+
init.icePwd = obj.Get("icePwd").As<Napi::String>();
383+
}
384+
}
385+
}
386+
387+
mRtcPeerConnPtr->setLocalDescription(type, init);
360388
}
361389

362390
void PeerConnectionWrapper::setRemoteDescription(const Napi::CallbackInfo &info)
@@ -1002,7 +1030,34 @@ Napi::Value PeerConnectionWrapper::maxMessageSize(const Napi::CallbackInfo &info
10021030

10031031
try
10041032
{
1005-
return Napi::Number::New(env, mRtcPeerConnPtr->remoteMaxMessageSize());
1033+
return Napi::Array::New(env, mRtcPeerConnPtr->remoteMaxMessageSize());
1034+
}
1035+
catch (std::exception &ex)
1036+
{
1037+
Napi::Error::New(env, std::string("libdatachannel error: ") + ex.what()).ThrowAsJavaScriptException();
1038+
return Napi::Number::New(info.Env(), 0);
1039+
}
1040+
}
1041+
1042+
Napi::Value PeerConnectionWrapper::remoteFingerprint(const Napi::CallbackInfo &info)
1043+
{
1044+
PLOG_DEBUG << "remoteFingerprints() called";
1045+
Napi::Env env = info.Env();
1046+
1047+
if (!mRtcPeerConnPtr)
1048+
{
1049+
return Napi::Number::New(info.Env(), 0);
1050+
}
1051+
1052+
try
1053+
{
1054+
auto fingerprint = mRtcPeerConnPtr->remoteFingerprint();
1055+
1056+
Napi::Object fingerprintObject = Napi::Object::New(env);
1057+
fingerprintObject.Set("value", fingerprint.value);
1058+
fingerprintObject.Set("algorithm", rtc::CertificateFingerprint::AlgorithmIdentifier(fingerprint.algorithm));
1059+
1060+
return fingerprintObject;
10061061
}
10071062
catch (std::exception &ex)
10081063
{

src/cpp/peer-connection-wrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class PeerConnectionWrapper : public Napi::ObjectWrap<PeerConnectionWrapper>
3333
Napi::Value iceState(const Napi::CallbackInfo &info);
3434
Napi::Value signalingState(const Napi::CallbackInfo &info);
3535
Napi::Value gatheringState(const Napi::CallbackInfo &info);
36+
Napi::Value remoteFingerprint(const Napi::CallbackInfo &info);
3637

3738
// Callbacks
3839
void onLocalDescription(const Napi::CallbackInfo &info);

0 commit comments

Comments
 (0)