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

middleware.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* @flow */
  2. import { getCurrentConference } from '../base/conference';
  3. import {
  4. PARTICIPANT_JOINED,
  5. getParticipantDisplayName
  6. } from '../base/participants';
  7. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  8. import {
  9. clearNotifications,
  10. showParticipantJoinedNotification
  11. } from './actions';
  12. /**
  13. * Middleware that captures actions to display notifications.
  14. *
  15. * @param {Store} store - The redux store.
  16. * @returns {Function}
  17. */
  18. MiddlewareRegistry.register(store => next => action => {
  19. const result = next(action);
  20. switch (action.type) {
  21. case PARTICIPANT_JOINED: {
  22. const { participant: p } = action;
  23. if (!p.local) {
  24. store.dispatch(showParticipantJoinedNotification(
  25. getParticipantDisplayName(store.getState, p.id)
  26. ));
  27. }
  28. }
  29. }
  30. return result;
  31. });
  32. /**
  33. * StateListenerRegistry provides a reliable way to detect the leaving of a
  34. * conference, where we need to clean up the notifications.
  35. */
  36. StateListenerRegistry.register(
  37. /* selector */ state => getCurrentConference(state),
  38. /* listener */ (conference, { dispatch }) => {
  39. if (!conference) {
  40. dispatch(clearNotifications());
  41. }
  42. }
  43. );