Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. init
  18. } from './functions';
  19. import './reducer';
  20. /**
  21. * Triggers an in-app navigation to a different route. Allows navigation to be
  22. * abstracted between the mobile and web versions.
  23. *
  24. * @param {(string|undefined)} urlOrRoom - The URL or room name to which to
  25. * navigate.
  26. * @returns {Function}
  27. */
  28. export function appNavigate(urlOrRoom) {
  29. return (dispatch, getState) => {
  30. const oldDomain = getDomain(getState());
  31. const { domain, room } = _getRoomAndDomainFromUrlString(urlOrRoom);
  32. // TODO Kostiantyn Tsaregradskyi: We should probably detect if user is
  33. // currently in a conference and ask her if she wants to close the
  34. // current conference and start a new one with the new room name or
  35. // domain.
  36. if (typeof domain === 'undefined' || oldDomain === domain) {
  37. // If both domain and room vars became undefined, that means we're
  38. // actually dealing with just room name and not with URL.
  39. dispatch(
  40. _setRoomAndNavigate(
  41. typeof room === 'undefined' && typeof domain === 'undefined'
  42. ? urlOrRoom
  43. : room));
  44. } else if (oldDomain !== domain) {
  45. // Update domain without waiting for config to be loaded to prevent
  46. // race conditions when we will start to load config multiple times.
  47. dispatch(setDomain(domain));
  48. // If domain has changed, we need to load the config of the new
  49. // domain and set it, and only after that we can navigate to
  50. // different route.
  51. loadConfig(`https://${domain}`)
  52. .then(
  53. config => configLoaded(/* err */ undefined, config),
  54. err => configLoaded(err, /* config */ undefined));
  55. }
  56. /**
  57. * Notifies that an attempt to load the config(uration) of domain has
  58. * completed.
  59. *
  60. * @param {string|undefined} err - If the loading has failed, the error
  61. * detailing the cause of the failure.
  62. * @param {Object|undefined} config - If the loading has succeeded, the
  63. * loaded config(uration).
  64. * @returns {void}
  65. */
  66. function configLoaded(err, config) {
  67. if (err) {
  68. // XXX The failure could be, for example, because of a
  69. // certificate-related error. In which case the connection will
  70. // fail later in Strophe anyway even if we use the default
  71. // config here.
  72. // The function loadConfig will log the err.
  73. return;
  74. }
  75. // We set room name only here to prevent race conditions on app
  76. // start to not make app re-render conference page for two times.
  77. dispatch(setRoom(room));
  78. dispatch(setConfig(config));
  79. _navigate(getState());
  80. }
  81. };
  82. }
  83. /**
  84. * Temporary solution. Should dispatch actions related to
  85. * initial settings of the app like setting log levels,
  86. * reading the config parameters from query string etc.
  87. *
  88. * @returns {Function}
  89. */
  90. export function appInit() {
  91. return () => {
  92. init();
  93. };
  94. }
  95. /**
  96. * Signals that a specific App will mount (in the terms of React).
  97. *
  98. * @param {App} app - The App which will mount.
  99. * @returns {{
  100. * type: APP_WILL_MOUNT,
  101. * app: App
  102. * }}
  103. */
  104. export function appWillMount(app) {
  105. return {
  106. type: APP_WILL_MOUNT,
  107. app
  108. };
  109. }
  110. /**
  111. * Signals that a specific App will unmount (in the terms of React).
  112. *
  113. * @param {App} app - The App which will unmount.
  114. * @returns {{
  115. * type: APP_WILL_UNMOUNT,
  116. * app: App
  117. * }}
  118. */
  119. export function appWillUnmount(app) {
  120. return {
  121. type: APP_WILL_UNMOUNT,
  122. app
  123. };
  124. }
  125. /**
  126. * Navigates to route corresponding to current room name.
  127. *
  128. * @param {Object} state - Redux state.
  129. * @private
  130. * @returns {void}
  131. */
  132. function _navigate(state) {
  133. const app = state['features/app'].app;
  134. const routeToRender = _getRouteToRender(state);
  135. app._navigate(routeToRender);
  136. }
  137. /**
  138. * Sets room and navigates to new route if needed.
  139. *
  140. * @param {string} newRoom - New room name.
  141. * @private
  142. * @returns {Function}
  143. */
  144. function _setRoomAndNavigate(newRoom) {
  145. return (dispatch, getState) => {
  146. const oldRoom = getState()['features/base/conference'].room;
  147. dispatch(setRoom(newRoom));
  148. const state = getState();
  149. const room = state['features/base/conference'].room;
  150. if (room !== oldRoom) {
  151. _navigate(state);
  152. }
  153. };
  154. }