您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if (typeof error.recoverable === 'undefined') {
  27. error.recoverable = true;
  28. }
  29. if (error.recoverable) {
  30. store.dispatch(_openPasswordRequiredPrompt(conference));
  31. }
  32. }
  33. break;
  34. }
  35. case LOCK_STATE_CHANGED:
  36. // TODO Remove this logic when all components interested in the lock
  37. // state change event are moved into react/redux.
  38. if (typeof APP !== 'undefined') {
  39. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, action.locked);
  40. }
  41. break;
  42. case SET_PASSWORD_FAILED:
  43. return _setPasswordFailed(store, next, action);
  44. }
  45. return next(action);
  46. });
  47. /**
  48. * Handles errors that occur when a password fails 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 _setPasswordFailed(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. const { error } = action;
  65. let title;
  66. let message;
  67. if (error === JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED) {
  68. logger.warn('room passwords not supported');
  69. title = 'dialog.warning';
  70. message = 'dialog.passwordNotSupported';
  71. } else {
  72. logger.warn('setting password failed', error);
  73. title = 'dialog.lockTitle';
  74. message = 'dialog.lockMessage';
  75. }
  76. APP.UI.messageHandler.showError(title, message);
  77. }
  78. return next(action);
  79. }