Merge branch 'master' of https://github.com/bigbluebutton/bigbluebutton into bbb-2x-mconf

This commit is contained in:
Richard Alam 2017-05-08 08:51:31 -07:00
commit 44e3fb8a07
6 changed files with 143 additions and 204 deletions

View File

@ -1,9 +1,5 @@
var monitoredTracks = {}; var monitoredTracks = {};
function isFirefox() {
return typeof mozRTCPeerConnection !== 'undefined';
}
function arrayAverage(array) { function arrayAverage(array) {
var sum = 0; var sum = 0;
for( var i = 0; i < array.length; i++ ){ for( var i = 0; i < array.length; i++ ){
@ -22,180 +18,138 @@ function customGetStats(peer, mediaStreamTrack, callback, interval) {
var nomore = false; var nomore = false;
(function getPrivateStats() { (function getPrivateStats() {
var promise = _getStats(peer, mediaStreamTrack); var promise;
try {
promise = peer.getStats(mediaStreamTrack);
} catch (e) {
promise = Promise.reject(e);
}
promise.then(function(results) { promise.then(function(results) {
var result = {
audio: {}, var inbound = {};
//video: {}, var outbound = {};
// TODO remove the raw results var localCandidate = {};
results: results, var remoteCandidate = {};
nomore: function() {
nomore = true; results.forEach(function(res) {
if ((res.type == 'outbound-rtp' || res.type == 'outboundrtp') && res.mediaType == 'audio') {
outbound = res;
} }
}; if ((res.type == 'inbound-rtp' || res.type == 'inboundrtp') && res.mediaType == 'audio') {
inbound = res;
for (var key in results) { }
var res = results[key]; if (res.type == 'ssrc' && res.mediaType == 'audio') {
if (typeof (res.audioInputLevel) !== 'undefined') {
res.timestamp = typeof res.timestamp === 'object'? res.timestamp.getTime(): res.timestamp; inbound = res;
res.packetsLost = typeof res.packetsLost === 'string'? parseInt(res.packetsLost): res.packetsLost; outbound = res;
res.packetsReceived = typeof res.packetsReceived === 'string'? parseInt(res.packetsReceived): res.packetsReceived; res.packetsSent = parseInt(res.packetsSent);
res.bytesReceived = typeof res.bytesReceived === 'string'? parseInt(res.bytesReceived): res.bytesReceived; res.bytesSent = parseInt(res.bytesSent);
res.packetsLost = parseInt(res.packetsLost);
if ((res.mediaType == 'audio' || (res.type == 'ssrc' && res.googCodecName == 'opus')) && typeof res.bytesSent !== 'undefined') { res.jitter = parseInt(res.googJitterReceived) / 1000;
if (typeof globalObject.audio.prevSent === 'undefined') { res.packetsReceived = res.packetsSent - res.packetsLost;
globalObject.audio.prevSent = res; }
}
if ((res.type == 'candidate-pair' && res.selected) ||
(res.type == 'googCandidatePair' && res.googActiveConnection == "true")) {
localCandidate = results[res.localCandidateId];
remoteCandidate = results[res.remoteCandidateId];
} }
var bytes = res.bytesSent - globalObject.audio.prevSent.bytesSent;
var diffTimestamp = res.timestamp - globalObject.audio.prevSent.timestamp;
var kilobytes = bytes / 1024;
var kbitsSentPerSecond = (kilobytes * 8) / (diffTimestamp / 1000.0);
result.audio = merge(result.audio, {
availableBandwidth: kilobytes,
inputLevel: res.audioInputLevel,
packetsSent: res.packetsSent,
bytesSent: res.bytesSent,
kbitsSentPerSecond: kbitsSentPerSecond
}); });
/*
globalObject.audio.prevSent = res; console.log("Inbound:");
console.log(inbound);
console.log("Outbound:");
console.log(outbound);
*/
var audioStats = {
inboundTimestamp: inbound.timestamp,
packetsReceived: inbound.packetsReceived,
bytesReceived: inbound.bytesReceived,
packetsLost: inbound.packetsLost,
jitter: inbound.jitter,
outboundTimestamp: outbound.timestamp,
packetsSent: outbound.packetsSent,
bytesSent: outbound.bytesSent,
};
if (typeof globalObject.audio.statsArray === 'undefined') {
globalObject.audio.statsArray = [];
globalObject.audio.haveStats = false;
} }
if ((res.mediaType == 'audio' || (res.type == 'ssrc' && res.googCodecName == 'opus')) && typeof res.bytesReceived !== 'undefined') { var statsArray = globalObject.audio.statsArray;
if (typeof globalObject.audio.prevReceived === 'undefined') { statsArray.push(audioStats);
globalObject.audio.prevReceived = res; while (statsArray.length > 12) {
globalObject.audio.consecutiveFlaws = 0; statsArray.shift();
globalObject.audio.globalBitrateArray = [ ];
} }
var intervalPacketsLost = res.packetsLost - globalObject.audio.prevReceived.packetsLost; var firstAudioStats = statsArray[0];
var intervalPacketsReceived = res.packetsReceived - globalObject.audio.prevReceived.packetsReceived; var lastAudioStats = statsArray[statsArray.length - 1];
var intervalBytesReceived = res.bytesReceived - globalObject.audio.prevReceived.bytesReceived;
var intervalLossRate = intervalPacketsLost + intervalPacketsReceived == 0? 1: intervalPacketsLost / (intervalPacketsLost + intervalPacketsReceived); var intervalPacketsLost = lastAudioStats.packetsLost - firstAudioStats.packetsLost;
var intervalBitrate = (intervalBytesReceived / interval) * 8; var intervalPacketsReceived = lastAudioStats.packetsReceived - firstAudioStats.packetsReceived;
var globalBitrate = arrayAverage(globalObject.audio.globalBitrateArray); var intervalPacketsSent = lastAudioStats.packetsSent - firstAudioStats.packetsSent;
var intervalEstimatedLossRate; var intervalBytesReceived = lastAudioStats.bytesReceived - firstAudioStats.bytesReceived;
if (isFirefox()) { var intervalBytesSent = lastAudioStats.bytesSent - firstAudioStats.bytesSent;
intervalEstimatedLossRate = Math.max(0, globalBitrate - intervalBitrate) / globalBitrate;
var receivedInterval = lastAudioStats.inboundTimestamp - firstAudioStats.inboundTimestamp;
var sentInterval = lastAudioStats.outboundTimestamp - firstAudioStats.outboundTimestamp;
var kbitsReceivedPerSecond = intervalBytesReceived * 8 / receivedInterval;
var kbitsSentPerSecond = intervalBytesSent * 8 / sentInterval;
var packetDuration = intervalPacketsSent / sentInterval * 1000;
var r = undefined, mos = undefined;
if (isNaN(intervalPacketsLost) && !globalObject.audio.haveStats) {
r = 100;
} else { } else {
intervalEstimatedLossRate = intervalLossRate; globalObject.audio.haveStats = true;
} r = (Math.max(0, intervalPacketsReceived - intervalPacketsLost) / intervalPacketsReceived) * 100;
var flaws = intervalPacketsLost;
if (flaws > 0) {
if (globalObject.audio.consecutiveFlaws > 0) {
flaws *= 2;
}
++globalObject.audio.consecutiveFlaws;
} else {
globalObject.audio.consecutiveFlaws = 0;
}
var packetsLost = res.packetsLost + flaws;
var r = (Math.max(0, res.packetsReceived - packetsLost) / res.packetsReceived) * 100;
if (r > 100) { if (r > 100) {
r = 100; r = 100;
} }
// https://freeswitch.org/stash/projects/FS/repos/freeswitch/browse/src/switch_rtp.c?at=refs%2Fheads%2Fv1.4#1671 }
var mos = 1 + (0.035) * r + (0.000007) * r * (r-60) * (100-r); mos = 1 + (0.035) * r + (0.000007) * r * (r-60) * (100-r);
var bytes = res.bytesReceived - globalObject.audio.prevReceived.bytesReceived; var intervalLossRate = 1 - (r / 100);
var diffTimestamp = res.timestamp - globalObject.audio.prevReceived.timestamp; console.log("Interval loss rate: " + intervalLossRate);
var packetDuration = diffTimestamp / (res.packetsReceived - globalObject.audio.prevReceived.packetsReceived); console.log("MOS: " + mos);
var kilobytes = bytes / 1024;
var kbitsReceivedPerSecond = (kilobytes * 8) / (diffTimestamp / 1000.0);
result.audio = merge(result.audio, { result = {
availableBandwidth: kilobytes, audio: {
outputLevel: res.audioOutputLevel, availableBandwidth: undefined,
packetsLost: res.packetsLost, bytesReceived: audioStats.bytesReceived,
jitter: typeof res.googJitterReceived !== 'undefined'? res.googJitterReceived: res.jitter, bytesSent: audioStats.bytesSent,
jitterBuffer: res.googJitterBufferMs, delay: undefined,
delay: res.googCurrentDelayMs, globalBitrate: undefined,
packetsReceived: res.packetsReceived, inputLevel: undefined,
bytesReceived: res.bytesReceived, intervalEstimatedLossRate: intervalLossRate,
kbitsReceivedPerSecond: kbitsReceivedPerSecond,
packetDuration: packetDuration,
r: r,
mos: mos,
intervalLossRate: intervalLossRate, intervalLossRate: intervalLossRate,
intervalEstimatedLossRate: intervalEstimatedLossRate, jitter: audioStats.jitter,
globalBitrate: globalBitrate jitterBuffer: undefined,
}); kbitsReceivedPerSecond: kbitsReceivedPerSecond,
kbitsSentPerSecond: kbitsSentPerSecond,
globalObject.audio.prevReceived = res; mos: mos,
globalObject.audio.globalBitrateArray.push(intervalBitrate); outputLevel: undefined,
// 12 is the number of seconds we use to calculate the global bitrate packetDuration: packetDuration,
if (globalObject.audio.globalBitrateArray.length > 12 / (interval / 1000)) { packetsLost: audioStats.packetsLost,
globalObject.audio.globalBitrateArray.shift(); packetsReceived: audioStats.packetsReceived,
} packetsSent: audioStats.packetsSent,
} r: r,
},
/* video: {},
// TODO make it work on Firefox connectionType: {
if (res.googCodecName == 'VP8') {
if (!globalObject.video.prevBytesSent)
globalObject.video.prevBytesSent = res.bytesSent;
var bytes = res.bytesSent - globalObject.video.prevBytesSent;
globalObject.video.prevBytesSent = res.bytesSent;
var kilobytes = bytes / 1024;
result.video = merge(result.video, {
availableBandwidth: kilobytes.toFixed(1),
googFrameHeightInput: res.googFrameHeightInput,
googFrameWidthInput: res.googFrameWidthInput,
googCaptureQueueDelayMsPerS: res.googCaptureQueueDelayMsPerS,
rtt: res.googRtt,
packetsLost: res.packetsLost,
packetsSent: res.packetsSent,
googEncodeUsagePercent: res.googEncodeUsagePercent,
googCpuLimitedResolution: res.googCpuLimitedResolution,
googNacksReceived: res.googNacksReceived,
googFrameRateInput: res.googFrameRateInput,
googPlisReceived: res.googPlisReceived,
googViewLimitedResolution: res.googViewLimitedResolution,
googCaptureJitterMs: res.googCaptureJitterMs,
googAvgEncodeMs: res.googAvgEncodeMs,
googFrameHeightSent: res.googFrameHeightSent,
googFrameRateSent: res.googFrameRateSent,
googBandwidthLimitedResolution: res.googBandwidthLimitedResolution,
googFrameWidthSent: res.googFrameWidthSent,
googFirsReceived: res.googFirsReceived,
bytesSent: res.bytesSent
});
}
if (res.type == 'VideoBwe') {
result.video.bandwidth = {
googActualEncBitrate: res.googActualEncBitrate,
googAvailableSendBandwidth: res.googAvailableSendBandwidth,
googAvailableReceiveBandwidth: res.googAvailableReceiveBandwidth,
googRetransmitBitrate: res.googRetransmitBitrate,
googTargetEncBitrate: res.googTargetEncBitrate,
googBucketDelay: res.googBucketDelay,
googTransmitBitrate: res.googTransmitBitrate
};
}
*/
// res.googActiveConnection means either STUN or TURN is used.
if (res.type == 'googCandidatePair' && res.googActiveConnection == 'true') {
result.connectionType = {
local: { local: {
candidateType: res.googLocalCandidateType, candidateType: localCandidate.candidateType,
ipAddress: res.googLocalAddress ipAddress: localCandidate.ipAddress,
transport: localCandidate.transport,
}, },
remote: { remote: {
candidateType: res.googRemoteCandidateType, candidateType: remoteCandidate.candidateType,
ipAddress: res.googRemoteAddress ipAddress: remoteCandidate.ipAddress,
transport: remoteCandidate.transport,
}, },
transport: res.googTransportType transport: localCandidate.transport
}; },
} nomore: function() { nomore = true; }
} }
callback(result); callback(result);
@ -210,29 +164,6 @@ function customGetStats(peer, mediaStreamTrack, callback, interval) {
}); });
})(); })();
// taken from http://blog.telenor.io/webrtc/2015/06/11/getstats-chrome-vs-firefox.html
function _getStats(pc, selector) {
if (navigator.mozGetUserMedia) {
return pc.getStats(selector);
}
return new Promise(function(resolve, reject) {
pc.getStats(function(response) {
var standardReport = {};
response.result().forEach(function(report) {
var standardStats = {
id: report.id,
timestamp: report.timestamp,
type: report.type
};
report.names().forEach(function(name) {
standardStats[name] = report.stat(name);
});
standardReport[standardStats.id] = standardStats;
});
resolve(standardReport);
}, selector, reject);
});
}
} }
function merge(mergein, mergeto) { function merge(mergein, mergeto) {
@ -246,7 +177,8 @@ function merge(mergein, mergeto) {
} }
function monitorTrackStart(peer, track, local) { function monitorTrackStart(peer, track, local) {
if (! monitoredTracks.hasOwnProperty(track.id)) { console.log("Starting stats monitoring on " + track.id);
if (!monitoredTracks[track.id]) {
monitoredTracks[track.id] = function() { console.log("Still didn't have any report for this track"); }; monitoredTracks[track.id] = function() { console.log("Still didn't have any report for this track"); };
customGetStats( customGetStats(
peer, peer,
@ -257,7 +189,6 @@ function monitorTrackStart(peer, track, local) {
} else { } else {
monitoredTracks[track.id] = results.nomore; monitoredTracks[track.id] = results.nomore;
results.audio.type = local? "local": "remote", results.audio.type = local? "local": "remote",
delete results.results;
BBB.webRTCMonitorUpdate(JSON.stringify(results)); BBB.webRTCMonitorUpdate(JSON.stringify(results));
console.log(JSON.stringify(results)); console.log(JSON.stringify(results));
} }
@ -270,9 +201,13 @@ function monitorTrackStart(peer, track, local) {
} }
function monitorTrackStop(trackId) { function monitorTrackStop(trackId) {
if (typeof (monitoredTracks[trackId]) === "function") {
monitoredTracks[trackId](); monitoredTracks[trackId]();
delete monitoredTracks[trackId]; delete monitoredTracks[trackId];
console.log("Track removed, monitoredTracks.length = " + Object.keys(monitoredTracks).length); console.log("Track removed, monitoredTracks.length = " + Object.keys(monitoredTracks).length);
} else {
console.log("Track is not monitored");
}
} }
function monitorTracksStart() { function monitorTracksStart() {
@ -289,12 +224,12 @@ function monitorTracksStart() {
monitorTrackStart(peer, track, true); monitorTrackStart(peer, track, true);
} }
} }
for (var streamId = 0; streamId < peer.getRemoteStreams().length; ++streamId) { /*for (var streamId = 0; streamId < peer.getRemoteStreams().length; ++streamId) {
for (var trackId = 0; trackId < peer.getRemoteStreams()[streamId].getAudioTracks().length; ++trackId) { for (var trackId = 0; trackId < peer.getRemoteStreams()[streamId].getAudioTracks().length; ++trackId) {
var track = peer.getRemoteStreams()[streamId].getAudioTracks()[trackId]; var track = peer.getRemoteStreams()[streamId].getAudioTracks()[trackId];
monitorTrackStart(peer, track, false); monitorTrackStart(peer, track, false);
} }
} }*/
}, 2000); }, 2000);
} }

View File

@ -1,16 +1,16 @@
import { getVoiceBridge } from '/imports/ui/components/audio/service';
import BaseAudioBridge from './base'; import BaseAudioBridge from './base';
export default class VertoBridge extends BaseAudioBridge { export default class VertoBridge extends BaseAudioBridge {
constructor(userData) { constructor(userData) {
super(); super();
const { const {
userId,
username, username,
voiceBridge, voiceBridge,
} = userData; } = userData;
this.voiceBridge = voiceBridge; this.voiceBridge = voiceBridge;
this.vertoUsername = 'FreeSWITCH User - ' + encodeURIComponent(username); this.vertoUsername = `${userId}-bbbID-${username}`;
} }
exitAudio(listenOnly) { exitAudio(listenOnly) {

View File

@ -6,6 +6,8 @@ import Storage from '/imports/ui/services/storage/session';
import Users from '/imports/api/users'; import Users from '/imports/api/users';
import { makeCall } from '/imports/ui/services/api'; import { makeCall } from '/imports/ui/services/api';
const CONNECTION_TIMEOUT = Meteor.settings.public.app.connectionTimeout;
class Auth { class Auth {
constructor() { constructor() {
this._meetingID = Storage.getItem('meetingID'); this._meetingID = Storage.getItem('meetingID');
@ -133,7 +135,7 @@ class Auth {
error: 500, error: 500,
description: 'Authentication timeout.', description: 'Authentication timeout.',
}); });
}, 5000); }, CONNECTION_TIMEOUT);
const didValidate = () => { const didValidate = () => {
this.loggedIn = true; this.loggedIn = true;

View File

@ -2,3 +2,4 @@
app: app:
# Flag for HTTPS. # Flag for HTTPS.
httpsConnection: false httpsConnection: false
connectionTimeout: 60000

View File

@ -2,3 +2,4 @@
app: app:
# Flag for HTTPS. # Flag for HTTPS.
httpsConnection: true httpsConnection: true
connectionTimeout: 5000