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.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { addKnownDomains } from '../known-domains';
  4. import { parseURIString } from '../util';
  5. import {
  6. CONFIG_WILL_LOAD,
  7. LOAD_CONFIG_ERROR,
  8. SET_CONFIG
  9. } from './actionTypes';
  10. import { _CONFIG_STORE_PREFIX } from './constants';
  11. import { setConfigFromURLParams } from './functions';
  12. /**
  13. * Signals that the configuration for a specific locationURL will be loaded now.
  14. *
  15. * @param {string|URL} locationURL - The URL of the location which necessitated
  16. * the loading of a configuration.
  17. * @returns {{
  18. * type: CONFIG_WILL_LOAD,
  19. * locationURL
  20. * }}
  21. */
  22. export function configWillLoad(locationURL: string | URL) {
  23. return {
  24. type: CONFIG_WILL_LOAD,
  25. locationURL
  26. };
  27. }
  28. /**
  29. * Signals that a configuration could not be loaded due to a specific error.
  30. *
  31. * @param {Error} error - The {@code Error} which prevented the successful
  32. * loading of a configuration.
  33. * @param {string|URL} locationURL - The URL of the location which necessitated
  34. * the loading of a configuration.
  35. * @returns {{
  36. * type: LOAD_CONFIG_ERROR,
  37. * error: Error,
  38. * locationURL
  39. * }}
  40. */
  41. export function loadConfigError(error: Error, locationURL: string | URL) {
  42. return {
  43. type: LOAD_CONFIG_ERROR,
  44. error,
  45. locationURL
  46. };
  47. }
  48. /**
  49. * Sets the configuration represented by the feature base/config. The
  50. * configuration is defined and consumed by the library lib-jitsi-meet but some
  51. * of its properties are consumed by the application jitsi-meet as well.
  52. *
  53. * @param {Object} config - The configuration to be represented by the feature
  54. * base/config.
  55. * @returns {Function}
  56. */
  57. export function setConfig(config: Object = {}) {
  58. return (dispatch: Dispatch<*>, getState: Function) => {
  59. const { locationURL } = getState()['features/base/connection'];
  60. // Now that the loading of the config was successful override the values
  61. // with the parameters passed in the hash part of the location URI.
  62. // TODO We're still in the middle ground between old Web with config,
  63. // interfaceConfig, and loggingConfig used via global variables and new
  64. // Web and mobile reading the respective values from the redux store.
  65. // On React Native there's no interfaceConfig at all yet and
  66. // loggingConfig is not loaded but there's a default value in the redux
  67. // store.
  68. // Only the config will be overridden on React Native, as the other
  69. // globals will be undefined here. It's intentional - we do not care to
  70. // override those configs yet.
  71. locationURL
  72. && setConfigFromURLParams(
  73. // On Web the config also comes from the window.config global,
  74. // but it is resolved in the loadConfig procedure.
  75. config,
  76. window.interfaceConfig,
  77. window.loggingConfig,
  78. locationURL);
  79. dispatch({
  80. type: SET_CONFIG,
  81. config
  82. });
  83. };
  84. }
  85. /**
  86. * Stores a specific Jitsi Meet config.js object into {@code localStorage}.
  87. *
  88. * @param {string} baseURL - The base URL from which the config.js was
  89. * downloaded.
  90. * @param {Object} config - The Jitsi Meet config.js to store.
  91. * @returns {Function}
  92. */
  93. export function storeConfig(baseURL: string, config: Object) {
  94. return (dispatch: Dispatch<*>) => {
  95. // Try to store the configuration in localStorage. If the deployment
  96. // specified 'getroom' as a function, for example, it does not make
  97. // sense to and it will not be stored.
  98. let b = false;
  99. try {
  100. if (typeof window.config === 'undefined'
  101. || window.config !== config) {
  102. window.localStorage.setItem(
  103. `${_CONFIG_STORE_PREFIX}/${baseURL}`,
  104. JSON.stringify(config));
  105. b = true;
  106. }
  107. } catch (e) {
  108. // Ignore the error because the caching is optional.
  109. }
  110. // If base/config knows a domain, then the app knows it.
  111. if (b) {
  112. try {
  113. dispatch(addKnownDomains(parseURIString(baseURL).host));
  114. } catch (e) {
  115. // Ignore the error because the fiddling with "known domains" is
  116. // a side effect here.
  117. }
  118. }
  119. return b;
  120. };
  121. }