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.

functions.any.ts 10KB

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