Skip to content

Commit ba4903f

Browse files
committed
feat: pass custom ICE ufrag and pwd as local description init
Adds an optional second argument to `rtc::PeerConnection::setLocalDescription` that can contain an ICE ufrag and pwd that if passed will be used in place of the randomly generated versions. Refs: #1166 Refs: #1201 (comment)
1 parent 541d646 commit ba4903f

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

include/rtc/peerconnection.hpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ struct RTC_CPP_EXPORT DataChannelInit {
3535
string protocol = "";
3636
};
3737

38+
struct RTC_CPP_EXPORT LocalDescriptionInit {
39+
Description::Type type = Description::Type::Unspec;
40+
optional<string> iceUfrag;
41+
optional<string> icePwd;
42+
};
43+
3844
class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
3945
public:
4046
enum class State : int {
@@ -90,7 +96,7 @@ class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
9096
uint16_t maxDataChannelId() const;
9197
bool getSelectedCandidatePair(Candidate *local, Candidate *remote);
9298

93-
void setLocalDescription(Description::Type type = Description::Type::Unspec);
99+
void setLocalDescription(Description::Type type = Description::Type::Unspec, LocalDescriptionInit init = {});
94100
void setRemoteDescription(Description description);
95101
void addRemoteCandidate(Candidate candidate);
96102
void gatherLocalCandidates(std::vector<IceServer> additionalIceServers = {});

src/impl/icetransport.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
140140
addIceServer(server);
141141
}
142142

143+
void IceTransport::setUfragAndPwd(string uFrag, string pwd) {
144+
juice_set_local_ice_attributes(mAgent.get(), uFrag.c_str(), pwd.c_str());
145+
}
146+
143147
void IceTransport::addIceServer(IceServer server) {
144148
if (server.hostname.empty())
145149
return;

src/impl/icetransport.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class IceTransport : public Transport {
5151
void setRemoteDescription(const Description &description);
5252
bool addRemoteCandidate(const Candidate &candidate);
5353
void gatherLocalCandidates(string mid, std::vector<IceServer> additionalIceServers = {});
54+
void setUfragAndPwd(string uFrag, string pwd);
5455

5556
optional<string> getLocalAddress() const;
5657
optional<string> getRemoteAddress() const;

src/peerconnection.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool PeerConnection::hasMedia() const {
7676
return local && local->hasAudioOrVideo();
7777
}
7878

79-
void PeerConnection::setLocalDescription(Description::Type type) {
79+
void PeerConnection::setLocalDescription(Description::Type type, LocalDescriptionInit init) {
8080
std::unique_lock signalingLock(impl()->signalingMutex);
8181
PLOG_VERBOSE << "Setting local description, type=" << Description::typeToString(type);
8282

@@ -140,6 +140,11 @@ void PeerConnection::setLocalDescription(Description::Type type) {
140140
if (!iceTransport)
141141
return; // closed
142142

143+
if (init.iceUfrag && init.icePwd) {
144+
PLOG_DEBUG << "Using custom ufrag/pwd";
145+
iceTransport->setUfragAndPwd(init.iceUfrag.value(), init.iceUfrag.value());
146+
}
147+
143148
Description local = iceTransport->getLocalDescription(type);
144149
impl()->processLocalDescription(std::move(local));
145150

0 commit comments

Comments
 (0)