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.

actions.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { setRoom } from '../base/conference';
  2. import {
  3. getDomain,
  4. setDomain
  5. } from '../base/connection';
  6. import {
  7. loadConfig,
  8. setConfig
  9. } from '../base/lib-jitsi-meet';
  10. import {
  11. APP_WILL_MOUNT,
  12. APP_WILL_UNMOUNT
  13. } from './actionTypes';
  14. import {
  15. _getRoomAndDomainFromUrlString,
  16. _getRouteToRender
  17. } from './functions';
  18. import './reducer';
  19. /**
  20. * Triggers an in-app navigation to a different route. Allows navigation to be
  21. * abstracted between the mobile and web versions.
  22. *
  23. * @param {(string|undefined)} urlOrRoom - The URL or room name to which to
  24. * navigate.
  25. * @returns {Function}
  26. */
  27. export function appNavigate(urlOrRoom) {
  28. return (dispatch, getState) => {
  29. const oldDomain = getDomain(getState());
  30. const { domain, room } = _getRoomAndDomainFromUrlString(urlOrRoom);
  31. // TODO Kostiantyn Tsaregradskyi: We should probably detect if user is
  32. // currently in a conference and ask her if she wants to close the
  33. // current conference and start a new one with the new room name or
  34. // domain.
  35. if (typeof domain === 'undefined' || oldDomain === domain) {
  36. // If both domain and room vars became undefined, that means we're
  37. // actually dealing with just room name and not with URL.
  38. dispatch(
  39. _setRoomAndNavigate(
  40. typeof room === 'undefined' && typeof domain === 'undefined'
  41. ? urlOrRoom
  42. : room));
  43. } else if (oldDomain !== domain) {
  44. // Update domain without waiting for config to be loaded to prevent
  45. // race conditions when we will start to load config multiple times.
  46. dispatch(setDomain(domain));
  47. // If domain has changed, that means we need to load new config
  48. // for that new domain and set it, and only after that we can
  49. // navigate to different route.
  50. loadConfig(`https://${domain}`)
  51. .then(config => {
  52. // We set room name only here to prevent race conditions on
  53. // app start to not make app re-render conference page for
  54. // two times.
  55. dispatch(setRoom(room));
  56. dispatch(setConfig(config));
  57. _navigate(getState());
  58. });
  59. }
  60. };
  61. }
  62. /**
  63. * Signals that a specific App will mount (in the terms of React).
  64. *
  65. * @param {App} app - The App which will mount.
  66. * @returns {{
  67. * type: APP_WILL_MOUNT,
  68. * app: App
  69. * }}
  70. */
  71. export function appWillMount(app) {
  72. return {
  73. type: APP_WILL_MOUNT,
  74. app
  75. };
  76. }
  77. /**
  78. * Signals that a specific App will unmount (in the terms of React).
  79. *
  80. * @param {App} app - The App which will unmount.
  81. * @returns {{
  82. * type: APP_WILL_UNMOUNT,
  83. * app: App
  84. * }}
  85. */
  86. export function appWillUnmount(app) {
  87. return {
  88. type: APP_WILL_UNMOUNT,
  89. app
  90. };
  91. }
  92. /**
  93. * Navigates to route corresponding to current room name.
  94. *
  95. * @param {Object} state - Redux state.
  96. * @private
  97. * @returns {void}
  98. */
  99. function _navigate(state) {
  100. const app = state['features/app'].app;
  101. const routeToRender = _getRouteToRender(state);
  102. app._navigate(routeToRender);
  103. }
  104. /**
  105. * Sets room and navigates to new route if needed.
  106. *
  107. * @param {string} newRoom - New room name.
  108. * @private
  109. * @returns {Function}
  110. */
  111. function _setRoomAndNavigate(newRoom) {
  112. return (dispatch, getState) => {
  113. const oldRoom = getState()['features/base/conference'].room;
  114. dispatch(setRoom(newRoom));
  115. const state = getState();
  116. const room = state['features/base/conference'].room;
  117. if (room !== oldRoom) {
  118. _navigate(state);
  119. }
  120. };
  121. }