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

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