Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

middleware.js 2.6KB

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