fix stat unsub, one loop for updating

This commit is contained in:
Leonard Kim 2017-07-13 11:44:12 -07:00
parent 44bbd26c96
commit 2132cd6736
2 changed files with 18 additions and 12 deletions

View File

@ -168,7 +168,7 @@ class ConnectionIndicator extends Component {
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if (prevProps.userID !== this.props.userID) { if (prevProps.userID !== this.props.userID) {
statsEmitter.unsubscribeToClientStats( statsEmitter.unsubscribeToClientStats(
this.props.userID, this._onStatsUpdated); prevProps.userID, this._onStatsUpdated);
statsEmitter.subscribeToClientStats( statsEmitter.subscribeToClientStats(
this.props.userID, this._onStatsUpdated); this.props.userID, this._onStatsUpdated);
} }

View File

@ -1,3 +1,5 @@
import _ from 'lodash';
import JitsiMeetJS from '../base/lib-jitsi-meet'; import JitsiMeetJS from '../base/lib-jitsi-meet';
declare var APP: Object; declare var APP: Object;
@ -27,7 +29,7 @@ const statsEmitter = {
const { connectionQuality } = JitsiMeetJS.events; const { connectionQuality } = JitsiMeetJS.events;
conference.on(connectionQuality.LOCAL_STATS_UPDATED, conference.on(connectionQuality.LOCAL_STATS_UPDATED,
stats => this._onStatsUpdated(stats)); stats => this._onStatsUpdated(conference.myUserId(), stats));
conference.on(connectionQuality.REMOTE_STATS_UPDATED, conference.on(connectionQuality.REMOTE_STATS_UPDATED,
(id, stats) => this._emitStatsUpdate(id, stats)); (id, stats) => this._emitStatsUpdate(id, stats));
@ -100,15 +102,15 @@ const statsEmitter = {
* also update listeners of remote user stats of changes related to their * also update listeners of remote user stats of changes related to their
* stats. * stats.
* *
* @param {string} currentUserId - The user id for the local user.
* @param {Object} stats - Connection stats for the local user as provided * @param {Object} stats - Connection stats for the local user as provided
* by the library. * by the library.
* @returns {void} * @returns {void}
*/ */
_onStatsUpdated(stats) { _onStatsUpdated(currentUserId, stats) {
const allUserFramerates = stats.framerate; const allUserFramerates = stats.framerate;
const allUserResolutions = stats.resolution; const allUserResolutions = stats.resolution;
const currentUserId = APP.conference.getMyUserId();
const currentUserFramerate = allUserFramerates[currentUserId]; const currentUserFramerate = allUserFramerates[currentUserId];
const currentUserResolution = allUserResolutions[currentUserId]; const currentUserResolution = allUserResolutions[currentUserId];
@ -121,26 +123,30 @@ const statsEmitter = {
this._emitStatsUpdate(currentUserId, stats); this._emitStatsUpdate(currentUserId, stats);
Object.keys(allUserFramerates) // Get all the unique user ids from the framerate and resolution stats
// and update remote user stats as needed.
const framerateUserIds = Object.keys(allUserFramerates);
const resolutionUserIds = Object.keys(allUserResolutions);
_.union(framerateUserIds, resolutionUserIds)
.filter(id => id !== currentUserId) .filter(id => id !== currentUserId)
.forEach(id => { .forEach(id => {
const remoteUserStats = {};
const framerate = allUserFramerates[id]; const framerate = allUserFramerates[id];
if (framerate) { if (framerate) {
this._emitStatsUpdate(id, { framerate }); remoteUserStats.framerate = framerate;
} }
});
Object.keys(allUserResolutions)
.filter(id => id !== currentUserId)
.forEach(id => {
const resolution = allUserResolutions[id]; const resolution = allUserResolutions[id];
if (resolution) { if (resolution) {
this._emitStatsUpdate(id, { resolution }); remoteUserStats.resolution = resolution;
} }
});
this._emitStatsUpdate(id, remoteUserStats);
});
} }
}; };