Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.native.ts 6.1KB

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