Skip to content

Commit

Permalink
feat: pass custom ICE ufrag and pwd as local description init
Browse files Browse the repository at this point in the history
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: paullouisageneau#1166
Refs: paullouisageneau#1201 (comment)
  • Loading branch information
achingbrain committed Jun 11, 2024
1 parent 541d646 commit ba4903f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion include/rtc/peerconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ struct RTC_CPP_EXPORT DataChannelInit {
string protocol = "";
};

struct RTC_CPP_EXPORT LocalDescriptionInit {
Description::Type type = Description::Type::Unspec;
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 +96,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
4 changes: 4 additions & 0 deletions src/impl/icetransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
addIceServer(server);
}

void IceTransport::setUfragAndPwd(string uFrag, string pwd) {
juice_set_local_ice_attributes(mAgent.get(), uFrag.c_str(), pwd.c_str());
}

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 setUfragAndPwd(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 ufrag/pwd";
iceTransport->setUfragAndPwd(init.iceUfrag.value(), init.iceUfrag.value());
}

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

Expand Down

0 comments on commit ba4903f

Please sign in to comment.