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 9.6KB

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