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.

MeetingParticipantItem.js 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. // @flow
  2. import React, { useCallback, useEffect, useState } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { JitsiTrackEvents } from '../../../base/lib-jitsi-meet';
  5. import { MEDIA_TYPE } from '../../../base/media';
  6. import {
  7. getLocalParticipant,
  8. getParticipantByIdOrUndefined,
  9. getParticipantDisplayName,
  10. isParticipantModerator
  11. } from '../../../base/participants';
  12. import { connect } from '../../../base/redux';
  13. import {
  14. getLocalAudioTrack,
  15. getTrackByMediaTypeAndParticipant,
  16. isParticipantAudioMuted,
  17. isParticipantVideoMuted
  18. } from '../../../base/tracks';
  19. import { ACTION_TRIGGER, type MediaState, MEDIA_STATE } from '../../constants';
  20. import {
  21. getParticipantAudioMediaState,
  22. getParticipantVideoMediaState,
  23. getQuickActionButtonType
  24. } from '../../functions';
  25. import ParticipantQuickAction from '../ParticipantQuickAction';
  26. import ParticipantItem from './ParticipantItem';
  27. import { ParticipantActionEllipsis } from './styled';
  28. type Props = {
  29. /**
  30. * Media state for audio.
  31. */
  32. _audioMediaState: MediaState,
  33. /**
  34. * The audio track related to the participant.
  35. */
  36. _audioTrack: ?Object,
  37. /**
  38. * Whether or not to disable the moderator indicator.
  39. */
  40. _disableModeratorIndicator: boolean,
  41. /**
  42. * The display name of the participant.
  43. */
  44. _displayName: string,
  45. /**
  46. * Whether or not moderation is supported.
  47. */
  48. _isModerationSupported: boolean,
  49. /**
  50. * True if the participant is the local participant.
  51. */
  52. _local: Boolean,
  53. /**
  54. * Whether or not the local participant is moderator.
  55. */
  56. _localModerator: boolean,
  57. /**
  58. * Shared video local participant owner.
  59. */
  60. _localVideoOwner: boolean,
  61. /**
  62. * The participant.
  63. */
  64. _participant: Object,
  65. /**
  66. * The participant ID.
  67. *
  68. * NOTE: This ID may be different from participantID prop in the case when we pass undefined for the local
  69. * participant. In this case the local participant ID will be filled trough _participantID prop.
  70. */
  71. _participantID: string,
  72. /**
  73. * The type of button to be rendered for the quick action.
  74. */
  75. _quickActionButtonType: string,
  76. /**
  77. * True if the participant have raised hand.
  78. */
  79. _raisedHand: boolean,
  80. /**
  81. * Media state for video.
  82. */
  83. _videoMediaState: MediaState,
  84. /**
  85. * The translated ask unmute text for the qiuck action buttons.
  86. */
  87. askUnmuteText: string,
  88. /**
  89. * Is this item highlighted
  90. */
  91. isHighlighted: boolean,
  92. /**
  93. * Callback used to open a confirmation dialog for audio muting.
  94. */
  95. muteAudio: Function,
  96. /**
  97. * The translated text for the mute participant button.
  98. */
  99. muteParticipantButtonText: string,
  100. /**
  101. * Callback for the activation of this item's context menu
  102. */
  103. onContextMenu: Function,
  104. /**
  105. * Callback for the mouse leaving this item
  106. */
  107. onLeave: Function,
  108. /**
  109. * Callback used to open an actions drawer for a participant.
  110. */
  111. openDrawerForParticipant: Function,
  112. /**
  113. * True if an overflow drawer should be displayed.
  114. */
  115. overflowDrawer: boolean,
  116. /**
  117. * The aria-label for the ellipsis action.
  118. */
  119. participantActionEllipsisLabel: string,
  120. /**
  121. * The ID of the participant.
  122. */
  123. participantID: ?string,
  124. /**
  125. * The translate function.
  126. */
  127. t: Function,
  128. /**
  129. * The translated "you" text.
  130. */
  131. youText: string
  132. };
  133. /**
  134. * Implements the MeetingParticipantItem component.
  135. *
  136. * @param {Props} props - The props of the component.
  137. * @returns {ReactElement}
  138. */
  139. function MeetingParticipantItem({
  140. _audioMediaState,
  141. _audioTrack,
  142. _disableModeratorIndicator,
  143. _displayName,
  144. _local,
  145. _localVideoOwner,
  146. _participant,
  147. _participantID,
  148. _quickActionButtonType,
  149. _raisedHand,
  150. _videoMediaState,
  151. askUnmuteText,
  152. isHighlighted,
  153. muteAudio,
  154. muteParticipantButtonText,
  155. onContextMenu,
  156. onLeave,
  157. openDrawerForParticipant,
  158. overflowDrawer,
  159. participantActionEllipsisLabel,
  160. t,
  161. youText
  162. }: Props) {
  163. const [ hasAudioLevels, setHasAudioLevel ] = useState(false);
  164. const [ registeredEvent, setRegisteredEvent ] = useState(false);
  165. const _updateAudioLevel = useCallback(level => {
  166. const audioLevel = typeof level === 'number' && !isNaN(level)
  167. ? level : 0;
  168. setHasAudioLevel(audioLevel > 0.009);
  169. }, []);
  170. useEffect(() => {
  171. if (_audioTrack && !registeredEvent) {
  172. const { jitsiTrack } = _audioTrack;
  173. if (jitsiTrack) {
  174. jitsiTrack.on(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, _updateAudioLevel);
  175. setRegisteredEvent(true);
  176. }
  177. }
  178. return () => {
  179. if (_audioTrack && registeredEvent) {
  180. const { jitsiTrack } = _audioTrack;
  181. jitsiTrack && jitsiTrack.off(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, _updateAudioLevel);
  182. }
  183. };
  184. }, [ _audioTrack ]);
  185. const audioMediaState = _audioMediaState === MEDIA_STATE.UNMUTED && hasAudioLevels
  186. ? MEDIA_STATE.DOMINANT_SPEAKER : _audioMediaState;
  187. let askToUnmuteText = askUnmuteText;
  188. if (_audioMediaState !== MEDIA_STATE.FORCE_MUTED && _videoMediaState === MEDIA_STATE.FORCE_MUTED) {
  189. askToUnmuteText = t('participantsPane.actions.allowVideo');
  190. }
  191. return (
  192. <ParticipantItem
  193. actionsTrigger = { ACTION_TRIGGER.HOVER }
  194. audioMediaState = { audioMediaState }
  195. disableModeratorIndicator = { _disableModeratorIndicator }
  196. displayName = { _displayName }
  197. isHighlighted = { isHighlighted }
  198. isModerator = { isParticipantModerator(_participant) }
  199. local = { _local }
  200. onLeave = { onLeave }
  201. openDrawerForParticipant = { openDrawerForParticipant }
  202. overflowDrawer = { overflowDrawer }
  203. participantID = { _participantID }
  204. raisedHand = { _raisedHand }
  205. videoMediaState = { _videoMediaState }
  206. youText = { youText }>
  207. {!overflowDrawer && !_participant?.isFakeParticipant
  208. && <>
  209. <ParticipantQuickAction
  210. askUnmuteText = { askToUnmuteText }
  211. buttonType = { _quickActionButtonType }
  212. muteAudio = { muteAudio }
  213. muteParticipantButtonText = { muteParticipantButtonText }
  214. participantID = { _participantID } />
  215. <ParticipantActionEllipsis
  216. aria-label = { participantActionEllipsisLabel }
  217. onClick = { onContextMenu } />
  218. </>
  219. }
  220. {!overflowDrawer && _localVideoOwner && _participant?.isFakeParticipant && (
  221. <ParticipantActionEllipsis
  222. aria-label = { participantActionEllipsisLabel }
  223. onClick = { onContextMenu } />
  224. )}
  225. </ParticipantItem>
  226. );
  227. }
  228. /**
  229. * Maps (parts of) the redux state to the associated props for this component.
  230. *
  231. * @param {Object} state - The Redux state.
  232. * @param {Object} ownProps - The own props of the component.
  233. * @private
  234. * @returns {Props}
  235. */
  236. function _mapStateToProps(state, ownProps): Object {
  237. const { participantID } = ownProps;
  238. const { ownerId } = state['features/shared-video'];
  239. const localParticipantId = getLocalParticipant(state).id;
  240. const participant = getParticipantByIdOrUndefined(state, participantID);
  241. const _isAudioMuted = isParticipantAudioMuted(participant, state);
  242. const _isVideoMuted = isParticipantVideoMuted(participant, state);
  243. const _audioMediaState = getParticipantAudioMediaState(participant, _isAudioMuted, state);
  244. const _videoMediaState = getParticipantVideoMediaState(participant, _isVideoMuted, state);
  245. const _quickActionButtonType = getQuickActionButtonType(participant, _isAudioMuted, state);
  246. const tracks = state['features/base/tracks'];
  247. const _audioTrack = participantID === localParticipantId
  248. ? getLocalAudioTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, participantID);
  249. const { disableModeratorIndicator } = state['features/base/config'];
  250. return {
  251. _audioMediaState,
  252. _audioTrack,
  253. _disableModeratorIndicator: disableModeratorIndicator,
  254. _displayName: getParticipantDisplayName(state, participant?.id),
  255. _local: Boolean(participant?.local),
  256. _localVideoOwner: Boolean(ownerId === localParticipantId),
  257. _participant: participant,
  258. _participantID: participant?.id,
  259. _quickActionButtonType,
  260. _raisedHand: Boolean(participant?.raisedHand),
  261. _videoMediaState
  262. };
  263. }
  264. export default translate(connect(_mapStateToProps)(MeetingParticipantItem));