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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 { normalizeAccents } from '../../../base/util/strings';
  21. import { ACTION_TRIGGER, type MediaState, MEDIA_STATE } 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. * 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 trough _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. * Callback used to open a confirmation dialog for audio muting.
  100. */
  101. muteAudio: Function,
  102. /**
  103. * The translated text for the mute participant button.
  104. */
  105. muteParticipantButtonText: string,
  106. /**
  107. * Callback for the activation of this item's context menu
  108. */
  109. onContextMenu: Function,
  110. /**
  111. * Callback for the mouse leaving this item
  112. */
  113. onLeave: Function,
  114. /**
  115. * Callback used to open an actions drawer for a participant.
  116. */
  117. openDrawerForParticipant: Function,
  118. /**
  119. * True if an overflow drawer should be displayed.
  120. */
  121. overflowDrawer: boolean,
  122. /**
  123. * The aria-label for the ellipsis action.
  124. */
  125. participantActionEllipsisLabel: string,
  126. /**
  127. * The ID of the participant.
  128. */
  129. participantID: ?string,
  130. /**
  131. * The translate function.
  132. */
  133. t: Function,
  134. /**
  135. * The translated "you" text.
  136. */
  137. youText: string
  138. };
  139. /**
  140. * Implements the MeetingParticipantItem component.
  141. *
  142. * @param {Props} props - The props of the component.
  143. * @returns {ReactElement}
  144. */
  145. function MeetingParticipantItem({
  146. _audioMediaState,
  147. _audioTrack,
  148. _disableModeratorIndicator,
  149. _displayName,
  150. _local,
  151. _localVideoOwner,
  152. _matchesSearch,
  153. _participant,
  154. _participantID,
  155. _quickActionButtonType,
  156. _raisedHand,
  157. _videoMediaState,
  158. askUnmuteText,
  159. isHighlighted,
  160. muteAudio,
  161. muteParticipantButtonText,
  162. onContextMenu,
  163. onLeave,
  164. openDrawerForParticipant,
  165. overflowDrawer,
  166. participantActionEllipsisLabel,
  167. t,
  168. youText
  169. }: Props) {
  170. const [ hasAudioLevels, setHasAudioLevel ] = useState(false);
  171. const [ registeredEvent, setRegisteredEvent ] = useState(false);
  172. const _updateAudioLevel = useCallback(level => {
  173. const audioLevel = typeof level === 'number' && !isNaN(level)
  174. ? level : 0;
  175. setHasAudioLevel(audioLevel > 0.009);
  176. }, []);
  177. useEffect(() => {
  178. if (_audioTrack && !registeredEvent) {
  179. const { jitsiTrack } = _audioTrack;
  180. if (jitsiTrack) {
  181. jitsiTrack.on(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, _updateAudioLevel);
  182. setRegisteredEvent(true);
  183. }
  184. }
  185. return () => {
  186. if (_audioTrack && registeredEvent) {
  187. const { jitsiTrack } = _audioTrack;
  188. jitsiTrack && jitsiTrack.off(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, _updateAudioLevel);
  189. }
  190. };
  191. }, [ _audioTrack ]);
  192. if (!_matchesSearch) {
  193. return null;
  194. }
  195. const audioMediaState = _audioMediaState === MEDIA_STATE.UNMUTED && hasAudioLevels
  196. ? MEDIA_STATE.DOMINANT_SPEAKER : _audioMediaState;
  197. let askToUnmuteText = askUnmuteText;
  198. if (_audioMediaState !== MEDIA_STATE.FORCE_MUTED && _videoMediaState === MEDIA_STATE.FORCE_MUTED) {
  199. askToUnmuteText = t('participantsPane.actions.allowVideo');
  200. }
  201. return (
  202. <ParticipantItem
  203. actionsTrigger = { ACTION_TRIGGER.HOVER }
  204. audioMediaState = { audioMediaState }
  205. disableModeratorIndicator = { _disableModeratorIndicator }
  206. displayName = { _displayName }
  207. isHighlighted = { isHighlighted }
  208. isModerator = { isParticipantModerator(_participant) }
  209. local = { _local }
  210. onLeave = { onLeave }
  211. openDrawerForParticipant = { openDrawerForParticipant }
  212. overflowDrawer = { overflowDrawer }
  213. participantID = { _participantID }
  214. raisedHand = { _raisedHand }
  215. videoMediaState = { _videoMediaState }
  216. youText = { youText }>
  217. {!overflowDrawer && !_participant?.isFakeParticipant
  218. && <>
  219. <ParticipantQuickAction
  220. askUnmuteText = { askToUnmuteText }
  221. buttonType = { _quickActionButtonType }
  222. muteAudio = { muteAudio }
  223. muteParticipantButtonText = { muteParticipantButtonText }
  224. participantID = { _participantID } />
  225. <ParticipantActionEllipsis
  226. aria-label = { participantActionEllipsisLabel }
  227. onClick = { onContextMenu } />
  228. </>
  229. }
  230. {!overflowDrawer && _localVideoOwner && _participant?.isFakeParticipant && (
  231. <ParticipantActionEllipsis
  232. aria-label = { participantActionEllipsisLabel }
  233. onClick = { onContextMenu } />
  234. )}
  235. </ParticipantItem>
  236. );
  237. }
  238. /**
  239. * Maps (parts of) the redux state to the associated props for this component.
  240. *
  241. * @param {Object} state - The Redux state.
  242. * @param {Object} ownProps - The own props of the component.
  243. * @private
  244. * @returns {Props}
  245. */
  246. function _mapStateToProps(state, ownProps): Object {
  247. const { participantID, searchString } = ownProps;
  248. const { ownerId } = state['features/shared-video'];
  249. const localParticipantId = getLocalParticipant(state).id;
  250. const participant = getParticipantByIdOrUndefined(state, participantID);
  251. const _displayName = getParticipantDisplayName(state, participant?.id);
  252. let _matchesSearch = false;
  253. const names = normalizeAccents(_displayName)
  254. .toLowerCase()
  255. .split(' ');
  256. const lowerCaseSearchString = searchString.toLowerCase();
  257. if (lowerCaseSearchString === '') {
  258. _matchesSearch = true;
  259. } else {
  260. for (const name of names) {
  261. if (name.startsWith(lowerCaseSearchString)) {
  262. _matchesSearch = true;
  263. break;
  264. }
  265. }
  266. }
  267. const _isAudioMuted = isParticipantAudioMuted(participant, state);
  268. const _isVideoMuted = isParticipantVideoMuted(participant, state);
  269. const _audioMediaState = getParticipantAudioMediaState(participant, _isAudioMuted, state);
  270. const _videoMediaState = getParticipantVideoMediaState(participant, _isVideoMuted, state);
  271. const _quickActionButtonType = getQuickActionButtonType(participant, _isAudioMuted, state);
  272. const tracks = state['features/base/tracks'];
  273. const _audioTrack = participantID === localParticipantId
  274. ? getLocalAudioTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, participantID);
  275. const { disableModeratorIndicator } = state['features/base/config'];
  276. return {
  277. _audioMediaState,
  278. _audioTrack,
  279. _disableModeratorIndicator: disableModeratorIndicator,
  280. _displayName,
  281. _local: Boolean(participant?.local),
  282. _localVideoOwner: Boolean(ownerId === localParticipantId),
  283. _matchesSearch,
  284. _participant: participant,
  285. _participantID: participant?.id,
  286. _quickActionButtonType,
  287. _raisedHand: hasRaisedHand(participant),
  288. _videoMediaState
  289. };
  290. }
  291. export default translate(connect(_mapStateToProps)(MeetingParticipantItem));