Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.js 4.5KB

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