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.

LargeVideo.native.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { ParticipantView } from '../../base/participants';
  5. import { DimensionsDetector } from '../../base/responsive-ui';
  6. import Labels from './Labels';
  7. import styles, { AVATAR_SIZE } from './styles';
  8. /**
  9. * The type of the React {@link Component} props of {@link LargeVideo}.
  10. */
  11. type Props = {
  12. /**
  13. * Callback to invoke when the {@code LargeVideo} is clicked/pressed.
  14. */
  15. onClick: Function,
  16. /**
  17. * The ID of the participant (to be) depicted by LargeVideo.
  18. *
  19. * @private
  20. */
  21. _participantId: string
  22. };
  23. /**
  24. * The type of the React {@link Component} state of {@link LargeVideo}.
  25. */
  26. type State = {
  27. /**
  28. * Size for the Avatar. It will be dynamically adjusted based on the
  29. * available size.
  30. */
  31. avatarSize: number,
  32. /**
  33. * Whether the connectivity indicator will be shown or not. It will be true
  34. * by default, but it may be turned off if there is not enough space.
  35. */
  36. useConnectivityInfoLabel: boolean
  37. };
  38. const DEFAULT_STATE = {
  39. avatarSize: AVATAR_SIZE,
  40. useConnectivityInfoLabel: true
  41. };
  42. /**
  43. * Implements a React {@link Component} which represents the large video (a.k.a.
  44. * the conference participant who is on the local stage) on mobile/React Native.
  45. *
  46. * @extends Component
  47. */
  48. class LargeVideo extends Component<Props, State> {
  49. state = {
  50. ...DEFAULT_STATE
  51. };
  52. /** Initializes a new {@code LargeVideo} instance.
  53. *
  54. * @param {Object} props - The read-only properties with which the new
  55. * instance is to be initialized.
  56. */
  57. constructor(props) {
  58. super(props);
  59. // Bind event handlers so they are only bound once per instance.
  60. this._onDimensionsChanged = this._onDimensionsChanged.bind(this);
  61. }
  62. _onDimensionsChanged: (width: number, height: number) => void;
  63. /**
  64. * Handle this component's dimension changes. In case we deem it's too
  65. * small, the connectivity indicator won't be rendered and the avatar
  66. * will occupy the entirety of the available screen state.
  67. *
  68. * @param {number} width - The component's current width.
  69. * @param {number} height - The component's current height.
  70. * @private
  71. * @returns {void}
  72. */
  73. _onDimensionsChanged(width: number, height: number) {
  74. // Get the size, rounded to the nearest even number.
  75. const size = 2 * Math.round(Math.min(height, width) / 2);
  76. let nextState;
  77. if (size < AVATAR_SIZE * 1.5) {
  78. nextState = {
  79. avatarSize: size - 15, // Leave some margin.
  80. useConnectivityInfoLabel: false
  81. };
  82. } else {
  83. nextState = DEFAULT_STATE;
  84. }
  85. this.setState(nextState);
  86. }
  87. /**
  88. * Implements React's {@link Component#render()}.
  89. *
  90. * @inheritdoc
  91. * @returns {ReactElement}
  92. */
  93. render() {
  94. const {
  95. avatarSize,
  96. useConnectivityInfoLabel
  97. } = this.state;
  98. const {
  99. _participantId,
  100. onClick
  101. } = this.props;
  102. return (
  103. <DimensionsDetector
  104. onDimensionsChanged = { this._onDimensionsChanged }>
  105. <ParticipantView
  106. avatarSize = { avatarSize }
  107. onPress = { onClick }
  108. participantId = { _participantId }
  109. style = { styles.largeVideo }
  110. testHintId = 'org.jitsi.meet.LargeVideo'
  111. useConnectivityInfoLabel = { useConnectivityInfoLabel }
  112. zOrder = { 0 }
  113. zoomEnabled = { true } />
  114. <Labels />
  115. </DimensionsDetector>
  116. );
  117. }
  118. }
  119. /**
  120. * Maps (parts of) the Redux state to the associated LargeVideo's props.
  121. *
  122. * @param {Object} state - Redux state.
  123. * @private
  124. * @returns {{
  125. * _participantId: string
  126. * }}
  127. */
  128. function _mapStateToProps(state) {
  129. return {
  130. _participantId: state['features/large-video'].participantId
  131. };
  132. }
  133. export default connect(_mapStateToProps)(LargeVideo);