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.
This commit is contained in:
paweldomas 2018-08-16 10:11:06 -05:00 committed by Любомир Маринов
parent d10d61fb7a
commit 6dea107bcd
3 changed files with 76 additions and 32 deletions

View File

@ -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(

View File

@ -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)));

View File

@ -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}.