您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.native.ts 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. // @ts-ignore
  34. import { setFatalError } from '../overlay';
  35. import { addTrackStateToURL, getDefaultURL } from './functions.native';
  36. import logger from './logger';
  37. import { IStore } from './types';
  38. export * from './actions.any';
  39. /**
  40. * Triggers an in-app navigation to a specific route. Allows navigation to be
  41. * abstracted between the mobile/React Native and Web/React applications.
  42. *
  43. * @param {string|undefined} uri - The URI to which to navigate. It may be a
  44. * full URL with an HTTP(S) scheme, a full or partial URI with the app-specific
  45. * scheme, or a mere room name.
  46. * @returns {Function}
  47. */
  48. export function appNavigate(uri?: string) {
  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 || !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, room } = location;
  71. const locationURL = new URL(location.toString());
  72. if (room) {
  73. navigateRoot(screen.connecting);
  74. }
  75. dispatch(disconnect());
  76. dispatch(configWillLoad(locationURL, room));
  77. let protocol = location.protocol.toLowerCase();
  78. // The React Native app supports an app-specific scheme which is sure to not
  79. // be supported by fetch.
  80. protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
  81. const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
  82. let url = `${baseURL}config.js`;
  83. // XXX In order to support multiple shards, tell the room to the deployment.
  84. room && (url = appendURLParam(url, 'room', getBackendSafeRoomName(room) ?? ''));
  85. const { release } = parseURLParams(location, true, 'search');
  86. release && (url = appendURLParam(url, 'release', release));
  87. let config;
  88. // Avoid (re)loading the config when there is no room.
  89. if (!room) {
  90. config = restoreConfig(baseURL);
  91. }
  92. if (!config) {
  93. try {
  94. config = await loadConfig(url);
  95. dispatch(storeConfig(baseURL, config));
  96. } catch (error: any) {
  97. config = restoreConfig(baseURL);
  98. if (!config) {
  99. if (room) {
  100. dispatch(loadConfigError(error, locationURL));
  101. return;
  102. }
  103. // If there is no room (we are on the welcome page), don't fail, just create a fake one.
  104. logger.warn('Failed to load config but there is no room, applying a fake one');
  105. config = createFakeConfig(baseURL);
  106. }
  107. }
  108. }
  109. if (getState()['features/base/config'].locationURL !== locationURL) {
  110. dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));
  111. return;
  112. }
  113. dispatch(setLocationURL(locationURL));
  114. dispatch(setConfig(config));
  115. dispatch(setRoom(room));
  116. if (room) {
  117. dispatch(createDesiredLocalTracks());
  118. dispatch(clearNotifications());
  119. if (isPrejoinPageEnabled(getState())) {
  120. navigateRoot(screen.preJoin);
  121. } else {
  122. dispatch(connect());
  123. navigateRoot(screen.conference.root);
  124. }
  125. } else {
  126. goBackToRoot(getState(), dispatch);
  127. }
  128. };
  129. }
  130. /**
  131. * Check if the welcome page is enabled and redirects to it.
  132. * If requested show a thank you dialog before that.
  133. * If we have a close page enabled, redirect to it without
  134. * showing any other dialog.
  135. *
  136. * @param {Object} options - Ignored.
  137. * @returns {Function}
  138. */
  139. export function maybeRedirectToWelcomePage(options: any) { // eslint-disable-line @typescript-eslint/no-unused-vars
  140. // Dummy.
  141. }
  142. /**
  143. * Reloads the page.
  144. *
  145. * @protected
  146. * @returns {Function}
  147. */
  148. export function reloadNow() {
  149. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  150. dispatch(setFatalError(undefined));
  151. const state = getState();
  152. const { locationURL } = state['features/base/connection'];
  153. // Preserve the local tracks muted state after the reload.
  154. // @ts-ignore
  155. const newURL = addTrackStateToURL(locationURL, state);
  156. logger.info(`Reloading the conference using URL: ${locationURL}`);
  157. dispatch(appNavigate(toURLString(newURL)));
  158. };
  159. }