您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VideoLayout.js 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /* global APP */
  2. import Logger from 'jitsi-meet-logger';
  3. import { MEDIA_TYPE, VIDEO_TYPE } from '../../../react/features/base/media';
  4. import {
  5. getPinnedParticipant,
  6. getParticipantById
  7. } from '../../../react/features/base/participants';
  8. import { getTrackByMediaTypeAndParticipant } from '../../../react/features/base/tracks';
  9. import { SHARED_VIDEO_CONTAINER_TYPE } from '../shared_video/SharedVideo';
  10. import LargeVideoManager from './LargeVideoManager';
  11. import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
  12. const logger = Logger.getLogger(__filename);
  13. let largeVideo;
  14. const VideoLayout = {
  15. /**
  16. * Handler for local flip X changed event.
  17. */
  18. onLocalFlipXChanged() {
  19. if (largeVideo) {
  20. const { store } = APP;
  21. const { localFlipX } = store.getState()['features/base/settings'];
  22. largeVideo.onLocalFlipXChange(localFlipX);
  23. }
  24. },
  25. /**
  26. * Cleans up state of this singleton {@code VideoLayout}.
  27. *
  28. * @returns {void}
  29. */
  30. reset() {
  31. this._resetLargeVideo();
  32. },
  33. initLargeVideo() {
  34. this._resetLargeVideo();
  35. largeVideo = new LargeVideoManager();
  36. const { store } = APP;
  37. const { localFlipX } = store.getState()['features/base/settings'];
  38. if (typeof localFlipX === 'boolean') {
  39. largeVideo.onLocalFlipXChange(localFlipX);
  40. }
  41. largeVideo.updateContainerSize();
  42. },
  43. /**
  44. * Sets the audio level of the video elements associated to the given id.
  45. *
  46. * @param id the video identifier in the form it comes from the library
  47. * @param lvl the new audio level to update to
  48. */
  49. setAudioLevel(id, lvl) {
  50. if (largeVideo && id === largeVideo.id) {
  51. largeVideo.updateLargeVideoAudioLevel(lvl);
  52. }
  53. },
  54. /**
  55. * FIXME get rid of this method once muted indicator are reactified (by
  56. * making sure that user with no tracks is displayed as muted )
  57. *
  58. * If participant has no tracks will make the UI display muted status.
  59. * @param {string} participantId
  60. */
  61. updateVideoMutedForNoTracks(participantId) {
  62. const participant = APP.conference.getParticipantById(participantId);
  63. if (participant && !participant.getTracksByMediaType('video').length) {
  64. VideoLayout._updateLargeVideoIfDisplayed(participantId, true);
  65. }
  66. },
  67. /**
  68. * Return the type of the remote video.
  69. * @param id the id for the remote video
  70. * @returns {String} the video type video or screen.
  71. */
  72. getRemoteVideoType(id) {
  73. const state = APP.store.getState();
  74. const participant = getParticipantById(state, id);
  75. if (participant?.isFakeParticipant) {
  76. return SHARED_VIDEO_CONTAINER_TYPE;
  77. }
  78. const videoTrack = getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id);
  79. return videoTrack?.videoType;
  80. },
  81. getPinnedId() {
  82. const { id } = getPinnedParticipant(APP.store.getState()) || {};
  83. return id || null;
  84. },
  85. /**
  86. * Shows/hides warning about a user's connectivity issues.
  87. *
  88. * @param {string} id - The ID of the remote participant(MUC nickname).
  89. * @returns {void}
  90. */
  91. onParticipantConnectionStatusChanged(id) {
  92. if (APP.conference.isLocalId(id)) {
  93. return;
  94. }
  95. // We have to trigger full large video update to transition from
  96. // avatar to video on connectivity restored.
  97. this._updateLargeVideoIfDisplayed(id, true);
  98. },
  99. /**
  100. * On last N change event.
  101. *
  102. * @param endpointsLeavingLastN the list currently leaving last N
  103. * endpoints
  104. * @param endpointsEnteringLastN the list currently entering last N
  105. * endpoints
  106. */
  107. onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
  108. if (endpointsLeavingLastN) {
  109. endpointsLeavingLastN.forEach(this._updateLargeVideoIfDisplayed, this);
  110. }
  111. if (endpointsEnteringLastN) {
  112. endpointsEnteringLastN.forEach(this._updateLargeVideoIfDisplayed, this);
  113. }
  114. },
  115. /**
  116. * Resizes the video area.
  117. */
  118. resizeVideoArea() {
  119. if (largeVideo) {
  120. largeVideo.updateContainerSize();
  121. largeVideo.resize(false);
  122. }
  123. },
  124. changeUserAvatar(id, avatarUrl) {
  125. if (this.isCurrentlyOnLarge(id)) {
  126. largeVideo.updateAvatar(avatarUrl);
  127. }
  128. },
  129. isLargeVideoVisible() {
  130. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  131. },
  132. /**
  133. * @return {LargeContainer} the currently displayed container on large
  134. * video.
  135. */
  136. getCurrentlyOnLargeContainer() {
  137. return largeVideo.getCurrentContainer();
  138. },
  139. isCurrentlyOnLarge(id) {
  140. return largeVideo && largeVideo.id === id;
  141. },
  142. updateLargeVideo(id, forceUpdate) {
  143. if (!largeVideo) {
  144. return;
  145. }
  146. const currentContainer = largeVideo.getCurrentContainer();
  147. const currentContainerType = largeVideo.getCurrentContainerType();
  148. const isOnLarge = this.isCurrentlyOnLarge(id);
  149. const state = APP.store.getState();
  150. const videoTrack = getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id);
  151. const videoStream = videoTrack?.jitsiTrack;
  152. if (isOnLarge && !forceUpdate
  153. && LargeVideoManager.isVideoContainer(currentContainerType)
  154. && videoStream) {
  155. const currentStreamId = currentContainer.getStreamID();
  156. const newStreamId = videoStream?.getId() || null;
  157. // FIXME it might be possible to get rid of 'forceUpdate' argument
  158. if (currentStreamId !== newStreamId) {
  159. logger.debug('Enforcing large video update for stream change');
  160. forceUpdate = true; // eslint-disable-line no-param-reassign
  161. }
  162. }
  163. if (!isOnLarge || forceUpdate) {
  164. const videoType = this.getRemoteVideoType(id);
  165. largeVideo.updateLargeVideo(
  166. id,
  167. videoStream,
  168. videoType || VIDEO_TYPE.CAMERA
  169. ).catch(() => {
  170. // do nothing
  171. });
  172. }
  173. },
  174. addLargeVideoContainer(type, container) {
  175. largeVideo && largeVideo.addContainer(type, container);
  176. },
  177. removeLargeVideoContainer(type) {
  178. largeVideo && largeVideo.removeContainer(type);
  179. },
  180. /**
  181. * @returns Promise
  182. */
  183. showLargeVideoContainer(type, show) {
  184. if (!largeVideo) {
  185. return Promise.reject();
  186. }
  187. const isVisible = this.isLargeContainerTypeVisible(type);
  188. if (isVisible === show) {
  189. return Promise.resolve();
  190. }
  191. let containerTypeToShow = type;
  192. // if we are hiding a container and there is focusedVideo
  193. // (pinned remote video) use its video type,
  194. // if not then use default type - large video
  195. if (!show) {
  196. const pinnedId = this.getPinnedId();
  197. if (pinnedId) {
  198. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  199. } else {
  200. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  201. }
  202. }
  203. return largeVideo.showContainer(containerTypeToShow);
  204. },
  205. isLargeContainerTypeVisible(type) {
  206. return largeVideo && largeVideo.state === type;
  207. },
  208. /**
  209. * Returns the id of the current video shown on large.
  210. * Currently used by tests (torture).
  211. */
  212. getLargeVideoID() {
  213. return largeVideo && largeVideo.id;
  214. },
  215. /**
  216. * Returns the the current video shown on large.
  217. * Currently used by tests (torture).
  218. */
  219. getLargeVideo() {
  220. return largeVideo;
  221. },
  222. /**
  223. * Returns the wrapper jquery selector for the largeVideo
  224. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  225. */
  226. getLargeVideoWrapper() {
  227. return this.getCurrentlyOnLargeContainer().$wrapper;
  228. },
  229. /**
  230. * Helper method to invoke when the video layout has changed and elements
  231. * have to be re-arranged and resized.
  232. *
  233. * @returns {void}
  234. */
  235. refreshLayout() {
  236. VideoLayout.resizeVideoArea();
  237. },
  238. /**
  239. * Cleans up any existing largeVideo instance.
  240. *
  241. * @private
  242. * @returns {void}
  243. */
  244. _resetLargeVideo() {
  245. if (largeVideo) {
  246. largeVideo.destroy();
  247. }
  248. largeVideo = null;
  249. },
  250. /**
  251. * Triggers an update of large video if the passed in participant is
  252. * currently displayed on large video.
  253. *
  254. * @param {string} participantId - The participant ID that should trigger an
  255. * update of large video if displayed.
  256. * @param {boolean} force - Whether or not the large video update should
  257. * happen no matter what.
  258. * @returns {void}
  259. */
  260. _updateLargeVideoIfDisplayed(participantId, force = false) {
  261. if (this.isCurrentlyOnLarge(participantId)) {
  262. this.updateLargeVideo(participantId, force);
  263. }
  264. },
  265. /**
  266. * Handles window resizes.
  267. */
  268. onResize() {
  269. VideoLayout.resizeVideoArea();
  270. }
  271. };
  272. export default VideoLayout;