Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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