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.

CalleeInfo.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Avatar } from '../../../base/avatar';
  4. import { MEDIA_TYPE } from '../../../base/media';
  5. import {
  6. getParticipants,
  7. getParticipantDisplayName,
  8. getParticipantPresenceStatus
  9. } from '../../../base/participants';
  10. import { Container, Text } from '../../../base/react';
  11. import { connect } from '../../../base/redux';
  12. import { isLocalTrackMuted } from '../../../base/tracks';
  13. import { CALLING, PresenceLabel } from '../../../presence-status';
  14. import styles from './styles';
  15. /**
  16. * The type of the React {@code Component} props of {@link CalleeInfo}.
  17. */
  18. type Props = {
  19. /**
  20. * The callee's information such as display name.
  21. */
  22. _callee: Object,
  23. _isVideoMuted: boolean
  24. };
  25. /**
  26. * Implements a React {@link Component} which depicts the establishment of a
  27. * call with a specific remote callee.
  28. *
  29. * @extends Component
  30. */
  31. class CalleeInfo extends Component<Props> {
  32. /**
  33. * Implements React's {@link Component#render()}.
  34. *
  35. * @inheritdoc
  36. * @returns {ReactElement}
  37. */
  38. render() {
  39. const {
  40. id,
  41. name,
  42. status = CALLING
  43. } = this.props._callee;
  44. const className = this.props._isVideoMuted ? 'solidBG' : undefined;
  45. return (
  46. <Container
  47. { ...this._style('ringing', className) }
  48. id = 'ringOverlay'>
  49. <Container
  50. { ...this._style('ringing__content') }>
  51. <Avatar
  52. { ...this._style('ringing__avatar') }
  53. participantId = { id } />
  54. <Container { ...this._style('ringing__status') }>
  55. <PresenceLabel
  56. defaultPresence = { status }
  57. { ...this._style('ringing__text') } />
  58. </Container>
  59. <Container { ...this._style('ringing__name') }>
  60. <Text
  61. { ...this._style('ringing__text') }>
  62. { name }
  63. </Text>
  64. </Container>
  65. </Container>
  66. </Container>
  67. );
  68. }
  69. /**
  70. * Attempts to convert specified CSS class names into React
  71. * {@link Component} props {@code style} or {@code className}.
  72. *
  73. * @param {Array<string>} classNames - The CSS class names to convert
  74. * into React {@code Component} props {@code style} or {@code className}.
  75. * @returns {{
  76. * className: string,
  77. * style: Object
  78. * }}
  79. */
  80. _style(...classNames: Array<?string>) {
  81. let className = '';
  82. let style;
  83. for (const aClassName of classNames) {
  84. if (aClassName) {
  85. // Attemp to convert aClassName into style.
  86. if (styles && aClassName in styles) {
  87. // React Native will accept an Array as the value of the
  88. // style prop. However, I do not know about React.
  89. style = {
  90. ...style,
  91. ...styles[aClassName]
  92. };
  93. } else {
  94. // Otherwise, leave it as className.
  95. className += `${aClassName} `;
  96. }
  97. }
  98. }
  99. // Choose which of the className and/or style props has a value and,
  100. // consequently, must be returned.
  101. const props = {};
  102. if (className) {
  103. props.className = className.trim();
  104. }
  105. if (style) {
  106. props.style = style;
  107. }
  108. return props;
  109. }
  110. }
  111. /**
  112. * Maps (parts of) the redux state to {@code CalleeInfo}'s props.
  113. *
  114. * @param {Object} state - The redux state.
  115. * @private
  116. * @returns {{
  117. * _callee: Object
  118. * }}
  119. */
  120. function _mapStateToProps(state) {
  121. const _isVideoMuted
  122. = isLocalTrackMuted(state['features/base/tracks'], MEDIA_TYPE.VIDEO);
  123. const poltergeist
  124. = getParticipants(state).find(p => p.botType === 'poltergeist');
  125. if (poltergeist) {
  126. const { id } = poltergeist;
  127. return {
  128. _callee: {
  129. id,
  130. name: getParticipantDisplayName(state, id),
  131. status: getParticipantPresenceStatus(state, id)
  132. },
  133. _isVideoMuted
  134. };
  135. }
  136. return {
  137. _callee: state['features/invite'].initialCalleeInfo,
  138. _isVideoMuted
  139. };
  140. }
  141. export default connect(_mapStateToProps)(CalleeInfo);