Fixes review comments.

Uses some ES6 syntax. Also removes inputHeight key for resolution as it makes no sence to have dictionary with one key. Removes some code duplication. Makes code consistent: method params for updateLocalStats and updateRemoteStats.
This commit is contained in:
damencho 2016-10-13 14:57:54 -05:00
parent a2c71d05e6
commit bbe475cb4e
4 changed files with 70 additions and 74 deletions

View File

@ -1373,7 +1373,11 @@ export default {
room.on(ConferenceEvents.CONNECTION_STATS, function (stats) { room.on(ConferenceEvents.CONNECTION_STATS, function (stats) {
ConnectionQuality.updateLocalStats( ConnectionQuality.updateLocalStats(
stats, connectionIsInterrupted, localVideo); stats,
connectionIsInterrupted,
localVideo.videoType,
localVideo.isMuted(),
localVideo.resolution);
}); });
ConnectionQuality.addListener(CQEvents.LOCALSTATS_UPDATED, ConnectionQuality.addListener(CQEvents.LOCALSTATS_UPDATED,
@ -1384,9 +1388,7 @@ export default {
bitrate: stats.bitrate, bitrate: stats.bitrate,
packetLoss: stats.packetLoss}; packetLoss: stats.packetLoss};
if (localVideo && localVideo.resolution) { if (localVideo && localVideo.resolution) {
data.resolution = { data.resolution = localVideo.resolution;
inputHeight: localVideo.resolution
};
} }
try { try {
@ -1402,12 +1404,13 @@ export default {
(participant, payload) => { (participant, payload) => {
switch(payload.type) { switch(payload.type) {
case this.commands.defaults.CONNECTION_QUALITY: { case this.commands.defaults.CONNECTION_QUALITY: {
let id = participant.getId(); let remoteVideo = participant.getTracks()
.find(tr => tr.isVideoTrack());
ConnectionQuality.updateRemoteStats( ConnectionQuality.updateRemoteStats(
id, participant.getId(),
payload.values, payload.values,
APP.UI.getRemoteVideoType(id), remoteVideo ? remoteVideo.videoType : undefined,
APP.UI.isRemoteVideoMuted(id)); remoteVideo ? remoteVideo.isMuted() : undefined);
break; break;
} }
default: default:

View File

@ -779,15 +779,6 @@ UI.getRemoteVideoType = function (jid) {
return VideoLayout.getRemoteVideoType(jid); return VideoLayout.getRemoteVideoType(jid);
}; };
/**
* Return the mute state of the remote video.
* @param jid the jid for the remote video
* @returns the video mute state.
*/
UI.isRemoteVideoMuted = function (jid) {
return VideoLayout.isRemoteVideoMuted(jid);
};
UI.connectionIndicatorShowMore = function(id) { UI.connectionIndicatorShowMore = function(id) {
VideoLayout.showMore(id); VideoLayout.showMore(id);
}; };

View File

@ -327,16 +327,6 @@ var VideoLayout = {
return smallVideo ? smallVideo.getVideoType() : null; return smallVideo ? smallVideo.getVideoType() : null;
}, },
/**
* Return the mute state of the remote video.
* @param id the id for the remote video
* @returns {boolean} the video mute state.
*/
isRemoteVideoMuted (id) {
let smallVideo = VideoLayout.getSmallVideo(id);
return smallVideo ? smallVideo.isVideoMuted : null;
},
isPinned (id) { isPinned (id) {
return (pinnedId) ? (id === pinnedId) : false; return (pinnedId) ? (id === pinnedId) : false;
}, },

View File

@ -38,7 +38,7 @@ function calculateQuality(newVal, oldVal) {
// webrtc table describing simulcast resolutions and used bandwidth // webrtc table describing simulcast resolutions and used bandwidth
// https://chromium.googlesource.com/external/webrtc/+/master/webrtc/media/engine/simulcast.cc#42 // https://chromium.googlesource.com/external/webrtc/+/master/webrtc/media/engine/simulcast.cc#42
var _bandwidthMap = [ const _bandwidthMap = [
{ width: 1920, height: 1080, layers:3, max: 5000, min: 800 }, { width: 1920, height: 1080, layers:3, max: 5000, min: 800 },
{ width: 1280, height: 720, layers:3, max: 2500, min: 600 }, { width: 1280, height: 720, layers:3, max: 2500, min: 600 },
{ width: 960, height: 540, layers:3, max: 900, min: 450 }, { width: 960, height: 540, layers:3, max: 900, min: 450 },
@ -52,7 +52,7 @@ var _bandwidthMap = [
* or enable it in case of no simulcast and we force it. * or enable it in case of no simulcast and we force it.
* @type {boolean} * @type {boolean}
*/ */
var disableQualityBasedOnBandwidth = const disableQualityBasedOnBandwidth =
config.forceQualityBasedOnBandwidth ? false : config.disableSimulcast; config.forceQualityBasedOnBandwidth ? false : config.disableSimulcast;
/** /**
@ -61,23 +61,17 @@ var disableQualityBasedOnBandwidth =
* _bandwidthMap. * _bandwidthMap.
* @param inputHeight the resolution used to open the camera. * @param inputHeight the resolution used to open the camera.
* @param upload the upload rate reported by client. * @param upload the upload rate reported by client.
* @returns {*} the percent of upload based on _bandwidthMap and maximum value * @returns {int} the percent of upload based on _bandwidthMap and maximum value
* of 100, as values of the map are approximate and clients can stream above * of 100, as values of the map are approximate and clients can stream above
* those values. * those values. Returns undefined if no result is found.
*/ */
function calculateQualityUsingUpload(inputHeight, upload) { function calculateQualityUsingUpload(inputHeight, upload) {
let foundResolution = null; // found resolution from _bandwidthMap which height is equal or less than
// the inputHeight
for (let i in _bandwidthMap) { let foundResolution = _bandwidthMap.find((r) => (r.height <= inputHeight));
let r = _bandwidthMap[i];
if (r.height <= inputHeight) {
foundResolution = r;
break;
}
}
if (!foundResolution) if (!foundResolution)
return false; return undefined;
if (upload <= foundResolution.min) if (upload <= foundResolution.min)
return 0; return 0;
@ -94,26 +88,23 @@ export default {
* @param data new statistics * @param data new statistics
* @param dontUpdateLocalConnectionQuality {boolean} if true - * @param dontUpdateLocalConnectionQuality {boolean} if true -
* localConnectionQuality wont be recalculated. * localConnectionQuality wont be recalculated.
* @param videoType the local video type
* @param isMuted current state of local video, whether it is muted
* @param resolution the current resolution used by local video
*/ */
updateLocalStats: updateLocalStats:
function (data, dontUpdateLocalConnectionQuality, localVideo) { function (data, dontUpdateLocalConnectionQuality,
videoType, isMuted, resolution) {
stats = data; stats = data;
if(!dontUpdateLocalConnectionQuality) { if(!dontUpdateLocalConnectionQuality) {
if (!disableQualityBasedOnBandwidth let val = this._getNewQualityValue(
&& !localVideo.isMuted() stats,
&& localVideo.videoType !== 'desktop' localConnectionQuality,
&& localVideo.resolution) { videoType,
let val = calculateQualityUsingUpload( isMuted,
localVideo.resolution, resolution);
data.bitrate.upload); if (val !== undefined)
if (val) { localConnectionQuality = val;
localConnectionQuality = val;
}
} else {
var newVal = 100 - stats.packetLoss.total;
localConnectionQuality =
calculateQuality(newVal, localConnectionQuality);
}
} }
eventEmitter.emit( eventEmitter.emit(
CQEvents.LOCALSTATS_UPDATED, localConnectionQuality, stats); CQEvents.LOCALSTATS_UPDATED, localConnectionQuality, stats);
@ -132,7 +123,9 @@ export default {
/** /**
* Updates remote statistics * Updates remote statistics
* @param id the id associated with the statistics * @param id the id associated with the statistics
* @param data the statistics * @param data the statistics received
* @param remoteVideoType the video type of the remote video
* @param isRemoteVideoMuted whether remote video is muted
*/ */
updateRemoteStats: updateRemoteStats:
function (id, data, remoteVideoType, isRemoteVideoMuted) { function (id, data, remoteVideoType, isRemoteVideoMuted) {
@ -149,28 +142,47 @@ export default {
remoteStats[id] = data; remoteStats[id] = data;
if (disableQualityBasedOnBandwidth let val = this._getNewQualityValue(
|| isRemoteVideoMuted data,
|| remoteVideoType === 'desktop' remoteConnectionQuality[id],
|| !inputResolution) { remoteVideoType,
var newVal = 100 - data.packetLoss.total; isRemoteVideoMuted,
var oldVal = remoteConnectionQuality[id]; inputResolution);
remoteConnectionQuality[id] if (val !== undefined)
= calculateQuality(newVal, oldVal || 100); remoteConnectionQuality[id] = val;
} else {
let val = calculateQualityUsingUpload(
inputResolution.inputHeight,
data.bitrate.upload);
if (val) {
remoteConnectionQuality[id] = val;
}
}
eventEmitter.emit( eventEmitter.emit(
CQEvents.REMOTESTATS_UPDATED, id, CQEvents.REMOTESTATS_UPDATED, id,
remoteConnectionQuality[id], remoteStats[id]); remoteConnectionQuality[id], remoteStats[id]);
}, },
/**
* Returns the new quality value based on the input parameters.
* Used to calculate remote and local values.
* @param data the data
* @param lastQualityValue the last value we calculated
* @param videoType need to check whether we are screen sharing
* @param isMuted is video muted
* @param resolution the input resolution used by the camera
* @returns {*} the newly calculated value or undefined if no result
* @private
*/
_getNewQualityValue:
function (data, lastQualityValue, videoType, isMuted, resolution) {
if (disableQualityBasedOnBandwidth
|| isMuted
|| videoType === 'desktop'
|| !resolution) {
return calculateQuality(
100 - data.packetLoss.total,
lastQualityValue || 100);
} else {
return calculateQualityUsingUpload(
resolution,
data.bitrate.upload);
}
},
/** /**
* Returns the local statistics. * Returns the local statistics.
*/ */