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.

Thumbnail.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import {
  4. Audio,
  5. MEDIA_TYPE
  6. } from '../../base/media';
  7. import {
  8. PARTICIPANT_ROLE,
  9. pinParticipant
  10. } from '../../base/participants';
  11. import { Container } from '../../base/react';
  12. import { getTrackByMediaTypeAndParticipant } from '../../base/tracks';
  13. import { ParticipantView } from '../../conference';
  14. import {
  15. AudioMutedIndicator,
  16. DominantSpeakerIndicator,
  17. ModeratorIndicator,
  18. styles,
  19. VideoMutedIndicator
  20. } from './_';
  21. /**
  22. * React component for video thumbnail.
  23. * @extends Component
  24. */
  25. class Thumbnail extends Component {
  26. /**
  27. * Initializes new Video Thumbnail component.
  28. *
  29. * @param {Object} props - Component props.
  30. */
  31. constructor(props) {
  32. super(props);
  33. // Bind event handlers so they are only bound once for every instance.
  34. this._onClick = this._onClick.bind(this);
  35. }
  36. /**
  37. * Handles click/tap event on the thumbnail.
  38. *
  39. * @returns {void}
  40. */
  41. _onClick() {
  42. const { dispatch, participant } = this.props;
  43. // TODO The following currently ignores interfaceConfig.filmStripOnly.
  44. dispatch(pinParticipant(participant.pinned ? null : participant.id));
  45. }
  46. /**
  47. * Implements React's {@link Component#render()}.
  48. *
  49. * @inheritdoc
  50. * @returns {ReactElement}
  51. */
  52. render() {
  53. const {
  54. audioTrack,
  55. largeVideo,
  56. participant,
  57. videoTrack
  58. } = this.props;
  59. let style = styles.thumbnail;
  60. if (participant.pinned) {
  61. style = {
  62. ...style,
  63. ...styles.thumbnailPinned
  64. };
  65. }
  66. // We don't render audio in any of the following:
  67. // 1. The audio (source) is muted. There's no practical reason (that we
  68. // know of, anyway) why we'd want to render it given that it's
  69. // silence (& not even comfort noise).
  70. // 2. The audio is local. If we were to render local audio, the local
  71. // participants would be hearing themselves.
  72. const audioMuted = !audioTrack || audioTrack.muted;
  73. const renderAudio = !audioMuted && !audioTrack.local;
  74. const participantId = participant.id;
  75. const participantNotInLargeVideo
  76. = participantId !== largeVideo.participantId;
  77. const videoMuted = !videoTrack || videoTrack.muted;
  78. return (
  79. <Container
  80. onClick = { this._onClick }
  81. style = { style }>
  82. { renderAudio
  83. && <Audio
  84. stream
  85. = { audioTrack.jitsiTrack.getOriginalStream() } /> }
  86. <ParticipantView
  87. participantId = { participantId }
  88. showAvatar = { participantNotInLargeVideo }
  89. showVideo = { participantNotInLargeVideo }
  90. zOrder = { 1 } />
  91. { participant.role === PARTICIPANT_ROLE.MODERATOR
  92. && <ModeratorIndicator /> }
  93. { participant.dominantSpeaker
  94. && <DominantSpeakerIndicator /> }
  95. { audioMuted
  96. && <AudioMutedIndicator /> }
  97. { videoMuted
  98. && <VideoMutedIndicator /> }
  99. </Container>
  100. );
  101. }
  102. }
  103. /**
  104. * Thumbnail component's property types.
  105. *
  106. * @static
  107. */
  108. Thumbnail.propTypes = {
  109. audioTrack: React.PropTypes.object,
  110. dispatch: React.PropTypes.func,
  111. largeVideo: React.PropTypes.object,
  112. participant: React.PropTypes.object,
  113. videoTrack: React.PropTypes.object
  114. };
  115. /**
  116. * Function that maps parts of Redux state tree into component props.
  117. *
  118. * @param {Object} state - Redux state.
  119. * @param {Object} ownProps - Properties of component.
  120. * @returns {{
  121. * audioTrack: Track,
  122. * largeVideo: Object,
  123. * videoTrack: Track
  124. * }}
  125. */
  126. function mapStateToProps(state, ownProps) {
  127. // We need read-only access to the state of features/largeVideo so that the
  128. // film strip doesn't render the video of the participant who is rendered on
  129. // the stage i.e. as a large video.
  130. const largeVideo = state['features/largeVideo'];
  131. const tracks = state['features/base/tracks'];
  132. const id = ownProps.participant.id;
  133. const audioTrack
  134. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, id);
  135. const videoTrack
  136. = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  137. return {
  138. audioTrack,
  139. largeVideo,
  140. videoTrack
  141. };
  142. }
  143. export default connect(mapStateToProps)(Thumbnail);