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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. getBackendSafeRoomName,
  17. parseURIString,
  18. toURLString
  19. } from '../base/util';
  20. import { navigateRoot } from '../mobile/navigation/rootNavigationContainerRef';
  21. import { screen } from '../mobile/navigation/routes';
  22. import { setFatalError } from '../overlay';
  23. import { getDefaultURL } from './functions';
  24. import { addTrackStateToURL } from './functions.native';
  25. import logger from './logger';
  26. export * from './actions.any';
  27. /**
  28. * Triggers an in-app navigation to a specific route. Allows navigation to be
  29. * abstracted between the mobile/React Native and Web/React applications.
  30. *
  31. * @param {string|undefined} uri - The URI to which to navigate. It may be a
  32. * full URL with an HTTP(S) scheme, a full or partial URI with the app-specific
  33. * scheme, or a mere room name.
  34. * @returns {Function}
  35. */
  36. export function appNavigate(uri: ?string) {
  37. return async (dispatch: Dispatch<any>, getState: Function) => {
  38. let location = parseURIString(uri);
  39. // If the specified location (URI) does not identify a host, use the app's
  40. // default.
  41. if (!location || !location.host) {
  42. const defaultLocation = parseURIString(getDefaultURL(getState));
  43. if (location) {
  44. location.host = defaultLocation.host;
  45. // FIXME Turn location's host, hostname, and port properties into
  46. // setters in order to reduce the risks of inconsistent state.
  47. location.hostname = defaultLocation.hostname;
  48. location.pathname
  49. = defaultLocation.pathname + location.pathname.substr(1);
  50. location.port = defaultLocation.port;
  51. location.protocol = defaultLocation.protocol;
  52. } else {
  53. location = defaultLocation;
  54. }
  55. }
  56. location.protocol || (location.protocol = 'https:');
  57. const { contextRoot, host, room } = location;
  58. const locationURL = new URL(location.toString());
  59. if (room) {
  60. navigateRoot(screen.connecting);
  61. }
  62. dispatch(disconnect());
  63. dispatch(configWillLoad(locationURL, room));
  64. let protocol = location.protocol.toLowerCase();
  65. // The React Native app supports an app-specific scheme which is sure to not
  66. // be supported by fetch.
  67. protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
  68. const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
  69. let url = `${baseURL}config.js`;
  70. // XXX In order to support multiple shards, tell the room to the deployment.
  71. room && (url += `?room=${getBackendSafeRoomName(room)}`);
  72. let config;
  73. // Avoid (re)loading the config when there is no room.
  74. if (!room) {
  75. config = restoreConfig(baseURL);
  76. }
  77. if (!config) {
  78. try {
  79. config = await loadConfig(url);
  80. dispatch(storeConfig(baseURL, config));
  81. } catch (error) {
  82. config = restoreConfig(baseURL);
  83. if (!config) {
  84. if (room) {
  85. dispatch(loadConfigError(error, locationURL));
  86. return;
  87. }
  88. // If there is no room (we are on the welcome page), don't fail, just create a fake one.
  89. logger.warn('Failed to load config but there is no room, applying a fake one');
  90. config = createFakeConfig(baseURL);
  91. }
  92. }
  93. }
  94. if (getState()['features/base/config'].locationURL !== locationURL) {
  95. dispatch(loadConfigError(new Error('Config no longer needed!'), locationURL));
  96. return;
  97. }
  98. dispatch(setLocationURL(locationURL));
  99. dispatch(setConfig(config));
  100. dispatch(setRoom(room));
  101. if (room) {
  102. dispatch(createDesiredLocalTracks());
  103. dispatch(connect());
  104. }
  105. };
  106. }
  107. /**
  108. * Reloads the page.
  109. *
  110. * @protected
  111. * @returns {Function}
  112. */
  113. export function reloadNow() {
  114. return (dispatch: Dispatch<Function>, getState: Function) => {
  115. dispatch(setFatalError(undefined));
  116. const state = getState();
  117. const { locationURL } = state['features/base/connection'];
  118. // Preserve the local tracks muted state after the reload.
  119. const newURL = addTrackStateToURL(locationURL, state);
  120. logger.info(`Reloading the conference using URL: ${locationURL}`);
  121. dispatch(appNavigate(toURLString(newURL)));
  122. };
  123. }