You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // @flow
  2. import { SET_ROOM } from '../base/conference';
  3. import {
  4. CONNECTION_ESTABLISHED,
  5. getURLWithoutParams,
  6. SET_LOCATION_URL
  7. } from '../base/connection';
  8. import { MiddlewareRegistry } from '../base/redux';
  9. import { _getRouteToRender } from './functions';
  10. MiddlewareRegistry.register(store => next => action => {
  11. switch (action.type) {
  12. case CONNECTION_ESTABLISHED:
  13. return _connectionEstablished(store, next, action);
  14. case SET_LOCATION_URL:
  15. return _setLocationURL(store, next, action);
  16. case SET_ROOM:
  17. return _setRoom(store, next, action);
  18. }
  19. return next(action);
  20. });
  21. /**
  22. * Notifies the feature app that the action {@link CONNECTION_ESTABLISHED} is
  23. * being dispatched within a specific redux {@code store}.
  24. *
  25. * @param {Store} store - The redux store in which the specified {@code action}
  26. * is being dispatched.
  27. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  28. * specified {@code action} to the specified {@code store}.
  29. * @param {Action} action - The redux action {@code CONNECTION_ESTABLISHED}
  30. * which is being dispatched in the specified {@code store}.
  31. * @private
  32. * @returns {Object} The new state that is the result of the reduction of the
  33. * specified {@code action}.
  34. */
  35. function _connectionEstablished(store, next, action) {
  36. const result = next(action);
  37. // In the Web app we explicitly do not want to display the hash and
  38. // query/search URL params. Unfortunately, window.location and, more
  39. // importantly, its params are used not only in jitsi-meet but also in
  40. // lib-jitsi-meet. Consequenlty, the time to remove the params is
  41. // determined by when no one needs them anymore.
  42. const { history, location } = window;
  43. if (history
  44. && location
  45. && history.length
  46. && typeof history.replaceState === 'function') {
  47. const replacement = getURLWithoutParams(location);
  48. if (location !== replacement) {
  49. history.replaceState(
  50. history.state,
  51. (document && document.title) || '',
  52. replacement);
  53. }
  54. }
  55. return result;
  56. }
  57. /**
  58. * Navigates to a route in accord with a specific redux state.
  59. *
  60. * @param {Store} store - The redux store which determines/identifies the route
  61. * to navigate to.
  62. * @private
  63. * @returns {void}
  64. */
  65. function _navigate({ getState }) {
  66. const state = getState();
  67. const { app } = state['features/app'];
  68. const routeToRender = _getRouteToRender(state);
  69. return app._navigate(routeToRender);
  70. }
  71. /**
  72. * Notifies the feature app that the action {@link SET_LOCATION_URL} is being
  73. * dispatched within a specific redux {@code store}.
  74. *
  75. * @param {Store} store - The redux store in which the specified {@code action}
  76. * is being dispatched.
  77. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  78. * specified {@code action} to the specified {@code store}.
  79. * @param {Action} action - The redux action, {@code SET_LOCATION_URL}, which is
  80. * being dispatched in the specified {@code store}.
  81. * @private
  82. * @returns {Object} The new state that is the result of the reduction of the
  83. * specified {@code action}.
  84. */
  85. function _setLocationURL({ getState }, next, action) {
  86. return (
  87. getState()['features/app'].app._navigate(undefined)
  88. .then(() => next(action)));
  89. }
  90. /**
  91. * Notifies the feature app that the action {@link SET_ROOM} is being dispatched
  92. * within a specific redux {@code store}.
  93. *
  94. * @param {Store} store - The redux store in which the specified {@code action}
  95. * is being dispatched.
  96. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  97. * specified {@code action} to the specified {@code store}.
  98. * @param {Action} action - The redux action, {@code SET_ROOM}, which is being
  99. * dispatched in the specified {@code store}.
  100. * @private
  101. * @returns {Object} The new state that is the result of the reduction of the
  102. * specified {@code action}.
  103. */
  104. function _setRoom(store, next, action) {
  105. const result = next(action);
  106. _navigate(store);
  107. return result;
  108. }