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

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