2017-10-13 19:31:05 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-04-22 22:57:08 +00:00
|
|
|
import { ReducerRegistry, set } from '../redux';
|
2017-02-28 23:12:02 +00:00
|
|
|
import { randomHexString } from '../util';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
DOMINANT_SPEAKER_CHANGED,
|
|
|
|
PARTICIPANT_ID_CHANGED,
|
|
|
|
PARTICIPANT_JOINED,
|
|
|
|
PARTICIPANT_LEFT,
|
|
|
|
PARTICIPANT_UPDATED,
|
|
|
|
PIN_PARTICIPANT
|
|
|
|
} from './actionTypes';
|
2017-10-18 18:15:49 +00:00
|
|
|
import { LOCAL_PARTICIPANT_DEFAULT_ID, PARTICIPANT_ROLE } from './constants';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Participant object.
|
|
|
|
* @typedef {Object} Participant
|
|
|
|
* @property {string} id - Participant ID.
|
|
|
|
* @property {string} name - Participant name.
|
|
|
|
* @property {string} avatar - Path to participant avatar if any.
|
|
|
|
* @property {string} role - Participant role.
|
|
|
|
* @property {boolean} local - If true, participant is local.
|
|
|
|
* @property {boolean} pinned - If true, participant is currently a
|
|
|
|
* "PINNED_ENDPOINT".
|
2016-11-04 18:28:47 +00:00
|
|
|
* @property {boolean} dominantSpeaker - If this participant is the dominant
|
2017-10-01 06:35:19 +00:00
|
|
|
* speaker in the (associated) conference, {@code true}; otherwise,
|
|
|
|
* {@code false}.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @property {string} email - Participant email.
|
|
|
|
*/
|
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* These properties should not be bulk assigned when updating a particular
|
|
|
|
* @see Participant.
|
|
|
|
* @type {string[]}
|
|
|
|
*/
|
|
|
|
const PARTICIPANT_PROPS_TO_OMIT_WHEN_UPDATE
|
2016-11-04 18:28:47 +00:00
|
|
|
= [ 'dominantSpeaker', 'id', 'local', 'pinned' ];
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducer function for a single participant.
|
|
|
|
*
|
|
|
|
* @param {Participant|undefined} state - Participant to be modified.
|
|
|
|
* @param {Object} action - Action object.
|
|
|
|
* @param {string} action.type - Type of action.
|
|
|
|
* @param {Participant} action.participant - Information about participant to be
|
|
|
|
* added/modified.
|
|
|
|
* @param {JitsiConference} action.conference - Conference instance.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2017-10-13 19:31:05 +00:00
|
|
|
* @returns {Participant}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-10-13 19:31:05 +00:00
|
|
|
function _participant(state: Object = {}, action) {
|
2016-10-05 14:36:59 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case DOMINANT_SPEAKER_CHANGED:
|
|
|
|
// Only one dominant speaker is allowed.
|
2016-11-04 18:28:47 +00:00
|
|
|
return (
|
2017-04-22 22:57:08 +00:00
|
|
|
set(state, 'dominantSpeaker', state.id === action.participant.id));
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
case PARTICIPANT_ID_CHANGED:
|
|
|
|
if (state.id === action.oldValue) {
|
2017-02-28 23:12:02 +00:00
|
|
|
return {
|
2016-10-05 14:36:59 +00:00
|
|
|
...state,
|
2017-02-28 23:12:02 +00:00
|
|
|
id: action.newValue
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
2016-11-04 18:28:47 +00:00
|
|
|
break;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
case PARTICIPANT_JOINED: {
|
2017-10-18 18:21:46 +00:00
|
|
|
const { participant } = action; // eslint-disable-line no-shadow
|
2017-03-29 09:26:46 +00:00
|
|
|
const {
|
|
|
|
avatarURL,
|
2017-04-05 09:01:57 +00:00
|
|
|
connectionStatus,
|
2017-03-29 09:26:46 +00:00
|
|
|
dominantSpeaker,
|
|
|
|
email,
|
2017-06-27 22:56:55 +00:00
|
|
|
isBot,
|
2017-03-29 09:26:46 +00:00
|
|
|
local,
|
2017-10-18 18:15:49 +00:00
|
|
|
name,
|
2017-03-29 09:26:46 +00:00
|
|
|
pinned,
|
|
|
|
role
|
|
|
|
} = participant;
|
2017-10-18 18:15:49 +00:00
|
|
|
let { avatarID, id } = participant;
|
2017-02-28 23:12:02 +00:00
|
|
|
|
|
|
|
// avatarID
|
|
|
|
//
|
|
|
|
// TODO Get the avatarID of the local participant from localStorage.
|
|
|
|
if (!avatarID && local) {
|
|
|
|
avatarID = randomHexString(32);
|
|
|
|
}
|
2017-03-07 16:50:17 +00:00
|
|
|
|
|
|
|
// id
|
|
|
|
//
|
2016-10-05 14:36:59 +00:00
|
|
|
// XXX The situation of not having an ID for a remote participant should
|
|
|
|
// not happen. Maybe we should raise an error in this case or generate a
|
|
|
|
// random ID.
|
2017-03-07 16:50:17 +00:00
|
|
|
if (!id && local) {
|
|
|
|
id = LOCAL_PARTICIPANT_DEFAULT_ID;
|
|
|
|
}
|
|
|
|
|
2017-02-28 23:12:02 +00:00
|
|
|
return {
|
|
|
|
avatarID,
|
|
|
|
avatarURL,
|
2017-04-05 09:01:57 +00:00
|
|
|
connectionStatus,
|
2017-03-07 16:50:17 +00:00
|
|
|
dominantSpeaker: dominantSpeaker || false,
|
2017-02-27 21:42:28 +00:00
|
|
|
email,
|
2016-10-05 14:36:59 +00:00
|
|
|
id,
|
2017-06-27 22:56:55 +00:00
|
|
|
isBot,
|
2017-03-07 16:50:17 +00:00
|
|
|
local: local || false,
|
2016-10-05 14:36:59 +00:00
|
|
|
name,
|
2017-03-07 16:50:17 +00:00
|
|
|
pinned: pinned || false,
|
|
|
|
role: role || PARTICIPANT_ROLE.NONE
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-07 16:50:17 +00:00
|
|
|
case PARTICIPANT_UPDATED: {
|
2017-10-18 18:21:46 +00:00
|
|
|
const { participant } = action; // eslint-disable-line no-shadow
|
2017-03-23 18:01:33 +00:00
|
|
|
let { id } = participant;
|
2017-10-18 18:21:46 +00:00
|
|
|
const { local } = participant;
|
2017-03-23 18:01:33 +00:00
|
|
|
|
|
|
|
if (!id && local) {
|
|
|
|
id = LOCAL_PARTICIPANT_DEFAULT_ID;
|
|
|
|
}
|
2017-03-07 16:50:17 +00:00
|
|
|
|
|
|
|
if (state.id === id) {
|
2016-10-05 14:36:59 +00:00
|
|
|
const newState = { ...state };
|
|
|
|
|
2017-03-07 16:50:17 +00:00
|
|
|
for (const key in participant) {
|
|
|
|
if (participant.hasOwnProperty(key)
|
2016-10-05 14:36:59 +00:00
|
|
|
&& PARTICIPANT_PROPS_TO_OMIT_WHEN_UPDATE.indexOf(key)
|
|
|
|
=== -1) {
|
2017-03-07 16:50:17 +00:00
|
|
|
newState[key] = participant[key];
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newState;
|
|
|
|
}
|
2016-11-04 18:28:47 +00:00
|
|
|
break;
|
2017-03-07 16:50:17 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
case PIN_PARTICIPANT:
|
|
|
|
// Currently, only one pinned participant is allowed.
|
2017-04-22 22:57:08 +00:00
|
|
|
return set(state, 'pinned', state.id === action.participant.id);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
2016-11-04 18:28:47 +00:00
|
|
|
|
|
|
|
return state;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen for actions which add, remove, or update the set of participants in
|
|
|
|
* the conference.
|
|
|
|
*
|
|
|
|
* @param {Participant[]} state - List of participants to be modified.
|
|
|
|
* @param {Object} action - Action object.
|
|
|
|
* @param {string} action.type - Type of action.
|
|
|
|
* @param {Participant} action.participant - Information about participant to be
|
|
|
|
* added/removed/modified.
|
|
|
|
* @returns {Participant[]}
|
|
|
|
*/
|
|
|
|
ReducerRegistry.register('features/base/participants', (state = [], action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case DOMINANT_SPEAKER_CHANGED:
|
|
|
|
case PARTICIPANT_ID_CHANGED:
|
|
|
|
case PARTICIPANT_UPDATED:
|
|
|
|
case PIN_PARTICIPANT:
|
2017-01-28 23:28:13 +00:00
|
|
|
return state.map(p => _participant(p, action));
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
case PARTICIPANT_JOINED:
|
|
|
|
return [ ...state, _participant(undefined, action) ];
|
|
|
|
|
|
|
|
case PARTICIPANT_LEFT:
|
|
|
|
return state.filter(p => p.id !== action.participant.id);
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
});
|