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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 && error === JitsiConferenceErrors.PASSWORD_REQUIRED) {
  25. store.dispatch(_openPasswordRequiredPrompt(conference));
  26. }
  27. break;
  28. }
  29. case LOCK_STATE_CHANGED:
  30. // TODO Remove this logic when all components interested in the lock
  31. // state change event are moved into react/redux.
  32. if (typeof APP !== 'undefined') {
  33. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, action.locked);
  34. }
  35. break;
  36. case SET_PASSWORD_FAILED:
  37. return _setPasswordFailed(store, next, action);
  38. }
  39. return next(action);
  40. });
  41. /**
  42. * Handles errors that occur when a password fails to be set.
  43. *
  44. * @param {Store} store - The Redux store in which the specified action is being
  45. * dispatched.
  46. * @param {Dispatch} next - The Redux dispatch function to dispatch the
  47. * specified action to the specified store.
  48. * @param {Action} action - The Redux action SET_PASSWORD_ERROR which has the
  49. * error type that should be handled.
  50. * @private
  51. * @returns {Object} The new state that is the result of the reduction of the
  52. * specified action.
  53. */
  54. function _setPasswordFailed(store, next, action) {
  55. if (typeof APP !== 'undefined') {
  56. // TODO Remove this logic when displaying of error messages on web is
  57. // handled through react/redux.
  58. const { error } = action;
  59. let title;
  60. let message;
  61. if (error === JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  62. logger.warn('room passwords not supported');
  63. title = 'dialog.warning';
  64. message = 'dialog.passwordNotSupported';
  65. } else {
  66. logger.warn('setting password failed', error);
  67. title = 'dialog.lockTitle';
  68. message = 'dialog.lockMessage';
  69. }
  70. APP.UI.messageHandler.showError(title, message);
  71. }
  72. return next(action);
  73. }