2018-06-14 09:14:32 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
import { getCurrentConference } from '../base/conference';
|
2019-06-25 22:25:43 +00:00
|
|
|
import {
|
|
|
|
PARTICIPANT_JOINED,
|
2019-06-26 20:14:32 +00:00
|
|
|
PARTICIPANT_LEFT,
|
|
|
|
getParticipantById,
|
2019-06-25 22:25:43 +00:00
|
|
|
getParticipantDisplayName
|
|
|
|
} from '../base/participants';
|
|
|
|
import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
2018-06-14 09:14:32 +00:00
|
|
|
|
2019-06-25 22:25:43 +00:00
|
|
|
import {
|
|
|
|
clearNotifications,
|
2019-06-26 20:14:32 +00:00
|
|
|
showNotification,
|
2019-06-25 22:25:43 +00:00
|
|
|
showParticipantJoinedNotification
|
|
|
|
} from './actions';
|
2019-06-26 20:14:32 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT } from './constants';
|
|
|
|
|
|
|
|
declare var interfaceConfig: Object;
|
2019-06-25 22:25:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware that captures actions to display notifications.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case PARTICIPANT_JOINED: {
|
2019-06-26 20:14:32 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2019-06-25 22:25:43 +00:00
|
|
|
const { participant: p } = action;
|
|
|
|
|
|
|
|
if (!p.local) {
|
|
|
|
store.dispatch(showParticipantJoinedNotification(
|
|
|
|
getParticipantDisplayName(store.getState, p.id)
|
|
|
|
));
|
|
|
|
}
|
2019-06-26 20:14:32 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
case PARTICIPANT_LEFT: {
|
|
|
|
const participant = getParticipantById(
|
|
|
|
store.getState(),
|
|
|
|
action.participant.id
|
|
|
|
);
|
|
|
|
|
|
|
|
if (typeof interfaceConfig === 'object'
|
|
|
|
&& participant
|
|
|
|
&& !participant.local) {
|
|
|
|
store.dispatch(showNotification({
|
|
|
|
descriptionKey: 'notify.disconnected',
|
|
|
|
titleKey: 'notify.somebody',
|
|
|
|
title: participant.name
|
|
|
|
},
|
|
|
|
NOTIFICATION_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
2019-06-25 22:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 20:14:32 +00:00
|
|
|
return next(action);
|
2019-06-25 22:25:43 +00:00
|
|
|
});
|
2018-06-14 09:14:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|