Files
jitsi-meet/react/features/notifications/middleware.js
robertpin 41f11e5adb feat(self-view) Added ability to hide self view
Added config option disableSelfView. This disables it on web and native

Added button on local video menu and toggle in settings on web to change the setting
2021-12-09 08:45:16 +01:00

132 lines
4.0 KiB
JavaScript

/* @flow */
import { CONFERENCE_JOINED, getCurrentConference } from '../base/conference';
import {
PARTICIPANT_JOINED,
PARTICIPANT_LEFT,
PARTICIPANT_ROLE,
PARTICIPANT_UPDATED,
getParticipantById,
getParticipantDisplayName,
getLocalParticipant
} from '../base/participants';
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
import { PARTICIPANTS_PANE_OPEN } from '../participants-pane/actionTypes';
import { openSettingsDialog, SETTINGS_TABS } from '../settings';
import {
clearNotifications,
hideRaiseHandNotifications,
showNotification,
showParticipantJoinedNotification,
showParticipantLeftNotification
} from './actions';
import { NOTIFICATION_TIMEOUT_TYPE } from './constants';
import { joinLeaveNotificationsDisabled } from './functions';
/**
* Middleware that captures actions to display notifications.
*
* @param {Store} store - The redux store.
* @returns {Function}
*/
MiddlewareRegistry.register(store => next => action => {
switch (action.type) {
case CONFERENCE_JOINED: {
const { dispatch, getState } = store;
const { disableSelfView } = getState()['features/base/settings'];
if (disableSelfView) {
dispatch(showNotification({
titleKey: 'notify.selfViewTitle',
customActionNameKey: [ 'settings.title' ],
customActionHandler: [ () =>
dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE))
]
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
}
break;
}
case PARTICIPANT_JOINED: {
const result = next(action);
const { participant: p } = action;
const { dispatch, getState } = store;
const state = getState();
const { conference } = state['features/base/conference'];
if (conference && !p.local && !joinLeaveNotificationsDisabled() && !p.isReplacing) {
dispatch(showParticipantJoinedNotification(
getParticipantDisplayName(state, p.id)
));
}
return result;
}
case PARTICIPANT_LEFT: {
if (!joinLeaveNotificationsDisabled()) {
const { dispatch, getState } = store;
const state = getState();
const participant = getParticipantById(
store.getState(),
action.participant.id
);
if (participant && !participant.local && !action.participant.isReplaced) {
dispatch(showParticipantLeftNotification(
getParticipantDisplayName(state, participant.id)
));
}
}
return next(action);
}
case PARTICIPANT_UPDATED: {
const state = store.getState();
const { disableModeratorIndicator } = state['features/base/config'];
if (disableModeratorIndicator) {
return next(action);
}
const { id, role } = action.participant;
const localParticipant = getLocalParticipant(state);
if (localParticipant?.id !== id) {
return next(action);
}
const oldParticipant = getParticipantById(state, id);
const oldRole = oldParticipant?.role;
if (oldRole && oldRole !== role && role === PARTICIPANT_ROLE.MODERATOR) {
store.dispatch(showNotification({
titleKey: 'notify.moderator'
},
NOTIFICATION_TIMEOUT_TYPE.SHORT));
}
return next(action);
}
case PARTICIPANTS_PANE_OPEN: {
store.dispatch(hideRaiseHandNotifications());
break;
}
}
return next(action);
});
/**
* StateListenerRegistry provides a reliable way to detect the leaving of a
* conference, where we need to clean up the notifications.
*/
StateListenerRegistry.register(
/* selector */ state => getCurrentConference(state),
/* listener */ (conference, { dispatch }) => {
if (!conference) {
dispatch(clearNotifications());
}
}
);