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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import {
  5. getLocalParticipant,
  6. getParticipantByIdOrUndefined,
  7. getParticipantDisplayName,
  8. isParticipantModerator
  9. } from '../../../base/participants';
  10. import { connect } from '../../../base/redux';
  11. import {
  12. isParticipantAudioMuted,
  13. isParticipantVideoMuted
  14. } from '../../../base/tracks';
  15. import { showConnectionStatus, showContextMenuDetails, showSharedVideoMenu } from '../../actions.native';
  16. import type { MediaState } from '../../constants';
  17. import { getParticipantAudioMediaState, getParticipantVideoMediaState } from '../../functions';
  18. import ParticipantItem from './ParticipantItem';
  19. type Props = {
  20. /**
  21. * Media state for audio.
  22. */
  23. _audioMediaState: MediaState,
  24. /**
  25. * The display name of the participant.
  26. */
  27. _displayName: string,
  28. /**
  29. * True if the participant is fake.
  30. */
  31. _isFakeParticipant: boolean,
  32. /**
  33. * Whether or not the user is a moderator.
  34. */
  35. _isModerator: boolean,
  36. /**
  37. * True if the participant is the local participant.
  38. */
  39. _local: boolean,
  40. /**
  41. * Shared video local participant owner.
  42. */
  43. _localVideoOwner: boolean,
  44. /**
  45. * The participant ID.
  46. */
  47. _participantID: string,
  48. /**
  49. * True if the participant have raised hand.
  50. */
  51. _raisedHand: boolean,
  52. /**
  53. * Media state for video.
  54. */
  55. _videoMediaState: MediaState,
  56. /**
  57. * The redux dispatch function.
  58. */
  59. dispatch: Function,
  60. /**
  61. * The ID of the participant.
  62. */
  63. participantID: ?string
  64. };
  65. /**
  66. * Implements the MeetingParticipantItem component.
  67. */
  68. class MeetingParticipantItem extends PureComponent<Props> {
  69. /**
  70. * Creates new MeetingParticipantItem instance.
  71. *
  72. * @param {Props} props - The props of the component.
  73. */
  74. constructor(props: Props) {
  75. super(props);
  76. this._onPress = this._onPress.bind(this);
  77. }
  78. _onPress: () => void;
  79. /**
  80. * Handles MeetingParticipantItem press events.
  81. *
  82. * @returns {void}
  83. */
  84. _onPress() {
  85. const {
  86. _local,
  87. _localVideoOwner,
  88. _isFakeParticipant,
  89. _participantID,
  90. dispatch
  91. } = this.props;
  92. if (_isFakeParticipant && _localVideoOwner) {
  93. dispatch(showSharedVideoMenu(_participantID));
  94. } else if (!_isFakeParticipant) {
  95. if (_local) {
  96. dispatch(showConnectionStatus(_participantID));
  97. } else {
  98. dispatch(showContextMenuDetails(_participantID));
  99. }
  100. } // else no-op
  101. }
  102. /**
  103. * Implements React's {@link Component#render()}.
  104. *
  105. * @inheritdoc
  106. * @returns {ReactElement}
  107. */
  108. render() {
  109. const {
  110. _audioMediaState,
  111. _displayName,
  112. _isModerator,
  113. _local,
  114. _participantID,
  115. _raisedHand,
  116. _videoMediaState
  117. } = this.props;
  118. return (
  119. <ParticipantItem
  120. audioMediaState = { _audioMediaState }
  121. displayName = { _displayName }
  122. isKnockingParticipant = { false }
  123. isModerator = { _isModerator }
  124. local = { _local }
  125. onPress = { this._onPress }
  126. participantID = { _participantID }
  127. raisedHand = { _raisedHand }
  128. videoMediaState = { _videoMediaState } />
  129. );
  130. }
  131. }
  132. /**
  133. * Maps (parts of) the redux state to the associated props for this component.
  134. *
  135. * @param {Object} state - The Redux state.
  136. * @param {Object} ownProps - The own props of the component.
  137. * @private
  138. * @returns {Props}
  139. */
  140. function mapStateToProps(state, ownProps): Object {
  141. const { participantID } = ownProps;
  142. const { ownerId } = state['features/shared-video'];
  143. const localParticipantId = getLocalParticipant(state).id;
  144. const participant = getParticipantByIdOrUndefined(state, participantID);
  145. const _isAudioMuted = isParticipantAudioMuted(participant, state);
  146. const _isVideoMuted = isParticipantVideoMuted(participant, state);
  147. const audioMediaState = getParticipantAudioMediaState(participant, _isAudioMuted, state);
  148. const videoMediaState = getParticipantVideoMediaState(participant, _isVideoMuted, state);
  149. return {
  150. _audioMediaState: audioMediaState,
  151. _displayName: getParticipantDisplayName(state, participant?.id),
  152. _isAudioMuted,
  153. _isFakeParticipant: Boolean(participant?.isFakeParticipant),
  154. _isModerator: isParticipantModerator(participant),
  155. _local: Boolean(participant?.local),
  156. _localVideoOwner: Boolean(ownerId === localParticipantId),
  157. _participantID: participant?.id,
  158. _raisedHand: Boolean(participant?.raisedHand),
  159. _videoMediaState: videoMediaState
  160. };
  161. }
  162. export default translate(connect(mapStateToProps)(MeetingParticipantItem));