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

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