Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MeetingParticipantItem.js 9.3KB

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