2022-10-11 10:47:54 +00:00
|
|
|
import { CONFERENCE_JOINED, CONFERENCE_LEFT, SET_PASSWORD } from '../base/conference/actionTypes';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IParticipant } from '../base/participants/types';
|
2022-08-10 09:56:24 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED,
|
|
|
|
KNOCKING_PARTICIPANT_LEFT,
|
2022-03-03 17:29:38 +00:00
|
|
|
REMOVE_LOBBY_CHAT_WITH_MODERATOR,
|
2020-04-15 13:13:43 +00:00
|
|
|
SET_KNOCKING_STATE,
|
2020-05-20 08:25:31 +00:00
|
|
|
SET_LOBBY_MODE_ENABLED,
|
2022-03-03 17:29:38 +00:00
|
|
|
SET_LOBBY_PARTICIPANT_CHAT_STATE,
|
2021-08-20 08:53:11 +00:00
|
|
|
SET_LOBBY_VISIBILITY,
|
2020-05-20 08:25:31 +00:00
|
|
|
SET_PASSWORD_JOIN_FAILED
|
2020-04-15 13:13:43 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
const DEFAULT_STATE = {
|
|
|
|
knocking: false,
|
|
|
|
knockingParticipants: [],
|
2020-05-20 08:25:31 +00:00
|
|
|
lobbyEnabled: false,
|
2021-08-20 08:53:11 +00:00
|
|
|
lobbyVisible: false,
|
2020-05-20 08:25:31 +00:00
|
|
|
passwordJoinFailed: false
|
2020-04-15 13:13:43 +00:00
|
|
|
};
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IKnockingParticipant extends IParticipant {
|
2022-08-10 09:56:24 +00:00
|
|
|
chattingWithModerator?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ILobbyState {
|
|
|
|
knocking: boolean;
|
2022-10-20 09:11:27 +00:00
|
|
|
knockingParticipants: IKnockingParticipant[];
|
2022-08-10 09:56:24 +00:00
|
|
|
lobbyEnabled: boolean;
|
|
|
|
lobbyVisible: boolean;
|
|
|
|
passwordJoinFailed: boolean;
|
|
|
|
}
|
|
|
|
|
2020-04-15 13:13:43 +00:00
|
|
|
/**
|
|
|
|
* Reduces redux actions which affect the display of notifications.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The current redux state.
|
|
|
|
* @param {Object} action - The redux action to reduce.
|
|
|
|
* @returns {Object} The next redux state which is the result of reducing the
|
|
|
|
* specified {@code action}.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<ILobbyState>('features/lobby', (state = DEFAULT_STATE, action): ILobbyState => {
|
2020-04-15 13:13:43 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_JOINED:
|
|
|
|
case CONFERENCE_LEFT:
|
|
|
|
return {
|
|
|
|
...state,
|
2020-05-20 08:25:31 +00:00
|
|
|
knocking: false,
|
|
|
|
passwordJoinFailed: false
|
2020-04-15 13:13:43 +00:00
|
|
|
};
|
|
|
|
case KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED:
|
|
|
|
return _knockingParticipantArrivedOrUpdated(action.participant, state);
|
|
|
|
case KNOCKING_PARTICIPANT_LEFT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
knockingParticipants: state.knockingParticipants.filter(p => p.id !== action.id)
|
|
|
|
};
|
|
|
|
case SET_KNOCKING_STATE:
|
|
|
|
return {
|
|
|
|
...state,
|
2020-05-20 08:25:31 +00:00
|
|
|
knocking: action.knocking,
|
|
|
|
passwordJoinFailed: false
|
2020-04-15 13:13:43 +00:00
|
|
|
};
|
|
|
|
case SET_LOBBY_MODE_ENABLED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lobbyEnabled: action.enabled
|
|
|
|
};
|
2021-08-20 08:53:11 +00:00
|
|
|
case SET_LOBBY_VISIBILITY:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lobbyVisible: action.visible
|
|
|
|
};
|
2020-05-20 08:25:31 +00:00
|
|
|
case SET_PASSWORD:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
passwordJoinFailed: false
|
|
|
|
};
|
|
|
|
case SET_PASSWORD_JOIN_FAILED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
passwordJoinFailed: action.failed
|
|
|
|
};
|
2022-03-03 17:29:38 +00:00
|
|
|
case SET_LOBBY_PARTICIPANT_CHAT_STATE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
knockingParticipants: state.knockingParticipants.map(participant => {
|
|
|
|
if (participant.id === action.participant.id) {
|
|
|
|
return {
|
|
|
|
...participant,
|
|
|
|
chattingWithModerator: action.moderator.id
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return participant;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
case REMOVE_LOBBY_CHAT_WITH_MODERATOR:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
knockingParticipants: state.knockingParticipants.map(participant => {
|
|
|
|
if (participant.chattingWithModerator === action.moderatorId) {
|
|
|
|
return {
|
|
|
|
...participant,
|
|
|
|
chattingWithModerator: undefined
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return participant;
|
|
|
|
})
|
|
|
|
};
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores or updates a knocking participant.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The arrived or updated knocking participant.
|
|
|
|
* @param {Object} state - The current Redux state of the feature.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function _knockingParticipantArrivedOrUpdated(participant: IKnockingParticipant, state: ILobbyState) {
|
2020-04-15 13:13:43 +00:00
|
|
|
let existingParticipant = state.knockingParticipants.find(p => p.id === participant.id);
|
|
|
|
|
|
|
|
existingParticipant = {
|
|
|
|
...existingParticipant,
|
|
|
|
...participant
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
knockingParticipants: [
|
|
|
|
...state.knockingParticipants.filter(p => p.id !== participant.id),
|
|
|
|
existingParticipant
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|