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 3.1KB

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