選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

middleware.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. // Create/destroy the local tracks as needed: create them the first time we
  69. // are going to render an actual route (be that the WelcomePage or the
  70. // Conference).
  71. //
  72. // When the WelcomePage is disabled, the app will transition to the
  73. // null/undefined route. Detect these transitions and create/destroy the
  74. // local tracks so the camera doesn't stay open if the app is not rendering
  75. // any component.
  76. if (typeof routeToRender === 'undefined' || routeToRender === null) {
  77. // Destroy the local tracks if there is no route to render and there is
  78. // no welcome page.
  79. app.props.welcomePageEnabled || dispatch(destroyLocalTracks());
  80. } else {
  81. // Create the local tracks if they haven't been created yet.
  82. state['features/base/tracks'].some(t => t.local)
  83. || dispatch(createInitialLocalTracks());
  84. }
  85. app._navigate(routeToRender);
  86. }
  87. /**
  88. * Notifies the feature app that the action {@link SET_LOCATION_URL} is being
  89. * dispatched within a specific redux {@code store}.
  90. *
  91. * @param {Store} store - The redux store in which the specified {@code action}
  92. * is being dispatched.
  93. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  94. * specified {@code action} to the specified {@code store}.
  95. * @param {Action} action - The redux action, {@code SET_LOCATION_URL}, which is
  96. * being dispatched in the specified {@code store}.
  97. * @private
  98. * @returns {Object} The new state that is the result of the reduction of the
  99. * specified {@code action}.
  100. */
  101. function _setLocationURL({ getState }, next, action) {
  102. const result = next(action);
  103. getState()['features/app'].app._navigate(undefined);
  104. return result;
  105. }
  106. /**
  107. * Notifies the feature app that the action {@link SET_ROOM} is being dispatched
  108. * within a specific redux {@code store}.
  109. *
  110. * @param {Store} store - The redux store in which the specified {@code action}
  111. * is being dispatched.
  112. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  113. * specified {@code action} to the specified {@code store}.
  114. * @param {Action} action - The redux action, {@code SET_ROOM}, which is being
  115. * dispatched in the specified {@code store}.
  116. * @private
  117. * @returns {Object} The new state that is the result of the reduction of the
  118. * specified {@code action}.
  119. */
  120. function _setRoom(store, next, action) {
  121. const result = next(action);
  122. _navigate(store);
  123. return result;
  124. }