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.

AudioTracksContainer.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* @flow */
  2. import React from 'react';
  3. import { AudioTrack, MEDIA_TYPE } from '../../../base/media';
  4. import { connect } from '../../../base/redux';
  5. /**
  6. * The type of the React {@code Component} props of {@link AudioTracksContainer}.
  7. */
  8. type Props = {
  9. /**
  10. * All media tracks stored in redux.
  11. */
  12. _tracks: Array<Object>
  13. };
  14. /**
  15. * A container for the remote tracks audio elements.
  16. *
  17. * @param {Props} props - The props of the component.
  18. * @returns {Array<ReactElement>}
  19. */
  20. function AudioTracksContainer(props: Props) {
  21. const { _tracks } = props;
  22. const remoteAudioTracks = _tracks.filter(t => !t.local && t.mediaType === MEDIA_TYPE.AUDIO);
  23. return (
  24. <div>
  25. {
  26. remoteAudioTracks.map(t => {
  27. const { jitsiTrack, participantId } = t;
  28. const audioTrackId = jitsiTrack && jitsiTrack.getId();
  29. const id = `remoteAudio_${audioTrackId || ''}`;
  30. return (
  31. <AudioTrack
  32. audioTrack = { t }
  33. id = { id }
  34. key = { id }
  35. participantId = { participantId } />);
  36. })
  37. }
  38. </div>);
  39. }
  40. /**
  41. * Maps (parts of) the Redux state to the associated {@code AudioTracksContainer}'s props.
  42. *
  43. * @param {Object} state - The Redux state.
  44. * @private
  45. * @returns {Props}
  46. */
  47. function _mapStateToProps(state) {
  48. // NOTE: The disadvantage of this approach is that the component will re-render on any track change.
  49. // One way to solve the problem would be to pass only the participant ID to the AudioTrack component and
  50. // find the corresponding track inside the AudioTrack's mapStateToProps. But currently this will be very
  51. // inefficient because features/base/tracks is an array and in order to find a track by participant ID
  52. // we need to go trough the array. Introducing a map participantID -> track could be beneficial in this case.
  53. return {
  54. _tracks: state['features/base/tracks']
  55. };
  56. }
  57. export default connect(_mapStateToProps)(AudioTracksContainer);