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

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