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

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