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

actions.web.ts 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // @ts-expect-error
  2. import { API_ID } from '../../../modules/API';
  3. import { setRoom } from '../base/conference/actions';
  4. import {
  5. configWillLoad,
  6. loadConfigError,
  7. setConfig,
  8. storeConfig
  9. } from '../base/config/actions';
  10. import { createFakeConfig, restoreConfig } from '../base/config/functions.web';
  11. import { setLocationURL } from '../base/connection/actions.web';
  12. import { loadConfig } from '../base/lib-jitsi-meet/functions.web';
  13. import { inIframe } from '../base/util/iframeUtils';
  14. import { parseURLParams } from '../base/util/parseURLParams';
  15. import {
  16. appendURLParam,
  17. getBackendSafeRoomName,
  18. parseURIString
  19. } from '../base/util/uri';
  20. import { isVpaasMeeting } from '../jaas/functions';
  21. import { clearNotifications, showNotification } from '../notifications/actions';
  22. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  23. import { isWelcomePageEnabled } from '../welcome/functions';
  24. import {
  25. redirectToStaticPage,
  26. redirectWithStoredParams,
  27. reloadWithStoredParams
  28. } from './actions.any';
  29. import { getDefaultURL, getName } from './functions.web';
  30. import logger from './logger';
  31. import { IStore } from './types';
  32. export * from './actions.any';
  33. /**
  34. * Triggers an in-app navigation to a specific route. Allows navigation to be
  35. * abstracted between the mobile/React Native and Web/React applications.
  36. *
  37. * @param {string|undefined} uri - The URI to which to navigate. It may be a
  38. * full URL with an HTTP(S) scheme, a full or partial URI with the app-specific
  39. * scheme, or a mere room name.
  40. * @returns {Function}
  41. */
  42. export function appNavigate(uri?: string) {
  43. return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  44. let location = parseURIString(uri);
  45. // If the specified location (URI) does not identify a host, use the app's
  46. // default.
  47. if (!location || !location.host) {
  48. const defaultLocation = parseURIString(getDefaultURL(getState));
  49. if (location) {
  50. location.host = defaultLocation.host;
  51. // FIXME Turn location's host, hostname, and port properties into
  52. // setters in order to reduce the risks of inconsistent state.
  53. location.hostname = defaultLocation.hostname;
  54. location.pathname
  55. = defaultLocation.pathname + location.pathname.substr(1);
  56. location.port = defaultLocation.port;
  57. location.protocol = defaultLocation.protocol;
  58. } else {
  59. location = defaultLocation;
  60. }
  61. }
  62. location.protocol || (location.protocol = 'https:');
  63. const { contextRoot, host, room } = location;
  64. const locationURL = new URL(location.toString());
  65. // There are notifications now that gets displayed after we technically left
  66. // the conference, but we're still on the conference screen.
  67. dispatch(clearNotifications());
  68. dispatch(configWillLoad(locationURL, room));
  69. let protocol = location.protocol.toLowerCase();
  70. // The React Native app supports an app-specific scheme which is sure to not
  71. // be supported by fetch.
  72. protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
  73. const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
  74. let url = `${baseURL}config.js`;
  75. // XXX In order to support multiple shards, tell the room to the deployment.
  76. room && (url = appendURLParam(url, 'room', getBackendSafeRoomName(room) ?? ''));
  77. const { release } = parseURLParams(location, true, 'search');
  78. release && (url = appendURLParam(url, 'release', release));
  79. let config;
  80. // Avoid (re)loading the config when there is no room.
  81. if (!room) {
  82. config = restoreConfig(baseURL);
  83. }
  84. if (!config) {
  85. try {
  86. config = await loadConfig(url);
  87. dispatch(storeConfig(baseURL, config));
  88. } catch (error: any) {
  89. config = restoreConfig(baseURL);
  90. if (!config) {
  91. if (room) {
  92. dispatch(loadConfigError(error, locationURL));
  93. return;
  94. }
  95. // If there is no room (we are on the welcome page), don't fail, just create a fake one.
  96. logger.warn('Failed to load config but there is no room, applying a fake one');
  97. config = createFakeConfig(baseURL);
  98. }
  99. }
  100. }
  101. if (getState()['features/base/config'].locationURL !== locationURL) {
  102. dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));
  103. return;
  104. }
  105. dispatch(setLocationURL(locationURL));
  106. dispatch(setConfig(config));
  107. dispatch(setRoom(room));
  108. };
  109. }
  110. /**
  111. * Check if the welcome page is enabled and redirects to it.
  112. * If requested show a thank you dialog before that.
  113. * If we have a close page enabled, redirect to it without
  114. * showing any other dialog.
  115. *
  116. * @param {Object} options - Used to decide which particular close page to show
  117. * or if close page is disabled, whether we should show the thankyou dialog.
  118. * @param {boolean} options.showThankYou - Whether we should
  119. * show thank you dialog.
  120. * @param {boolean} options.feedbackSubmitted - Whether feedback was submitted.
  121. * @returns {Function}
  122. */
  123. export function maybeRedirectToWelcomePage(options: { feedbackSubmitted?: boolean; showThankYou?: boolean; } = {}) {
  124. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  125. const {
  126. enableClosePage
  127. } = getState()['features/base/config'];
  128. // if close page is enabled redirect to it, without further action
  129. if (enableClosePage) {
  130. if (isVpaasMeeting(getState())) {
  131. const isOpenedInIframe = inIframe();
  132. if (isOpenedInIframe) {
  133. // @ts-ignore
  134. window.location = 'about:blank';
  135. } else {
  136. dispatch(redirectToStaticPage('/'));
  137. }
  138. return;
  139. }
  140. const { jwt } = getState()['features/base/jwt'];
  141. let hashParam;
  142. // save whether current user is guest or not, and pass auth token,
  143. // before navigating to close page
  144. window.sessionStorage.setItem('guest', (!jwt).toString());
  145. window.sessionStorage.setItem('jwt', jwt ?? '');
  146. let path = 'close.html';
  147. if (interfaceConfig.SHOW_PROMOTIONAL_CLOSE_PAGE) {
  148. if (Number(API_ID) === API_ID) {
  149. hashParam = `#jitsi_meet_external_api_id=${API_ID}`;
  150. }
  151. path = 'close3.html';
  152. } else if (!options.feedbackSubmitted) {
  153. path = 'close2.html';
  154. }
  155. dispatch(redirectToStaticPage(`static/${path}`, hashParam));
  156. return;
  157. }
  158. // else: show thankYou dialog only if there is no feedback
  159. if (options.showThankYou) {
  160. dispatch(showNotification({
  161. titleArguments: { appName: getName() },
  162. titleKey: 'dialog.thankYou'
  163. }, NOTIFICATION_TIMEOUT_TYPE.STICKY));
  164. }
  165. // if Welcome page is enabled redirect to welcome page after 3 sec, if
  166. // there is a thank you message to be shown, 0.5s otherwise.
  167. if (isWelcomePageEnabled(getState())) {
  168. setTimeout(
  169. () => {
  170. dispatch(redirectWithStoredParams('/'));
  171. },
  172. options.showThankYou ? 3000 : 500);
  173. }
  174. };
  175. }
  176. /**
  177. * Reloads the page.
  178. *
  179. * @protected
  180. * @returns {Function}
  181. */
  182. export function reloadNow() {
  183. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  184. const state = getState();
  185. const { locationURL } = state['features/base/connection'];
  186. logger.info(`Reloading the conference using URL: ${locationURL}`);
  187. dispatch(reloadWithStoredParams());
  188. };
  189. }