jiti-meet/react/features/toolbox/functions.web.ts

148 lines
4.5 KiB
TypeScript
Raw Normal View History

import { IState } from '../app/types';
import { getToolbarButtons } from '../base/config/functions.web';
import { hasAvailableDevices } from '../base/devices/functions';
import { MEET_FEATURES } from '../base/jwt/constants';
import { isJwtFeatureEnabled } from '../base/jwt/functions';
import { isScreenMediaShared } from '../screen-share/functions';
import { isWhiteboardVisible } from '../whiteboard/functions';
2020-04-16 10:47:10 +00:00
import { TOOLBAR_TIMEOUT } from './constants';
export * from './functions.any';
/**
* Helper for getting the height of the toolbox.
*
* @returns {number} The height of the toolbox.
*/
export function getToolboxHeight() {
const toolbox = document.getElementById('new-toolbox');
return toolbox?.clientHeight || 0;
}
2017-07-26 20:52:41 +00:00
/**
* Indicates if a toolbar button is enabled.
*
* @param {string} name - The name of the setting section as defined in
* interface_config.js.
* @param {IState} state - The redux state.
2020-08-04 22:25:16 +00:00
* @returns {boolean|undefined} - True to indicate that the given toolbar button
* is enabled, false - otherwise.
2017-07-26 20:52:41 +00:00
*/
export function isButtonEnabled(name: string, state: IState) {
const toolbarButtons = getToolbarButtons(state);
2020-08-04 22:25:16 +00:00
return toolbarButtons.indexOf(name) !== -1;
2017-07-26 20:52:41 +00:00
}
2019-03-12 17:45:53 +00:00
/**
* Indicates if the toolbox is visible or not.
*
* @param {IState} state - The state from the Redux store.
2019-03-12 17:45:53 +00:00
* @returns {boolean} - True to indicate that the toolbox is visible, false -
* otherwise.
*/
export function isToolboxVisible(state: IState) {
const { iAmRecorder, iAmSipGateway, toolbarConfig } = state['features/base/config'];
const { alwaysVisible } = toolbarConfig || {};
2019-03-12 17:45:53 +00:00
const {
timeoutID,
visible
} = state['features/toolbox'];
const { audioSettingsVisible, videoSettingsVisible } = state['features/settings'];
const whiteboardVisible = isWhiteboardVisible(state);
2019-03-12 17:45:53 +00:00
return Boolean(!iAmRecorder && !iAmSipGateway
&& (
timeoutID
|| visible
|| alwaysVisible
|| audioSettingsVisible
|| videoSettingsVisible
|| whiteboardVisible
));
2019-03-12 17:45:53 +00:00
}
2020-04-16 10:47:10 +00:00
/**
* Indicates if the audio settings button is disabled or not.
*
* @param {IState} state - The state from the Redux store.
2020-04-16 10:47:10 +00:00
* @returns {boolean}
*/
export function isAudioSettingsButtonDisabled(state: IState) {
return !(hasAvailableDevices(state, 'audioInput')
|| hasAvailableDevices(state, 'audioOutput'))
|| state['features/base/config'].startSilent;
2020-04-16 10:47:10 +00:00
}
/**
* Indicates if the desktop share button is disabled or not.
*
* @param {IState} state - The state from the Redux store.
* @returns {boolean}
*/
export function isDesktopShareButtonDisabled(state: IState) {
const { muted, unmuteBlocked } = state['features/base/media'].video;
const videoOrShareInProgress = !muted || isScreenMediaShared(state);
const enabledInJwt = isJwtFeatureEnabled(state, MEET_FEATURES.SCREEN_SHARING, true, true);
return !enabledInJwt || (unmuteBlocked && !videoOrShareInProgress);
}
2020-04-16 10:47:10 +00:00
/**
* Indicates if the video settings button is disabled or not.
*
* @param {IState} state - The state from the Redux store.
2020-04-16 10:47:10 +00:00
* @returns {boolean}
*/
export function isVideoSettingsButtonDisabled(state: IState) {
return !hasAvailableDevices(state, 'videoInput');
2020-04-16 10:47:10 +00:00
}
/**
* Indicates if the video mute button is disabled or not.
*
* @param {IState} state - The state from the Redux store.
* @returns {boolean}
*/
export function isVideoMuteButtonDisabled(state: IState) {
const { muted, unmuteBlocked } = state['features/base/media'].video;
return !hasAvailableDevices(state, 'videoInput') || (unmuteBlocked && Boolean(muted));
}
/**
* If an overflow drawer should be displayed or not.
* This is usually done for mobile devices or on narrow screens.
*
* @param {IState} state - The state from the Redux store.
* @returns {boolean}
*/
export function showOverflowDrawer(state: IState) {
return state['features/toolbox'].overflowDrawer;
}
/**
* Indicates whether the toolbox is enabled or not.
*
* @param {IState} state - The state from the Redux store.
* @returns {boolean}
*/
export function isToolboxEnabled(state: IState) {
return state['features/toolbox'].enabled;
}
/**
* Returns the toolbar timeout from config or the default value.
*
* @param {IState} state - The state from the Redux store.
2022-08-30 14:21:58 +00:00
* @returns {number} - Toolbar timeout in milliseconds.
*/
export function getToolbarTimeout(state: IState) {
const { toolbarConfig } = state['features/base/config'];
return toolbarConfig?.timeout || TOOLBAR_TIMEOUT;
}