Skip to content

Commit 4eb035b

Browse files
author
Yuqi Huang
committed
Add fallback method to log selected ICE candidate pairs when getSelectedCandidatePair() is not supported
1 parent d6ef207 commit 4eb035b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

examples/app.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,39 @@ async function printPeerConnectionStateInfo(event, logPrefix, remoteClientId) {
469469
console.debug(`Chosen candidate pair (${trackType || 'unknown'}):`, iceTransport.getSelectedCandidatePair());
470470
iceTransport.onselectedcandidatepairchange = logSelectedCandidate;
471471
logSelectedCandidate();
472+
} else {
473+
// Find nominated candidate pair
474+
const nominatedPair = Array.from(stats.values()).find(report =>
475+
report.type === 'candidate-pair' &&
476+
report.nominated === true
477+
);
478+
479+
if (nominatedPair) {
480+
// Get local and remote candidate detailsl;
481+
const localCandidate = stats.get(nominatedPair.localCandidateId);
482+
const remoteCandidate = stats.get(nominatedPair.remoteCandidateId);
483+
484+
if (localCandidate && remoteCandidate) {
485+
console.debug(`Chosen candidate pair (${trackType || 'unknown'}):`, {
486+
local: {
487+
id: localCandidate.id,
488+
address: localCandidate.address,
489+
port: localCandidate.port,
490+
type: localCandidate.candidateType,
491+
protocol: localCandidate.protocol,
492+
priority: localCandidate.priority
493+
},
494+
remote: {
495+
id: remoteCandidate.id,
496+
address: remoteCandidate.address,
497+
port: remoteCandidate.port,
498+
type: remoteCandidate.candidateType,
499+
protocol: remoteCandidate.protocol,
500+
priority: remoteCandidate.priority
501+
}
502+
});
503+
}
504+
}
472505
}
473506
} else {
474507
console.error('Failed to fetch the candidate pair!');

0 commit comments

Comments
 (0)