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.

DisplayNameLabel.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Text, View } from 'react-native';
  4. import {
  5. getLocalParticipant,
  6. getParticipantById,
  7. getParticipantDisplayName,
  8. shouldRenderParticipantVideo
  9. } from '../../../base/participants';
  10. import { connect } from '../../../base/redux';
  11. import styles from './styles';
  12. type Props = {
  13. /**
  14. * The name of the participant to render.
  15. */
  16. _participantName: string,
  17. /**
  18. * True of the label needs to be rendered. False otherwise.
  19. */
  20. _render: boolean,
  21. /**
  22. * The ID of the participant to render the label for.
  23. */
  24. participantId: string
  25. }
  26. /**
  27. * Renders a label with the display name of the on-stage participant.
  28. */
  29. class DisplayNameLabel extends Component<Props> {
  30. /**
  31. * Implements {@code Component#render}.
  32. *
  33. * @inheritdoc
  34. */
  35. render() {
  36. if (!this.props._render) {
  37. return null;
  38. }
  39. return (
  40. <View style = { styles.displayNameBackdrop }>
  41. <Text style = { styles.displayNameText }>
  42. { this.props._participantName }
  43. </Text>
  44. </View>
  45. );
  46. }
  47. }
  48. /**
  49. * Maps part of the Redux state to the props of this component.
  50. *
  51. * @param {Object} state - The Redux state.
  52. * @param {Props} ownProps - The own props of the component.
  53. * @returns {{
  54. * }}
  55. */
  56. function _mapStateToProps(state: Object, ownProps: Props) {
  57. const { participantId } = ownProps;
  58. const localParticipant = getLocalParticipant(state);
  59. const participant = getParticipantById(state, participantId);
  60. const isFakeParticipant = participant && participant.isFakeParticipant;
  61. // Currently we only render the display name if it's not the local
  62. // participant and there is no video rendered for
  63. // them.
  64. const _render = Boolean(participantId)
  65. && localParticipant?.id !== participantId
  66. && !shouldRenderParticipantVideo(state, participantId)
  67. && !isFakeParticipant;
  68. return {
  69. _participantName:
  70. getParticipantDisplayName(state, participantId),
  71. _render
  72. };
  73. }
  74. export default connect(_mapStateToProps)(DisplayNameLabel);