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.native.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { setRoom } from '../base/conference';
  4. import {
  5. configWillLoad,
  6. createFakeConfig,
  7. loadConfigError,
  8. restoreConfig,
  9. setConfig,
  10. storeConfig
  11. } from '../base/config';
  12. import { connect, disconnect, setLocationURL } from '../base/connection';
  13. import { loadConfig } from '../base/lib-jitsi-meet/functions.native';
  14. import { createDesiredLocalTracks } from '../base/tracks';
  15. import {
  16. appendURLParam,
  17. getBackendSafeRoomName,
  18. parseURIString,
  19. parseURLParams,
  20. toURLString
  21. } from '../base/util';
  22. import { isPrejoinPageEnabled } from '../mobile/navigation/functions';
  23. import {
  24. goBackToRoot,
  25. navigateRoot
  26. } from '../mobile/navigation/rootNavigationContainerRef';
  27. import { screen } from '../mobile/navigation/routes';
  28. import { setFatalError } from '../overlay';
  29. import { getDefaultURL } from './functions';
  30. import { addTrackStateToURL } from './functions.native';
  31. import logger from './logger';
  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. logger.info(`appNavigate to ${uri}`);
  44. return async (dispatch: Dispatch<any>, getState: Function) => {
  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. if (room) {
  67. navigateRoot(screen.connecting);
  68. }
  69. dispatch(disconnect());
  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 = appendURLParam(url, 'room', getBackendSafeRoomName(room)));
  79. const { release } = parseURLParams(location, true, 'search');
  80. release && (url = appendURLParam(url, 'release', release));
  81. let config;
  82. // Avoid (re)loading the config when there is no room.
  83. if (!room) {
  84. config = restoreConfig(baseURL);
  85. }
  86. if (!config) {
  87. try {
  88. config = await loadConfig(url);
  89. dispatch(storeConfig(baseURL, config));
  90. } catch (error) {
  91. config = restoreConfig(baseURL);
  92. if (!config) {
  93. if (room) {
  94. dispatch(loadConfigError(error, locationURL));
  95. return;
  96. }
  97. // If there is no room (we are on the welcome page), don't fail, just create a fake one.
  98. logger.warn('Failed to load config but there is no room, applying a fake one');
  99. config = createFakeConfig(baseURL);
  100. }
  101. }
  102. }
  103. if (getState()['features/base/config'].locationURL !== locationURL) {
  104. dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));
  105. return;
  106. }
  107. dispatch(setLocationURL(locationURL));
  108. dispatch(setConfig(config));
  109. dispatch(setRoom(room));
  110. if (room) {
  111. dispatch(createDesiredLocalTracks());
  112. if (isPrejoinPageEnabled(getState())) {
  113. navigateRoot(screen.preJoin);
  114. } else {
  115. dispatch(connect());
  116. navigateRoot(screen.conference.root);
  117. }
  118. } else {
  119. goBackToRoot(getState(), dispatch);
  120. }
  121. };
  122. }
  123. /**
  124. * Reloads the page.
  125. *
  126. * @protected
  127. * @returns {Function}
  128. */
  129. export function reloadNow() {
  130. return (dispatch: Dispatch<Function>, getState: Function) => {
  131. dispatch(setFatalError(undefined));
  132. const state = getState();
  133. const { locationURL } = state['features/base/connection'];
  134. // Preserve the local tracks muted state after the reload.
  135. const newURL = addTrackStateToURL(locationURL, state);
  136. logger.info(`Reloading the conference using URL: ${locationURL}`);
  137. dispatch(appNavigate(toURLString(newURL)));
  138. };
  139. }