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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 {
  9. KICK_PARTICIPANT,
  10. MUTE_REMOTE_PARTICIPANT,
  11. PARTICIPANT_DISPLAY_NAME_CHANGED
  12. } from './actionTypes';
  13. import { LOCAL_PARTICIPANT_DEFAULT_ID } from './constants';
  14. import { getLocalParticipant } from './functions';
  15. declare var APP: Object;
  16. /**
  17. * Middleware that captures CONFERENCE_JOINED and CONFERENCE_LEFT actions and
  18. * updates respectively ID of local participant.
  19. *
  20. * @param {Store} store - Redux store.
  21. * @returns {Function}
  22. */
  23. MiddlewareRegistry.register(store => next => action => {
  24. switch (action.type) {
  25. case CONFERENCE_JOINED:
  26. store.dispatch(localParticipantIdChanged(action.conference.myUserId()));
  27. break;
  28. case CONFERENCE_LEFT:
  29. store.dispatch(localParticipantIdChanged(LOCAL_PARTICIPANT_DEFAULT_ID));
  30. break;
  31. case KICK_PARTICIPANT:
  32. if (typeof APP !== 'undefined') {
  33. APP.UI.emitEvent(UIEvents.USER_KICKED, action.id);
  34. }
  35. break;
  36. case MUTE_REMOTE_PARTICIPANT:
  37. if (typeof APP !== 'undefined') {
  38. APP.UI.messageHandler.openTwoButtonDialog({
  39. titleKey: 'dialog.muteParticipantTitle',
  40. msgString:
  41. '<div data-i18n="dialog.muteParticipantBody"></div>',
  42. leftButtonKey: 'dialog.muteParticipantButton',
  43. dontShowAgain: {
  44. id: 'dontShowMuteParticipantDialog',
  45. textKey: 'dialog.doNotShowMessageAgain',
  46. checked: true,
  47. buttonValues: [ true ]
  48. },
  49. submitFunction: () => {
  50. APP.UI.emitEvent(UIEvents.REMOTE_AUDIO_MUTED, action.id);
  51. }
  52. });
  53. }
  54. break;
  55. // TODO Remove this middleware when the local display name update flow is
  56. // fully brought into redux.
  57. case PARTICIPANT_DISPLAY_NAME_CHANGED: {
  58. if (typeof APP !== 'undefined') {
  59. const participant = getLocalParticipant(store.getState());
  60. if (participant && participant.id === action.id) {
  61. APP.UI.emitEvent(UIEvents.NICKNAME_CHANGED, action.name);
  62. }
  63. }
  64. break;
  65. }
  66. }
  67. return next(action);
  68. });