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 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* @flow */
  2. import UIEvents from '../../../../service/UI/UIEvents';
  3. import {
  4. CONFERENCE_JOINED,
  5. CONFERENCE_LEFT
  6. } from '../conference';
  7. import { MiddlewareRegistry } from '../redux';
  8. import { localParticipantIdChanged } from './actions';
  9. import {
  10. KICK_PARTICIPANT,
  11. MUTE_REMOTE_PARTICIPANT,
  12. PARTICIPANT_DISPLAY_NAME_CHANGED
  13. } from './actionTypes';
  14. import { LOCAL_PARTICIPANT_DEFAULT_ID } from './constants';
  15. import { getLocalParticipant } from './functions';
  16. declare var APP: Object;
  17. /**
  18. * Middleware that captures CONFERENCE_JOINED and CONFERENCE_LEFT actions and
  19. * updates respectively ID of local participant.
  20. *
  21. * @param {Store} store - Redux store.
  22. * @returns {Function}
  23. */
  24. MiddlewareRegistry.register(store => next => action => {
  25. const { conference } = store.getState()['features/base/conference'];
  26. switch (action.type) {
  27. case CONFERENCE_JOINED:
  28. store.dispatch(localParticipantIdChanged(action.conference.myUserId()));
  29. break;
  30. case CONFERENCE_LEFT:
  31. store.dispatch(localParticipantIdChanged(LOCAL_PARTICIPANT_DEFAULT_ID));
  32. break;
  33. case KICK_PARTICIPANT:
  34. conference.kickParticipant(action.id);
  35. break;
  36. case MUTE_REMOTE_PARTICIPANT:
  37. conference.muteParticipant(action.id);
  38. break;
  39. // TODO Remove this middleware when the local display name update flow is
  40. // fully brought into redux.
  41. case PARTICIPANT_DISPLAY_NAME_CHANGED: {
  42. if (typeof APP !== 'undefined') {
  43. const participant = getLocalParticipant(store.getState());
  44. if (participant && participant.id === action.id) {
  45. APP.UI.emitEvent(UIEvents.NICKNAME_CHANGED, action.name);
  46. }
  47. }
  48. break;
  49. }
  50. }
  51. return next(action);
  52. });