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

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