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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // @flow
  2. import {
  3. CONFERENCE_FAILED,
  4. LOCK_STATE_CHANGED,
  5. SET_PASSWORD_FAILED
  6. } from '../base/conference';
  7. import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
  8. import { MiddlewareRegistry } from '../base/redux';
  9. import UIEvents from '../../../service/UI/UIEvents';
  10. import { _openPasswordRequiredPrompt } from './actions';
  11. declare var APP: Object;
  12. const logger = require('jitsi-meet-logger').getLogger(__filename);
  13. /**
  14. * Middleware that captures conference failed and checks for password required
  15. * error and requests a dialog for user to enter password.
  16. *
  17. * @param {Store} store - Redux store.
  18. * @returns {Function}
  19. */
  20. MiddlewareRegistry.register(store => next => action => {
  21. switch (action.type) {
  22. case CONFERENCE_FAILED: {
  23. const { conference, error } = action;
  24. if (conference
  25. && error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) {
  26. store.dispatch(_openPasswordRequiredPrompt(conference));
  27. }
  28. break;
  29. }
  30. case LOCK_STATE_CHANGED:
  31. // TODO Remove this logic when all components interested in the lock
  32. // state change event are moved into react/redux.
  33. if (typeof APP !== 'undefined') {
  34. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, action.locked);
  35. }
  36. break;
  37. case SET_PASSWORD_FAILED:
  38. return _setPasswordFailed(store, next, action);
  39. }
  40. return next(action);
  41. });
  42. /**
  43. * Handles errors that occur when a password fails to be set.
  44. *
  45. * @param {Store} store - The Redux store in which the specified action is being
  46. * dispatched.
  47. * @param {Dispatch} next - The Redux dispatch function to dispatch the
  48. * specified action to the specified store.
  49. * @param {Action} action - The Redux action SET_PASSWORD_ERROR which has the
  50. * error type that should be handled.
  51. * @private
  52. * @returns {Object} The new state that is the result of the reduction of the
  53. * specified action.
  54. */
  55. function _setPasswordFailed(store, next, action) {
  56. if (typeof APP !== 'undefined') {
  57. // TODO Remove this logic when displaying of error messages on web is
  58. // handled through react/redux.
  59. const { error } = action;
  60. let title;
  61. let message;
  62. if (error === JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  63. logger.warn('room passwords not supported');
  64. title = 'dialog.warning';
  65. message = 'dialog.passwordNotSupported';
  66. } else {
  67. logger.warn('setting password failed', error);
  68. title = 'dialog.lockTitle';
  69. message = 'dialog.lockMessage';
  70. }
  71. APP.UI.messageHandler.showError(title, message);
  72. }
  73. return next(action);
  74. }