Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.js 4.5KB

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