您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 1.9KB

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