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.

SharedVideo.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { View } from 'react-native';
  4. import { getLocalParticipant } from '../../../base/participants';
  5. import { connect } from '../../../base/redux';
  6. import { ASPECT_RATIO_WIDE } from '../../../base/responsive-ui';
  7. import { setToolboxVisible } from '../../../toolbox/actions';
  8. import VideoManager from './VideoManager';
  9. import YoutubeVideoManager from './YoutubeVideoManager';
  10. import styles from './styles';
  11. type Props = {
  12. /**
  13. * The Redux dispatch function.
  14. */
  15. dispatch: Function,
  16. /**
  17. * Is the video shared by the local user.
  18. *
  19. * @private
  20. */
  21. isOwner: boolean,
  22. /**
  23. * True if in landscape mode.
  24. *
  25. * @private
  26. */
  27. isWideScreen: boolean,
  28. /**
  29. * The available player width
  30. */
  31. playerHeight: number,
  32. /**
  33. * The available player width
  34. */
  35. playerWidth: number,
  36. /**
  37. * The shared video url
  38. */
  39. videoUrl: string,
  40. }
  41. /**
  42. * Implements a React {@link Component} which represents the large video (a.k.a.
  43. * the conference participant who is on the local stage) on Web/React.
  44. *
  45. * @extends Component
  46. */
  47. class SharedVideo extends Component<Props> {
  48. /**
  49. * Initializes a new {@code SharedVideo} instance.
  50. *
  51. * @param {Object} props - The properties.
  52. */
  53. constructor(props: Props) {
  54. super(props);
  55. this.setWideScreenMode(props.isWideScreen);
  56. }
  57. /**
  58. * Implements React's {@link Component#componentDidUpdate()}.
  59. *
  60. * @inheritdoc
  61. * @returns {void}
  62. */
  63. componentDidUpdate(prevProps: Props) {
  64. const { isWideScreen } = this.props;
  65. if (isWideScreen !== prevProps.isWideScreen) {
  66. this.setWideScreenMode(isWideScreen);
  67. }
  68. }
  69. /**
  70. * Dispatches action to set the visibility of the toolbox, true if not widescreen, false otherwise.
  71. *
  72. * @param {isWideScreen} isWideScreen - Whether the screen is wide.
  73. * @private
  74. * @returns {void}
  75. */
  76. setWideScreenMode(isWideScreen) {
  77. this.props.dispatch(setToolboxVisible(!isWideScreen));
  78. }
  79. /**
  80. * Implements React's {@link Component#render()}.
  81. *
  82. * @inheritdoc
  83. * @returns {React$Element}
  84. */
  85. render() {
  86. const {
  87. isOwner,
  88. playerHeight,
  89. playerWidth,
  90. videoUrl
  91. } = this.props;
  92. if (!videoUrl) {
  93. return null;
  94. }
  95. return (
  96. <View
  97. pointerEvents = { isOwner ? 'auto' : 'none' }
  98. style = { styles.videoContainer } >
  99. {videoUrl.match(/http/)
  100. ? (
  101. <VideoManager
  102. height = { playerHeight }
  103. videoId = { videoUrl }
  104. width = { playerWidth } />
  105. ) : (
  106. <YoutubeVideoManager
  107. height = { playerHeight }
  108. videoId = { videoUrl }
  109. width = { playerWidth } />
  110. )
  111. }
  112. </View>
  113. );
  114. }
  115. }
  116. /**
  117. * Maps (parts of) the Redux state to the associated LargeVideo props.
  118. *
  119. * @param {Object} state - The Redux state.
  120. * @private
  121. * @returns {Props}
  122. */
  123. function _mapStateToProps(state) {
  124. const { ownerId, videoUrl } = state['features/shared-video'];
  125. const { aspectRatio, clientHeight, clientWidth } = state['features/base/responsive-ui'];
  126. const isWideScreen = aspectRatio === ASPECT_RATIO_WIDE;
  127. const localParticipant = getLocalParticipant(state);
  128. let playerHeight, playerWidth;
  129. if (isWideScreen) {
  130. playerHeight = clientHeight;
  131. playerWidth = playerHeight * 16 / 9;
  132. } else {
  133. playerWidth = clientWidth;
  134. playerHeight = playerWidth * 9 / 16;
  135. }
  136. return {
  137. isOwner: ownerId === localParticipant.id,
  138. isWideScreen,
  139. playerHeight,
  140. playerWidth,
  141. videoUrl
  142. };
  143. }
  144. export default connect(_mapStateToProps)(SharedVideo);