2020-04-15 13:13:43 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference';
|
|
|
|
import { JitsiConferenceErrors, JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2020-07-06 14:54:33 +00:00
|
|
|
import { getFirstLoadableAvatarUrl, getParticipantDisplayName } from '../base/participants';
|
2020-04-15 13:13:43 +00:00
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
2020-10-01 12:53:33 +00:00
|
|
|
import { isTestModeEnabled } from '../base/testing';
|
2020-04-15 13:13:43 +00:00
|
|
|
import { NOTIFICATION_TYPE, showNotification } from '../notifications';
|
2021-02-24 09:35:32 +00:00
|
|
|
import { shouldAutoKnock } from '../prejoin/functions';
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
import { KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED } from './actionTypes';
|
|
|
|
import {
|
2020-05-20 08:25:31 +00:00
|
|
|
hideLobbyScreen,
|
2020-04-15 13:13:43 +00:00
|
|
|
knockingParticipantLeft,
|
|
|
|
openLobbyScreen,
|
|
|
|
participantIsKnockingOrUpdated,
|
2020-05-20 08:25:31 +00:00
|
|
|
setLobbyModeEnabled,
|
|
|
|
startKnocking,
|
|
|
|
setPasswordJoinFailed
|
2020-04-15 13:13:43 +00:00
|
|
|
} from './actions';
|
|
|
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_FAILED:
|
|
|
|
return _conferenceFailed(store, next, action);
|
|
|
|
case CONFERENCE_JOINED:
|
|
|
|
return _conferenceJoined(store, next, action);
|
|
|
|
case KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED: {
|
|
|
|
// We need the full update result to be in the store already
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
_findLoadableAvatarForKnockingParticipant(store, action.participant);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a change handler for state['features/base/conference'].conference to
|
|
|
|
* set the event listeners needed for the lobby feature to operate.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => state['features/base/conference'].conference,
|
2020-07-06 14:54:33 +00:00
|
|
|
(conference, { dispatch, getState }, previousConference) => {
|
2020-04-15 13:13:43 +00:00
|
|
|
if (conference && !previousConference) {
|
|
|
|
conference.on(JitsiConferenceEvents.MEMBERS_ONLY_CHANGED, enabled => {
|
|
|
|
dispatch(setLobbyModeEnabled(enabled));
|
|
|
|
});
|
|
|
|
|
|
|
|
conference.on(JitsiConferenceEvents.LOBBY_USER_JOINED, (id, name) => {
|
|
|
|
dispatch(participantIsKnockingOrUpdated({
|
|
|
|
id,
|
|
|
|
name
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
conference.on(JitsiConferenceEvents.LOBBY_USER_UPDATED, (id, participant) => {
|
|
|
|
dispatch(participantIsKnockingOrUpdated({
|
|
|
|
...participant,
|
|
|
|
id
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
conference.on(JitsiConferenceEvents.LOBBY_USER_LEFT, id => {
|
|
|
|
dispatch(knockingParticipantLeft(id));
|
|
|
|
});
|
2020-07-06 14:54:33 +00:00
|
|
|
|
|
|
|
conference.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, (origin, sender) =>
|
|
|
|
_maybeSendLobbyNotification(origin, sender, {
|
|
|
|
dispatch,
|
|
|
|
getState
|
|
|
|
})
|
|
|
|
);
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to handle the conference failed event and navigate the user to the lobby screen
|
|
|
|
* based on the failure reason.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The Redux store.
|
|
|
|
* @param {Function} next - The Redux next function.
|
|
|
|
* @param {Object} action - The Redux action.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2020-05-20 08:25:31 +00:00
|
|
|
function _conferenceFailed({ dispatch, getState }, next, action) {
|
2020-04-15 13:13:43 +00:00
|
|
|
const { error } = action;
|
2020-05-20 08:25:31 +00:00
|
|
|
const state = getState();
|
|
|
|
const nonFirstFailure = Boolean(state['features/base/conference'].membersOnly);
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
if (error.name === JitsiConferenceErrors.MEMBERS_ONLY_ERROR) {
|
|
|
|
if (typeof error.recoverable === 'undefined') {
|
|
|
|
error.recoverable = true;
|
|
|
|
}
|
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2020-04-15 13:13:43 +00:00
|
|
|
dispatch(openLobbyScreen());
|
2020-05-20 08:25:31 +00:00
|
|
|
|
2021-02-24 09:35:32 +00:00
|
|
|
if (shouldAutoKnock(state)) {
|
2020-05-20 08:25:31 +00:00
|
|
|
dispatch(startKnocking());
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
2020-05-20 08:25:31 +00:00
|
|
|
|
|
|
|
dispatch(setPasswordJoinFailed(nonFirstFailure));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(hideLobbyScreen());
|
|
|
|
|
|
|
|
if (error.name === JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED) {
|
|
|
|
dispatch(showNotification({
|
|
|
|
appearance: NOTIFICATION_TYPE.ERROR,
|
|
|
|
hideErrorSupportLink: true,
|
|
|
|
titleKey: 'lobby.joinRejectedMessage'
|
|
|
|
}));
|
2020-04-15 13:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles cleanup of lobby state when a conference is joined.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The Redux store.
|
|
|
|
* @param {Function} next - The Redux next function.
|
|
|
|
* @param {Object} action - The Redux action.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function _conferenceJoined({ dispatch }, next, action) {
|
2020-05-20 08:25:31 +00:00
|
|
|
dispatch(hideLobbyScreen());
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the loadable avatar URL and updates the participant accordingly.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The Redux store.
|
|
|
|
* @param {Object} participant - The knocking participant.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2020-11-15 21:33:55 +00:00
|
|
|
function _findLoadableAvatarForKnockingParticipant(store, { id }) {
|
|
|
|
const { dispatch, getState } = store;
|
2020-04-15 13:13:43 +00:00
|
|
|
const updatedParticipant = getState()['features/lobby'].knockingParticipants.find(p => p.id === id);
|
2020-05-20 08:25:31 +00:00
|
|
|
const { disableThirdPartyRequests } = getState()['features/base/config'];
|
2020-04-15 13:13:43 +00:00
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
if (!disableThirdPartyRequests && updatedParticipant && !updatedParticipant.loadableAvatarUrl) {
|
2020-11-15 21:33:55 +00:00
|
|
|
getFirstLoadableAvatarUrl(updatedParticipant, store).then(loadableAvatarUrl => {
|
2020-04-15 13:13:43 +00:00
|
|
|
if (loadableAvatarUrl) {
|
|
|
|
dispatch(participantIsKnockingOrUpdated({
|
|
|
|
loadableAvatarUrl,
|
|
|
|
id
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 14:54:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the endpoint message that arrived through the conference and
|
|
|
|
* sends a lobby notification, if the message belongs to the feature.
|
|
|
|
*
|
|
|
|
* @param {Object} origin - The origin (initiator) of the message.
|
|
|
|
* @param {Object} message - The actual message.
|
|
|
|
* @param {Object} store - The Redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _maybeSendLobbyNotification(origin, message, { dispatch, getState }) {
|
|
|
|
if (!origin?._id || message?.type !== 'lobby-notify') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const notificationProps: any = {
|
|
|
|
descriptionArguments: {
|
2020-07-20 16:32:51 +00:00
|
|
|
originParticipantName: getParticipantDisplayName(getState, origin._id),
|
|
|
|
targetParticipantName: message.name
|
2020-07-06 14:54:33 +00:00
|
|
|
},
|
|
|
|
titleKey: 'lobby.notificationTitle'
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (message.event) {
|
|
|
|
case 'LOBBY-ENABLED':
|
|
|
|
notificationProps.descriptionKey = `lobby.notificationLobby${message.value ? 'En' : 'Dis'}abled`;
|
|
|
|
break;
|
|
|
|
case 'LOBBY-ACCESS-GRANTED':
|
|
|
|
notificationProps.descriptionKey = 'lobby.notificationLobbyAccessGranted';
|
|
|
|
break;
|
|
|
|
case 'LOBBY-ACCESS-DENIED':
|
|
|
|
notificationProps.descriptionKey = 'lobby.notificationLobbyAccessDenied';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-01 12:53:33 +00:00
|
|
|
dispatch(showNotification(notificationProps, isTestModeEnabled(getState()) ? undefined : 5000));
|
2020-07-06 14:54:33 +00:00
|
|
|
}
|