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

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