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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import {
  5. getLocalParticipant,
  6. getParticipantByIdOrUndefined,
  7. getParticipantDisplayName
  8. } from '../../../base/participants';
  9. import { connect } from '../../../base/redux';
  10. import {
  11. isParticipantAudioMuted,
  12. isParticipantVideoMuted
  13. } from '../../../base/tracks';
  14. import { showConnectionStatus, showContextMenuDetails, showSharedVideoMenu } from '../../actions.native';
  15. import { MEDIA_STATE } from '../../constants';
  16. import type { MediaState } from '../../constants';
  17. import { getParticipantAudioMediaState } 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. * True if the participant is video muted.
  34. */
  35. _isVideoMuted: 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. * The redux dispatch function.
  54. */
  55. dispatch: Function,
  56. /**
  57. * The ID of the participant.
  58. */
  59. participantID: ?string
  60. };
  61. /**
  62. * Implements the MeetingParticipantItem component.
  63. */
  64. class MeetingParticipantItem extends PureComponent<Props> {
  65. /**
  66. * Creates new MeetingParticipantItem instance.
  67. *
  68. * @param {Props} props - The props of the component.
  69. */
  70. constructor(props: Props) {
  71. super(props);
  72. this._onPress = this._onPress.bind(this);
  73. }
  74. _onPress: () => void;
  75. /**
  76. * Handles MeetingParticipantItem press events.
  77. *
  78. * @returns {void}
  79. */
  80. _onPress() {
  81. const {
  82. _local,
  83. _localVideoOwner,
  84. _isFakeParticipant,
  85. _participantID,
  86. dispatch
  87. } = this.props;
  88. if (_isFakeParticipant && _localVideoOwner) {
  89. dispatch(showSharedVideoMenu(_participantID));
  90. } else if (!_isFakeParticipant) {
  91. if (_local) {
  92. dispatch(showConnectionStatus(_participantID));
  93. } else {
  94. dispatch(showContextMenuDetails(_participantID));
  95. }
  96. } // else no-op
  97. }
  98. /**
  99. * Implements React's {@link Component#render()}.
  100. *
  101. * @inheritdoc
  102. * @returns {ReactElement}
  103. */
  104. render() {
  105. const {
  106. _audioMediaState,
  107. _displayName,
  108. _isVideoMuted,
  109. _local,
  110. _participantID,
  111. _raisedHand
  112. } = this.props;
  113. return (
  114. <ParticipantItem
  115. audioMediaState = { _audioMediaState }
  116. displayName = { _displayName }
  117. isKnockingParticipant = { false }
  118. local = { _local }
  119. onPress = { this._onPress }
  120. participantID = { _participantID }
  121. raisedHand = { _raisedHand }
  122. videoMediaState = { _isVideoMuted ? MEDIA_STATE.MUTED : MEDIA_STATE.UNMUTED } />
  123. );
  124. }
  125. }
  126. /**
  127. * Maps (parts of) the redux state to the associated props for this component.
  128. *
  129. * @param {Object} state - The Redux state.
  130. * @param {Object} ownProps - The own props of the component.
  131. * @private
  132. * @returns {Props}
  133. */
  134. function mapStateToProps(state, ownProps): Object {
  135. const { participantID } = ownProps;
  136. const { ownerId } = state['features/shared-video'];
  137. const localParticipantId = getLocalParticipant(state).id;
  138. const participant = getParticipantByIdOrUndefined(state, participantID);
  139. const _isAudioMuted = isParticipantAudioMuted(participant, state);
  140. const isVideoMuted = isParticipantVideoMuted(participant, state);
  141. const audioMediaState = getParticipantAudioMediaState(participant, _isAudioMuted, state);
  142. return {
  143. _audioMediaState: audioMediaState,
  144. _displayName: getParticipantDisplayName(state, participant?.id),
  145. _isAudioMuted,
  146. _isFakeParticipant: Boolean(participant?.isFakeParticipant),
  147. _isVideoMuted: isVideoMuted,
  148. _local: Boolean(participant?.local),
  149. _localVideoOwner: Boolean(ownerId === localParticipantId),
  150. _participantID: participant?.id,
  151. _raisedHand: Boolean(participant?.raisedHand)
  152. };
  153. }
  154. export default translate(connect(mapStateToProps)(MeetingParticipantItem));