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.web.ts 8.1KB

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