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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 { MEDIA_STATE, type MediaState, AudioStateIcons, VideoStateIcons } from '../../constants';
  11. import { RaisedHandIndicator } from './RaisedHandIndicator';
  12. import styles from './styles';
  13. type Props = {
  14. /**
  15. * Media state for audio
  16. */
  17. audioMediaState: MediaState,
  18. /**
  19. * React children
  20. */
  21. children?: Node,
  22. /**
  23. * Is the participant waiting?
  24. */
  25. isKnockingParticipant: boolean,
  26. /**
  27. * The name of the participant. Used for showing lobby names.
  28. */
  29. name?: string,
  30. /**
  31. * Callback to be invoked on pressing the participant item.
  32. */
  33. onPress?: Function,
  34. /**
  35. * Participant reference
  36. */
  37. participant: Object,
  38. /**
  39. * Media state for video
  40. */
  41. videoMediaState: MediaState
  42. }
  43. /**
  44. * Participant item.
  45. *
  46. * @returns {React$Element<any>}
  47. */
  48. function ParticipantItem({
  49. children,
  50. isKnockingParticipant,
  51. name,
  52. onPress,
  53. participant: p,
  54. audioMediaState = MEDIA_STATE.NONE,
  55. videoMediaState = MEDIA_STATE.NONE
  56. }: Props) {
  57. const displayName = name || useSelector(getParticipantDisplayNameWithId(p.id));
  58. const { t } = useTranslation();
  59. return (
  60. <View style = { styles.participantContainer } >
  61. <TouchableOpacity
  62. onPress = { onPress }
  63. style = { styles.participantContent }>
  64. <Avatar
  65. className = 'participant-avatar'
  66. participantId = { p.id }
  67. size = { 32 } />
  68. <View style = { styles.participantNameContainer }>
  69. <Text style = { styles.participantName }>
  70. { displayName }
  71. </Text>
  72. { p.local ? <Text style = { styles.isLocal }>({t('chat.you')})</Text> : null }
  73. </View>
  74. {
  75. !isKnockingParticipant
  76. && <>
  77. {
  78. p.raisedHand && <RaisedHandIndicator />
  79. }
  80. <View style = { styles.participantStatesContainer }>
  81. <View style = { styles.participantStateVideo }>{VideoStateIcons[videoMediaState]}</View>
  82. <View>{AudioStateIcons[audioMediaState]}</View>
  83. </View>
  84. </>
  85. }
  86. </TouchableOpacity>
  87. { !p.local && children }
  88. </View>
  89. );
  90. }
  91. export default ParticipantItem;