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

middleware.js 2.8KB

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