mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 15:15:28 +00:00
Implemented getSelectedCandidatePair() for libjuice
This commit is contained in:
2
deps/libjuice
vendored
2
deps/libjuice
vendored
Submodule deps/libjuice updated: 92fc9e7a9d...6942c8b521
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user