Implemented getSelectedCandidatePair() for libjuice

This commit is contained in:
Paul-Louis Ageneau
2020-10-16 23:50:14 +02:00
parent 137d4e3e8e
commit 05b7141478
6 changed files with 40 additions and 15 deletions

2
deps/libjuice vendored

View File

@ -52,10 +52,12 @@ Candidate::Candidate(string candidate, string mid)
: mFamily(Family::Unresolved), mType(Type::Unknown), mTransportType(TransportType::Unknown),
mPort(0), mPriority(0) {
if (!candidate.empty()) {
const std::array prefixes{"a=", "candidate:"};
for (const string &prefix : prefixes)
if (hasprefix(candidate, prefix))
candidate.erase(0, prefix.size());
}
mCandidate = std::move(candidate);
mMid = std::move(mid);

View File

@ -187,6 +187,24 @@ std::optional<string> IceTransport::getRemoteAddress() const {
return nullopt;
}
bool IceTransport::getSelectedCandidatePair(Candidate *local, Candidate *remote) {
char sdpLocal[JUICE_MAX_CANDIDATE_SDP_STRING_LEN];
char sdpRemote[JUICE_MAX_CANDIDATE_SDP_STRING_LEN];
if (juice_get_selected_candidates(mAgent.get(), sdpLocal, JUICE_MAX_CANDIDATE_SDP_STRING_LEN,
sdpRemote, JUICE_MAX_CANDIDATE_SDP_STRING_LEN) == 0) {
if (local) {
*local = Candidate(sdpLocal);
local->resolve(Candidate::ResolveMode::Simple);
}
if (remote) {
*remote = Candidate(sdpRemote);
remote->resolve(Candidate::ResolveMode::Simple);
}
return true;
}
return false;
}
bool IceTransport::send(message_ptr message) {
auto s = state();
if (!message || (s != State::Connected && s != State::Completed))
@ -729,7 +747,9 @@ bool IceTransport::getSelectedCandidatePair(Candidate *local, Candidate *remote)
if(remote) *remote = Candidate(sdpRemote);
g_free(sdpRemote);
if (local)
local->resolve(Candidate::ResolveMode::Simple);
if (remote)
remote->resolve(Candidate::ResolveMode::Simple);
return true;
}

View File

@ -63,9 +63,7 @@ public:
bool stop() override;
bool send(message_ptr message) override; // false if dropped
#if USE_NICE
bool getSelectedCandidatePair(Candidate *local, Candidate *remote);
#endif
private:
bool outgoing(message_ptr message) override;

View File

@ -902,13 +902,8 @@ void PeerConnection::resetCallbacks() {
bool PeerConnection::getSelectedCandidatePair([[maybe_unused]] Candidate *local,
[[maybe_unused]] Candidate *remote) {
#if USE_NICE
auto iceTransport = std::atomic_load(&mIceTransport);
return iceTransport->getSelectedCandidatePair(local, remote);
#else
PLOG_WARNING << "getSelectedCandidatePair() is only implemented with libnice as ICE backend";
return false;
#endif
return iceTransport ? iceTransport->getSelectedCandidatePair(local, remote) : false;
}
void PeerConnection::clearStats() {

View File

@ -147,6 +147,16 @@ void test_connectivity() {
if (auto addr = pc2->remoteAddress())
cout << "Remote address 2: " << *addr << endl;
Candidate local, remote;
if(pc1->getSelectedCandidatePair(&local, &remote)) {
cout << "Local candidate 1: " << local << endl;
cout << "Remote candidate 1: " << remote << endl;
}
if(pc2->getSelectedCandidatePair(&local, &remote)) {
cout << "Local candidate 2: " << local << endl;
cout << "Remote candidate 2: " << remote << endl;
}
// Try to open a second data channel with another label
shared_ptr<DataChannel> second2;
pc2->onDataChannel([&second2](shared_ptr<DataChannel> dc) {