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

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