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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { ColorSchemeRegistry } from '../../base/color-scheme';
  4. import { ParticipantView, getParticipantById } from '../../base/participants';
  5. import { connect } from '../../base/redux';
  6. import { StyleType } from '../../base/styles';
  7. import { isLocalVideoTrackDesktop } from '../../base/tracks/functions';
  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. * Whether video should be disabled.
  15. */
  16. _disableVideo: boolean,
  17. /**
  18. * Application's viewport height.
  19. */
  20. _height: number,
  21. /**
  22. * The ID of the participant (to be) depicted by LargeVideo.
  23. *
  24. * @private
  25. */
  26. _participantId: string,
  27. /**
  28. * The color-schemed stylesheet of the feature.
  29. */
  30. _styles: StyleType,
  31. /**
  32. * Application's viewport height.
  33. */
  34. _width: number,
  35. /**
  36. * Callback to invoke when the {@code LargeVideo} is clicked/pressed.
  37. */
  38. onClick: Function,
  39. };
  40. /**
  41. * The type of the React {@link Component} state of {@link LargeVideo}.
  42. */
  43. type State = {
  44. /**
  45. * Size for the Avatar. It will be dynamically adjusted based on the
  46. * available size.
  47. */
  48. avatarSize: number,
  49. /**
  50. * Whether the connectivity indicator will be shown or not. It will be true
  51. * by default, but it may be turned off if there is not enough space.
  52. */
  53. useConnectivityInfoLabel: boolean
  54. };
  55. const DEFAULT_STATE = {
  56. avatarSize: AVATAR_SIZE,
  57. useConnectivityInfoLabel: true
  58. };
  59. /**
  60. * Implements a React {@link Component} which represents the large video (a.k.a.
  61. * the conference participant who is on the local stage) on mobile/React Native.
  62. *
  63. * @extends Component
  64. */
  65. class LargeVideo extends PureComponent<Props, State> {
  66. state = {
  67. ...DEFAULT_STATE
  68. };
  69. /**
  70. * Handles dimension changes. In case we deem it's too
  71. * small, the connectivity indicator won't be rendered and the avatar
  72. * will occupy the entirety of the available screen state.
  73. *
  74. * @inheritdoc
  75. */
  76. static getDerivedStateFromProps(props: Props) {
  77. const { _height, _width } = props;
  78. // Get the size, rounded to the nearest even number.
  79. const size = 2 * Math.round(Math.min(_height, _width) / 2);
  80. if (size < AVATAR_SIZE * 1.5) {
  81. return {
  82. avatarSize: size - 15, // Leave some margin.
  83. useConnectivityInfoLabel: false
  84. };
  85. }
  86. return DEFAULT_STATE;
  87. }
  88. /**
  89. * Implements React's {@link Component#render()}.
  90. *
  91. * @inheritdoc
  92. * @returns {ReactElement}
  93. */
  94. render() {
  95. const {
  96. avatarSize,
  97. useConnectivityInfoLabel
  98. } = this.state;
  99. const {
  100. _disableVideo,
  101. _participantId,
  102. _styles,
  103. onClick
  104. } = this.props;
  105. return (
  106. <ParticipantView
  107. avatarSize = { avatarSize }
  108. disableVideo = { _disableVideo }
  109. onPress = { onClick }
  110. participantId = { _participantId }
  111. style = { _styles.largeVideo }
  112. testHintId = 'org.jitsi.meet.LargeVideo'
  113. useConnectivityInfoLabel = { useConnectivityInfoLabel }
  114. zOrder = { 0 }
  115. zoomEnabled = { true } />
  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 {Props}
  125. */
  126. function _mapStateToProps(state) {
  127. const { participantId } = state['features/large-video'];
  128. const participant = getParticipantById(state, participantId);
  129. const { clientHeight: height, clientWidth: width } = state['features/base/responsive-ui'];
  130. let disableVideo = false;
  131. if (participant?.local) {
  132. disableVideo = isLocalVideoTrackDesktop(state);
  133. }
  134. return {
  135. _disableVideo: disableVideo,
  136. _height: height,
  137. _participantId: participantId,
  138. _styles: ColorSchemeRegistry.get(state, 'LargeVideo'),
  139. _width: width
  140. };
  141. }
  142. export default connect(_mapStateToProps)(LargeVideo);