2021-12-13 13:51:05 +00:00
|
|
|
import { withStyles } from '@material-ui/styles';
|
2022-03-11 13:00:49 +00:00
|
|
|
import clsx from 'clsx';
|
2021-07-13 06:50:08 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
|
|
|
import {
|
2021-07-20 11:31:49 +00:00
|
|
|
createReactionMenuEvent,
|
2021-07-13 06:50:08 +00:00
|
|
|
createToolbarEvent,
|
|
|
|
sendAnalytics
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
} from '../../../analytics';
|
2022-06-08 07:44:47 +00:00
|
|
|
import { IStore } from '../../../app/types';
|
|
|
|
// @ts-ignore
|
2021-09-21 17:30:24 +00:00
|
|
|
import { isMobileBrowser } from '../../../base/environment/utils';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-10-21 09:40:57 +00:00
|
|
|
import { getLocalParticipant, hasRaisedHand, raiseHand } from '../../../base/participants';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2022-03-11 13:00:49 +00:00
|
|
|
import { GifsMenu, GifsMenuButton } from '../../../gifs/components';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2022-03-11 13:00:49 +00:00
|
|
|
import { isGifEnabled, isGifsMenuOpen } from '../../../gifs/functions';
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import { dockToolbox } from '../../../toolbox/actions.web';
|
2021-07-20 11:31:49 +00:00
|
|
|
import { addReactionToBuffer } from '../../actions.any';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { toggleReactionsMenuVisibility } from '../../actions.web';
|
2021-12-13 13:51:05 +00:00
|
|
|
import { REACTIONS, REACTIONS_MENU_HEIGHT } from '../../constants';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import ReactionButton from './ReactionButton';
|
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
interface Classes {
|
|
|
|
overflow: string
|
|
|
|
}
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Docks the toolbox.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2021-09-21 17:30:24 +00:00
|
|
|
_dockToolbox: Function,
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2022-03-11 13:00:49 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the GIF feature is enabled.
|
|
|
|
*/
|
|
|
|
_isGifEnabled: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the GIF menu is visible.
|
|
|
|
*/
|
|
|
|
_isGifMenuVisible: boolean,
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
2021-09-21 17:30:24 +00:00
|
|
|
* Whether or not it's a mobile browser.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2021-09-21 17:30:24 +00:00
|
|
|
_isMobile: boolean,
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ID of the local participant.
|
|
|
|
*/
|
|
|
|
_localParticipantID: String,
|
|
|
|
|
2021-09-21 17:30:24 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the local participant's hand is raised.
|
|
|
|
*/
|
|
|
|
_raisedHand: boolean,
|
|
|
|
|
2021-12-13 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* An object containing the CSS classes.
|
|
|
|
*/
|
2022-06-08 07:44:47 +00:00
|
|
|
classes: Classes,
|
2021-12-13 13:51:05 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* The Redux Dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
|
|
|
/**
|
2021-09-21 17:30:24 +00:00
|
|
|
* Whether or not it's displayed in the overflow menu.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2021-09-21 17:30:24 +00:00
|
|
|
overflowMenu: boolean,
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
2021-09-21 17:30:24 +00:00
|
|
|
* Used for translation.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2021-09-21 17:30:24 +00:00
|
|
|
t: Function
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
declare var APP: Object;
|
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
const styles = (theme: any) => {
|
2021-12-13 13:51:05 +00:00
|
|
|
return {
|
|
|
|
overflow: {
|
|
|
|
width: 'auto',
|
|
|
|
paddingBottom: 'max(env(safe-area-inset-bottom, 0), 16px)',
|
|
|
|
backgroundColor: theme.palette.ui01,
|
|
|
|
boxShadow: 'none',
|
|
|
|
borderRadius: 0,
|
|
|
|
position: 'relative',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
height: `${REACTIONS_MENU_HEIGHT}px`
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* Implements the reactions menu.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
class ReactionsMenu extends Component<Props> {
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code ReactionsMenu} instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The read-only React {@code Component} props with
|
|
|
|
* which the new instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
|
|
|
|
this._getReactionButtons = this._getReactionButtons.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React Component's componentDidMount.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
this.props._dockToolbox(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React Component's componentWillUnmount.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.props._dockToolbox(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an analytics toolbar event and dispatches an action for toggling
|
|
|
|
* raise hand.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onToolbarToggleRaiseHand() {
|
2021-08-31 11:00:27 +00:00
|
|
|
const { dispatch, _raisedHand } = this.props;
|
2021-08-23 09:57:56 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
sendAnalytics(createToolbarEvent(
|
|
|
|
'raise.hand',
|
2021-08-23 09:57:56 +00:00
|
|
|
{ enable: !_raisedHand }));
|
2021-07-13 06:50:08 +00:00
|
|
|
this._doToggleRaiseHand();
|
2021-08-23 09:57:56 +00:00
|
|
|
dispatch(toggleReactionsMenuVisibility());
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches an action to toggle the local participant's raised hand state.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_doToggleRaiseHand() {
|
2021-10-21 09:40:57 +00:00
|
|
|
const { _raisedHand } = this.props;
|
|
|
|
|
|
|
|
this.props.dispatch(raiseHand(!_raisedHand));
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the emoji reaction buttons.
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
_getReactionButtons() {
|
|
|
|
const { t, dispatch } = this.props;
|
2021-07-20 11:31:49 +00:00
|
|
|
let modifierKey = 'Alt';
|
|
|
|
|
|
|
|
if (window.navigator?.platform) {
|
|
|
|
if (window.navigator.platform.indexOf('Mac') !== -1) {
|
|
|
|
modifierKey = '⌥';
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
return Object.keys(REACTIONS).map(key => {
|
|
|
|
/**
|
|
|
|
* Sends reaction message.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-07-20 11:31:49 +00:00
|
|
|
function doSendReaction() {
|
|
|
|
dispatch(addReactionToBuffer(key));
|
|
|
|
sendAnalytics(createReactionMenuEvent(key));
|
2021-07-13 06:50:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
return (<ReactionButton
|
|
|
|
accessibilityLabel = { t(`toolbar.accessibilityLabel.${key}`) }
|
|
|
|
icon = { REACTIONS[key].emoji }
|
|
|
|
key = { key }
|
2021-07-20 11:31:49 +00:00
|
|
|
onClick = { doSendReaction }
|
2021-07-13 06:50:08 +00:00
|
|
|
toggled = { false }
|
2021-07-20 11:31:49 +00:00
|
|
|
tooltip = { `${t(`toolbar.${key}`)} (${modifierKey} + ${REACTIONS[key].shortcutChar})` } />);
|
2021-07-13 06:50:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
2022-03-11 13:00:49 +00:00
|
|
|
const { _raisedHand, t, overflowMenu, _isMobile, classes, _isGifMenuVisible, _isGifEnabled } = this.props;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
return (
|
2022-03-11 13:00:49 +00:00
|
|
|
<div
|
|
|
|
className = { clsx('reactions-menu', _isGifEnabled && 'with-gif',
|
|
|
|
overflowMenu && `overflow ${classes.overflow}`) }>
|
|
|
|
{_isGifEnabled && _isGifMenuVisible && <GifsMenu />}
|
2021-09-14 08:15:03 +00:00
|
|
|
<div className = 'reactions-row'>
|
2021-07-13 06:50:08 +00:00
|
|
|
{ this._getReactionButtons() }
|
2022-03-11 13:00:49 +00:00
|
|
|
{_isGifEnabled && <GifsMenuButton />}
|
2021-09-14 08:15:03 +00:00
|
|
|
</div>
|
2021-09-21 17:30:24 +00:00
|
|
|
{_isMobile && (
|
|
|
|
<div className = 'raise-hand-row'>
|
2022-06-08 07:44:47 +00:00
|
|
|
{/* @ts-ignore */}
|
2021-09-21 17:30:24 +00:00
|
|
|
<ReactionButton
|
|
|
|
accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
|
|
|
|
icon = '✋'
|
|
|
|
key = 'raisehand'
|
|
|
|
label = {
|
|
|
|
`${t(`toolbar.${_raisedHand ? 'lowerYourHand' : 'raiseYourHand'}`)}
|
|
|
|
${overflowMenu ? '' : ' (R)'}`
|
|
|
|
}
|
|
|
|
onClick = { this._onToolbarToggleRaiseHand }
|
|
|
|
toggled = { true } />
|
|
|
|
</div>
|
|
|
|
)}
|
2021-07-13 06:50:08 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-06-08 07:44:47 +00:00
|
|
|
function mapStateToProps(state: any) {
|
2021-07-13 06:50:08 +00:00
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
return {
|
|
|
|
_localParticipantID: localParticipant.id,
|
2021-09-21 17:30:24 +00:00
|
|
|
_isMobile: isMobileBrowser(),
|
2022-03-11 13:00:49 +00:00
|
|
|
_isGifEnabled: isGifEnabled(state),
|
|
|
|
_isGifMenuVisible: isGifsMenuOpen(state),
|
2021-10-21 09:40:57 +00:00
|
|
|
_raisedHand: hasRaisedHand(localParticipant)
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux actions into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} dispatch - Redux dispatch.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-06-08 07:44:47 +00:00
|
|
|
function mapDispatchToProps(dispatch: IStore['dispatch']) {
|
2021-07-13 06:50:08 +00:00
|
|
|
return {
|
|
|
|
dispatch,
|
|
|
|
...bindActionCreators(
|
|
|
|
{
|
|
|
|
_dockToolbox: dockToolbox
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
}, dispatch)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(
|
|
|
|
mapStateToProps,
|
2021-11-04 21:10:43 +00:00
|
|
|
mapDispatchToProps
|
2022-06-08 07:44:47 +00:00
|
|
|
// @ts-ignore
|
2021-12-13 13:51:05 +00:00
|
|
|
)(withStyles(styles)(ReactionsMenu)));
|