openvidu-testapp: RTCIceCandidate stats for publisher and subscriber peer connections

master
pabloFuente 2025-07-09 18:23:48 +02:00
parent 91aa127dad
commit d44e24592d
1 changed files with 68 additions and 10 deletions

View File

@ -1205,6 +1205,7 @@ export class OpenviduInstanceComponent {
const sub: PCTransport = this.getSubscriberPC()!;
return JSON.stringify(
{
PCTransports: {
publisher: {
connectedAddress: await pub.getConnectedAddress(),
connectionState: pub.getConnectionState(),
@ -1218,6 +1219,11 @@ export class OpenviduInstanceComponent {
signallingState: sub.getSignallingState(),
},
},
RTCIceCandidateStats: {
publisher: await this.getPublisherRTCIceCandidateStats(),
subscriber: await this.getSubscriberRTCIceCandidateStats(),
},
},
null,
2
);
@ -1238,4 +1244,56 @@ export class OpenviduInstanceComponent {
getSubscriberPC(): PCTransport | undefined {
return this.room?.localParticipant.engine.pcManager?.subscriber;
}
async getPublisherRTCIceCandidateStats() {
return this.getRTCIceCandidateStats(this.getPublisherPC()!);
}
async getSubscriberRTCIceCandidateStats() {
return this.getRTCIceCandidateStats(this.getSubscriberPC()!);
}
async getRTCIceCandidateStats(pcTransport: PCTransport) {
return new Promise(async (resolve) => {
let selectedCandidatePairId: string = '';
const stats: any = await new Promise((res) => {
const reports_stats: any[] = [];
pcTransport.getStats().then((stats: any) => {
stats.forEach((report: any) => {
if (report.type === 'transport') {
if (report.selectedCandidatePairId) {
selectedCandidatePairId = report.selectedCandidatePairId;
}
}
if (report.type === 'candidate-pair') {
console.log('Candidate Pair Report:', report);
const report_stats_object = {
report: report,
stats: stats,
};
reports_stats.push(report_stats_object);
}
});
return res(reports_stats);
});
});
const selectedCandidates = [] as any[];
for (const report_stats_object of stats) {
if (report_stats_object.report.id === selectedCandidatePairId) {
selectedCandidates.push(
report_stats_object.stats.get(
report_stats_object.report.localCandidateId
)
);
console.log(
'Selected Candidate:',
report_stats_object.stats.get(
report_stats_object.report.localCandidateId
)
);
}
}
return resolve(selectedCandidates);
});
}
}