Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

middleware.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 { createInitialLocalTracks, destroyLocalTracks } from '../base/tracks';
  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({ dispatch, getState }) {
  65. const state = getState();
  66. const { app, getRouteToRender } = state['features/app'];
  67. const routeToRender = getRouteToRender && getRouteToRender(state);
  68. // FIXME The following is logic specific to the user experience of the
  69. // mobile/React Native app. Firstly, I don't like that it's here at all.
  70. // Secondly, I copied the mobile/React Native detection from
  71. // react/features/base/config/reducer.js because I couldn't iron out an
  72. // abstraction. Because of the first point, I'm leaving the second point
  73. // unresolved to attract attention to the fact that the following needs more
  74. // thinking.
  75. if (navigator.product === 'ReactNative') {
  76. // Create/destroy the local tracks as needed: create them the first time
  77. // we are going to render an actual route (be that the WelcomePage or
  78. // the Conference).
  79. //
  80. // When the WelcomePage is disabled, the app will transition to the
  81. // null/undefined route. Detect these transitions and create/destroy the
  82. // local tracks so the camera doesn't stay open if the app is not
  83. // rendering any component.
  84. if (typeof routeToRender === 'undefined' || routeToRender === null) {
  85. // Destroy the local tracks if there is no route to render and there
  86. // is no WelcomePage.
  87. app.props.welcomePageEnabled || dispatch(destroyLocalTracks());
  88. } else {
  89. // Create the local tracks if they haven't been created yet.
  90. state['features/base/tracks'].some(t => t.local)
  91. || dispatch(createInitialLocalTracks());
  92. }
  93. }
  94. app._navigate(routeToRender);
  95. }
  96. /**
  97. * Notifies the feature app that the action {@link SET_LOCATION_URL} is being
  98. * dispatched within a specific redux {@code store}.
  99. *
  100. * @param {Store} store - The redux store in which the specified {@code action}
  101. * is being dispatched.
  102. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  103. * specified {@code action} to the specified {@code store}.
  104. * @param {Action} action - The redux action, {@code SET_LOCATION_URL}, which is
  105. * being dispatched in the specified {@code store}.
  106. * @private
  107. * @returns {Object} The new state that is the result of the reduction of the
  108. * specified {@code action}.
  109. */
  110. function _setLocationURL({ getState }, next, action) {
  111. const result = next(action);
  112. getState()['features/app'].app._navigate(undefined);
  113. return result;
  114. }
  115. /**
  116. * Notifies the feature app that the action {@link SET_ROOM} is being dispatched
  117. * within a specific redux {@code store}.
  118. *
  119. * @param {Store} store - The redux store in which the specified {@code action}
  120. * is being dispatched.
  121. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  122. * specified {@code action} to the specified {@code store}.
  123. * @param {Action} action - The redux action, {@code SET_ROOM}, which is being
  124. * dispatched in the specified {@code store}.
  125. * @private
  126. * @returns {Object} The new state that is the result of the reduction of the
  127. * specified {@code action}.
  128. */
  129. function _setRoom(store, next, action) {
  130. const result = next(action);
  131. _navigate(store);
  132. return result;
  133. }