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

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