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

ParticipantItem.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // @flow
  2. import React, { type Node } from 'react';
  3. import { Avatar } from '../../../base/avatar';
  4. import {
  5. ACTION_TRIGGER,
  6. AudioStateIcons,
  7. MEDIA_STATE,
  8. type ActionTrigger,
  9. type MediaState,
  10. VideoStateIcons
  11. } from '../../constants';
  12. import { RaisedHandIndicator } from './RaisedHandIndicator';
  13. import {
  14. ParticipantActionsHover,
  15. ParticipantActionsPermanent,
  16. ParticipantContainer,
  17. ParticipantContent,
  18. ParticipantName,
  19. ParticipantNameContainer,
  20. ParticipantStates
  21. } from './styled';
  22. /**
  23. * Participant actions component mapping depending on trigger type.
  24. */
  25. const Actions = {
  26. [ACTION_TRIGGER.HOVER]: ParticipantActionsHover,
  27. [ACTION_TRIGGER.PERMANENT]: ParticipantActionsPermanent
  28. };
  29. type Props = {
  30. /**
  31. * Type of trigger for the participant actions
  32. */
  33. actionsTrigger: ActionTrigger,
  34. /**
  35. * Media state for audio
  36. */
  37. audioMediaState: MediaState,
  38. /**
  39. * React children
  40. */
  41. children: Node,
  42. /**
  43. * The name of the participant. Used for showing lobby names.
  44. */
  45. displayName: string,
  46. /**
  47. * Is this item highlighted/raised
  48. */
  49. isHighlighted?: boolean,
  50. /**
  51. * True if the participant is local.
  52. */
  53. local: boolean,
  54. /**
  55. * Callback for when the mouse leaves this component
  56. */
  57. onLeave?: Function,
  58. /**
  59. * The ID of the participant.
  60. */
  61. participantID: string,
  62. /**
  63. * True if the participant have raised hand.
  64. */
  65. raisedHand: boolean,
  66. /**
  67. * Media state for video
  68. */
  69. videoMuteState: MediaState,
  70. /**
  71. * The translated "you" text.
  72. */
  73. youText: string
  74. }
  75. /**
  76. * A component representing a participant entry in ParticipantPane and Lobby.
  77. *
  78. * @param {Props} props - The props of the component.
  79. * @returns {ReactNode}
  80. */
  81. export default function ParticipantItem({
  82. children,
  83. isHighlighted,
  84. onLeave,
  85. actionsTrigger = ACTION_TRIGGER.HOVER,
  86. audioMediaState = MEDIA_STATE.NONE,
  87. videoMuteState = MEDIA_STATE.NONE,
  88. displayName,
  89. participantID,
  90. local,
  91. raisedHand,
  92. youText
  93. }: Props) {
  94. const ParticipantActions = Actions[actionsTrigger];
  95. return (
  96. <ParticipantContainer
  97. id = { `participant-item-${participantID}` }
  98. isHighlighted = { isHighlighted }
  99. local = { local }
  100. onMouseLeave = { onLeave }
  101. trigger = { actionsTrigger }>
  102. <Avatar
  103. className = 'participant-avatar'
  104. participantId = { participantID }
  105. size = { 32 } />
  106. <ParticipantContent>
  107. <ParticipantNameContainer>
  108. <ParticipantName>
  109. { displayName }
  110. </ParticipantName>
  111. { local ? <span>&nbsp;({ youText })</span> : null }
  112. </ParticipantNameContainer>
  113. { !local && <ParticipantActions children = { children } /> }
  114. <ParticipantStates>
  115. { raisedHand && <RaisedHandIndicator /> }
  116. { VideoStateIcons[videoMuteState] }
  117. { AudioStateIcons[audioMediaState] }
  118. </ParticipantStates>
  119. </ParticipantContent>
  120. </ParticipantContainer>
  121. );
  122. }