Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AudioTracksContainer.tsx 2.3KB

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