2018-02-12 17:42:38 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
import { PARTICIPANT_JOINED, PARTICIPANT_LEFT } from '../base/participants';
|
2017-05-23 18:58:07 +00:00
|
|
|
import { ReducerRegistry } from '../base/redux';
|
2018-02-05 21:52:41 +00:00
|
|
|
|
2018-02-06 09:40:16 +00:00
|
|
|
import {
|
|
|
|
SET_FILMSTRIP_ENABLED,
|
2020-01-24 16:28:47 +00:00
|
|
|
SET_FILMSTRIP_VISIBLE,
|
|
|
|
SET_HORIZONTAL_VIEW_DIMENSIONS,
|
2021-03-26 20:23:05 +00:00
|
|
|
SET_TILE_VIEW_DIMENSIONS,
|
|
|
|
SET_VERTICAL_VIEW_DIMENSIONS,
|
2021-05-19 23:23:40 +00:00
|
|
|
SET_VISIBLE_REMOTE_PARTICIPANTS,
|
2021-03-26 20:23:05 +00:00
|
|
|
SET_VOLUME
|
2018-02-06 09:40:16 +00:00
|
|
|
} from './actionTypes';
|
2017-05-23 18:58:07 +00:00
|
|
|
|
|
|
|
const DEFAULT_STATE = {
|
2018-02-12 17:42:38 +00:00
|
|
|
/**
|
|
|
|
* The indicator which determines whether the {@link Filmstrip} is enabled.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2018-02-06 09:40:16 +00:00
|
|
|
enabled: true,
|
2018-02-12 17:42:38 +00:00
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
/**
|
|
|
|
* The horizontal view dimensions.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
horizontalViewDimensions: {},
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
/**
|
|
|
|
* The custom audio volume levels per perticipant.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
participantsVolume: {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ordered IDs of the remote participants displayed in the filmstrip.
|
|
|
|
*
|
|
|
|
* NOTE: Currently the order will match the one from the base/participants array. But this is good initial step for
|
|
|
|
* reordering the remote participants.
|
|
|
|
*/
|
|
|
|
remoteParticipants: [],
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
/**
|
|
|
|
* The tile view dimensions.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
tileViewDimensions: {},
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
/**
|
|
|
|
* The vertical view dimensions.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
verticalViewDimensions: {},
|
|
|
|
|
2018-02-12 17:42:38 +00:00
|
|
|
/**
|
|
|
|
* The indicator which determines whether the {@link Filmstrip} is visible.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2021-05-19 23:23:40 +00:00
|
|
|
visible: true,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The end index in the remote participants array that is visible in the filmstrip.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
visibleParticipantsEndIndex: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The visible participants in the filmstrip.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {Array<string>}
|
|
|
|
*/
|
|
|
|
visibleParticipants: [],
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The start index in the remote participants array that is visible in the filmstrip.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
visibleParticipantsStartIndex: 0
|
2017-05-23 18:58:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReducerRegistry.register(
|
|
|
|
'features/filmstrip',
|
|
|
|
(state = DEFAULT_STATE, action) => {
|
|
|
|
switch (action.type) {
|
2018-02-06 09:40:16 +00:00
|
|
|
case SET_FILMSTRIP_ENABLED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
enabled: action.enabled
|
|
|
|
};
|
|
|
|
|
2018-02-05 21:52:41 +00:00
|
|
|
case SET_FILMSTRIP_VISIBLE:
|
2017-05-23 18:58:07 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
visible: action.visible
|
|
|
|
};
|
2020-01-24 16:28:47 +00:00
|
|
|
|
|
|
|
case SET_HORIZONTAL_VIEW_DIMENSIONS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
horizontalViewDimensions: action.dimensions
|
|
|
|
};
|
|
|
|
case SET_TILE_VIEW_DIMENSIONS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
tileViewDimensions: action.dimensions
|
|
|
|
};
|
2021-03-26 20:23:05 +00:00
|
|
|
case SET_VERTICAL_VIEW_DIMENSIONS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verticalViewDimensions: action.dimensions
|
|
|
|
};
|
|
|
|
case SET_VOLUME:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
participantsVolume: {
|
|
|
|
...state.participantsVolume,
|
|
|
|
|
|
|
|
// NOTE: This would fit better in the features/base/participants. But currently we store
|
|
|
|
// the participants as an array which will make it expensive to search for the volume for
|
|
|
|
// every participant separately.
|
|
|
|
[action.participantId]: action.volume
|
|
|
|
}
|
|
|
|
};
|
2021-05-19 23:23:40 +00:00
|
|
|
case SET_VISIBLE_REMOTE_PARTICIPANTS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
visibleParticipantsStartIndex: action.startIndex,
|
|
|
|
visibleParticipantsEndIndex: action.endIndex,
|
|
|
|
visibleParticipants: state.remoteParticipants.slice(action.startIndex, action.endIndex + 1)
|
|
|
|
};
|
2021-03-26 20:23:05 +00:00
|
|
|
case PARTICIPANT_JOINED: {
|
|
|
|
const { id, local } = action.participant;
|
|
|
|
|
|
|
|
if (!local) {
|
|
|
|
state.remoteParticipants = [ ...state.remoteParticipants, id ];
|
2021-05-19 23:23:40 +00:00
|
|
|
|
|
|
|
const { visibleParticipantsStartIndex: startIndex, visibleParticipantsEndIndex: endIndex } = state;
|
|
|
|
|
|
|
|
if (state.remoteParticipants.length - 1 <= endIndex) {
|
|
|
|
state.visibleParticipants = state.remoteParticipants.slice(startIndex, endIndex + 1);
|
|
|
|
}
|
2021-03-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
case PARTICIPANT_LEFT: {
|
|
|
|
const { id, local } = action.participant;
|
|
|
|
|
|
|
|
if (local) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2021-05-19 23:23:40 +00:00
|
|
|
let removedParticipantIndex = 0;
|
|
|
|
|
|
|
|
state.remoteParticipants = state.remoteParticipants.filter((participantId, index) => {
|
|
|
|
if (participantId === id) {
|
|
|
|
removedParticipantIndex = index;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
const { visibleParticipantsStartIndex: startIndex, visibleParticipantsEndIndex: endIndex } = state;
|
|
|
|
|
|
|
|
if (removedParticipantIndex >= startIndex && removedParticipantIndex <= endIndex) {
|
|
|
|
state.visibleParticipants = state.remoteParticipants.slice(startIndex, endIndex + 1);
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:23:05 +00:00
|
|
|
delete state.participantsVolume[id];
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
2017-05-23 18:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|