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.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { API_ID } from '../../../modules/API';
  4. import { setRoom } from '../base/conference';
  5. import {
  6. configWillLoad,
  7. createFakeConfig,
  8. loadConfigError,
  9. restoreConfig,
  10. setConfig,
  11. storeConfig
  12. } from '../base/config';
  13. import { setLocationURL } from '../base/connection';
  14. import { loadConfig } from '../base/lib-jitsi-meet/functions.web';
  15. import {
  16. getBackendSafeRoomName,
  17. parseURIString
  18. } from '../base/util';
  19. import { isVpaasMeeting } from '../jaas/functions';
  20. import {
  21. clearNotifications,
  22. NOTIFICATION_TIMEOUT_TYPE,
  23. showNotification
  24. } from '../notifications';
  25. import { setFatalError } from '../overlay';
  26. import {
  27. redirectToStaticPage,
  28. redirectWithStoredParams,
  29. reloadWithStoredParams
  30. } from './actions.any';
  31. import { getDefaultURL, getName } from './functions';
  32. import logger from './logger';
  33. declare var interfaceConfig: Object;
  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. * @returns {Function}
  43. */
  44. export function appNavigate(uri: ?string) {
  45. return async (dispatch: Dispatch<any>, getState: Function) => {
  46. let location = parseURIString(uri);
  47. // If the specified location (URI) does not identify a host, use the app's
  48. // default.
  49. if (!location || !location.host) {
  50. const defaultLocation = parseURIString(getDefaultURL(getState));
  51. if (location) {
  52. location.host = defaultLocation.host;
  53. // FIXME Turn location's host, hostname, and port properties into
  54. // setters in order to reduce the risks of inconsistent state.
  55. location.hostname = defaultLocation.hostname;
  56. location.pathname
  57. = defaultLocation.pathname + location.pathname.substr(1);
  58. location.port = defaultLocation.port;
  59. location.protocol = defaultLocation.protocol;
  60. } else {
  61. location = defaultLocation;
  62. }
  63. }
  64. location.protocol || (location.protocol = 'https:');
  65. const { contextRoot, host, room } = location;
  66. const locationURL = new URL(location.toString());
  67. // There are notifications now that gets displayed after we technically left
  68. // the conference, but we're still on the conference screen.
  69. dispatch(clearNotifications());
  70. dispatch(configWillLoad(locationURL, room));
  71. let protocol = location.protocol.toLowerCase();
  72. // The React Native app supports an app-specific scheme which is sure to not
  73. // be supported by fetch.
  74. protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
  75. const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
  76. let url = `${baseURL}config.js`;
  77. // XXX In order to support multiple shards, tell the room to the deployment.
  78. room && (url += `?room=${getBackendSafeRoomName(room)}`);
  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) {
  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: Object = {}) {
  124. return (dispatch: Dispatch<any>, getState: Function) => {
  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. redirectToStaticPage('/');
  132. return;
  133. }
  134. const { jwt } = getState()['features/base/jwt'];
  135. let hashParam;
  136. // save whether current user is guest or not, and pass auth token,
  137. // before navigating to close page
  138. window.sessionStorage.setItem('guest', !jwt);
  139. window.sessionStorage.setItem('jwt', jwt);
  140. let path = 'close.html';
  141. if (interfaceConfig.SHOW_PROMOTIONAL_CLOSE_PAGE) {
  142. if (Number(API_ID) === API_ID) {
  143. hashParam = `#jitsi_meet_external_api_id=${API_ID}`;
  144. }
  145. path = 'close3.html';
  146. } else if (!options.feedbackSubmitted) {
  147. path = 'close2.html';
  148. }
  149. dispatch(redirectToStaticPage(`static/${path}`, hashParam));
  150. return;
  151. }
  152. // else: show thankYou dialog only if there is no feedback
  153. if (options.showThankYou) {
  154. dispatch(showNotification({
  155. titleArguments: { appName: getName() },
  156. titleKey: 'dialog.thankYou'
  157. }, NOTIFICATION_TIMEOUT_TYPE.STICKY));
  158. }
  159. // if Welcome page is enabled redirect to welcome page after 3 sec, if
  160. // there is a thank you message to be shown, 0.5s otherwise.
  161. if (getState()['features/base/config'].enableWelcomePage) {
  162. setTimeout(
  163. () => {
  164. dispatch(redirectWithStoredParams('/'));
  165. },
  166. options.showThankYou ? 3000 : 500);
  167. }
  168. };
  169. }
  170. /**
  171. * Reloads the page.
  172. *
  173. * @protected
  174. * @returns {Function}
  175. */
  176. export function reloadNow() {
  177. return (dispatch: Dispatch<Function>, getState: Function) => {
  178. dispatch(setFatalError(undefined));
  179. const state = getState();
  180. const { locationURL } = state['features/base/connection'];
  181. logger.info(`Reloading the conference using URL: ${locationURL}`);
  182. dispatch(reloadWithStoredParams());
  183. };
  184. }