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.tsx 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. // @ts-expect-error
  4. import Filmstrip from '../../../../../modules/UI/videolayout/Filmstrip';
  5. import { IReduxState } from '../../../app/types';
  6. import { FakeParticipant } from '../../../base/participants/types';
  7. import { getVerticalViewMaxWidth } from '../../../filmstrip/functions.web';
  8. import { getLargeVideoParticipant } from '../../../large-video/functions';
  9. import { getToolboxHeight } from '../../../toolbox/functions.web';
  10. import { isSharedVideoEnabled, isVideoPlaying } from '../../functions';
  11. import VideoManager from './VideoManager';
  12. import YoutubeVideoManager from './YoutubeVideoManager';
  13. interface IProps {
  14. /**
  15. * The available client width.
  16. */
  17. clientHeight: number;
  18. /**
  19. * The available client width.
  20. */
  21. clientWidth: number;
  22. /**
  23. * Whether the (vertical) filmstrip is visible or not.
  24. */
  25. filmstripVisible: boolean;
  26. /**
  27. * The width of the vertical filmstrip.
  28. */
  29. filmstripWidth: number;
  30. /**
  31. * Whether the shared video is enabled or not.
  32. */
  33. isEnabled: boolean;
  34. /**
  35. * Whether the user is actively resizing the filmstrip.
  36. */
  37. isResizing: boolean;
  38. /**
  39. * Whether the shared video is currently playing.
  40. */
  41. isVideoShared: boolean;
  42. /**
  43. * Whether the shared video should be shown on stage.
  44. */
  45. onStage: boolean;
  46. /**
  47. * The shared video url.
  48. */
  49. videoUrl?: string;
  50. }
  51. /** .
  52. * Implements a React {@link Component} which represents the large video (a.k.a.
  53. * The conference participant who is on the local stage) on Web/React.
  54. *
  55. * @augments Component
  56. */
  57. class SharedVideo extends Component<IProps> {
  58. /**
  59. * Computes the width and the height of the component.
  60. *
  61. * @returns {{
  62. * height: number,
  63. * width: number
  64. * }}
  65. */
  66. getDimensions() {
  67. const { clientHeight, clientWidth, filmstripVisible, filmstripWidth } = this.props;
  68. let width;
  69. let height;
  70. if (interfaceConfig.VERTICAL_FILMSTRIP) {
  71. if (filmstripVisible) {
  72. width = `${clientWidth - filmstripWidth}px`;
  73. } else {
  74. width = `${clientWidth}px`;
  75. }
  76. height = `${clientHeight - getToolboxHeight()}px`;
  77. } else {
  78. if (filmstripVisible) {
  79. height = `${clientHeight - Filmstrip.getFilmstripHeight()}px`;
  80. } else {
  81. height = `${clientHeight}px`;
  82. }
  83. width = `${clientWidth}px`;
  84. }
  85. return {
  86. width,
  87. height
  88. };
  89. }
  90. /**
  91. * Retrieves the manager to be used for playing the shared video.
  92. *
  93. * @returns {Component}
  94. */
  95. getManager() {
  96. const { videoUrl } = this.props;
  97. if (!videoUrl) {
  98. return null;
  99. }
  100. if (videoUrl.match(/http/)) {
  101. return <VideoManager videoId = { videoUrl } />;
  102. }
  103. return <YoutubeVideoManager videoId = { videoUrl } />;
  104. }
  105. /**
  106. * Implements React's {@link Component#render()}.
  107. *
  108. * @inheritdoc
  109. * @returns {React$Element}
  110. */
  111. render() {
  112. const { isEnabled, isResizing, isVideoShared, onStage } = this.props;
  113. if (!isEnabled || !isVideoShared) {
  114. return null;
  115. }
  116. const style: any = this.getDimensions();
  117. if (!onStage) {
  118. style.display = 'none';
  119. }
  120. return (
  121. <div
  122. className = { (isResizing && 'disable-pointer') || '' }
  123. id = 'sharedVideo'
  124. style = { style }>
  125. {this.getManager()}
  126. </div>
  127. );
  128. }
  129. }
  130. /**
  131. * Maps (parts of) the Redux state to the associated LargeVideo props.
  132. *
  133. * @param {Object} state - The Redux state.
  134. * @private
  135. * @returns {IProps}
  136. */
  137. function _mapStateToProps(state: IReduxState) {
  138. const { videoUrl } = state['features/shared-video'];
  139. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  140. const { visible, isResizing } = state['features/filmstrip'];
  141. const onStage = getLargeVideoParticipant(state)?.fakeParticipant === FakeParticipant.SharedVideo;
  142. const isVideoShared = isVideoPlaying(state);
  143. return {
  144. clientHeight,
  145. clientWidth,
  146. filmstripVisible: visible,
  147. filmstripWidth: getVerticalViewMaxWidth(state),
  148. isEnabled: isSharedVideoEnabled(state),
  149. isResizing,
  150. isVideoShared,
  151. onStage,
  152. videoUrl
  153. };
  154. }
  155. export default connect(_mapStateToProps)(SharedVideo);