您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 5.1KB

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