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 6.1KB

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