Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

VideoManager.js 3.6KB

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