ref(stats): do not modify stats object from lib

This is more of a principle change than a necessary one.
In lib-jitsi-meet, when a getStats call finishes, the
stats are processed and first emitted (and received by
jitsi-meet) and then processed again for sending to
remote participants. Modifying the stats in place changes
the structure of stats before the second processing,
which maybe be unexpected.
This commit is contained in:
Leonard Kim 2017-09-29 18:35:23 -07:00
parent cfe4564ab3
commit eb1a44f5ba
1 changed files with 7 additions and 8 deletions

View File

@ -108,20 +108,19 @@ const statsEmitter = {
* @returns {void} * @returns {void}
*/ */
_onStatsUpdated(currentUserId, stats) { _onStatsUpdated(currentUserId, stats) {
const allUserFramerates = stats.framerate; const allUserFramerates = stats.framerate || {};
const allUserResolutions = stats.resolution; const allUserResolutions = stats.resolution || {};
const currentUserFramerate = allUserFramerates[currentUserId];
const currentUserResolution = allUserResolutions[currentUserId];
// FIXME resolution and framerate are hashes keyed off of user ids with // FIXME resolution and framerate are hashes keyed off of user ids with
// stat values. Receivers of stats expect resolution and framerate to // stat values. Receivers of stats expect resolution and framerate to
// be primatives, not hashes, so overwrites the 'lib-jitsi-meet' stats // be primatives, not hashes, so overwrites the 'lib-jitsi-meet' stats
// objects. // objects.
stats.framerate = currentUserFramerate; const modifiedLocalStats = Object.assign({}, stats, {
stats.resolution = currentUserResolution; framerate: allUserFramerates[currentUserId],
resolution: allUserResolutions[currentUserId]
});
this._emitStatsUpdate(currentUserId, stats); this._emitStatsUpdate(currentUserId, modifiedLocalStats);
// Get all the unique user ids from the framerate and resolution stats // Get all the unique user ids from the framerate and resolution stats
// and update remote user stats as needed. // and update remote user stats as needed.