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

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