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.6KB

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