Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

middleware.js 3.1KB

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