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

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