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

middleware.js 1.4KB

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