Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

middleware.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 - Redux store.
  20. * @returns {Function}
  21. */
  22. MiddlewareRegistry.register(store => next => action => {
  23. switch (action.type) {
  24. case CONFERENCE_FAILED: {
  25. const { conference, error } = action;
  26. if (conference
  27. && error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) {
  28. // XXX The feature room-lock affords recovery after
  29. // CONFERENCE_FAILED caused by
  30. // JitsiConferenceErrors.PASSWORD_REQUIRED.
  31. if (typeof error.recoverable === 'undefined') {
  32. error.recoverable = true;
  33. }
  34. if (error.recoverable) {
  35. store.dispatch(_openPasswordRequiredPrompt(conference));
  36. }
  37. } else {
  38. store.dispatch(hideDialog(PasswordRequiredPrompt));
  39. store.dispatch(hideDialog(RoomLockPrompt));
  40. }
  41. break;
  42. }
  43. case LOCK_STATE_CHANGED:
  44. // TODO Remove this logic when all components interested in the lock
  45. // state change event are moved into react/redux.
  46. if (typeof APP !== 'undefined') {
  47. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, action.locked);
  48. }
  49. break;
  50. case SET_PASSWORD_FAILED:
  51. return _setPasswordFailed(store, next, action);
  52. }
  53. return next(action);
  54. });
  55. /**
  56. * Handles errors that occur when a password fails to be set.
  57. *
  58. * @param {Store} store - The Redux store in which the specified action is being
  59. * dispatched.
  60. * @param {Dispatch} next - The Redux dispatch function to dispatch the
  61. * specified action to the specified store.
  62. * @param {Action} action - The Redux action SET_PASSWORD_ERROR which has the
  63. * error type that should be handled.
  64. * @private
  65. * @returns {Object} The new state that is the result of the reduction of the
  66. * specified action.
  67. */
  68. function _setPasswordFailed(store, next, action) {
  69. if (typeof APP !== 'undefined') {
  70. // TODO Remove this logic when displaying of error messages on web is
  71. // handled through react/redux.
  72. const { error } = action;
  73. let descriptionKey;
  74. let titleKey;
  75. if (error === JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  76. logger.warn('room passwords not supported');
  77. descriptionKey = 'dialog.passwordNotSupported';
  78. titleKey = 'dialog.passwordNotSupportedTitle';
  79. } else {
  80. logger.warn('setting password failed', error);
  81. descriptionKey = 'dialog.lockMessage';
  82. titleKey = 'dialog.lockTitle';
  83. }
  84. APP.UI.messageHandler.showError({
  85. descriptionKey,
  86. titleKey
  87. });
  88. }
  89. return next(action);
  90. }