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.5KB

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