Skip to content

Commit

Permalink
Merge pull request #1207 from achingbrain/feat/allow-overriding-ice-u…
Browse files Browse the repository at this point in the history
…frag-and-pwd2

feat: pass custom ICE ufrag and pwd as local description init
  • Loading branch information
paullouisageneau authored Jun 14, 2024
2 parents d624c82 + f0432d1 commit 4261b4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion include/rtc/peerconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ struct RTC_CPP_EXPORT DataChannelInit {
string protocol = "";
};

struct RTC_CPP_EXPORT LocalDescriptionInit {
optional<string> iceUfrag;
optional<string> icePwd;
};

class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
public:
enum class State : int {
Expand Down Expand Up @@ -90,7 +95,7 @@ class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
uint16_t maxDataChannelId() const;
bool getSelectedCandidatePair(Candidate *local, Candidate *remote);

void setLocalDescription(Description::Type type = Description::Type::Unspec);
void setLocalDescription(Description::Type type = Description::Type::Unspec, LocalDescriptionInit init = {});
void setRemoteDescription(Description description);
void addRemoteCandidate(Candidate candidate);
void gatherLocalCandidates(std::vector<IceServer> additionalIceServers = {});
Expand Down
10 changes: 10 additions & 0 deletions src/impl/icetransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
addIceServer(server);
}

void IceTransport::setIceAttributes(string uFrag, string pwd) {
if (juice_set_local_ice_attributes(mAgent.get(), uFrag.c_str(), pwd.c_str()) < 0) {
throw std::invalid_argument("Invalid ICE attributes");
}
}

void IceTransport::addIceServer(IceServer server) {
if (server.hostname.empty())
return;
Expand Down Expand Up @@ -569,6 +575,10 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
RecvCallback, this);
}

void IceTransport::setIceAttributes([[maybe_unused]] string uFrag, [[maybe_unused]] string pwd) {
PLOG_WARNING << "Setting custom ICE attributes is not supported with libnice, please use libjuice";
}

void IceTransport::addIceServer(IceServer server) {
if (server.hostname.empty())
return;
Expand Down
1 change: 1 addition & 0 deletions src/impl/icetransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class IceTransport : public Transport {
void setRemoteDescription(const Description &description);
bool addRemoteCandidate(const Candidate &candidate);
void gatherLocalCandidates(string mid, std::vector<IceServer> additionalIceServers = {});
void setIceAttributes(string uFrag, string pwd);

optional<string> getLocalAddress() const;
optional<string> getRemoteAddress() const;
Expand Down
7 changes: 6 additions & 1 deletion src/peerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool PeerConnection::hasMedia() const {
return local && local->hasAudioOrVideo();
}

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

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

if (init.iceUfrag && init.icePwd) {
PLOG_DEBUG << "Using custom ICE attributes, ufrag=\"" << init.iceUfrag.value() << "\", pwd=\"" << init.icePwd.value() << "\"";
iceTransport->setIceAttributes(init.iceUfrag.value(), init.icePwd.value());
}

Description local = iceTransport->getLocalDescription(type);
impl()->processLocalDescription(std::move(local));

Expand Down

0 comments on commit 4261b4f

Please sign in to comment.