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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // @flow
  2. import {
  3. CONFERENCE_FAILED,
  4. LOCK_STATE_CHANGED,
  5. SET_PASSWORD_FAILED
  6. } from '../base/conference';
  7. import { hideDialog } from '../base/dialog';
  8. import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
  9. import { MiddlewareRegistry } from '../base/redux';
  10. import UIEvents from '../../../service/UI/UIEvents';
  11. import { _openPasswordRequiredPrompt } from './actions';
  12. import { PasswordRequiredPrompt, RoomLockPrompt } from './components';
  13. declare var APP: Object;
  14. const logger = require('jitsi-meet-logger').getLogger(__filename);
  15. /**
  16. * Middleware that captures conference failed and checks for password required
  17. * error and requests a dialog for user to enter password.
  18. *
  19. * @param {Store} store - The redux store.
  20. * @returns {Function}
  21. */
  22. MiddlewareRegistry.register(store => next => action => {
  23. switch (action.type) {
  24. case CONFERENCE_FAILED:
  25. return _conferenceFailed(store, next, action);
  26. case LOCK_STATE_CHANGED:
  27. // TODO Remove this logic when all components interested in the lock
  28. // state change event are moved into react/redux.
  29. if (typeof APP !== 'undefined') {
  30. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, action.locked);
  31. }
  32. break;
  33. case SET_PASSWORD_FAILED:
  34. return _setPasswordFailed(store, next, action);
  35. }
  36. return next(action);
  37. });
  38. /**
  39. * Handles errors that occur when a conference fails.
  40. *
  41. * @param {Store} store - The redux store in which the specified action is being
  42. * dispatched.
  43. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  44. * specified action to the specified store.
  45. * @param {Action} action - The redux action {@code CONFERENCE_FAILED} which
  46. * specifies the details associated with the error and the failed conference.
  47. * @private
  48. * @returns {*}
  49. */
  50. function _conferenceFailed({ dispatch }, next, action) {
  51. const { conference, error } = action;
  52. if (conference && error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) {
  53. // XXX The feature room-lock affords recovery after CONFERENCE_FAILED
  54. // caused by JitsiConferenceErrors.PASSWORD_REQUIRED.
  55. if (typeof error.recoverable === 'undefined') {
  56. error.recoverable = true;
  57. }
  58. if (error.recoverable) {
  59. dispatch(_openPasswordRequiredPrompt(conference));
  60. }
  61. } else {
  62. dispatch(hideDialog(PasswordRequiredPrompt));
  63. dispatch(hideDialog(RoomLockPrompt));
  64. }
  65. return next(action);
  66. }
  67. /**
  68. * Handles errors that occur when a password fails to be set.
  69. *
  70. * @param {Store} store - The redux store in which the specified action is being
  71. * dispatched.
  72. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  73. * specified action to the specified store.
  74. * @param {Action} action - The redux action {@code SET_PASSWORD_ERROR} which
  75. * has the error type that should be handled.
  76. * @private
  77. * @returns {*}
  78. */
  79. function _setPasswordFailed(store, next, action) {
  80. if (typeof APP !== 'undefined') {
  81. // TODO Remove this logic when displaying of error messages on web is
  82. // handled through react/redux.
  83. const { error } = action;
  84. let descriptionKey;
  85. let titleKey;
  86. if (error === JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  87. logger.warn('room passwords not supported');
  88. descriptionKey = 'dialog.passwordNotSupported';
  89. titleKey = 'dialog.passwordNotSupportedTitle';
  90. } else {
  91. logger.warn('setting password failed', error);
  92. descriptionKey = 'dialog.lockMessage';
  93. titleKey = 'dialog.lockTitle';
  94. }
  95. APP.UI.messageHandler.showError({
  96. descriptionKey,
  97. titleKey
  98. });
  99. }
  100. return next(action);
  101. }