Skip to content

Commit 2181a3b

Browse files
committedJan 24, 2025
feat: allow specifying initial ice mode
Exposes the new parameter introduced in paullouisageneau/libjuice#294 Please see that PR for rationale.
1 parent 6fa7cff commit 2181a3b

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed
 

‎include/rtc/peerconnection.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct RTC_CPP_EXPORT DataChannelInit {
3838
struct RTC_CPP_EXPORT LocalDescriptionInit {
3939
optional<string> iceUfrag;
4040
optional<string> icePwd;
41+
optional<string> iceMode;
4142
};
4243

4344
class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {

‎src/impl/icetransport.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,16 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
140140
addIceServer(server);
141141
}
142142

143-
void IceTransport::setIceAttributes(string uFrag, string pwd) {
144-
if (juice_set_local_ice_attributes(mAgent.get(), uFrag.c_str(), pwd.c_str()) < 0) {
143+
void IceTransport::setIceAttributes(string uFrag, string pwd, string iceMode) {
144+
juice_ice_mode_t mode = JUICE_ICE_MODE_UNKNOWN;
145+
146+
if (iceMode.compare("controlling") == 0) {
147+
mode = JUICE_ICE_MODE_CONTROLLING;
148+
} else if (iceMode.compare("controlled") == 0) {
149+
mode = JUICE_ICE_MODE_CONTROLLED;
150+
}
151+
152+
if (juice_set_local_ice_attributes(mAgent.get(), uFrag.c_str(), pwd.c_str(), mode) < 0) {
145153
throw std::invalid_argument("Invalid ICE attributes");
146154
}
147155
}
@@ -584,7 +592,7 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
584592
RecvCallback, this);
585593
}
586594

587-
void IceTransport::setIceAttributes([[maybe_unused]] string uFrag, [[maybe_unused]] string pwd) {
595+
void IceTransport::setIceAttributes([[maybe_unused]] string uFrag, [[maybe_unused]] string pwd, [[maybe_unused]] string iceMode) {
588596
PLOG_WARNING << "Setting custom ICE attributes is not supported with libnice, please use libjuice";
589597
}
590598

‎src/impl/icetransport.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +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 setIceAttributes(string uFrag, string pwd);
54+
void setIceAttributes(string uFrag, string pwd, string iceMode);
5555

5656
optional<string> getLocalAddress() const;
5757
optional<string> getRemoteAddress() const;

‎src/peerconnection.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ void PeerConnection::setLocalDescription(Description::Type type, LocalDescriptio
140140
return; // closed
141141

142142
if (init.iceUfrag && init.icePwd) {
143-
PLOG_DEBUG << "Setting custom ICE attributes, ufrag=\"" << *init.iceUfrag << "\", pwd=\"" << *init.icePwd << "\"";
144-
iceTransport->setIceAttributes(*init.iceUfrag, *init.icePwd);
143+
string iceMode = (init.iceMode ? init.iceMode : "auto").value();
144+
145+
PLOG_DEBUG << "Setting custom ICE attributes, ufrag=\"" << *init.iceUfrag << "\", pwd=\"" << *init.icePwd << "\", iceMode=\"" << iceMode << "\"";
146+
iceTransport->setIceAttributes(*init.iceUfrag, *init.icePwd, iceMode);
145147
}
146148

147149
Description local = iceTransport->getLocalDescription(type);

0 commit comments

Comments
 (0)