Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

middleware.js 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // @flow
  2. import { setLastN } from '../base/conference';
  3. import { SET_CALLEE_INFO_VISIBLE } from '../base/jwt';
  4. import { pinParticipant } from '../base/participants';
  5. import { MiddlewareRegistry } from '../base/redux';
  6. import Filmstrip from '../../../modules/UI/videolayout/Filmstrip';
  7. import { SET_FILMSTRIP_ENABLED } from './actionTypes';
  8. declare var APP: Object;
  9. MiddlewareRegistry.register(store => next => action => {
  10. switch (action.type) {
  11. case SET_CALLEE_INFO_VISIBLE:
  12. return _setCalleeInfoVisible(store, next, action);
  13. case SET_FILMSTRIP_ENABLED:
  14. return _setFilmstripEnabled(store, next, action);
  15. }
  16. return next(action);
  17. });
  18. /**
  19. * Notifies the feature filmstrip that the action
  20. * {@link SET_CALLEE_INFO_VISIBLE} is being dispatched within a specific redux
  21. * store.
  22. *
  23. * @param {Store} store - The redux store in which the specified action is being
  24. * dispatched.
  25. * @param {Dispatch} next - The redux dispatch function to dispatch the
  26. * specified action to the specified store.
  27. * @param {Action} action - The redux action {@code SET_CALLEE_INFO_VISIBLE}
  28. * which is being dispatched in the specified store.
  29. * @private
  30. * @returns {Object} The value returned by {@code next(action)}.
  31. */
  32. function _setCalleeInfoVisible({ getState }, next, action) {
  33. if (typeof APP !== 'undefined') {
  34. const oldValue
  35. = Boolean(getState()['features/base/jwt'].calleeInfoVisible);
  36. const result = next(action);
  37. const newValue
  38. = Boolean(getState()['features/base/jwt'].calleeInfoVisible);
  39. oldValue === newValue
  40. // FIXME The following accesses the private state filmstrip of
  41. // Filmstrip. It is written with the understanding that Filmstrip
  42. // will be rewritten in React and, consequently, will not need the
  43. // middleware implemented here, Filmstrip.init, and UI.start.
  44. || (Filmstrip.filmstrip && Filmstrip.toggleFilmstrip(!newValue));
  45. return result;
  46. }
  47. return next(action);
  48. }
  49. /**
  50. * Notifies the feature filmstrip that the action {@link SET_FILMSTRIP_ENABLED}
  51. * is being dispatched within a specific redux store.
  52. *
  53. * @param {Store} store - The redux store in which the specified action is being
  54. * dispatched.
  55. * @param {Dispatch} next - The redux dispatch function to dispatch the
  56. * specified action to the specified store.
  57. * @param {Action} action - The redux action {@code SET_FILMSTRIP_ENABLED} which
  58. * is being dispatched in the specified store.
  59. * @private
  60. * @returns {Object} The value returned by {@code next(action)}.
  61. */
  62. function _setFilmstripEnabled({ dispatch, getState }, next, action) {
  63. const result = next(action);
  64. // FIXME The logic for participant pinning / unpinning is not on React yet
  65. // so dispatching the action is not enough. Hence, perform the following
  66. // only where it will be sufficient i.e. mobile.
  67. if (typeof APP === 'undefined') {
  68. const state = getState();
  69. const { enabled } = state['features/filmstrip'];
  70. const { audioOnly } = state['features/base/conference'];
  71. enabled || dispatch(pinParticipant(null));
  72. // FIXME Audio-only mode fiddles with lastN as well. That's why we don't
  73. // touch lastN in audio-only mode. But it's not clear what the value of
  74. // lastN should be upon exit from audio-only mode if the filmstrip is
  75. // disabled already. Currently, audio-only mode will set undefined
  76. // regardless of whether the filmstrip is disabled. But we don't have a
  77. // practical use case in which audio-only mode is exited while the
  78. // filmstrip is disabled.
  79. audioOnly || dispatch(setLastN(enabled ? undefined : 1));
  80. }
  81. return result;
  82. }