You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* @flow */
  2. import { getCurrentConference } from '../base/conference';
  3. import {
  4. PARTICIPANT_JOINED,
  5. PARTICIPANT_LEFT,
  6. getParticipantById,
  7. getParticipantDisplayName
  8. } from '../base/participants';
  9. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  10. import {
  11. clearNotifications,
  12. showNotification,
  13. showParticipantJoinedNotification
  14. } from './actions';
  15. import { NOTIFICATION_TIMEOUT } from './constants';
  16. import { joinLeaveNotificationsDisabled } from './functions';
  17. declare var interfaceConfig: Object;
  18. /**
  19. * Middleware that captures actions to display notifications.
  20. *
  21. * @param {Store} store - The redux store.
  22. * @returns {Function}
  23. */
  24. MiddlewareRegistry.register(store => next => action => {
  25. switch (action.type) {
  26. case PARTICIPANT_JOINED: {
  27. const result = next(action);
  28. const { participant: p } = action;
  29. if (!p.local && !joinLeaveNotificationsDisabled()) {
  30. store.dispatch(showParticipantJoinedNotification(
  31. getParticipantDisplayName(store.getState, p.id)
  32. ));
  33. }
  34. return result;
  35. }
  36. case PARTICIPANT_LEFT: {
  37. if (!joinLeaveNotificationsDisabled()) {
  38. const participant = getParticipantById(
  39. store.getState(),
  40. action.participant.id
  41. );
  42. if (typeof interfaceConfig === 'object'
  43. && participant
  44. && !participant.local) {
  45. store.dispatch(showNotification({
  46. descriptionKey: 'notify.disconnected',
  47. titleKey: 'notify.somebody',
  48. title: participant.name
  49. }, NOTIFICATION_TIMEOUT));
  50. }
  51. }
  52. return next(action);
  53. }
  54. }
  55. return next(action);
  56. });
  57. /**
  58. * StateListenerRegistry provides a reliable way to detect the leaving of a
  59. * conference, where we need to clean up the notifications.
  60. */
  61. StateListenerRegistry.register(
  62. /* selector */ state => getCurrentConference(state),
  63. /* listener */ (conference, { dispatch }) => {
  64. if (!conference) {
  65. dispatch(clearNotifications());
  66. }
  67. }
  68. );