openvidu-browser: WebRtcStats get selected ice candidate info

pull/73/head
pabloFuente 2018-06-11 13:19:52 +02:00
parent 75332533b2
commit a4ecd3677d
1 changed files with 44 additions and 5 deletions

View File

@ -18,7 +18,6 @@
// tslint:disable:no-string-literal
import { Stream } from '../../OpenVidu/Stream';
import * as adapter from 'webrtc-adapter';
import platform = require('platform');
export class WebRtcStats {
@ -94,6 +93,41 @@ export class WebRtcStats {
}
}
public getSelectedIceCandidateInfo(): Promise<any> {
return new Promise((resolve, reject) => {
this.getStatsAgnostic(this.stream.getRTCPeerConnection(),
(stats) => {
if (platform.name!.indexOf('Chrome') !== -1) {
let localCandidateId, remoteCandidateId, googCandidatePair;
const localCandidates = {};
const remoteCandidates = {};
for (const key in stats) {
const stat = stats[key];
if (stat.type === 'localcandidate') {
localCandidates[stat.id] = stat;
} else if (stat.type === 'remotecandidate') {
remoteCandidates[stat.id] = stat;
} else if (stat.type === 'googCandidatePair' && (stat.googActiveConnection === 'true')) {
googCandidatePair = stat;
localCandidateId = stat.localCandidateId;
remoteCandidateId = stat.remoteCandidateId;
}
}
resolve({
googCandidatePair,
localCandidate: localCandidates[localCandidateId],
remoteCandidate: remoteCandidates[remoteCandidateId]
});
} else {
reject('Selected ICE candidate info only available for Chrome');
}
},
(error) => {
reject(error);
});
});
}
private sendStatsToHttpEndpoint(instrumentation): void {
const sendPost = (json) => {
@ -306,12 +340,17 @@ export class WebRtcStats {
}
private standardizeReport(response) {
console.log(response);
const standardReport = {};
if (platform.name!.indexOf('Firefox') !== -1) {
Object.keys(response).forEach(key => {
console.log(response[key]);
});
return response;
}
const standardReport = {};
response.result().forEach((report) => {
response.result().forEach(report => {
const standardStats = {
id: report.id,
timestamp: report.timestamp,
@ -329,10 +368,10 @@ export class WebRtcStats {
private getStatsAgnostic(pc, successCb, failureCb) {
if (platform.name!.indexOf('Firefox') !== -1) {
// getStats takes args in different order in Chrome and Firefox
return pc.getStats(null, (response) => {
return pc.getStats(null).then(response => {
const report = this.standardizeReport(response);
successCb(report);
}, failureCb);
}).catch(failureCb);
} else if (platform.name!.indexOf('Chrome') !== -1) {
// In Chrome, the first two arguments are reversed
return pc.getStats((response) => {