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.
pull/3425/head
paweldomas 6 years ago committed by Любомир Маринов
parent d10d61fb7a
commit 6dea107bcd
  1. 28
      conference.js
  2. 16
      react/features/base/conference/actions.js
  3. 64
      react/features/base/conference/functions.js

@ -31,14 +31,16 @@ import EventEmitter from 'events';
import { import {
AVATAR_ID_COMMAND, AVATAR_ID_COMMAND,
AVATAR_URL_COMMAND, AVATAR_URL_COMMAND,
EMAIL_COMMAND,
authStatusChanged, authStatusChanged,
commonUserJoinedHandling,
commonUserLeftHandling,
conferenceFailed, conferenceFailed,
conferenceJoined, conferenceJoined,
conferenceLeft, conferenceLeft,
conferenceWillJoin, conferenceWillJoin,
conferenceWillLeave, conferenceWillLeave,
dataChannelOpened, dataChannelOpened,
EMAIL_COMMAND,
lockStateChanged, lockStateChanged,
onStartMutedPolicyChanged, onStartMutedPolicyChanged,
p2pStatusChanged, p2pStatusChanged,
@ -75,14 +77,10 @@ import {
getAvatarURLByParticipantId, getAvatarURLByParticipantId,
getLocalParticipant, getLocalParticipant,
getParticipantById, getParticipantById,
hiddenParticipantJoined,
hiddenParticipantLeft,
localParticipantConnectionStatusChanged, localParticipantConnectionStatusChanged,
localParticipantRoleChanged, localParticipantRoleChanged,
MAX_DISPLAY_NAME_LENGTH, MAX_DISPLAY_NAME_LENGTH,
participantConnectionStatusChanged, participantConnectionStatusChanged,
participantJoined,
participantLeft,
participantPresenceChanged, participantPresenceChanged,
participantRoleChanged, participantRoleChanged,
participantUpdated participantUpdated
@ -1694,22 +1692,14 @@ export default {
room.on(JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED, room.on(JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
user => APP.UI.onUserFeaturesChanged(user)); user => APP.UI.onUserFeaturesChanged(user));
room.on(JitsiConferenceEvents.USER_JOINED, (id, 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()) { if (user.isHidden()) {
APP.store.dispatch(hiddenParticipantJoined(id, displayName));
return; return;
} }
APP.store.dispatch(participantJoined({ const displayName = user.getDisplayName();
botType: user.getBotType(),
conference: room,
id,
name: displayName,
presence: user.getStatus(),
role: user.getRole()
}));
logger.log(`USER ${id} connnected:`, user); logger.log(`USER ${id} connnected:`, user);
APP.API.notifyUserJoined(id, { APP.API.notifyUserJoined(id, {
@ -1724,13 +1714,13 @@ export default {
}); });
room.on(JitsiConferenceEvents.USER_LEFT, (id, user) => { room.on(JitsiConferenceEvents.USER_LEFT, (id, user) => {
if (user.isHidden()) { // The logic shared between RN and web.
APP.store.dispatch(hiddenParticipantLeft(id)); commonUserLeftHandling(APP.store, room, user);
if (user.isHidden()) {
return; return;
} }
APP.store.dispatch(participantLeft(id, room));
logger.log(`USER ${id} LEFT:`, user); logger.log(`USER ${id} LEFT:`, user);
APP.API.notifyUserLeft(id); APP.API.notifyUserLeft(id);
APP.UI.messageHandler.participantNotification( APP.UI.messageHandler.participantNotification(

@ -13,8 +13,6 @@ import {
MAX_DISPLAY_NAME_LENGTH, MAX_DISPLAY_NAME_LENGTH,
dominantSpeakerChanged, dominantSpeakerChanged,
participantConnectionStatusChanged, participantConnectionStatusChanged,
participantJoined,
participantLeft,
participantPresenceChanged, participantPresenceChanged,
participantRoleChanged, participantRoleChanged,
participantUpdated participantUpdated
@ -52,6 +50,8 @@ import {
} from './constants'; } from './constants';
import { import {
_addLocalTracksToConference, _addLocalTracksToConference,
commonUserJoinedHandling,
commonUserLeftHandling,
getCurrentConference, getCurrentConference,
sendLocalParticipant sendLocalParticipant
} from './functions'; } from './functions';
@ -143,18 +143,10 @@ function _addConferenceListeners(conference, dispatch) {
conference.on( conference.on(
JitsiConferenceEvents.USER_JOINED, JitsiConferenceEvents.USER_JOINED,
(id, user) => !user.isHidden() && dispatch(participantJoined({ (id, user) => commonUserJoinedHandling({ dispatch }, conference, user));
botType: user.getBotType(),
conference,
id,
name: user.getDisplayName(),
presence: user.getStatus(),
role: user.getRole()
})));
conference.on( conference.on(
JitsiConferenceEvents.USER_LEFT, JitsiConferenceEvents.USER_LEFT,
(id, user) => !user.isHidden() (id, user) => commonUserLeftHandling({ dispatch }, conference, user));
&& dispatch(participantLeft(id, conference)));
conference.on( conference.on(
JitsiConferenceEvents.USER_ROLE_CHANGED, JitsiConferenceEvents.USER_ROLE_CHANGED,
(...args) => dispatch(participantRoleChanged(...args))); (...args) => dispatch(participantRoleChanged(...args)));

@ -1,7 +1,13 @@
// @flow // @flow
import { JitsiTrackErrors } from '../lib-jitsi-meet'; import { JitsiTrackErrors } from '../lib-jitsi-meet';
import { getLocalParticipant } from '../participants'; import {
getLocalParticipant,
hiddenParticipantJoined,
hiddenParticipantLeft,
participantJoined,
participantLeft
} from '../participants';
import { toState } from '../redux'; import { toState } from '../redux';
import { import {
@ -44,6 +50,62 @@ export function _addLocalTracksToConference(
return Promise.all(promises); 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 * Evaluates a specific predicate for each {@link JitsiConference} known to the
* redux state features/base/conference while it returns {@code true}. * redux state features/base/conference while it returns {@code true}.

Loading…
Cancel
Save