Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LargeVideo.native.js 3.5KB

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