From 8cd2bd272be96f96303027328d888ca24a6e201c Mon Sep 17 00:00:00 2001 From: Lyubo Marinov Date: Tue, 22 May 2018 17:41:53 -0500 Subject: [PATCH] Reduce direct read access to the features/base/participants redux state As part of the work on fixing the problem with the multiplying thumbnails, we've associated remote participant w/ JitsiConference. However, there are periods of time when multiple JitsiConferences are in the redux state (and that period is going to be shorted by StateListenerRegistry). In order to give more control to the feature base/participants, reduce the occurrences of direct access to the features/base/participants redux state and utilize the feature's existing read access functions. Which will allow us in the future to enhance these functions to access participants which are relevant to the current conference of interest to the user only. --- .../components/ParticipantView.native.js | 5 +---- react/features/base/participants/functions.js | 11 ++++------- .../conference/components/Conference.native.js | 4 ++-- react/features/filmstrip/functions.js | 10 ++++++---- .../invite/components/InfoDialogButton.web.js | 8 ++++---- react/features/invite/middleware.any.js | 14 ++++++-------- .../presence-status/components/PresenceLabel.js | 4 +--- .../components/RemoteControlAuthorizationDialog.js | 5 +---- .../components/WelcomePageSideBar.native.js | 6 +++--- 9 files changed, 28 insertions(+), 39 deletions(-) diff --git a/react/features/base/participants/components/ParticipantView.native.js b/react/features/base/participants/components/ParticipantView.native.js index 3e9394b0c..21908aa5d 100644 --- a/react/features/base/participants/components/ParticipantView.native.js +++ b/react/features/base/participants/components/ParticipantView.native.js @@ -313,10 +313,7 @@ function _toBoolean(value, undefinedValue) { */ function _mapStateToProps(state, ownProps) { const { participantId } = ownProps; - const participant - = getParticipantById( - state['features/base/participants'], - participantId); + const participant = getParticipantById(state, participantId); let avatar; let connectionStatus; let participantName; diff --git a/react/features/base/participants/functions.js b/react/features/base/participants/functions.js index 33fdda0c4..f602aa2a1 100644 --- a/react/features/base/participants/functions.js +++ b/react/features/base/participants/functions.js @@ -240,11 +240,8 @@ export function isLocalParticipantModerator(stateful: Object | Function) { return false; } - const isModerator = localParticipant.role === PARTICIPANT_ROLE.MODERATOR; - - if (state['features/base/config'].enableUserRolesBasedOnToken) { - return isModerator && !state['features/base/jwt'].isGuest; - } - - return isModerator; + return ( + localParticipant.role === PARTICIPANT_ROLE.MODERATOR + && (!state['features/base/config'].enableUserRolesBasedOnToken + || !state['features/base/jwt'].isGuest)); } diff --git a/react/features/conference/components/Conference.native.js b/react/features/conference/components/Conference.native.js index c26b90d2b..00f3d2538 100644 --- a/react/features/conference/components/Conference.native.js +++ b/react/features/conference/components/Conference.native.js @@ -10,6 +10,7 @@ import { appNavigate } from '../../app'; import { connect, disconnect } from '../../base/connection'; import { DialogContainer } from '../../base/dialog'; import { CalleeInfoContainer } from '../../base/jwt'; +import { getParticipantCount } from '../../base/participants'; import { Container, LoadingIndicator, TintedView } from '../../base/react'; import { TestConnectionInfo } from '../../base/testing'; import { createDesiredLocalTracks } from '../../base/tracks'; @@ -383,7 +384,6 @@ function _mapStateToProps(state) { const { connecting, connection } = state['features/base/connection']; const { conference, joining, leaving } = state['features/base/conference']; const { reducedUI } = state['features/base/responsive-ui']; - const participants = state['features/base/participants']; // XXX There is a window of time between the successful establishment of the // XMPP connection and the subsequent commencement of joining the MUC during @@ -415,7 +415,7 @@ function _mapStateToProps(state) { * @private * @type {number} */ - _participantCount: participants.length, + _participantCount: getParticipantCount(state), /** * The indicator which determines whether the UI is reduced (to diff --git a/react/features/filmstrip/functions.js b/react/features/filmstrip/functions.js index 8656e4d69..d250f9cad 100644 --- a/react/features/filmstrip/functions.js +++ b/react/features/filmstrip/functions.js @@ -1,6 +1,9 @@ // @flow -import { getPinnedParticipant } from '../base/participants'; +import { + getParticipantCount, + getPinnedParticipant +} from '../base/participants'; declare var interfaceConfig: Object; @@ -13,8 +16,7 @@ declare var interfaceConfig: Object; * in the filmstrip, then {@code true}; otherwise, {@code false}. */ export function shouldRemoteVideosBeVisible(state: Object) { - const participants = state['features/base/participants']; - const participantCount = participants.length; + const participantCount = getParticipantCount(state); let pinnedParticipant; return Boolean( @@ -26,7 +28,7 @@ export function shouldRemoteVideosBeVisible(state: Object) { || (participantCount > 1 && (state['features/filmstrip'].hovered || state['features/toolbox'].visible - || ((pinnedParticipant = getPinnedParticipant(participants)) + || ((pinnedParticipant = getPinnedParticipant(state)) && pinnedParticipant.local))) || (typeof interfaceConfig === 'object' diff --git a/react/features/invite/components/InfoDialogButton.web.js b/react/features/invite/components/InfoDialogButton.web.js index 30c1f785a..0df0acb4b 100644 --- a/react/features/invite/components/InfoDialogButton.web.js +++ b/react/features/invite/components/InfoDialogButton.web.js @@ -236,10 +236,10 @@ function _mapStateToProps(state) { return { _dialIn: state['features/invite'], _disableAutoShow: state['features/base/config'].iAmRecorder, - _liveStreamViewURL: currentLiveStreamingSession - && currentLiveStreamingSession.liveStreamViewURL, - _participantCount: - getParticipantCount(state['features/base/participants']), + _liveStreamViewURL: + currentLiveStreamingSession + && currentLiveStreamingSession.liveStreamViewURL, + _participantCount: getParticipantCount(state), _toolboxVisible: state['features/toolbox'].visible }; } diff --git a/react/features/invite/middleware.any.js b/react/features/invite/middleware.any.js index a83061ca9..d51c3b3da 100644 --- a/react/features/invite/middleware.any.js +++ b/react/features/invite/middleware.any.js @@ -118,15 +118,13 @@ MiddlewareRegistry.register(store => next => action => { * @returns {string} - The presence status. */ function _getParticipantPresence(state, id) { - if (!id) { - return undefined; - } - const participants = state['features/base/participants']; - const participantById = getParticipantById(participants, id); + if (id) { + const participantById = getParticipantById(state, id); - if (!participantById) { - return undefined; + if (participantById) { + return participantById.presence; + } } - return participantById.presence; + return undefined; } diff --git a/react/features/presence-status/components/PresenceLabel.js b/react/features/presence-status/components/PresenceLabel.js index 5282da3b1..0140d2079 100644 --- a/react/features/presence-status/components/PresenceLabel.js +++ b/react/features/presence-status/components/PresenceLabel.js @@ -99,9 +99,7 @@ class PresenceLabel extends Component { * }} */ function _mapStateToProps(state, ownProps) { - const participant - = getParticipantById( - state['features/base/participants'], ownProps.participantID); + const participant = getParticipantById(state, ownProps.participantID); return { _presence: participant && participant.presence diff --git a/react/features/remote-control/components/RemoteControlAuthorizationDialog.js b/react/features/remote-control/components/RemoteControlAuthorizationDialog.js index 8bda33bca..77e5b39b7 100644 --- a/react/features/remote-control/components/RemoteControlAuthorizationDialog.js +++ b/react/features/remote-control/components/RemoteControlAuthorizationDialog.js @@ -159,10 +159,7 @@ class RemoteControlAuthorizationDialog extends Component<*> { */ function _mapStateToProps(state, ownProps) { const { _displayName, participantId } = ownProps; - const participant - = getParticipantById( - state['features/base/participants'], - participantId); + const participant = getParticipantById(state, participantId); return { _displayName: participant ? participant.name : _displayName diff --git a/react/features/welcome/components/WelcomePageSideBar.native.js b/react/features/welcome/components/WelcomePageSideBar.native.js index be75282c5..c76a10ef3 100644 --- a/react/features/welcome/components/WelcomePageSideBar.native.js +++ b/react/features/welcome/components/WelcomePageSideBar.native.js @@ -156,11 +156,11 @@ class WelcomePageSideBar extends Component { * @returns {Object} */ function _mapStateToProps(state: Object) { - const _localParticipant = getLocalParticipant(state); + const localParticipant = getLocalParticipant(state); return { - _avatar: getAvatarURL(_localParticipant), - _displayName: getParticipantDisplayName(state, _localParticipant.id), + _avatar: getAvatarURL(localParticipant), + _displayName: getParticipantDisplayName(state, localParticipant.id), _visible: state['features/welcome'].sideBarVisible }; }