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.

ParticipantItem.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // @flow
  2. import React from 'react';
  3. import type { Node } from 'react';
  4. import { useTranslation } from 'react-i18next';
  5. import { TouchableOpacity, View } from 'react-native';
  6. import { Text } from 'react-native-paper';
  7. import { useSelector } from 'react-redux';
  8. import { Avatar } from '../../../base/avatar';
  9. import { getParticipantDisplayNameWithId } from '../../../base/participants';
  10. import {
  11. AudioStateIcons,
  12. MediaState,
  13. VideoStateIcons
  14. } from '../../constants';
  15. import { RaisedHandIndicator } from './RaisedHandIndicator';
  16. import styles from './styles';
  17. type Props = {
  18. /**
  19. * Media state for audio
  20. */
  21. audioMuteState: MediaState,
  22. /**
  23. * React children
  24. */
  25. children?: Node,
  26. /**
  27. * The name of the participant. Used for showing lobby names.
  28. */
  29. name?: string,
  30. /**
  31. * Callback for when the mouse leaves this component
  32. */
  33. onLeave?: Function,
  34. /**
  35. * Callback to be invoked on pressing the participant item.
  36. */
  37. onPress?: Function,
  38. /**
  39. * Participant reference
  40. */
  41. participant: Object,
  42. /**
  43. * Media state for video
  44. */
  45. videoMuteState: MediaState
  46. }
  47. /**
  48. * Participant item.
  49. *
  50. * @returns {React$Element<any>}
  51. */
  52. function ParticipantItem({
  53. audioMuteState = MediaState.None,
  54. children,
  55. name,
  56. onPress,
  57. participant: p,
  58. videoMuteState = MediaState.None
  59. }: Props) {
  60. const displayName = name || useSelector(getParticipantDisplayNameWithId(p.id));
  61. const { t } = useTranslation();
  62. return (
  63. <View style = { styles.participantContainer } >
  64. <TouchableOpacity
  65. /* eslint-disable-next-line react/jsx-no-bind */
  66. onPress = { onPress }
  67. style = { styles.participantContent }>
  68. <Avatar
  69. className = 'participant-avatar'
  70. participantId = { p.id }
  71. size = { 32 } />
  72. <View style = { styles.participantNameContainer }>
  73. <Text style = { styles.participantName }>
  74. { displayName }
  75. </Text>
  76. { p.local ? <Text style = { styles.isLocal }>({t('chat.you')})</Text> : null }
  77. </View>
  78. <View style = { styles.participantStatesContainer } >
  79. {p.raisedHand && <RaisedHandIndicator />}
  80. <View style = { styles.participantStateVideo }>{VideoStateIcons[videoMuteState]}</View>
  81. <View style = { styles.participantStateAudio }>{AudioStateIcons[audioMuteState]}</View>
  82. </View>
  83. </TouchableOpacity>
  84. { children }
  85. </View>
  86. );
  87. }
  88. export default ParticipantItem;