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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. switch (action.type) {
  26. case CONFERENCE_JOINED:
  27. store.dispatch(localParticipantIdChanged(action.conference.myUserId()));
  28. break;
  29. case CONFERENCE_LEFT:
  30. store.dispatch(localParticipantIdChanged(LOCAL_PARTICIPANT_DEFAULT_ID));
  31. break;
  32. case KICK_PARTICIPANT:
  33. if (typeof APP !== 'undefined') {
  34. APP.UI.emitEvent(UIEvents.USER_KICKED, action.id);
  35. }
  36. break;
  37. case MUTE_REMOTE_PARTICIPANT:
  38. if (typeof APP !== 'undefined') {
  39. APP.UI.messageHandler.openTwoButtonDialog({
  40. titleKey: 'dialog.muteParticipantTitle',
  41. msgString:
  42. '<div data-i18n="dialog.muteParticipantBody"></div>',
  43. leftButtonKey: 'dialog.muteParticipantButton',
  44. dontShowAgain: {
  45. id: 'dontShowMuteParticipantDialog',
  46. textKey: 'dialog.doNotShowMessageAgain',
  47. checked: true,
  48. buttonValues: [ true ]
  49. },
  50. submitFunction: () => {
  51. APP.UI.emitEvent(UIEvents.REMOTE_AUDIO_MUTED, action.id);
  52. }
  53. });
  54. }
  55. break;
  56. // TODO Remove this middleware when the local display name update flow is
  57. // fully brought into redux.
  58. case PARTICIPANT_DISPLAY_NAME_CHANGED: {
  59. if (typeof APP !== 'undefined') {
  60. const participant = getLocalParticipant(store.getState());
  61. if (participant && participant.id === action.id) {
  62. APP.UI.emitEvent(UIEvents.NICKNAME_CHANGED, action.name);
  63. }
  64. }
  65. break;
  66. }
  67. }
  68. return next(action);
  69. });