Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

middleware.ts 5.1KB

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