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 6.5KB

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