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

middleware.js 5.3KB

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