Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass custom ICE ufrag and pwd as local description init #1207

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading