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

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