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

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