Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

ref(toolbar) Convert to function component (#13511)

Robert Pintilii52fbd3aeb877
diff --git a/react/features/toolbox/components/web/Toolbox.tsx b/react/features/toolbox/components/web/Toolbox.tsx
index cc15970c71..1ad2fd7c82 100644
--- a/react/features/toolbox/components/web/Toolbox.tsx
+++ b/react/features/toolbox/components/web/Toolbox.tsx
@@ -1,12 +1,8 @@
-import { withStyles } from '@mui/styles';
-import clsx from 'clsx';
-import React, { Component, RefObject } from 'react';
+import React, { useCallback, useEffect, useRef } from 'react';
import { WithTranslation } from 'react-i18next';
-import { batch, connect } from 'react-redux';
+import { connect } from 'react-redux';
+import { makeStyles } from 'tss-react/mui';
-import { isSpeakerStatsDisabled } from '../../../../features/speaker-stats/functions';
-import { ACTION_SHORTCUT_TRIGGERED, createShortcutEvent } from '../../../analytics/AnalyticsEvents';
-import { sendAnalytics } from '../../../analytics/functions';
import { IReduxState, IStore } from '../../../app/types';
import { VISITORS_MODE_BUTTONS } from '../../../base/config/constants';
import {
@@ -14,47 +10,13 @@ import {
getToolbarButtons,
isToolbarButtonEnabled
} from '../../../base/config/functions.web';
-import { toggleDialog } from '../../../base/dialog/actions';
import { isMobileBrowser } from '../../../base/environment/utils';
import { translate } from '../../../base/i18n/functions';
-import JitsiMeetJS from '../../../base/lib-jitsi-meet';
-import {
- raiseHand
-} from '../../../base/participants/actions';
-import {
- getLocalParticipant,
- hasRaisedHand,
- isLocalParticipantModerator
-} from '../../../base/participants/functions';
+import { isLocalParticipantModerator } from '../../../base/participants/functions';
import ContextMenu from '../../../base/ui/components/web/ContextMenu';
-import { toggleChat } from '../../../chat/actions.web';
-import { setGifMenuVisibility } from '../../../gifs/actions';
-import { isGifEnabled } from '../../../gifs/functions.web';
-import { registerShortcut, unregisterShortcut } from '../../../keyboard-shortcuts/actions';
-import {
- close as closeParticipantsPane,
- open as openParticipantsPane
-} from '../../../participants-pane/actions.web';
-import { getParticipantsPaneOpen } from '../../../participants-pane/functions';
-import {
- addReactionToBuffer,
- toggleReactionsMenuVisibility
-} from '../../../reactions/actions.web';
-import { REACTIONS } from '../../../reactions/constants';
import { isReactionsButtonEnabled, isReactionsEnabled } from '../../../reactions/functions.web';
-import {
- startScreenShareFlow
-} from '../../../screen-share/actions.web';
-import {
- isScreenVideoShared
-} from '../../../screen-share/functions';
-import SpeakerStats from '../../../speaker-stats/components/web/SpeakerStats';
-import { toggleTileView } from '../../../video-layout/actions.web';
-import { shouldDisplayTileView } from '../../../video-layout/functions.web';
-import VideoQualityDialog from '../../../video-quality/components/VideoQualityDialog.web';
import { iAmVisitor } from '../../../visitors/functions';
import {
- setFullScreen,
setHangupMenuVisible,
setOverflowMenuVisible,
setToolbarHovered,
@@ -64,9 +26,9 @@ import { NOTIFY_CLICK_MODE, NOT_APPLICABLE, THRESHOLDS } from '../../constants';
import {
getAllToolboxButtons,
getJwtDisabledButtons,
- isDesktopShareButtonDisabled,
isToolboxVisible
} from '../../functions.web';
+import { useKeyboardShortcuts } from '../../hooks.web';
import { IToolboxButton } from '../../types';
import HangupButton from '../HangupButton';
@@ -104,16 +66,6 @@ interface IProps extends WithTranslation {
*/
_customToolbarButtons?: Array<{ icon: string; id: string; text: string; }>;
- /**
- * Whether or not screensharing button is disabled.
- */
- _desktopSharingButtonDisabled: boolean;
-
- /**
- * Whether or not screensharing is initialized.
- */
- _desktopSharingEnabled: boolean;
-
/**
* Whether or not a dialog is displayed.
*/
@@ -129,16 +81,6 @@ interface IProps extends WithTranslation {
*/
_endConferenceSupported: boolean;
- /**
- * Whether or not the app is currently in full screen.
- */
- _fullScreen?: boolean;
-
- /**
- * Whether or not the GIFs feature is enabled.
- */
- _gifsEnabled: boolean;
-
/**
* Whether the hangup menu is visible.
*/
@@ -154,15 +96,10 @@ interface IProps extends WithTranslation {
*/
_isNarrowLayout: boolean;
- /**
- * Whether or not speaker stats is disable.
- */
- _isSpeakerStatsDisabled?: boolean;
-
/**
* The array of toolbar buttons disabled through jwt features.
*/
- _jwtDisabledButons: string[];
+ _jwtDisabledButtons: string[];
/**
* Whether or not the overflow menu is displayed in a drawer drawer.
@@ -174,16 +111,6 @@ interface IProps extends WithTranslation {
*/
_overflowMenuVisible: boolean;
- /**
- * Whether or not the participants pane is open.
- */
- _participantsPaneOpen: boolean;
-
- /**
- * Whether or not the local participant's hand is raised.
- */
- _raisedHand: boolean;
-
/**
* Whether or not to display reactions in separate button.
*/
@@ -194,21 +121,11 @@ interface IProps extends WithTranslation {
*/
_reactionsEnabled: boolean;
- /**
- * Whether or not the local participant is screenSharing.
- */
- _screenSharing: boolean;
-
/**
* Whether the toolbox should be shifted up or not.
*/
_shiftUp: boolean;
- /**
- * Whether or not the tile view is enabled.
- */
- _tileViewEnabled: boolean;
-
/**
* The enabled buttons.
*/
@@ -219,11 +136,6 @@ interface IProps extends WithTranslation {
*/
_visible: boolean;
- /**
- * An object containing the CSS classes.
- */
- classes: any;
-
/**
* Invoked to active other features of the app.
*/
@@ -235,10 +147,10 @@ interface IProps extends WithTranslation {
toolbarButtons: Array<string>;
}
-const styles = () => {
+const useStyles = makeStyles()(() => {
return {
contextMenu: {
- position: 'relative' as const,
+ position: 'relative',
right: 'auto',
margin: 0,
marginBottom: '8px',
@@ -247,231 +159,94 @@ const styles = () => {
},
hangupMenu: {
- position: 'relative' as const,
+ position: 'relative',
right: 'auto',
display: 'flex',
- flexDirection: 'column' as const,
+ flexDirection: 'column',
rowGap: '8px',
margin: 0,
padding: '16px',
marginBottom: '4px'
}
};
-};
-
-/**
- * Implements the conference toolbox on React/Web.
- *
- * @augments Component
- */
-class Toolbox extends Component<IProps> {
- _toolboxRef: RefObject<HTMLDivElement>;
-
- /**
- * Initializes a new {@code Toolbox} instance.
- *
- * @param {IProps} props - The read-only React {@code Component} props with
- * which the new instance is to be initialized.
- */
- constructor(props: IProps) {
- super(props);
-
- this._toolboxRef = React.createRef();
-
- // Bind event handlers so they are only bound once per instance.
- this._onMouseOut = this._onMouseOut.bind(this);
- this._onMouseOver = this._onMouseOver.bind(this);
- this._onSetHangupVisible = this._onSetHangupVisible.bind(this);
- this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
- this._onTabIn = this._onTabIn.bind(this);
-
- this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
- this._onShortcutToggleFullScreen = this._onShortcutToggleFullScreen.bind(this);
- this._onShortcutToggleParticipantsPane = this._onShortcutToggleParticipantsPane.bind(this);
- this._onShortcutToggleRaiseHand = this._onShortcutToggleRaiseHand.bind(this);
- this._onShortcutToggleScreenshare = this._onShortcutToggleScreenshare.bind(this);
- this._onShortcutToggleVideoQuality = this._onShortcutToggleVideoQuality.bind(this);
- this._onShortcutToggleTileView = this._onShortcutToggleTileView.bind(this);
- this._onShortcutSpeakerStats = this._onShortcutSpeakerStats.bind(this);
- this._onEscKey = this._onEscKey.bind(this);
- }
-
- /**
- * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
- *
- * @inheritdoc
- * @returns {void}
- */
- componentDidMount() {
- const { _toolbarButtons, dispatch, _reactionsEnabled, _gifsEnabled, _isSpeakerStatsDisabled } = this.props;
-
- const KEYBOARD_SHORTCUTS = [
- isToolbarButtonEnabled('videoquality', _toolbarButtons) && {
- character: 'A',
- exec: this._onShortcutToggleVideoQuality,
- helpDescription: 'toolbar.callQuality'
- },
- isToolbarButtonEnabled('chat', _toolbarButtons) && {
- character: 'C',
- exec: this._onShortcutToggleChat,
- helpDescription: 'keyboardShortcuts.toggleChat'
- },
- isToolbarButtonEnabled('desktop', _toolbarButtons) && {
- character: 'D',
- exec: this._onShortcutToggleScreenshare,
- helpDescription: 'keyboardShortcuts.toggleScreensharing'
- },
- isToolbarButtonEnabled('participants-pane', _toolbarButtons) && {
- character: 'P',
- exec: this._onShortcutToggleParticipantsPane,
- helpDescription: 'keyboardShortcuts.toggleParticipantsPane'
- },
- isToolbarButtonEnabled('raisehand', _toolbarButtons) && {
- character: 'R',
- exec: this._onShortcutToggleRaiseHand,
- helpDescription: 'keyboardShortcuts.raiseHand'
- },
- isToolbarButtonEnabled('fullscreen', _toolbarButtons) && {
- character: 'S',
- exec: this._onShortcutToggleFullScreen,
- helpDescription: 'keyboardShortcuts.fullScreen'
- },
- isToolbarButtonEnabled('tileview', _toolbarButtons) && {
- character: 'W',
- exec: this._onShortcutToggleTileView,
- helpDescription: 'toolbar.tileViewToggle'
- },
- !_isSpeakerStatsDisabled && isToolbarButtonEnabled('stats', _toolbarButtons) && {
- character: 'T',
- exec: this._onShortcutSpeakerStats,
- helpDescription: 'keyboardShortcuts.showSpeakerStats'
- }
- ];
-
- KEYBOARD_SHORTCUTS.forEach(shortcut => {
- if (typeof shortcut === 'object') {
- dispatch(registerShortcut({
- character: shortcut.character,
- handler: shortcut.exec,
- helpDescription: shortcut.helpDescription
- }));
- }
- });
-
- if (_reactionsEnabled) {
- const REACTION_SHORTCUTS = Object.keys(REACTIONS).map(key => {
- const onShortcutSendReaction = () => {
- dispatch(addReactionToBuffer(key));
- sendAnalytics(createShortcutEvent(
- `reaction.${key}`
- ));
- };
-
- return {
- character: REACTIONS[key].shortcutChar,
- exec: onShortcutSendReaction,
- helpDescription: `toolbar.reaction${key.charAt(0).toUpperCase()}${key.slice(1)}`,
- altKey: true
- };
- });
-
- REACTION_SHORTCUTS.forEach(shortcut => {
- dispatch(registerShortcut({
- alt: shortcut.altKey,
- character: shortcut.character,
- handler: shortcut.exec,
- helpDescription: shortcut.helpDescription
- }));
- });
-
- if (_gifsEnabled) {
- const onGifShortcut = () => {
- batch(() => {
- dispatch(toggleReactionsMenuVisibility());
- dispatch(setGifMenuVisibility(true));
- });
- };
-
- dispatch(registerShortcut({
- character: 'G',
- handler: onGifShortcut,
- helpDescription: 'keyboardShortcuts.giphyMenu'
- }));
- }
- }
- }
-
- /**
- * Update the visibility of the {@code OverflowMenuButton}.
- *
- * @inheritdoc
- */
- componentDidUpdate(prevProps: IProps) {
- const { _dialog, _visible, dispatch } = this.props;
-
- if (prevProps._overflowMenuVisible
- && !prevProps._dialog
- && _dialog) {
- this._onSetOverflowVisible(false);
- dispatch(setToolbarHovered(false));
- }
- if (prevProps._hangupMenuVisible
- && prevProps._visible
- && !_visible) {
- this._onSetHangupVisible(false);
- dispatch(setToolbarHovered(false));
- }
-
- if (!_visible && prevProps._visible !== _visible) {
+});
+
+const Toolbox = ({
+ _buttonsWithNotifyClick,
+ _chatOpen,
+ _clientWidth,
+ _customToolbarButtons,
+ _dialog,
+ _disabled,
+ _endConferenceSupported,
+ _hangupMenuVisible,
+ _isMobile,
+ _isNarrowLayout,
+ _jwtDisabledButtons,
+ _overflowDrawer,
+ _overflowMenuVisible,
+ _reactionsButtonEnabled,
+ _reactionsEnabled,
+ _shiftUp,
+ _toolbarButtons,
+ _visible,
+ dispatch,
+ t,
+ toolbarButtons
+}: IProps) => {
+ const { classes, cx } = useStyles();
+ const _toolboxRef = useRef<HTMLDivElement>(null);
+
+ useKeyboardShortcuts(toolbarButtons);
+
+ useEffect(() => {
+ if (!_visible) {
if (document.activeElement instanceof HTMLElement
- && this._toolboxRef.current?.contains(document.activeElement)) {
+ && _toolboxRef.current?.contains(document.activeElement)) {
document.activeElement.blur();
}
}
- }
+ }, [ _visible ]);
/**
- * Removes keyboard shortcuts registered by this component.
+ * Sets the visibility of the hangup menu.
*
- * @inheritdoc
+ * @param {boolean} visible - Whether or not the hangup menu should be
+ * displayed.
+ * @private
* @returns {void}
*/
- componentWillUnmount() {
- const { dispatch } = this.props;
-
- [ 'A', 'C', 'D', 'P', 'R', 'S', 'W', 'T', 'G' ].forEach(letter =>
- dispatch(unregisterShortcut(letter)));
-
- if (this.props._reactionsEnabled) {
- Object.keys(REACTIONS).map(key => REACTIONS[key].shortcutChar)
- .forEach(letter =>
- dispatch(unregisterShortcut(letter, true)));
- }
- }
+ const onSetHangupVisible = useCallback((visible: boolean) => {
+ dispatch(setHangupMenuVisible(visible));
+ dispatch(setToolbarHovered(visible));
+ }, []);
/**
- * Implements React's {@link Component#render()}.
+ * Sets the visibility of the overflow menu.
*
- * @inheritdoc
- * @returns {ReactElement}
+ * @param {boolean} visible - Whether or not the overflow menu should be
+ * displayed.
+ * @private
+ * @returns {void}
*/
- render() {
- if (this.props._disabled) {
- return null;
- }
+ const onSetOverflowVisible = useCallback((visible: boolean) => {
+ dispatch(setOverflowMenuVisible(visible));
+ dispatch(setToolbarHovered(visible));
+ }, []);
- const { _chatOpen, _visible, _toolbarButtons } = this.props;
- const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
- _toolbarButtons.length ? '' : 'no-buttons'} ${_chatOpen ? 'shift-right' : ''}`;
+ useEffect(() => {
+ if (_hangupMenuVisible && !_visible) {
+ onSetHangupVisible(false);
+ dispatch(setToolbarHovered(false));
+ }
+ }, [ _hangupMenuVisible, _visible ]);
- return (
- <div
- className = { clsx(rootClassNames, this.props._shiftUp && 'shift-up') }
- id = 'new-toolbox'>
- { this._renderToolboxContent() }
- </div>
- );
- }
+ useEffect(() => {
+ if (_overflowMenuVisible && _dialog) {
+ onSetOverflowVisible(false);
+ dispatch(setToolbarHovered(false));
+ }
+ }, [ _overflowMenuVisible, _dialog ]);
/**
* Key handler for overflow/hangup menus.
@@ -479,15 +254,13 @@ class Toolbox extends Component<IProps> {
* @param {KeyboardEvent} e - Esc key click to close the popup.
* @returns {void}
*/
- _onEscKey(e?: React.KeyboardEvent) {
- const { dispatch, _hangupMenuVisible, _overflowMenuVisible } = this.props;
-
+ const onEscKey = useCallback((e?: React.KeyboardEvent) => {
if (e?.key === 'Escape') {
e?.stopPropagation();
_hangupMenuVisible && dispatch(setHangupMenuVisible(false));
_overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
}
- }
+ }, [ _hangupMenuVisible, _overflowMenuVisible ]);
/**
* Returns the notify mode of the given toolbox button.
@@ -495,8 +268,8 @@ class Toolbox extends Component<IProps> {
* @param {string} btnName - The toolbar button's name.
* @returns {string|undefined} - The button's notify mode.
*/
- _getButtonNotifyMode(btnName: string) {
- const notify = this.props._buttonsWithNotifyClick?.find(
+ function getButtonNotifyMode(btnName: string) {
+ const notify = _buttonsWithNotifyClick?.find(
btn =>
(typeof btn === 'string' && btn === btnName)
|| (typeof btn === 'object' && btn.key === btnName)
@@ -515,14 +288,14 @@ class Toolbox extends Component<IProps> {
* @param {Object} buttons - The list of toolbar buttons.
* @returns {void}
*/
- _setButtonsNotifyClickMode(buttons: Object) {
- if (typeof APP === 'undefined' || !this.props._buttonsWithNotifyClick?.length) {
+ function setButtonsNotifyClickMode(buttons: Object) {
+ if (typeof APP === 'undefined' || !_buttonsWithNotifyClick?.length) {
return;
}
Object.values(buttons).forEach((button: any) => {
if (typeof button === 'object') {
- button.notifyMode = this._getButtonNotifyMode(button.key);
+ button.notifyMode = getButtonNotifyMode(button.key);
}
});
}
@@ -533,17 +306,10 @@ class Toolbox extends Component<IProps> {
* @param {Object} state - The redux state.
* @returns {Object} The visible buttons arrays .
*/
- _getVisibleButtons() {
- const {
- _clientWidth,
- _toolbarButtons,
- _jwtDisabledButons,
- _customToolbarButtons
- } = this.props;
-
+ function getVisibleButtons() {
const buttons = getAllToolboxButtons(_customToolbarButtons);
- this._setButtonsNotifyClickMode(buttons);
+ setButtonsNotifyClickMode(buttons);
const isHangupVisible = isToolbarButtonEnabled('hangup', _toolbarButtons);
let { order } = THRESHOLDS.find(({ width }) => _clientWidth > width)
|| THRESHOLDS[THRESHOLDS.length - 1];
@@ -554,7 +320,7 @@ class Toolbox extends Component<IProps> {
...order.map(key => buttons[key as keyof typeof buttons]),
...Object.values(buttons).filter((button, index) => !order.includes(keys[index]))
].filter(({ key, alias = NOT_APPLICABLE }) =>
- !_jwtDisabledButons.includes(key)
+ !_jwtDisabledButtons.includes(key)
&& (isToolbarButtonEnabled(key, _toolbarButtons) || isToolbarButtonEnabled(alias, _toolbarButtons))
);
const filteredKeys = filtered.map(button => button.key);
@@ -584,9 +350,7 @@ class Toolbox extends Component<IProps> {
* @private
* @returns {void}
*/
- _onMouseOut() {
- const { _overflowMenuVisible, dispatch } = this.props;
-
+ function onMouseOut() {
!_overflowMenuVisible && dispatch(setToolbarHovered(false));
}
@@ -596,200 +360,8 @@ class Toolbox extends Component<IProps> {
* @private
* @returns {void}
*/
- _onMouseOver() {
- this.props.dispatch(setToolbarHovered(true));
- }
-
- /**
- * Sets the visibility of the hangup menu.
- *
- * @param {boolean} visible - Whether or not the hangup menu should be
- * displayed.
- * @private
- * @returns {void}
- */
- _onSetHangupVisible(visible: boolean) {
- this.props.dispatch(setHangupMenuVisible(visible));
- this.props.dispatch(setToolbarHovered(visible));
- }
-
- /**
- * Sets the visibility of the overflow menu.
- *
- * @param {boolean} visible - Whether or not the overflow menu should be
- * displayed.
- * @private
- * @returns {void}
- */
- _onSetOverflowVisible(visible: boolean) {
- this.props.dispatch(setOverflowMenuVisible(visible));
- this.props.dispatch(setToolbarHovered(visible));
- }
-
- /**
- * Creates an analytics keyboard shortcut event and dispatches an action for
- * toggling the display of chat.
- *
- * @private
- * @returns {void}
- */
- _onShortcutToggleChat() {
- sendAnalytics(createShortcutEvent(
- 'toggle.chat',
- ACTION_SHORTCUT_TRIGGERED,
- {
- enable: !this.props._chatOpen
- }));
-
- // Checks if there was any text selected by the user.
- // Used for when we press simultaneously keys for copying
- // text messages from the chat board
- if (window.getSelection()?.toString() !== '') {
- return false;
- }
-
- this.props.dispatch(toggleChat());
- }
-
- /**
- * Creates an analytics keyboard shortcut event and dispatches an action for
- * toggling the display of the participants pane.
- *
- * @private
- * @returns {void}
- */
- _onShortcutToggleParticipantsPane() {
- const { dispatch, _participantsPaneOpen } = this.props;
-
- sendAnalytics(createShortcutEvent(
- 'toggle.participants-pane',
- ACTION_SHORTCUT_TRIGGERED,
- {
- enable: !this.props._participantsPaneOpen
- }));
-
- if (_participantsPaneOpen) {
- dispatch(closeParticipantsPane());
- } else {
- dispatch(openParticipantsPane());
- }
- }
-
- /**
- * Creates an analytics keyboard shortcut event and dispatches an action for
- * toggling the display of Video Quality.
- *
- * @private
- * @returns {void}
- */
- _onShortcutToggleVideoQuality() {
- sendAnalytics(createShortcutEvent('video.quality'));
-
- this.props.dispatch(toggleDialog(VideoQualityDialog));
- }
-
- /**
- * Dispatches an action for toggling the tile view.
- *
- * @private
- * @returns {void}
- */
- _onShortcutToggleTileView() {
- sendAnalytics(createShortcutEvent(
- 'toggle.tileview',
- ACTION_SHORTCUT_TRIGGERED,
- {
- enable: !this.props._tileViewEnabled
- }));
-
- this.props.dispatch(toggleTileView());
- }
-
- /**
- * Creates an analytics keyboard shortcut event and dispatches an action for
- * toggling full screen mode.
- *
- * @private
- * @returns {void}
- */
- _onShortcutToggleFullScreen() {
- const { dispatch, _fullScreen } = this.props;
-
- sendAnalytics(createShortcutEvent(
- 'toggle.fullscreen',
- ACTION_SHORTCUT_TRIGGERED,
- {
- enable: !_fullScreen
- }));
- dispatch(setFullScreen(!_fullScreen));
- }
-
- /**
- * Creates an analytics keyboard shortcut event and dispatches an action for
- * toggling raise hand.
- *
- * @private
- * @returns {void}
- */
- _onShortcutToggleRaiseHand() {
- const { dispatch, _raisedHand } = this.props;
-
- sendAnalytics(createShortcutEvent(
- 'toggle.raise.hand',
- ACTION_SHORTCUT_TRIGGERED,
- { enable: !_raisedHand }));
-
- dispatch(raiseHand(!_raisedHand));
- }
-
- /**
- * Creates an analytics keyboard shortcut event and dispatches an action for
- * toggling screensharing.
- *
- * @private
- * @returns {void}
- */
- _onShortcutToggleScreenshare() {
- const {
- _desktopSharingButtonDisabled,
- _desktopSharingEnabled,
- _screenSharing,
- dispatch
- } = this.props;
-
- // Ignore the shortcut if the button is disabled.
- if (_desktopSharingButtonDisabled) {
- return;
- }
- sendAnalytics(createShortcutEvent(
- 'toggle.screen.sharing',
- ACTION_SHORTCUT_TRIGGERED,
- {
- enable: !_screenSharing
- }));
-
- if (_desktopSharingEnabled && !_desktopSharingButtonDisabled) {
- dispatch(startScreenShareFlow(!_screenSharing));
- }
- }
-
- /**
- * Creates an analytics keyboard shortcut event and dispatches an action for
- * toggling speaker stats.
- *
- * @private
- * @returns {void}
- */
- _onShortcutSpeakerStats() {
- const { dispatch } = this.props;
-
- sendAnalytics(createShortcutEvent(
- 'speaker.stats'
- ));
-
- dispatch(toggleDialog(SpeakerStats, {
- conference: APP.conference
- }));
+ function onMouseOver() {
+ dispatch(setToolbarHovered(true));
}
/**
@@ -797,36 +369,22 @@ class Toolbox extends Component<IProps> {
*
* @returns {void}
*/
- _onTabIn() {
- if (!this.props._visible) {
- this.props.dispatch(showToolbox());
+ const onTabIn = useCallback(() => {
+ if (!_visible) {
+ dispatch(showToolbox());
}
- }
+ }, [ _visible ]);
/**
* Renders the toolbox content.
*
* @returns {ReactElement}
*/
- _renderToolboxContent() {
- const {
- _endConferenceSupported,
- _hangupMenuVisible,
- _isMobile,
- _isNarrowLayout,
- _overflowDrawer,
- _overflowMenuVisible,
- _reactionsEnabled,
- _reactionsButtonEnabled,
- _toolbarButtons,
- classes,
- t
- } = this.props;
-
+ function renderToolboxContent() {
const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
const containerClassName = `toolbox-content${_isMobile || _isNarrowLayout ? ' toolbox-content-mobile' : ''}`;
- const { mainMenuButtons, overflowMenuButtons } = this._getVisibleButtons();
+ const { mainMenuButtons, overflowMenuButtons } = getVisibleButtons();
const raiseHandInOverflowMenu = overflowMenuButtons.some(({ key }) => key === 'raisehand');
const showReactionsInOverflowMenu
= (_reactionsEnabled && !_reactionsButtonEnabled
@@ -838,15 +396,15 @@ class Toolbox extends Component<IProps> {
<div className = { containerClassName }>
<div
className = 'toolbox-content-wrapper'
- onFocus = { this._onTabIn }
+ onFocus = { onTabIn }
{ ...(_isMobile ? {} : {
- onMouseOut: this._onMouseOut,
- onMouseOver: this._onMouseOver
+ onMouseOut,
+ onMouseOver
}) }>
<div
className = 'toolbox-content-items'
- ref = { this._toolboxRef }>
+ ref = { _toolboxRef }>
{mainMenuButtons.map(({ Content, key, ...rest }) => Content !== Separator && (
<Content
{ ...rest }
@@ -882,39 +440,39 @@ class Toolbox extends Component<IProps> {
}, []) }
isOpen = { _overflowMenuVisible }
key = 'overflow-menu'
- onToolboxEscKey = { this._onEscKey }
- onVisibilityChange = { this._onSetOverflowVisible }
+ onToolboxEscKey = { onEscKey }
+ onVisibilityChange = { onSetOverflowVisible }
showRaiseHandInReactionsMenu = { showRaiseHandInReactionsMenu }
showReactionsMenu = { showReactionsInOverflowMenu } />
)}
- { isToolbarButtonEnabled('hangup', _toolbarButtons) && (
+ {isToolbarButtonEnabled('hangup', _toolbarButtons) && (
_endConferenceSupported
? <HangupMenuButton
ariaControls = 'hangup-menu'
isOpen = { _hangupMenuVisible }
key = 'hangup-menu'
- notifyMode = { this._getButtonNotifyMode('hangup-menu') }
- onVisibilityChange = { this._onSetHangupVisible }>
+ notifyMode = { getButtonNotifyMode('hangup-menu') }
+ onVisibilityChange = { onSetHangupVisible }>
<ContextMenu
accessibilityLabel = { t(toolbarAccLabel) }
className = { classes.hangupMenu }
hidden = { false }
inDrawer = { _overflowDrawer }
- onKeyDown = { this._onEscKey }>
+ onKeyDown = { onEscKey }>
<EndConferenceButton
buttonKey = 'end-meeting'
- notifyMode = { this._getButtonNotifyMode('end-meeting') } />
+ notifyMode = { getButtonNotifyMode('end-meeting') } />
<LeaveConferenceButton
buttonKey = 'hangup'
- notifyMode = { this._getButtonNotifyMode('hangup') } />
+ notifyMode = { getButtonNotifyMode('hangup') } />
</ContextMenu>
</HangupMenuButton>
: <HangupButton
buttonKey = 'hangup'
customClass = 'hangup-button'
key = 'hangup-button'
- notifyMode = { this._getButtonNotifyMode('hangup') }
+ notifyMode = { getButtonNotifyMode('hangup') }
visible = { isToolbarButtonEnabled('hangup', _toolbarButtons) } />
)}
</div>
@@ -922,7 +480,22 @@ class Toolbox extends Component<IProps> {
</div>
);
}
-}
+
+ if (_disabled) {
+ return null;
+ }
+
+ const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
+ _toolbarButtons.length ? '' : 'no-buttons'} ${_chatOpen ? 'shift-right' : ''}`;
+
+ return (
+ <div
+ className = { cx(rootClassNames, _shiftUp && 'shift-up') }
+ id = 'new-toolbox'>
+ {renderToolboxContent()}
+ </div>
+ );
+};
/**
* Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
@@ -944,12 +517,10 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
iAmSipGateway
} = state['features/base/config'];
const {
- fullScreen,
hangupMenuVisible,
overflowMenuVisible,
overflowDrawer
} = state['features/toolbox'];
- const localParticipant = getLocalParticipant(state);
const { clientWidth } = state['features/base/responsive-ui'];
let toolbarButtons = ownProps.toolbarButtons || getToolbarButtons(state);
const _reactionsEnabled = isReactionsEnabled(state);
@@ -963,30 +534,21 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
_chatOpen: state['features/chat'].isOpen,
_clientWidth: clientWidth,
_customToolbarButtons: customToolbarButtons,
- _desktopSharingEnabled: JitsiMeetJS.isDesktopSharingEnabled(),
- _desktopSharingButtonDisabled: isDesktopShareButtonDisabled(state),
_dialog: Boolean(state['features/base/dialog'].component),
_disabled: Boolean(iAmRecorder || iAmSipGateway),
_endConferenceSupported: Boolean(endConferenceSupported),
- _fullScreen: fullScreen,
- _gifsEnabled: isGifEnabled(state),
_isMobile: isMobileBrowser(),
- _isSpeakerStatsDisabled: isSpeakerStatsDisabled(state),
- _jwtDisabledButons: getJwtDisabledButtons(state),
+ _jwtDisabledButtons: getJwtDisabledButtons(state),
_hangupMenuVisible: hangupMenuVisible,
_isNarrowLayout: isNarrowLayout,
_overflowMenuVisible: overflowMenuVisible,
_overflowDrawer: overflowDrawer,
- _participantsPaneOpen: getParticipantsPaneOpen(state),
- _raisedHand: hasRaisedHand(localParticipant),
_reactionsButtonEnabled: isReactionsButtonEnabled(state),
_reactionsEnabled,
- _screenSharing: isScreenVideoShared(state),
_shiftUp: state['features/toolbox'].shiftUp,
- _tileViewEnabled: shouldDisplayTileView(state),
_toolbarButtons: toolbarButtons,
_visible: isToolboxVisible(state)
};
}
-export default translate(connect(_mapStateToProps)(withStyles(styles)(Toolbox)));
+export default translate(connect(_mapStateToProps)(Toolbox));
diff --git a/react/features/toolbox/hooks.web.ts b/react/features/toolbox/hooks.web.ts
new file mode 100644
index 0000000000..45c2f97ee4
--- /dev/null
+++ b/react/features/toolbox/hooks.web.ts
@@ -0,0 +1,310 @@
+import { useEffect } from 'react';
+import { batch, useDispatch, useSelector } from 'react-redux';
+
+import { ACTION_SHORTCUT_TRIGGERED, createShortcutEvent } from '../analytics/AnalyticsEvents';
+import { sendAnalytics } from '../analytics/functions';
+import { IReduxState } from '../app/types';
+import { getToolbarButtons, isToolbarButtonEnabled } from '../base/config/functions.web';
+import { toggleDialog } from '../base/dialog/actions';
+import JitsiMeetJS from '../base/lib-jitsi-meet';
+import { raiseHand } from '../base/participants/actions';
+import { getLocalParticipant, hasRaisedHand } from '../base/participants/functions';
+import { toggleChat } from '../chat/actions.web';
+import { setGifMenuVisibility } from '../gifs/actions';
+import { isGifEnabled } from '../gifs/function.any';
+import { registerShortcut, unregisterShortcut } from '../keyboard-shortcuts/actions.any';
+import {
+ close as closeParticipantsPane,
+ open as openParticipantsPane
+} from '../participants-pane/actions.web';
+import { getParticipantsPaneOpen } from '../participants-pane/functions';
+import { addReactionToBuffer } from '../reactions/actions.any';
+import { toggleReactionsMenuVisibility } from '../reactions/actions.web';
+import { REACTIONS } from '../reactions/constants';
+import { isReactionsEnabled } from '../reactions/functions.any';
+import { startScreenShareFlow } from '../screen-share/actions.web';
+import { isScreenVideoShared } from '../screen-share/functions';
+import SpeakerStats from '../speaker-stats/components/web/SpeakerStats';
+import { isSpeakerStatsDisabled } from '../speaker-stats/functions';
+import { toggleTileView } from '../video-layout/actions.any';
+import { shouldDisplayTileView } from '../video-layout/functions.any';
+import VideoQualityDialog from '../video-quality/components/VideoQualityDialog.web';
+
+import { setFullScreen } from './actions.web';
+import { isDesktopShareButtonDisabled } from './functions.web';
+
+export const useKeyboardShortcuts = (toolbarButtons: Array<string>) => {
+ const dispatch = useDispatch();
+ const _isSpeakerStatsDisabled = useSelector(isSpeakerStatsDisabled);
+ const _toolbarButtons = useSelector((state: IReduxState) => toolbarButtons || getToolbarButtons(state));
+ const chatOpen = useSelector((state: IReduxState) => state['features/chat'].isOpen);
+ const desktopSharingButtonDisabled = useSelector(isDesktopShareButtonDisabled);
+ const desktopSharingEnabled = JitsiMeetJS.isDesktopSharingEnabled();
+ const fullScreen = useSelector((state: IReduxState) => state['features/toolbox'].fullScreen);
+ const gifsEnabled = useSelector(isGifEnabled);
+ const localParticipant = useSelector(getLocalParticipant);
+ const participantsPaneOpen = useSelector(getParticipantsPaneOpen);
+ const raisedHand = hasRaisedHand(localParticipant);
+ const reactionsEnabled = useSelector(isReactionsEnabled);
+ const screenSharing = useSelector(isScreenVideoShared);
+ const tileViewEnabled = useSelector(shouldDisplayTileView);
+
+ /**
+ * Creates an analytics keyboard shortcut event and dispatches an action for
+ * toggling the display of chat.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onToggleChat() {
+ sendAnalytics(createShortcutEvent(
+ 'toggle.chat',
+ ACTION_SHORTCUT_TRIGGERED,
+ {
+ enable: !chatOpen
+ }));
+
+ // Checks if there was any text selected by the user.
+ // Used for when we press simultaneously keys for copying
+ // text messages from the chat board
+ if (window.getSelection()?.toString() !== '') {
+ return false;
+ }
+
+ dispatch(toggleChat());
+ }
+
+ /**
+ * Creates an analytics keyboard shortcut event and dispatches an action for
+ * toggling the display of the participants pane.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onToggleParticipantsPane() {
+ sendAnalytics(createShortcutEvent(
+ 'toggle.participants-pane',
+ ACTION_SHORTCUT_TRIGGERED,
+ {
+ enable: !participantsPaneOpen
+ }));
+
+ if (participantsPaneOpen) {
+ dispatch(closeParticipantsPane());
+ } else {
+ dispatch(openParticipantsPane());
+ }
+ }
+
+ /**
+ * Creates an analytics keyboard shortcut event and dispatches an action for
+ * toggling the display of Video Quality.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onToggleVideoQuality() {
+ sendAnalytics(createShortcutEvent('video.quality'));
+
+ dispatch(toggleDialog(VideoQualityDialog));
+ }
+
+ /**
+ * Dispatches an action for toggling the tile view.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onToggleTileView() {
+ sendAnalytics(createShortcutEvent(
+ 'toggle.tileview',
+ ACTION_SHORTCUT_TRIGGERED,
+ {
+ enable: !tileViewEnabled
+ }));
+
+ dispatch(toggleTileView());
+ }
+
+ /**
+ * Creates an analytics keyboard shortcut event and dispatches an action for
+ * toggling full screen mode.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onToggleFullScreen() {
+ sendAnalytics(createShortcutEvent(
+ 'toggle.fullscreen',
+ ACTION_SHORTCUT_TRIGGERED,
+ {
+ enable: !fullScreen
+ }));
+ dispatch(setFullScreen(!fullScreen));
+ }
+
+ /**
+ * Creates an analytics keyboard shortcut event and dispatches an action for
+ * toggling raise hand.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onToggleRaiseHand() {
+ sendAnalytics(createShortcutEvent(
+ 'toggle.raise.hand',
+ ACTION_SHORTCUT_TRIGGERED,
+ { enable: !raisedHand }));
+
+ dispatch(raiseHand(!raisedHand));
+ }
+
+ /**
+ * Creates an analytics keyboard shortcut event and dispatches an action for
+ * toggling screensharing.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onToggleScreenshare() {
+ // Ignore the shortcut if the button is disabled.
+ if (desktopSharingButtonDisabled) {
+ return;
+ }
+ sendAnalytics(createShortcutEvent(
+ 'toggle.screen.sharing',
+ ACTION_SHORTCUT_TRIGGERED,
+ {
+ enable: !screenSharing
+ }));
+
+ if (desktopSharingEnabled && !desktopSharingButtonDisabled) {
+ dispatch(startScreenShareFlow(!screenSharing));
+ }
+ }
+
+ /**
+ * Creates an analytics keyboard shortcut event and dispatches an action for
+ * toggling speaker stats.
+ *
+ * @private
+ * @returns {void}
+ */
+ function onSpeakerStats() {
+ sendAnalytics(createShortcutEvent(
+ 'speaker.stats'
+ ));
+
+ dispatch(toggleDialog(SpeakerStats, {
+ conference: APP.conference
+ }));
+ }
+
+ useEffect(() => {
+ const KEYBOARD_SHORTCUTS = [
+ isToolbarButtonEnabled('videoquality', _toolbarButtons) && {
+ character: 'A',
+ exec: onToggleVideoQuality,
+ helpDescription: 'toolbar.callQuality'
+ },
+ isToolbarButtonEnabled('chat', _toolbarButtons) && {
+ character: 'C',
+ exec: onToggleChat,
+ helpDescription: 'keyboardShortcuts.toggleChat'
+ },
+ isToolbarButtonEnabled('desktop', _toolbarButtons) && {
+ character: 'D',
+ exec: onToggleScreenshare,
+ helpDescription: 'keyboardShortcuts.toggleScreensharing'
+ },
+ isToolbarButtonEnabled('participants-pane', _toolbarButtons) && {
+ character: 'P',
+ exec: onToggleParticipantsPane,
+ helpDescription: 'keyboardShortcuts.toggleParticipantsPane'
+ },
+ isToolbarButtonEnabled('raisehand', _toolbarButtons) && {
+ character: 'R',
+ exec: onToggleRaiseHand,
+ helpDescription: 'keyboardShortcuts.raiseHand'
+ },
+ isToolbarButtonEnabled('fullscreen', _toolbarButtons) && {
+ character: 'S',
+ exec: onToggleFullScreen,
+ helpDescription: 'keyboardShortcuts.fullScreen'
+ },
+ isToolbarButtonEnabled('tileview', _toolbarButtons) && {
+ character: 'W',
+ exec: onToggleTileView,
+ helpDescription: 'toolbar.tileViewToggle'
+ },
+ !_isSpeakerStatsDisabled && isToolbarButtonEnabled('stats', _toolbarButtons) && {
+ character: 'T',
+ exec: onSpeakerStats,
+ helpDescription: 'keyboardShortcuts.showSpeakerStats'
+ }
+ ];
+
+ KEYBOARD_SHORTCUTS.forEach(shortcut => {
+ if (typeof shortcut === 'object') {
+ dispatch(registerShortcut({
+ character: shortcut.character,
+ handler: shortcut.exec,
+ helpDescription: shortcut.helpDescription
+ }));
+ }
+ });
+
+ if (reactionsEnabled) {
+ const REACTION_SHORTCUTS = Object.keys(REACTIONS).map(key => {
+ const onShortcutSendReaction = () => {
+ dispatch(addReactionToBuffer(key));
+ sendAnalytics(createShortcutEvent(
+ `reaction.${key}`
+ ));
+ };
+
+ return {
+ character: REACTIONS[key].shortcutChar,
+ exec: onShortcutSendReaction,
+ helpDescription: `toolbar.reaction${key.charAt(0).toUpperCase()}${key.slice(1)}`,
+ altKey: true
+ };
+ });
+
+ REACTION_SHORTCUTS.forEach(shortcut => {
+ dispatch(registerShortcut({
+ alt: shortcut.altKey,
+ character: shortcut.character,
+ handler: shortcut.exec,
+ helpDescription: shortcut.helpDescription
+ }));
+ });
+
+ if (gifsEnabled) {
+ const onGifShortcut = () => {
+ batch(() => {
+ dispatch(toggleReactionsMenuVisibility());
+ dispatch(setGifMenuVisibility(true));
+ });
+ };
+
+ dispatch(registerShortcut({
+ character: 'G',
+ handler: onGifShortcut,
+ helpDescription: 'keyboardShortcuts.giphyMenu'
+ }));
+ }
+ }
+
+ return () => {
+ [ 'A', 'C', 'D', 'P', 'R', 'S', 'W', 'T', 'G' ].forEach(letter =>
+ dispatch(unregisterShortcut(letter)));
+
+ if (reactionsEnabled) {
+ Object.keys(REACTIONS).map(key => REACTIONS[key].shortcutChar)
+ .forEach(letter =>
+ dispatch(unregisterShortcut(letter, true)));
+ }
+ };
+ }, []);
+};