Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

VideoManager.js 3.3KB

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