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 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // @flow
  2. import React, { type Node, useCallback } 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. * Opens a drawer with participant actions.
  56. */
  57. openDrawerForParticipant: Function,
  58. /**
  59. * Callback for when the mouse leaves this component
  60. */
  61. onLeave?: Function,
  62. /**
  63. * If an overflow drawer can be opened.
  64. */
  65. overflowDrawer?: boolean,
  66. /**
  67. * The ID of the participant.
  68. */
  69. participantID: string,
  70. /**
  71. * True if the participant have raised hand.
  72. */
  73. raisedHand: boolean,
  74. /**
  75. * Media state for video
  76. */
  77. videoMediaState: MediaState,
  78. /**
  79. * The translated "you" text.
  80. */
  81. youText: string
  82. }
  83. /**
  84. * A component representing a participant entry in ParticipantPane and Lobby.
  85. *
  86. * @param {Props} props - The props of the component.
  87. * @returns {ReactNode}
  88. */
  89. export default function ParticipantItem({
  90. children,
  91. isHighlighted,
  92. onLeave,
  93. actionsTrigger = ACTION_TRIGGER.HOVER,
  94. audioMediaState = MEDIA_STATE.NONE,
  95. videoMediaState = MEDIA_STATE.NONE,
  96. displayName,
  97. participantID,
  98. local,
  99. openDrawerForParticipant,
  100. overflowDrawer,
  101. raisedHand,
  102. youText
  103. }: Props) {
  104. const ParticipantActions = Actions[actionsTrigger];
  105. const onClick = useCallback(
  106. () => openDrawerForParticipant({
  107. participantID,
  108. displayName
  109. }));
  110. return (
  111. <ParticipantContainer
  112. id = { `participant-item-${participantID}` }
  113. isHighlighted = { isHighlighted }
  114. local = { local }
  115. onClick = { !local && overflowDrawer ? onClick : undefined }
  116. onMouseLeave = { onLeave }
  117. trigger = { actionsTrigger }>
  118. <Avatar
  119. className = 'participant-avatar'
  120. participantId = { participantID }
  121. size = { 32 } />
  122. <ParticipantContent>
  123. <ParticipantNameContainer>
  124. <ParticipantName>
  125. { displayName }
  126. </ParticipantName>
  127. { local ? <span>&nbsp;({ youText })</span> : null }
  128. </ParticipantNameContainer>
  129. { !local && <ParticipantActions children = { children } /> }
  130. <ParticipantStates>
  131. { raisedHand && <RaisedHandIndicator /> }
  132. { VideoStateIcons[videoMediaState] }
  133. { AudioStateIcons[audioMediaState] }
  134. </ParticipantStates>
  135. </ParticipantContent>
  136. </ParticipantContainer>
  137. );
  138. }