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

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