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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* global APP */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. import UIEvents from '../../../service/UI/UIEvents';
  4. import {
  5. CONFERENCE_FAILED,
  6. LOCK_STATE_CHANGED,
  7. SET_PASSWORD_FAILED
  8. } from '../base/conference';
  9. import JitsiMeetJS from '../base/lib-jitsi-meet';
  10. import { MiddlewareRegistry } from '../base/redux';
  11. import { _showPasswordDialog } from './actions';
  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 JitsiConferenceErrors = JitsiMeetJS.errors.conference;
  23. if (action.conference
  24. && JitsiConferenceErrors.PASSWORD_REQUIRED === action.error) {
  25. // XXX temporary solution while some components are not listening
  26. // for lock state updates in redux
  27. if (typeof APP !== 'undefined') {
  28. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, true);
  29. }
  30. store.dispatch(_showPasswordDialog(action.conference));
  31. }
  32. break;
  33. }
  34. case LOCK_STATE_CHANGED: {
  35. // TODO Remove this logic when all components interested in the lock
  36. // state change event are moved into react/redux.
  37. if (typeof APP !== 'undefined') {
  38. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, action.locked);
  39. }
  40. break;
  41. }
  42. case SET_PASSWORD_FAILED:
  43. return _notifySetPasswordError(store, next, action);
  44. }
  45. return next(action);
  46. });
  47. /**
  48. * Handles errors that occur when a password is failed to be set.
  49. *
  50. * @param {Store} store - The Redux store in which the specified action is being
  51. * dispatched.
  52. * @param {Dispatch} next - The Redux dispatch function to dispatch the
  53. * specified action to the specified store.
  54. * @param {Action} action - The Redux action SET_PASSWORD_ERROR which has the
  55. * error type that should be handled.
  56. * @private
  57. * @returns {Object} The new state that is the result of the reduction of the
  58. * specified action.
  59. */
  60. function _notifySetPasswordError(store, next, action) {
  61. if (typeof APP !== 'undefined') {
  62. // TODO remove this logic when displaying of error messages on web is
  63. // handled through react/redux
  64. if (action.error
  65. === JitsiMeetJS.errors.conference.PASSWORD_NOT_SUPPORTED) {
  66. logger.warn('room passwords not supported');
  67. APP.UI.messageHandler.showError(
  68. 'dialog.warning', 'dialog.passwordNotSupported');
  69. } else {
  70. logger.warn('setting password failed', action.error);
  71. APP.UI.messageHandler.showError(
  72. 'dialog.lockTitle', 'dialog.lockMessage');
  73. }
  74. }
  75. return next(action);
  76. }