From 6dea107bcd910020a7111dfdbe8ba0fc3f422bbb Mon Sep 17 00:00:00 2001 From: paweldomas Date: Thu, 16 Aug 2018 10:11:06 -0500 Subject: [PATCH] ref(conference.js): unify "user joined/left" handling on web and RN Extracts methods which share the common logic. There are still some leftovers on the web side left which are not used on RN. But this can be a first step. --- conference.js | 28 +++------ react/features/base/conference/actions.js | 16 ++---- react/features/base/conference/functions.js | 64 ++++++++++++++++++++- 3 files changed, 76 insertions(+), 32 deletions(-) diff --git a/conference.js b/conference.js index a54bc1acc..528848592 100644 --- a/conference.js +++ b/conference.js @@ -31,14 +31,16 @@ import EventEmitter from 'events'; import { AVATAR_ID_COMMAND, AVATAR_URL_COMMAND, + EMAIL_COMMAND, authStatusChanged, + commonUserJoinedHandling, + commonUserLeftHandling, conferenceFailed, conferenceJoined, conferenceLeft, conferenceWillJoin, conferenceWillLeave, dataChannelOpened, - EMAIL_COMMAND, lockStateChanged, onStartMutedPolicyChanged, p2pStatusChanged, @@ -75,14 +77,10 @@ import { getAvatarURLByParticipantId, getLocalParticipant, getParticipantById, - hiddenParticipantJoined, - hiddenParticipantLeft, localParticipantConnectionStatusChanged, localParticipantRoleChanged, MAX_DISPLAY_NAME_LENGTH, participantConnectionStatusChanged, - participantJoined, - participantLeft, participantPresenceChanged, participantRoleChanged, participantUpdated @@ -1694,22 +1692,14 @@ export default { room.on(JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED, user => APP.UI.onUserFeaturesChanged(user)); room.on(JitsiConferenceEvents.USER_JOINED, (id, user) => { - const displayName = user.getDisplayName(); + // The logic shared between RN and web. + commonUserJoinedHandling(APP.store, room, user); if (user.isHidden()) { - APP.store.dispatch(hiddenParticipantJoined(id, displayName)); - return; } - APP.store.dispatch(participantJoined({ - botType: user.getBotType(), - conference: room, - id, - name: displayName, - presence: user.getStatus(), - role: user.getRole() - })); + const displayName = user.getDisplayName(); logger.log(`USER ${id} connnected:`, user); APP.API.notifyUserJoined(id, { @@ -1724,13 +1714,13 @@ export default { }); room.on(JitsiConferenceEvents.USER_LEFT, (id, user) => { - if (user.isHidden()) { - APP.store.dispatch(hiddenParticipantLeft(id)); + // The logic shared between RN and web. + commonUserLeftHandling(APP.store, room, user); + if (user.isHidden()) { return; } - APP.store.dispatch(participantLeft(id, room)); logger.log(`USER ${id} LEFT:`, user); APP.API.notifyUserLeft(id); APP.UI.messageHandler.participantNotification( diff --git a/react/features/base/conference/actions.js b/react/features/base/conference/actions.js index 5f976f99a..d6deb1ce5 100644 --- a/react/features/base/conference/actions.js +++ b/react/features/base/conference/actions.js @@ -13,8 +13,6 @@ import { MAX_DISPLAY_NAME_LENGTH, dominantSpeakerChanged, participantConnectionStatusChanged, - participantJoined, - participantLeft, participantPresenceChanged, participantRoleChanged, participantUpdated @@ -52,6 +50,8 @@ import { } from './constants'; import { _addLocalTracksToConference, + commonUserJoinedHandling, + commonUserLeftHandling, getCurrentConference, sendLocalParticipant } from './functions'; @@ -143,18 +143,10 @@ function _addConferenceListeners(conference, dispatch) { conference.on( JitsiConferenceEvents.USER_JOINED, - (id, user) => !user.isHidden() && dispatch(participantJoined({ - botType: user.getBotType(), - conference, - id, - name: user.getDisplayName(), - presence: user.getStatus(), - role: user.getRole() - }))); + (id, user) => commonUserJoinedHandling({ dispatch }, conference, user)); conference.on( JitsiConferenceEvents.USER_LEFT, - (id, user) => !user.isHidden() - && dispatch(participantLeft(id, conference))); + (id, user) => commonUserLeftHandling({ dispatch }, conference, user)); conference.on( JitsiConferenceEvents.USER_ROLE_CHANGED, (...args) => dispatch(participantRoleChanged(...args))); diff --git a/react/features/base/conference/functions.js b/react/features/base/conference/functions.js index fd0692539..48417d5a6 100644 --- a/react/features/base/conference/functions.js +++ b/react/features/base/conference/functions.js @@ -1,7 +1,13 @@ // @flow import { JitsiTrackErrors } from '../lib-jitsi-meet'; -import { getLocalParticipant } from '../participants'; +import { + getLocalParticipant, + hiddenParticipantJoined, + hiddenParticipantLeft, + participantJoined, + participantLeft +} from '../participants'; import { toState } from '../redux'; import { @@ -44,6 +50,62 @@ export function _addLocalTracksToConference( return Promise.all(promises); } +/** + * Logic shared between web and RN which processes the {@code USER_JOINED} + * conference event and dispatches either {@link participantJoined} or + * {@link hiddenParticipantJoined}. + * + * @param {Object} store - The redux store. + * @param {JitsiMeetConference} conference - The conference for which the + * {@code USER_JOINED} event is being processed. + * @param {JitsiParticipant} user - The user who has just joined. + * @returns {void} + */ +export function commonUserJoinedHandling( + { dispatch }: Object, + conference: Object, + user: Object) { + const id = user.getId(); + const displayName = user.getDisplayName(); + + if (user.isHidden()) { + dispatch(hiddenParticipantJoined(id, displayName)); + } else { + dispatch(participantJoined({ + botType: user.getBotType(), + conference, + id, + name: displayName, + presence: user.getStatus(), + role: user.getRole() + })); + } +} + +/** + * Logic shared between web and RN which processes the {@code USER_LEFT} + * conference event and dispatches either {@link participantLeft} or + * {@link hiddenParticipantLeft}. + * + * @param {Object} store - The redux store. + * @param {JitsiMeetConference} conference - The conference for which the + * {@code USER_LEFT} event is being processed. + * @param {JitsiParticipant} user - The user who has just left. + * @returns {void} + */ +export function commonUserLeftHandling( + { dispatch }: Object, + conference: Object, + user: Object) { + const id = user.getId(); + + if (user.isHidden()) { + dispatch(hiddenParticipantLeft(id)); + } else { + dispatch(participantLeft(id, conference)); + } +} + /** * Evaluates a specific predicate for each {@link JitsiConference} known to the * redux state features/base/conference while it returns {@code true}.