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.

RemoteVideo.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* global $, APP, config */
  2. /* eslint-disable no-unused-vars */
  3. import { AtlasKitThemeProvider } from '@atlaskit/theme';
  4. import Logger from 'jitsi-meet-logger';
  5. import React from 'react';
  6. import ReactDOM from 'react-dom';
  7. import { I18nextProvider } from 'react-i18next';
  8. import { Provider } from 'react-redux';
  9. import { i18next } from '../../../react/features/base/i18n';
  10. import {
  11. JitsiParticipantConnectionStatus
  12. } from '../../../react/features/base/lib-jitsi-meet';
  13. import { getParticipantById } from '../../../react/features/base/participants';
  14. import { isTestModeEnabled } from '../../../react/features/base/testing';
  15. import { updateLastTrackVideoMediaEvent } from '../../../react/features/base/tracks';
  16. import { Thumbnail, isVideoPlayable } from '../../../react/features/filmstrip';
  17. import { PresenceLabel } from '../../../react/features/presence-status';
  18. import { stopController, requestRemoteControl } from '../../../react/features/remote-control';
  19. import { RemoteVideoMenuTriggerButton } from '../../../react/features/remote-video-menu';
  20. /* eslint-enable no-unused-vars */
  21. import UIUtils from '../util/UIUtil';
  22. import SmallVideo from './SmallVideo';
  23. const logger = Logger.getLogger(__filename);
  24. /**
  25. * List of container events that we are going to process, will be added as listener to the
  26. * container for every event in the list. The latest event will be stored in redux.
  27. */
  28. const containerEvents = [
  29. 'abort', 'canplay', 'canplaythrough', 'emptied', 'ended', 'error', 'loadeddata', 'loadedmetadata', 'loadstart',
  30. 'pause', 'play', 'playing', 'ratechange', 'stalled', 'suspend', 'waiting'
  31. ];
  32. /**
  33. *
  34. * @param {*} spanId
  35. */
  36. function createContainer(spanId) {
  37. const container = document.createElement('span');
  38. container.id = spanId;
  39. container.className = 'videocontainer';
  40. const remoteVideosContainer
  41. = document.getElementById('filmstripRemoteVideosContainer');
  42. const localVideoContainer
  43. = document.getElementById('localVideoTileViewContainer');
  44. remoteVideosContainer.insertBefore(container, localVideoContainer);
  45. return container;
  46. }
  47. /**
  48. *
  49. */
  50. export default class RemoteVideo extends SmallVideo {
  51. /**
  52. * Creates new instance of the <tt>RemoteVideo</tt>.
  53. * @param user {JitsiParticipant} the user for whom remote video instance will
  54. * be created.
  55. * @constructor
  56. */
  57. constructor(user) {
  58. super();
  59. this.user = user;
  60. this.id = user.getId();
  61. this.videoSpanId = `participant_${this.id}`;
  62. this.addRemoteVideoContainer();
  63. this.bindHoverHandler();
  64. this.flipX = false;
  65. this.isLocal = false;
  66. /**
  67. * The flag is set to <tt>true</tt> after the 'canplay' event has been
  68. * triggered on the current video element. It goes back to <tt>false</tt>
  69. * when the stream is removed. It is used to determine whether the video
  70. * playback has ever started.
  71. * @type {boolean}
  72. */
  73. this._canPlayEventReceived = false;
  74. this.container.onclick = this._onContainerClick;
  75. }
  76. /**
  77. *
  78. */
  79. addRemoteVideoContainer() {
  80. this.container = createContainer(this.videoSpanId);
  81. this.$container = $(this.container);
  82. this.renderThumbnail();
  83. this._setThumbnailSize();
  84. this.initBrowserSpecificProperties();
  85. return this.container;
  86. }
  87. /**
  88. * Renders the thumbnail.
  89. */
  90. renderThumbnail(isHovered = false) {
  91. ReactDOM.render(
  92. <Provider store = { APP.store }>
  93. <I18nextProvider i18n = { i18next }>
  94. <Thumbnail participantID = { this.id } isHovered = { isHovered } />
  95. </I18nextProvider>
  96. </Provider>, this.container);
  97. }
  98. /**
  99. * Removes the remote stream element corresponding to the given stream and
  100. * parent container.
  101. *
  102. * @param stream the MediaStream
  103. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  104. */
  105. removeRemoteStreamElement(stream) {
  106. if (!this.container) {
  107. return false;
  108. }
  109. const isVideo = stream.isVideoTrack();
  110. const elementID = `remoteVideo_${stream.getId()}`;
  111. const select = $(`#${elementID}`);
  112. select.remove();
  113. if (isVideo) {
  114. this._canPlayEventReceived = false;
  115. }
  116. logger.info(`Video removed ${this.id}`, select);
  117. this.updateView();
  118. }
  119. /**
  120. * The remote video is considered "playable" once the can play event has been received.
  121. *
  122. * @inheritdoc
  123. * @override
  124. */
  125. isVideoPlayable() {
  126. return isVideoPlayable(APP.store.getState(), this.id) && this._canPlayEventReceived;
  127. }
  128. /**
  129. * @inheritDoc
  130. */
  131. updateView() {
  132. this.$container.toggleClass('audio-only', APP.conference.isAudioOnly());
  133. super.updateView();
  134. }
  135. /**
  136. * Removes RemoteVideo from the page.
  137. */
  138. remove() {
  139. ReactDOM.unmountComponentAtNode(this.container);
  140. super.remove();
  141. }
  142. /**
  143. *
  144. * @param {*} streamElement
  145. * @param {*} stream
  146. */
  147. waitForPlayback(streamElement, stream) {
  148. $(streamElement).hide();
  149. const webRtcStream = stream.getOriginalStream();
  150. const isVideo = stream.isVideoTrack();
  151. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  152. return;
  153. }
  154. const listener = () => {
  155. this._canPlayEventReceived = true;
  156. logger.info(`${this.id} video is now active`, streamElement);
  157. if (streamElement) {
  158. $(streamElement).show();
  159. }
  160. streamElement.removeEventListener('canplay', listener);
  161. // Refresh to show the video
  162. this.updateView();
  163. };
  164. streamElement.addEventListener('canplay', listener);
  165. }
  166. /**
  167. *
  168. * @param {*} stream
  169. */
  170. addRemoteStreamElement(stream) {
  171. if (!this.container) {
  172. logger.debug('Not attaching remote stream due to no container');
  173. return;
  174. }
  175. const isVideo = stream.isVideoTrack();
  176. if (!stream.getOriginalStream()) {
  177. logger.debug('Remote video stream has no original stream');
  178. return;
  179. }
  180. let streamElement = document.createElement('video');
  181. streamElement.autoplay = !config.testing?.noAutoPlayVideo;
  182. streamElement.id = `remoteVideo_${stream.getId()}`;
  183. streamElement.mute = true;
  184. streamElement.playsInline = true;
  185. // Put new stream element always in front
  186. streamElement = UIUtils.prependChild(this.container, streamElement);
  187. this.waitForPlayback(streamElement, stream);
  188. stream.attach(streamElement);
  189. if (isVideo && isTestModeEnabled(APP.store.getState())) {
  190. const cb = name => APP.store.dispatch(updateLastTrackVideoMediaEvent(stream, name));
  191. containerEvents.forEach(event => {
  192. streamElement.addEventListener(event, cb.bind(this, event));
  193. });
  194. }
  195. }
  196. }