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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { IReduxState } from '../../app/types';
  2. import { iAmVisitor } from '../../visitors/functions';
  3. import { IStateful } from '../app/types';
  4. import CONFIG_WHITELIST from '../config/configWhitelist';
  5. import { IConfigState } from '../config/reducer';
  6. import { IJwtState } from '../jwt/reducer';
  7. import { toState } from '../redux/functions';
  8. import { parseURLParams } from '../util/parseURLParams';
  9. import { DEFAULT_SERVER_URL } from './constants';
  10. import { ISettingsState } from './reducer';
  11. /**
  12. * Returns the effective value of a configuration/preference/setting by applying
  13. * a precedence among the values specified by JWT, URL, settings,
  14. * and config.
  15. *
  16. * @param {Object|Function} stateful - The redux state object or {@code getState} function.
  17. * @param {string} propertyName - The name of the
  18. * configuration/preference/setting (property) to retrieve.
  19. * @param {Object} sources - Flags indicating the configuration/preference/setting sources to
  20. * consider/retrieve values from.
  21. * @param {boolean} sources.config - Config.
  22. * @param {boolean} jwt - JWT.
  23. * @param {boolean} settings - Settings.
  24. * @param {boolean} urlParams - URL parameters.
  25. * @returns {any}
  26. */
  27. export function getPropertyValue(
  28. stateful: IStateful,
  29. propertyName: string,
  30. sources?: any
  31. ) {
  32. // Default values don't play nicely with partial objects and we want to make
  33. // the function easy to use without exhaustively defining all flags:
  34. sources = { // eslint-disable-line no-param-reassign
  35. // Defaults:
  36. config: true,
  37. jwt: true,
  38. settings: true,
  39. urlParams: true,
  40. ...sources
  41. };
  42. // Precedence: jwt -> urlParams -> settings -> config.
  43. const state = toState(stateful);
  44. // jwt
  45. if (sources.jwt) {
  46. const value = state['features/base/jwt'][propertyName as keyof IJwtState];
  47. if (typeof value !== 'undefined') {
  48. return value[propertyName as keyof typeof value];
  49. }
  50. }
  51. // urlParams
  52. if (sources.urlParams) {
  53. if (CONFIG_WHITELIST.indexOf(propertyName) !== -1) {
  54. const urlParams
  55. = parseURLParams(state['features/base/connection'].locationURL ?? '');
  56. const value = urlParams[`config.${propertyName}`];
  57. if (typeof value !== 'undefined') {
  58. return value;
  59. }
  60. }
  61. }
  62. // settings
  63. if (sources.settings) {
  64. const value = state['features/base/settings'][propertyName as keyof ISettingsState];
  65. if (typeof value !== 'undefined') {
  66. return value;
  67. }
  68. }
  69. // config
  70. if (sources.config) {
  71. const value = state['features/base/config'][propertyName as keyof IConfigState];
  72. if (typeof value !== 'undefined') {
  73. return value;
  74. }
  75. }
  76. return undefined;
  77. }
  78. /**
  79. * Gets the currently configured server URL.
  80. *
  81. * @param {Object|Function} stateful - The redux state object or
  82. * {@code getState} function.
  83. * @returns {string} - The currently configured server URL.
  84. */
  85. export function getServerURL(stateful: IStateful) {
  86. const state = toState(stateful);
  87. return state['features/base/settings'].serverURL || DEFAULT_SERVER_URL;
  88. }
  89. /**
  90. * Should we hide the helper dialog when a user tries to do audio only screen sharing.
  91. *
  92. * @param {Object} state - The state of the application.
  93. * @returns {boolean}
  94. */
  95. export function shouldHideShareAudioHelper(state: IReduxState): boolean | undefined {
  96. return state['features/base/settings'].hideShareAudioHelper;
  97. }
  98. /**
  99. * Gets the disabled self view setting.
  100. *
  101. * @param {Object} state - Redux state.
  102. * @returns {boolean}
  103. */
  104. export function getHideSelfView(state: IReduxState) {
  105. return state['features/base/config'].disableSelfView || state['features/base/settings'].disableSelfView
  106. || iAmVisitor(state);
  107. }