Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

VideoManager.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { PLAYBACK_STATUSES } from '../../constants';
  4. import AbstractVideoManager, {
  5. IProps,
  6. _mapDispatchToProps,
  7. _mapStateToProps
  8. } from './AbstractVideoManager';
  9. /**
  10. * Manager of shared video.
  11. */
  12. class VideoManager extends AbstractVideoManager {
  13. playerRef: React.RefObject<HTMLVideoElement>;
  14. /**
  15. * Initializes a new VideoManager instance.
  16. *
  17. * @param {Object} props - This component's props.
  18. *
  19. * @returns {void}
  20. */
  21. constructor(props: IProps) {
  22. super(props);
  23. this.playerRef = React.createRef();
  24. }
  25. /**
  26. * Retrieves the current player ref.
  27. */
  28. get player() {
  29. return this.playerRef.current;
  30. }
  31. /**
  32. * Indicates the playback state of the video.
  33. *
  34. * @returns {string}
  35. */
  36. getPlaybackStatus() {
  37. let status;
  38. if (!this.player) {
  39. return;
  40. }
  41. if (this.player.paused) {
  42. status = PLAYBACK_STATUSES.PAUSED;
  43. } else {
  44. status = PLAYBACK_STATUSES.PLAYING;
  45. }
  46. return status;
  47. }
  48. /**
  49. * Indicates whether the video is muted.
  50. *
  51. * @returns {boolean}
  52. */
  53. isMuted() {
  54. return this.player?.muted;
  55. }
  56. /**
  57. * Retrieves current volume.
  58. *
  59. * @returns {number}
  60. */
  61. getVolume() {
  62. return Number(this.player?.volume);
  63. }
  64. /**
  65. * Retrieves current time.
  66. *
  67. * @returns {number}
  68. */
  69. getTime() {
  70. return Number(this.player?.currentTime);
  71. }
  72. /**
  73. * Seeks video to provided time.
  74. *
  75. * @param {number} time - The time to seek to.
  76. *
  77. * @returns {void}
  78. */
  79. seek(time: number) {
  80. if (this.player) {
  81. this.player.currentTime = time;
  82. }
  83. }
  84. /**
  85. * Plays video.
  86. *
  87. * @returns {void}
  88. */
  89. play() {
  90. return this.player?.play();
  91. }
  92. /**
  93. * Pauses video.
  94. *
  95. * @returns {void}
  96. */
  97. pause() {
  98. return this.player?.pause();
  99. }
  100. /**
  101. * Mutes video.
  102. *
  103. * @returns {void}
  104. */
  105. mute() {
  106. if (this.player) {
  107. this.player.muted = true;
  108. }
  109. }
  110. /**
  111. * Unmutes video.
  112. *
  113. * @returns {void}
  114. */
  115. unMute() {
  116. if (this.player) {
  117. this.player.muted = false;
  118. }
  119. }
  120. /**
  121. * Retrieves video tag params.
  122. *
  123. * @returns {void}
  124. */
  125. getPlayerOptions() {
  126. const { _isOwner, videoId } = this.props;
  127. let options: any = {
  128. autoPlay: true,
  129. src: videoId,
  130. controls: _isOwner,
  131. onError: () => this.onError(),
  132. onPlay: () => this.onPlay(),
  133. onVolumeChange: () => this.onVolumeChange()
  134. };
  135. if (_isOwner) {
  136. options = {
  137. ...options,
  138. onPause: () => this.onPause(),
  139. onTimeUpdate: this.throttledFireUpdateSharedVideoEvent
  140. };
  141. }
  142. return options;
  143. }
  144. /**
  145. * Implements React Component's render.
  146. *
  147. * @inheritdoc
  148. */
  149. render() {
  150. return (
  151. <video
  152. id = 'sharedVideoPlayer'
  153. ref = { this.playerRef }
  154. { ...this.getPlayerOptions() } />
  155. );
  156. }
  157. }
  158. export default connect(_mapStateToProps, _mapDispatchToProps)(VideoManager);