Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.any.ts 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* eslint-disable lines-around-comment */
  2. // @ts-ignore
  3. import Bourne from '@hapi/bourne';
  4. // @ts-ignore
  5. import { jitsiLocalStorage } from '@jitsi/js-utils';
  6. import _ from 'lodash';
  7. import { IReduxState } from '../../app/types';
  8. import { browser } from '../lib-jitsi-meet';
  9. import { parseURLParams } from '../util/parseURLParams';
  10. import { IConfig } from './configType';
  11. import CONFIG_WHITELIST from './configWhitelist';
  12. import { _CONFIG_STORE_PREFIX } from './constants';
  13. import INTERFACE_CONFIG_WHITELIST from './interfaceConfigWhitelist';
  14. import logger from './logger';
  15. // XXX The function getRoomName is split out of
  16. // functions.any.js because it is bundled in both app.bundle and
  17. // do_external_connect, webpack 1 does not support tree shaking, and we don't
  18. // want all functions to be bundled in do_external_connect.
  19. export { default as getRoomName } from './getRoomName';
  20. /**
  21. * Create a "fake" configuration object for the given base URL. This is used in case the config
  22. * couldn't be loaded in the welcome page, so at least we have something to try with.
  23. *
  24. * @param {string} baseURL - URL of the deployment for which we want the fake config.
  25. * @returns {Object}
  26. */
  27. export function createFakeConfig(baseURL: string) {
  28. const url = new URL(baseURL);
  29. return {
  30. hosts: {
  31. domain: url.hostname,
  32. muc: `conference.${url.hostname}`
  33. },
  34. bosh: `${baseURL}http-bind`,
  35. p2p: {
  36. enabled: true
  37. }
  38. };
  39. }
  40. /**
  41. * Selector used to get the meeting region.
  42. *
  43. * @param {Object} state - The global state.
  44. * @returns {string}
  45. */
  46. export function getMeetingRegion(state: IReduxState) {
  47. return state['features/base/config']?.deploymentInfo?.region || '';
  48. }
  49. /**
  50. * Selector for determining if sending multiple stream support is enabled.
  51. *
  52. * @param {Object} state - The global state.
  53. * @returns {boolean}
  54. */
  55. export function getMultipleVideoSendingSupportFeatureFlag(state: IReduxState) {
  56. return navigator.product !== 'ReactNative' && isUnifiedPlanEnabled(state);
  57. }
  58. /**
  59. * Selector used to get a feature flag.
  60. *
  61. * @param {Object} state - The global state.
  62. * @param {string} featureFlag - The name of the feature flag.
  63. * @returns {boolean}
  64. */
  65. export function getFeatureFlag(state: IReduxState, featureFlag: string) {
  66. const featureFlags = state['features/base/config']?.flags || {};
  67. return featureFlags[featureFlag as keyof typeof featureFlags];
  68. }
  69. /**
  70. * Selector used to get the disableRemoveRaisedHandOnFocus.
  71. *
  72. * @param {Object} state - The global state.
  73. * @returns {boolean}
  74. */
  75. export function getDisableRemoveRaisedHandOnFocus(state: IReduxState) {
  76. return state['features/base/config']?.disableRemoveRaisedHandOnFocus || false;
  77. }
  78. /**
  79. * Selector used to get the endpoint used for fetching the recording.
  80. *
  81. * @param {Object} state - The global state.
  82. * @returns {string}
  83. */
  84. export function getRecordingSharingUrl(state: IReduxState) {
  85. return state['features/base/config'].recordingSharingUrl;
  86. }
  87. /**
  88. * Overrides JSON properties in {@code config} and
  89. * {@code interfaceConfig} Objects with the values from {@code newConfig}.
  90. * Overrides only the whitelisted keys.
  91. *
  92. * @param {Object} config - The config Object in which we'll be overriding
  93. * properties.
  94. * @param {Object} interfaceConfig - The interfaceConfig Object in which we'll
  95. * be overriding properties.
  96. * @param {Object} json - Object containing configuration properties.
  97. * Destination object is selected based on root property name:
  98. * {
  99. * config: {
  100. * // config.js properties here
  101. * },
  102. * interfaceConfig: {
  103. * // interface_config.js properties here
  104. * }
  105. * }.
  106. * @returns {void}
  107. */
  108. export function overrideConfigJSON(config: IConfig, interfaceConfig: any, json: any) {
  109. for (const configName of Object.keys(json)) {
  110. let configObj;
  111. if (configName === 'config') {
  112. configObj = config;
  113. } else if (configName === 'interfaceConfig') {
  114. configObj = interfaceConfig;
  115. }
  116. if (configObj) {
  117. const configJSON
  118. = getWhitelistedJSON(configName as 'interfaceConfig' | 'config', json[configName]);
  119. if (!_.isEmpty(configJSON)) {
  120. logger.info(
  121. `Extending ${configName} with: ${
  122. JSON.stringify(configJSON)}`);
  123. // eslint-disable-next-line arrow-body-style
  124. _.mergeWith(configObj, configJSON, (oldValue, newValue) => {
  125. // XXX We don't want to merge the arrays, we want to
  126. // overwrite them.
  127. return Array.isArray(oldValue) ? newValue : undefined;
  128. });
  129. }
  130. }
  131. }
  132. }
  133. /* eslint-enable max-params, no-shadow */
  134. /**
  135. * Apply whitelist filtering for configs with whitelists.
  136. * Only extracts overridden values for keys we allow to be overridden.
  137. *
  138. * @param {string} configName - The config name, one of config or interfaceConfig.
  139. * @param {Object} configJSON - The object with keys and values to override.
  140. * @returns {Object} - The result object only with the keys
  141. * that are whitelisted.
  142. */
  143. export function getWhitelistedJSON(configName: 'interfaceConfig' | 'config', configJSON: any): Object {
  144. if (configName === 'interfaceConfig') {
  145. return _.pick(configJSON, INTERFACE_CONFIG_WHITELIST);
  146. } else if (configName === 'config') {
  147. return _.pick(configJSON, CONFIG_WHITELIST);
  148. }
  149. return configJSON;
  150. }
  151. /**
  152. * Selector for determining if the display name is read only.
  153. *
  154. * @param {Object} state - The state of the app.
  155. * @returns {boolean}
  156. */
  157. export function isNameReadOnly(state: IReduxState): boolean {
  158. return Boolean(state['features/base/config'].disableProfile
  159. || state['features/base/config'].readOnlyName);
  160. }
  161. /**
  162. * Selector for determining if the display name is visible.
  163. *
  164. * @param {Object} state - The state of the app.
  165. * @returns {boolean}
  166. */
  167. export function isDisplayNameVisible(state: IReduxState): boolean {
  168. return !state['features/base/config'].hideDisplayName;
  169. }
  170. /**
  171. * Selector for determining if Unified plan support is enabled.
  172. *
  173. * @param {Object} state - The state of the app.
  174. * @returns {boolean}
  175. */
  176. export function isUnifiedPlanEnabled(state: IReduxState): boolean {
  177. const { enableUnifiedOnChrome = true } = state['features/base/config'];
  178. return browser.supportsUnifiedPlan()
  179. && (!browser.isChromiumBased() || (browser.isChromiumBased() && enableUnifiedOnChrome));
  180. }
  181. /**
  182. * Restores a Jitsi Meet config.js from {@code localStorage} if it was
  183. * previously downloaded from a specific {@code baseURL} and stored with
  184. * {@link storeConfig}.
  185. *
  186. * @param {string} baseURL - The base URL from which the config.js was
  187. * previously downloaded and stored with {@code storeConfig}.
  188. * @returns {?Object} The Jitsi Meet config.js which was previously downloaded
  189. * from {@code baseURL} and stored with {@code storeConfig} if it was restored;
  190. * otherwise, {@code undefined}.
  191. */
  192. export function restoreConfig(baseURL: string) {
  193. const key = `${_CONFIG_STORE_PREFIX}/${baseURL}`;
  194. const config = jitsiLocalStorage.getItem(key);
  195. if (config) {
  196. try {
  197. return Bourne.parse(config) || undefined;
  198. } catch (e) {
  199. // Somehow incorrect data ended up in the storage. Clean it up.
  200. jitsiLocalStorage.removeItem(key);
  201. }
  202. }
  203. return undefined;
  204. }
  205. /* eslint-disable max-params */
  206. /**
  207. * Inspects the hash part of the location URI and overrides values specified
  208. * there in the corresponding config objects given as the arguments. The syntax
  209. * is: {@code https://server.com/room#config.debug=true
  210. * &interfaceConfig.showButton=false}.
  211. *
  212. * In the hash part each parameter will be parsed to JSON and then the root
  213. * object will be matched with the corresponding config object given as the
  214. * argument to this function.
  215. *
  216. * @param {Object} config - This is the general config.
  217. * @param {Object} interfaceConfig - This is the interface config.
  218. * @param {URI} location - The new location to which the app is navigating to.
  219. * @returns {void}
  220. */
  221. export function setConfigFromURLParams(
  222. config: IConfig, interfaceConfig: any, location: string | URL) {
  223. const params = parseURLParams(location);
  224. const json: any = {};
  225. // At this point we have:
  226. // params = {
  227. // "config.disableAudioLevels": false,
  228. // "config.channelLastN": -1,
  229. // "interfaceConfig.APP_NAME": "Jitsi Meet"
  230. // }
  231. // We want to have:
  232. // json = {
  233. // config: {
  234. // "disableAudioLevels": false,
  235. // "channelLastN": -1
  236. // },
  237. // interfaceConfig: {
  238. // "APP_NAME": "Jitsi Meet"
  239. // }
  240. // }
  241. config && (json.config = {});
  242. interfaceConfig && (json.interfaceConfig = {});
  243. for (const param of Object.keys(params)) {
  244. let base = json;
  245. const names = param.split('.');
  246. const last = names.pop() ?? '';
  247. for (const name of names) {
  248. base = base[name] = base[name] || {};
  249. }
  250. base[last] = params[param];
  251. }
  252. overrideConfigJSON(config, interfaceConfig, json);
  253. }
  254. /* eslint-enable max-params */
  255. /**
  256. * Returns the dial out url.
  257. *
  258. * @param {Object} state - The state of the app.
  259. * @returns {string}
  260. */
  261. export function getDialOutStatusUrl(state: IReduxState) {
  262. return state['features/base/config'].guestDialOutStatusUrl;
  263. }
  264. /**
  265. * Returns the dial out status url.
  266. *
  267. * @param {Object} state - The state of the app.
  268. * @returns {string}
  269. */
  270. export function getDialOutUrl(state: IReduxState) {
  271. return state['features/base/config'].guestDialOutUrl;
  272. }