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.web.ts 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { IReduxState } from '../app/types';
  2. import { getToolbarButtons } from '../base/config/functions.web';
  3. import { hasAvailableDevices } from '../base/devices/functions';
  4. import { MEET_FEATURES } from '../base/jwt/constants';
  5. import { isJwtFeatureEnabled } from '../base/jwt/functions';
  6. import { isScreenMediaShared } from '../screen-share/functions';
  7. import { isWhiteboardVisible } from '../whiteboard/functions';
  8. import { TOOLBAR_TIMEOUT } from './constants';
  9. export * from './functions.any';
  10. /**
  11. * Helper for getting the height of the toolbox.
  12. *
  13. * @returns {number} The height of the toolbox.
  14. */
  15. export function getToolboxHeight() {
  16. const toolbox = document.getElementById('new-toolbox');
  17. return toolbox?.clientHeight || 0;
  18. }
  19. /**
  20. * Indicates if a toolbar button is enabled.
  21. *
  22. * @param {string} name - The name of the setting section as defined in
  23. * interface_config.js.
  24. * @param {IReduxState} state - The redux state.
  25. * @returns {boolean|undefined} - True to indicate that the given toolbar button
  26. * is enabled, false - otherwise.
  27. */
  28. export function isButtonEnabled(name: string, state: IReduxState) {
  29. const toolbarButtons = getToolbarButtons(state);
  30. return toolbarButtons.indexOf(name) !== -1;
  31. }
  32. /**
  33. * Indicates if the toolbox is visible or not.
  34. *
  35. * @param {IReduxState} state - The state from the Redux store.
  36. * @returns {boolean} - True to indicate that the toolbox is visible, false -
  37. * otherwise.
  38. */
  39. export function isToolboxVisible(state: IReduxState) {
  40. const { iAmRecorder, iAmSipGateway, toolbarConfig } = state['features/base/config'];
  41. const { alwaysVisible } = toolbarConfig || {};
  42. const {
  43. timeoutID,
  44. visible
  45. } = state['features/toolbox'];
  46. const { audioSettingsVisible, videoSettingsVisible } = state['features/settings'];
  47. const whiteboardVisible = isWhiteboardVisible(state);
  48. return Boolean(!iAmRecorder && !iAmSipGateway
  49. && (
  50. timeoutID
  51. || visible
  52. || alwaysVisible
  53. || audioSettingsVisible
  54. || videoSettingsVisible
  55. || whiteboardVisible
  56. ));
  57. }
  58. /**
  59. * Indicates if the audio settings button is disabled or not.
  60. *
  61. * @param {IReduxState} state - The state from the Redux store.
  62. * @returns {boolean}
  63. */
  64. export function isAudioSettingsButtonDisabled(state: IReduxState) {
  65. return !(hasAvailableDevices(state, 'audioInput')
  66. || hasAvailableDevices(state, 'audioOutput'))
  67. || state['features/base/config'].startSilent;
  68. }
  69. /**
  70. * Indicates if the desktop share button is disabled or not.
  71. *
  72. * @param {IReduxState} state - The state from the Redux store.
  73. * @returns {boolean}
  74. */
  75. export function isDesktopShareButtonDisabled(state: IReduxState) {
  76. const { muted, unmuteBlocked } = state['features/base/media'].video;
  77. const videoOrShareInProgress = !muted || isScreenMediaShared(state);
  78. const enabledInJwt = isJwtFeatureEnabled(state, MEET_FEATURES.SCREEN_SHARING, true, true);
  79. return !enabledInJwt || (unmuteBlocked && !videoOrShareInProgress);
  80. }
  81. /**
  82. * Indicates if the video settings button is disabled or not.
  83. *
  84. * @param {IReduxState} state - The state from the Redux store.
  85. * @returns {boolean}
  86. */
  87. export function isVideoSettingsButtonDisabled(state: IReduxState) {
  88. return !hasAvailableDevices(state, 'videoInput');
  89. }
  90. /**
  91. * Indicates if the video mute button is disabled or not.
  92. *
  93. * @param {IReduxState} state - The state from the Redux store.
  94. * @returns {boolean}
  95. */
  96. export function isVideoMuteButtonDisabled(state: IReduxState) {
  97. const { muted, unmuteBlocked } = state['features/base/media'].video;
  98. return !hasAvailableDevices(state, 'videoInput') || (unmuteBlocked && Boolean(muted));
  99. }
  100. /**
  101. * If an overflow drawer should be displayed or not.
  102. * This is usually done for mobile devices or on narrow screens.
  103. *
  104. * @param {IReduxState} state - The state from the Redux store.
  105. * @returns {boolean}
  106. */
  107. export function showOverflowDrawer(state: IReduxState) {
  108. return state['features/toolbox'].overflowDrawer;
  109. }
  110. /**
  111. * Indicates whether the toolbox is enabled or not.
  112. *
  113. * @param {IReduxState} state - The state from the Redux store.
  114. * @returns {boolean}
  115. */
  116. export function isToolboxEnabled(state: IReduxState) {
  117. return state['features/toolbox'].enabled;
  118. }
  119. /**
  120. * Returns the toolbar timeout from config or the default value.
  121. *
  122. * @param {IReduxState} state - The state from the Redux store.
  123. * @returns {number} - Toolbar timeout in milliseconds.
  124. */
  125. export function getToolbarTimeout(state: IReduxState) {
  126. const { toolbarConfig } = state['features/base/config'];
  127. return toolbarConfig?.timeout || TOOLBAR_TIMEOUT;
  128. }