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

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