您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ParticipantItem.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * Is the participant waiting?
  28. */
  29. isKnockingParticipant: boolean,
  30. /**
  31. * The name of the participant. Used for showing lobby names.
  32. */
  33. name?: string,
  34. /**
  35. * Callback for when the mouse leaves this component
  36. */
  37. onLeave?: Function,
  38. /**
  39. * Callback to be invoked on pressing the participant item.
  40. */
  41. onPress?: Function,
  42. /**
  43. * Participant reference
  44. */
  45. participant: Object,
  46. /**
  47. * Media state for video
  48. */
  49. videoMuteState: MediaState
  50. }
  51. /**
  52. * Participant item.
  53. *
  54. * @returns {React$Element<any>}
  55. */
  56. function ParticipantItem({
  57. children,
  58. isKnockingParticipant,
  59. name,
  60. onPress,
  61. participant: p,
  62. audioMuteState = MediaState.None,
  63. videoMuteState = MediaState.None
  64. }: Props) {
  65. const displayName = name || useSelector(getParticipantDisplayNameWithId(p.id));
  66. const { t } = useTranslation();
  67. return (
  68. <View style = { styles.participantContainer } >
  69. <TouchableOpacity
  70. /* eslint-disable-next-line react/jsx-no-bind */
  71. onPress = { onPress }
  72. style = { styles.participantContent }>
  73. <Avatar
  74. className = 'participant-avatar'
  75. participantId = { p.id }
  76. size = { 32 } />
  77. <View style = { styles.participantNameContainer }>
  78. <Text style = { styles.participantName }>
  79. { displayName }
  80. </Text>
  81. { p.local ? <Text style = { styles.isLocal }>({t('chat.you')})</Text> : null }
  82. </View>
  83. {
  84. !isKnockingParticipant
  85. && <>
  86. {
  87. p.raisedHand && <RaisedHandIndicator />
  88. }
  89. <View style = { styles.participantStatesContainer }>
  90. <View style = { styles.participantStateVideo }>{VideoStateIcons[videoMuteState]}</View>
  91. <View>{AudioStateIcons[audioMuteState]}</View>
  92. </View>
  93. </>
  94. }
  95. </TouchableOpacity>
  96. { !p.local && children }
  97. </View>
  98. );
  99. }
  100. export default ParticipantItem;