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.

ReactionsMenu.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { bindActionCreators } from 'redux';
  4. import {
  5. createReactionMenuEvent,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import { translate } from '../../../base/i18n';
  10. import { getLocalParticipant, getParticipantCount, participantUpdated } from '../../../base/participants';
  11. import { connect } from '../../../base/redux';
  12. import { playSound } from '../../../base/sounds';
  13. import { dockToolbox } from '../../../toolbox/actions.web';
  14. import { addReactionToBuffer } from '../../actions.any';
  15. import { toggleReactionsMenuVisibility } from '../../actions.web';
  16. import { RAISE_HAND_SOUND_ID, REACTIONS } from '../../constants';
  17. import ReactionButton from './ReactionButton';
  18. type Props = {
  19. /**
  20. * The number of conference participants.
  21. */
  22. _participantCount: number,
  23. /**
  24. * Used for translation.
  25. */
  26. t: Function,
  27. /**
  28. * Whether or not the local participant's hand is raised.
  29. */
  30. _raisedHand: boolean,
  31. /**
  32. * The ID of the local participant.
  33. */
  34. _localParticipantID: String,
  35. /**
  36. * The Redux Dispatch function.
  37. */
  38. dispatch: Function,
  39. /**
  40. * Docks the toolbox
  41. */
  42. _dockToolbox: Function,
  43. /**
  44. * Whether or not it's displayed in the overflow menu.
  45. */
  46. overflowMenu: boolean,
  47. /**
  48. * Whether or not reaction sounds are enabled.
  49. */
  50. _reactionSounds: boolean
  51. };
  52. declare var APP: Object;
  53. /**
  54. * Implements the reactions menu.
  55. *
  56. * @returns {ReactElement}
  57. */
  58. class ReactionsMenu extends Component<Props> {
  59. /**
  60. * Initializes a new {@code ReactionsMenu} instance.
  61. *
  62. * @param {Props} props - The read-only React {@code Component} props with
  63. * which the new instance is to be initialized.
  64. */
  65. constructor(props: Props) {
  66. super(props);
  67. this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
  68. this._getReactionButtons = this._getReactionButtons.bind(this);
  69. }
  70. _onToolbarToggleRaiseHand: () => void;
  71. _getReactionButtons: () => Array<React$Element<*>>;
  72. /**
  73. * Implements React Component's componentDidMount.
  74. *
  75. * @inheritdoc
  76. */
  77. componentDidMount() {
  78. this.props._dockToolbox(true);
  79. }
  80. /**
  81. * Implements React Component's componentWillUnmount.
  82. *
  83. * @inheritdoc
  84. */
  85. componentWillUnmount() {
  86. this.props._dockToolbox(false);
  87. }
  88. /**
  89. * Creates an analytics toolbar event and dispatches an action for toggling
  90. * raise hand.
  91. *
  92. * @returns {void}
  93. */
  94. _onToolbarToggleRaiseHand() {
  95. const { dispatch, _raisedHand, _reactionSounds } = this.props;
  96. sendAnalytics(createToolbarEvent(
  97. 'raise.hand',
  98. { enable: !_raisedHand }));
  99. this._doToggleRaiseHand();
  100. dispatch(toggleReactionsMenuVisibility());
  101. if (_reactionSounds && _raisedHand) {
  102. dispatch(playSound(RAISE_HAND_SOUND_ID));
  103. }
  104. }
  105. /**
  106. * Dispatches an action to toggle the local participant's raised hand state.
  107. *
  108. * @private
  109. * @returns {void}
  110. */
  111. _doToggleRaiseHand() {
  112. const { _localParticipantID, _raisedHand } = this.props;
  113. const newRaisedStatus = !_raisedHand;
  114. this.props.dispatch(participantUpdated({
  115. // XXX Only the local participant is allowed to update without
  116. // stating the JitsiConference instance (i.e. participant property
  117. // `conference` for a remote participant) because the local
  118. // participant is uniquely identified by the very fact that there is
  119. // only one local participant.
  120. id: _localParticipantID,
  121. local: true,
  122. raisedHand: newRaisedStatus
  123. }));
  124. APP.API.notifyRaiseHandUpdated(_localParticipantID, newRaisedStatus);
  125. }
  126. /**
  127. * Returns the emoji reaction buttons.
  128. *
  129. * @returns {Array}
  130. */
  131. _getReactionButtons() {
  132. const { t, dispatch } = this.props;
  133. let modifierKey = 'Alt';
  134. if (window.navigator?.platform) {
  135. if (window.navigator.platform.indexOf('Mac') !== -1) {
  136. modifierKey = '⌥';
  137. }
  138. }
  139. return Object.keys(REACTIONS).map(key => {
  140. /**
  141. * Sends reaction message.
  142. *
  143. * @returns {void}
  144. */
  145. function doSendReaction() {
  146. dispatch(addReactionToBuffer(key));
  147. sendAnalytics(createReactionMenuEvent(key));
  148. }
  149. return (<ReactionButton
  150. accessibilityLabel = { t(`toolbar.accessibilityLabel.${key}`) }
  151. icon = { REACTIONS[key].emoji }
  152. key = { key }
  153. onClick = { doSendReaction }
  154. toggled = { false }
  155. tooltip = { `${t(`toolbar.${key}`)} (${modifierKey} + ${REACTIONS[key].shortcutChar})` } />);
  156. });
  157. }
  158. /**
  159. * Implements React's {@link Component#render}.
  160. *
  161. * @inheritdoc
  162. */
  163. render() {
  164. const { _participantCount, _raisedHand, t, overflowMenu } = this.props;
  165. return (
  166. <div className = { `reactions-menu ${overflowMenu ? 'overflow' : ''}` }>
  167. { _participantCount > 1 && <div className = 'reactions-row'>
  168. { this._getReactionButtons() }
  169. </div> }
  170. <div className = 'raise-hand-row'>
  171. <ReactionButton
  172. accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
  173. icon = '✋'
  174. key = 'raisehand'
  175. label = {
  176. `${t(`toolbar.${_raisedHand ? 'lowerYourHand' : 'raiseYourHand'}`)}
  177. ${overflowMenu ? '' : ' (R)'}`
  178. }
  179. onClick = { this._onToolbarToggleRaiseHand }
  180. toggled = { true } />
  181. </div>
  182. </div>
  183. );
  184. }
  185. }
  186. /**
  187. * Function that maps parts of Redux state tree into component props.
  188. *
  189. * @param {Object} state - Redux state.
  190. * @returns {Object}
  191. */
  192. function mapStateToProps(state) {
  193. const localParticipant = getLocalParticipant(state);
  194. const { soundsReactions } = state['features/base/settings'];
  195. return {
  196. _localParticipantID: localParticipant.id,
  197. _raisedHand: localParticipant.raisedHand,
  198. _participantCount: getParticipantCount(state),
  199. _reactionSounds: soundsReactions
  200. };
  201. }
  202. /**
  203. * Function that maps parts of Redux actions into component props.
  204. *
  205. * @param {Object} dispatch - Redux dispatch.
  206. * @returns {Object}
  207. */
  208. function mapDispatchToProps(dispatch) {
  209. return {
  210. dispatch,
  211. ...bindActionCreators(
  212. {
  213. _dockToolbox: dockToolbox
  214. }, dispatch)
  215. };
  216. }
  217. export default translate(connect(
  218. mapStateToProps,
  219. mapDispatchToProps,
  220. )(ReactionsMenu));