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

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