Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SharedVideo.tsx 4.0KB

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