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.native.ts 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import { setRoom } from '../base/conference/actions';
  2. import { getConferenceState } from '../base/conference/functions';
  3. import {
  4. configWillLoad,
  5. loadConfigError,
  6. setConfig,
  7. storeConfig
  8. } from '../base/config/actions';
  9. import {
  10. createFakeConfig,
  11. restoreConfig
  12. } from '../base/config/functions.native';
  13. import { connect, disconnect, setLocationURL } from '../base/connection/actions.native';
  14. import { JITSI_CONNECTION_URL_KEY } from '../base/connection/constants';
  15. import { loadConfig } from '../base/lib-jitsi-meet/functions.native';
  16. import { createDesiredLocalTracks } from '../base/tracks/actions.native';
  17. import isInsecureRoomName from '../base/util/isInsecureRoomName';
  18. import { parseURLParams } from '../base/util/parseURLParams';
  19. import {
  20. appendURLParam,
  21. getBackendSafeRoomName,
  22. parseURIString,
  23. toURLString
  24. } from '../base/util/uri';
  25. import { isPrejoinPageEnabled } from '../mobile/navigation/functions';
  26. import {
  27. goBackToRoot,
  28. navigateRoot
  29. } from '../mobile/navigation/rootNavigationContainerRef';
  30. import { screen } from '../mobile/navigation/routes';
  31. import { clearNotifications } from '../notifications/actions';
  32. import { isUnsafeRoomWarningEnabled } from '../prejoin/functions';
  33. import { maybeRedirectToTokenAuthUrl } from './actions.any';
  34. import { addTrackStateToURL, getDefaultURL } from './functions.native';
  35. import logger from './logger';
  36. import { IReloadNowOptions, IStore } from './types';
  37. export * from './actions.any';
  38. /**
  39. * Triggers an in-app navigation to a specific route. Allows navigation to be
  40. * abstracted between the mobile/React Native and Web/React applications.
  41. *
  42. * @param {string|undefined} uri - The URI to which to navigate. It may be a
  43. * full URL with an HTTP(S) scheme, a full or partial URI with the app-specific
  44. * scheme, or a mere room name.
  45. * @param {Object} [options] - Options.
  46. * @returns {Function}
  47. */
  48. export function appNavigate(uri?: string, options: IReloadNowOptions = {}) {
  49. logger.info(`appNavigate to ${uri}`);
  50. return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  51. let location = parseURIString(uri);
  52. // If the specified location (URI) does not identify a host, use the app's
  53. // default.
  54. if (!location?.host) {
  55. const defaultLocation = parseURIString(getDefaultURL(getState));
  56. if (location) {
  57. location.host = defaultLocation.host;
  58. // FIXME Turn location's host, hostname, and port properties into
  59. // setters in order to reduce the risks of inconsistent state.
  60. location.hostname = defaultLocation.hostname;
  61. location.pathname
  62. = defaultLocation.pathname + location.pathname.substr(1);
  63. location.port = defaultLocation.port;
  64. location.protocol = defaultLocation.protocol;
  65. } else {
  66. location = defaultLocation;
  67. }
  68. }
  69. location.protocol || (location.protocol = 'https:');
  70. const { contextRoot, host, hostname, pathname, room } = location;
  71. const locationURL = new URL(location.toString());
  72. const { conference } = getConferenceState(getState());
  73. if (room) {
  74. if (conference) {
  75. // We need to check if the location is the same with the previous one.
  76. const currentLocationURL = conference?.getConnection()[JITSI_CONNECTION_URL_KEY];
  77. const { hostname: currentHostName, pathname: currentPathName } = currentLocationURL;
  78. if (currentHostName === hostname && currentPathName === pathname) {
  79. logger.warn(`Joining same conference using URL: ${currentLocationURL}`);
  80. return;
  81. }
  82. } else {
  83. navigateRoot(screen.connecting);
  84. }
  85. }
  86. dispatch(disconnect());
  87. dispatch(configWillLoad(locationURL, room));
  88. let protocol = location.protocol.toLowerCase();
  89. // The React Native app supports an app-specific scheme which is sure to not
  90. // be supported by fetch.
  91. protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
  92. const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
  93. let url = `${baseURL}config.js`;
  94. // XXX In order to support multiple shards, tell the room to the deployment.
  95. room && (url = appendURLParam(url, 'room', getBackendSafeRoomName(room) ?? ''));
  96. const { release } = parseURLParams(location, true, 'search');
  97. release && (url = appendURLParam(url, 'release', release));
  98. let config;
  99. // Avoid (re)loading the config when there is no room.
  100. if (!room) {
  101. config = restoreConfig(baseURL);
  102. }
  103. if (!config) {
  104. try {
  105. config = await loadConfig(url);
  106. dispatch(storeConfig(baseURL, config));
  107. } catch (error: any) {
  108. config = restoreConfig(baseURL);
  109. if (!config) {
  110. if (room) {
  111. dispatch(loadConfigError(error, locationURL));
  112. return;
  113. }
  114. // If there is no room (we are on the welcome page), don't fail, just create a fake one.
  115. logger.warn('Failed to load config but there is no room, applying a fake one');
  116. config = createFakeConfig(baseURL);
  117. }
  118. }
  119. }
  120. if (getState()['features/base/config'].locationURL !== locationURL) {
  121. dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));
  122. return;
  123. }
  124. dispatch(setLocationURL(locationURL));
  125. dispatch(setConfig(config));
  126. dispatch(setRoom(room));
  127. if (!room) {
  128. goBackToRoot(getState(), dispatch);
  129. return;
  130. }
  131. dispatch(createDesiredLocalTracks());
  132. dispatch(clearNotifications());
  133. if (!options.hidePrejoin && isPrejoinPageEnabled(getState())) {
  134. if (isUnsafeRoomWarningEnabled(getState()) && isInsecureRoomName(room)) {
  135. navigateRoot(screen.unsafeRoomWarning);
  136. } else {
  137. navigateRoot(screen.preJoin);
  138. }
  139. } else {
  140. dispatch(connect());
  141. navigateRoot(screen.conference.root);
  142. }
  143. };
  144. }
  145. /**
  146. * Check if the welcome page is enabled and redirects to it.
  147. * If requested show a thank you dialog before that.
  148. * If we have a close page enabled, redirect to it without
  149. * showing any other dialog.
  150. *
  151. * @param {Object} _options - Ignored.
  152. * @returns {Function}
  153. */
  154. export function maybeRedirectToWelcomePage(_options?: any): any {
  155. // Dummy.
  156. }
  157. /**
  158. * Reloads the page.
  159. *
  160. * @protected
  161. * @returns {Function}
  162. */
  163. export function reloadNow() {
  164. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  165. const state = getState();
  166. const { locationURL } = state['features/base/connection'];
  167. // Preserve the local tracks muted state after the reload.
  168. // @ts-ignore
  169. const newURL = addTrackStateToURL(locationURL, state);
  170. const reloadAction = () => {
  171. logger.info(`Reloading the conference using URL: ${locationURL}`);
  172. dispatch(appNavigate(toURLString(newURL), {
  173. hidePrejoin: true
  174. }));
  175. };
  176. if (maybeRedirectToTokenAuthUrl(dispatch, getState, reloadAction)) {
  177. return;
  178. }
  179. reloadAction();
  180. };
  181. }