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.0KB

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