選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VideoLayout.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. /* global APP, $, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. import {
  4. getNearestReceiverVideoQualityLevel,
  5. setMaxReceiverVideoQuality
  6. } from '../../../react/features/base/conference';
  7. import {
  8. JitsiParticipantConnectionStatus
  9. } from '../../../react/features/base/lib-jitsi-meet';
  10. import { VIDEO_TYPE } from '../../../react/features/base/media';
  11. import {
  12. getLocalParticipant as getLocalParticipantFromStore,
  13. getPinnedParticipant,
  14. pinParticipant
  15. } from '../../../react/features/base/participants';
  16. import {
  17. shouldDisplayTileView
  18. } from '../../../react/features/video-layout';
  19. import { SHARED_VIDEO_CONTAINER_TYPE } from '../shared_video/SharedVideo';
  20. import SharedVideoThumb from '../shared_video/SharedVideoThumb';
  21. import Filmstrip from './Filmstrip';
  22. import UIEvents from '../../../service/UI/UIEvents';
  23. import RemoteVideo from './RemoteVideo';
  24. import LargeVideoManager from './LargeVideoManager';
  25. import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
  26. import LocalVideo from './LocalVideo';
  27. const remoteVideos = {};
  28. let localVideoThumbnail = null;
  29. let eventEmitter = null;
  30. let largeVideo;
  31. /**
  32. * flipX state of the localVideo
  33. */
  34. let localFlipX = null;
  35. /**
  36. * Handler for local flip X changed event.
  37. * @param {Object} val
  38. */
  39. function onLocalFlipXChanged(val) {
  40. localFlipX = val;
  41. if (largeVideo) {
  42. largeVideo.onLocalFlipXChange(val);
  43. }
  44. }
  45. /**
  46. * Returns an array of all thumbnails in the filmstrip.
  47. *
  48. * @private
  49. * @returns {Array}
  50. */
  51. function getAllThumbnails() {
  52. return [
  53. localVideoThumbnail,
  54. ...Object.values(remoteVideos)
  55. ];
  56. }
  57. /**
  58. * Private helper to get the redux representation of the local participant.
  59. *
  60. * @private
  61. * @returns {Object}
  62. */
  63. function getLocalParticipant() {
  64. return getLocalParticipantFromStore(APP.store.getState());
  65. }
  66. const VideoLayout = {
  67. init(emitter) {
  68. eventEmitter = emitter;
  69. localVideoThumbnail = new LocalVideo(
  70. VideoLayout,
  71. emitter,
  72. this._updateLargeVideoIfDisplayed.bind(this));
  73. // sets default video type of local video
  74. // FIXME container type is totally different thing from the video type
  75. localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
  76. // if we do not resize the thumbs here, if there is no video device
  77. // the local video thumb maybe one pixel
  78. this.resizeThumbnails(true);
  79. this.registerListeners();
  80. },
  81. /**
  82. * Registering listeners for UI events in Video layout component.
  83. *
  84. * @returns {void}
  85. */
  86. registerListeners() {
  87. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
  88. onLocalFlipXChanged);
  89. },
  90. /**
  91. * Cleans up state of this singleton {@code VideoLayout}.
  92. *
  93. * @returns {void}
  94. */
  95. reset() {
  96. this._resetLargeVideo();
  97. this._resetFilmstrip();
  98. },
  99. initLargeVideo() {
  100. this._resetLargeVideo();
  101. largeVideo = new LargeVideoManager(eventEmitter);
  102. if (localFlipX) {
  103. largeVideo.onLocalFlipXChange(localFlipX);
  104. }
  105. largeVideo.updateContainerSize();
  106. },
  107. /**
  108. * Sets the audio level of the video elements associated to the given id.
  109. *
  110. * @param id the video identifier in the form it comes from the library
  111. * @param lvl the new audio level to update to
  112. */
  113. setAudioLevel(id, lvl) {
  114. const smallVideo = this.getSmallVideo(id);
  115. if (smallVideo) {
  116. smallVideo.updateAudioLevelIndicator(lvl);
  117. }
  118. if (largeVideo && id === largeVideo.id) {
  119. largeVideo.updateLargeVideoAudioLevel(lvl);
  120. }
  121. },
  122. changeLocalVideo(stream) {
  123. const localId = getLocalParticipant().id;
  124. this.onVideoTypeChanged(localId, stream.videoType);
  125. localVideoThumbnail.changeVideo(stream);
  126. this._updateLargeVideoIfDisplayed(localId);
  127. },
  128. /**
  129. * Get's the localID of the conference and set it to the local video
  130. * (small one). This needs to be called as early as possible, when muc is
  131. * actually joined. Otherwise events can come with information like email
  132. * and setting them assume the id is already set.
  133. */
  134. mucJoined() {
  135. // FIXME: replace this call with a generic update call once SmallVideo
  136. // only contains a ReactElement. Then remove this call once the
  137. // Filmstrip is fully in React.
  138. localVideoThumbnail.updateIndicators();
  139. },
  140. /**
  141. * Shows/hides local video.
  142. * @param {boolean} true to make the local video visible, false - otherwise
  143. */
  144. setLocalVideoVisible(visible) {
  145. localVideoThumbnail.setVisible(visible);
  146. },
  147. onRemoteStreamAdded(stream) {
  148. const id = stream.getParticipantId();
  149. const remoteVideo = remoteVideos[id];
  150. logger.debug(`Received a new ${stream.getType()} stream for ${id}`);
  151. if (!remoteVideo) {
  152. logger.debug('No remote video element to add stream');
  153. return;
  154. }
  155. remoteVideo.addRemoteStreamElement(stream);
  156. // Make sure track's muted state is reflected
  157. if (stream.getType() === 'audio') {
  158. this.onAudioMute(stream.getParticipantId(), stream.isMuted());
  159. } else {
  160. this.onVideoMute(stream.getParticipantId(), stream.isMuted());
  161. }
  162. },
  163. onRemoteStreamRemoved(stream) {
  164. const id = stream.getParticipantId();
  165. const remoteVideo = remoteVideos[id];
  166. // Remote stream may be removed after participant left the conference.
  167. if (remoteVideo) {
  168. remoteVideo.removeRemoteStreamElement(stream);
  169. }
  170. this.updateMutedForNoTracks(id, stream.getType());
  171. },
  172. /**
  173. * FIXME get rid of this method once muted indicator are reactified (by
  174. * making sure that user with no tracks is displayed as muted )
  175. *
  176. * If participant has no tracks will make the UI display muted status.
  177. * @param {string} participantId
  178. * @param {string} mediaType 'audio' or 'video'
  179. */
  180. updateMutedForNoTracks(participantId, mediaType) {
  181. const participant = APP.conference.getParticipantById(participantId);
  182. if (participant
  183. && !participant.getTracksByMediaType(mediaType).length) {
  184. if (mediaType === 'audio') {
  185. APP.UI.setAudioMuted(participantId, true);
  186. } else if (mediaType === 'video') {
  187. APP.UI.setVideoMuted(participantId, true);
  188. } else {
  189. logger.error(`Unsupported media type: ${mediaType}`);
  190. }
  191. }
  192. },
  193. /**
  194. * Return the type of the remote video.
  195. * @param id the id for the remote video
  196. * @returns {String} the video type video or screen.
  197. */
  198. getRemoteVideoType(id) {
  199. const smallVideo = VideoLayout.getSmallVideo(id);
  200. return smallVideo ? smallVideo.getVideoType() : null;
  201. },
  202. isPinned(id) {
  203. return id === this.getPinnedId();
  204. },
  205. getPinnedId() {
  206. const { id } = getPinnedParticipant(APP.store.getState()) || {};
  207. return id || null;
  208. },
  209. /**
  210. * Triggers a thumbnail to pin or unpin itself.
  211. *
  212. * @param {number} videoNumber - The index of the video to toggle pin on.
  213. * @private
  214. */
  215. togglePin(videoNumber) {
  216. const videos = getAllThumbnails();
  217. const videoView = videos[videoNumber];
  218. videoView && videoView.togglePin();
  219. },
  220. /**
  221. * Callback invoked to update display when the pin participant has changed.
  222. *
  223. * @paramn {string|null} pinnedParticipantID - The participant ID of the
  224. * participant that is pinned or null if no one is pinned.
  225. * @returns {void}
  226. */
  227. onPinChange(pinnedParticipantID) {
  228. if (interfaceConfig.filmStripOnly) {
  229. return;
  230. }
  231. getAllThumbnails().forEach(thumbnail =>
  232. thumbnail.focus(pinnedParticipantID === thumbnail.getId()));
  233. },
  234. /**
  235. * Creates a participant container for the given id.
  236. *
  237. * @param {Object} participant - The redux representation of a remote
  238. * participant.
  239. * @returns {void}
  240. */
  241. addRemoteParticipantContainer(participant) {
  242. if (!participant || participant.local) {
  243. return;
  244. } else if (participant.isFakeParticipant) {
  245. const sharedVideoThumb = new SharedVideoThumb(
  246. participant,
  247. SHARED_VIDEO_CONTAINER_TYPE,
  248. VideoLayout);
  249. this.addRemoteVideoContainer(participant.id, sharedVideoThumb);
  250. return;
  251. }
  252. const id = participant.id;
  253. const jitsiParticipant = APP.conference.getParticipantById(id);
  254. const remoteVideo = new RemoteVideo(jitsiParticipant, VideoLayout);
  255. this._setRemoteControlProperties(jitsiParticipant, remoteVideo);
  256. this.addRemoteVideoContainer(id, remoteVideo);
  257. this.updateMutedForNoTracks(id, 'audio');
  258. this.updateMutedForNoTracks(id, 'video');
  259. },
  260. /**
  261. * Adds remote video container for the given id and <tt>SmallVideo</tt>.
  262. *
  263. * @param {string} the id of the video to add
  264. * @param {SmallVideo} smallVideo the small video instance to add as a
  265. * remote video
  266. */
  267. addRemoteVideoContainer(id, remoteVideo) {
  268. remoteVideos[id] = remoteVideo;
  269. if (!remoteVideo.getVideoType()) {
  270. // make video type the default one (camera)
  271. // FIXME container type is not a video type
  272. remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
  273. }
  274. VideoLayout.resizeThumbnails(true);
  275. // Initialize the view
  276. remoteVideo.updateView();
  277. },
  278. // FIXME: what does this do???
  279. remoteVideoActive(videoElement, resourceJid) {
  280. logger.info(`${resourceJid} video is now active`, videoElement);
  281. VideoLayout.resizeThumbnails(
  282. false, () => {
  283. if (videoElement) {
  284. $(videoElement).show();
  285. }
  286. });
  287. this._updateLargeVideoIfDisplayed(resourceJid, true);
  288. },
  289. /**
  290. * Shows a visual indicator for the moderator of the conference.
  291. * On local or remote participants.
  292. */
  293. showModeratorIndicator() {
  294. const isModerator = APP.conference.isModerator;
  295. if (isModerator) {
  296. localVideoThumbnail.addModeratorIndicator();
  297. } else {
  298. localVideoThumbnail.removeModeratorIndicator();
  299. }
  300. APP.conference.listMembers().forEach(member => {
  301. const id = member.getId();
  302. const remoteVideo = remoteVideos[id];
  303. if (!remoteVideo) {
  304. return;
  305. }
  306. if (member.isModerator()) {
  307. remoteVideo.addModeratorIndicator();
  308. }
  309. remoteVideo.updateRemoteVideoMenu();
  310. });
  311. },
  312. /*
  313. * Shows or hides the audio muted indicator over the local thumbnail video.
  314. * @param {boolean} isMuted
  315. */
  316. showLocalAudioIndicator(isMuted) {
  317. localVideoThumbnail.showAudioIndicator(isMuted);
  318. },
  319. /**
  320. * Resizes thumbnails.
  321. */
  322. resizeThumbnails(forceUpdate = false, onComplete = null) {
  323. const { localVideo, remoteVideo } = Filmstrip.calculateThumbnailSize();
  324. Filmstrip.resizeThumbnails(localVideo, remoteVideo, forceUpdate);
  325. if (shouldDisplayTileView(APP.store.getState())) {
  326. const height = (localVideo && localVideo.thumbHeight) || (remoteVideo && remoteVideo.thumbnHeight) || 0;
  327. const qualityLevel = getNearestReceiverVideoQualityLevel(height);
  328. APP.store.dispatch(setMaxReceiverVideoQuality(qualityLevel));
  329. }
  330. localVideoThumbnail && localVideoThumbnail.rerender();
  331. Object.values(remoteVideos).forEach(remoteVideoThumbnail => remoteVideoThumbnail.rerender());
  332. if (onComplete && typeof onComplete === 'function') {
  333. onComplete();
  334. }
  335. },
  336. /**
  337. * On audio muted event.
  338. */
  339. onAudioMute(id, isMuted) {
  340. if (APP.conference.isLocalId(id)) {
  341. localVideoThumbnail.showAudioIndicator(isMuted);
  342. } else {
  343. const remoteVideo = remoteVideos[id];
  344. if (!remoteVideo) {
  345. return;
  346. }
  347. remoteVideo.showAudioIndicator(isMuted);
  348. remoteVideo.updateRemoteVideoMenu(isMuted);
  349. }
  350. },
  351. /**
  352. * On video muted event.
  353. */
  354. onVideoMute(id, value) {
  355. if (APP.conference.isLocalId(id)) {
  356. localVideoThumbnail && localVideoThumbnail.setVideoMutedView(value);
  357. } else {
  358. const remoteVideo = remoteVideos[id];
  359. if (remoteVideo) {
  360. remoteVideo.setVideoMutedView(value);
  361. }
  362. }
  363. // large video will show avatar instead of muted stream
  364. this._updateLargeVideoIfDisplayed(id, true);
  365. },
  366. /**
  367. * Display name changed.
  368. */
  369. onDisplayNameChanged(id) {
  370. if (id === 'localVideoContainer'
  371. || APP.conference.isLocalId(id)) {
  372. localVideoThumbnail.updateDisplayName();
  373. } else {
  374. const remoteVideo = remoteVideos[id];
  375. if (remoteVideo) {
  376. remoteVideo.updateDisplayName();
  377. }
  378. }
  379. },
  380. /**
  381. * On dominant speaker changed event.
  382. *
  383. * @param {string} id - The participant ID of the new dominant speaker.
  384. * @returns {void}
  385. */
  386. onDominantSpeakerChanged(id) {
  387. getAllThumbnails().forEach(thumbnail =>
  388. thumbnail.showDominantSpeakerIndicator(id === thumbnail.getId()));
  389. },
  390. /**
  391. * Shows/hides warning about a user's connectivity issues.
  392. *
  393. * @param {string} id - The ID of the remote participant(MUC nickname).
  394. * @param {status} status - The new connection status.
  395. * @returns {void}
  396. */
  397. onParticipantConnectionStatusChanged(id, status) {
  398. if (APP.conference.isLocalId(id)) {
  399. // Maintain old logic of passing in either interrupted or active
  400. // to updateConnectionStatus.
  401. localVideoThumbnail.updateConnectionStatus(status);
  402. if (status === JitsiParticipantConnectionStatus.INTERRUPTED) {
  403. largeVideo && largeVideo.onVideoInterrupted();
  404. } else {
  405. largeVideo && largeVideo.onVideoRestored();
  406. }
  407. return;
  408. }
  409. // We have to trigger full large video update to transition from
  410. // avatar to video on connectivity restored.
  411. this._updateLargeVideoIfDisplayed(id, true);
  412. const remoteVideo = remoteVideos[id];
  413. if (remoteVideo) {
  414. // Updating only connection status indicator is not enough, because
  415. // when we the connection is restored while the avatar was displayed
  416. // (due to 'muted while disconnected' condition) we may want to show
  417. // the video stream again and in order to do that the display mode
  418. // must be updated.
  419. // remoteVideo.updateConnectionStatusIndicator(isActive);
  420. remoteVideo.updateView();
  421. }
  422. },
  423. /**
  424. * On last N change event.
  425. *
  426. * @param endpointsLeavingLastN the list currently leaving last N
  427. * endpoints
  428. * @param endpointsEnteringLastN the list currently entering last N
  429. * endpoints
  430. */
  431. onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
  432. if (endpointsLeavingLastN) {
  433. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  434. }
  435. if (endpointsEnteringLastN) {
  436. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  437. }
  438. },
  439. /**
  440. * Updates remote video by id if it exists.
  441. * @param {string} id of the remote video
  442. * @private
  443. */
  444. _updateRemoteVideo(id) {
  445. const remoteVideo = remoteVideos[id];
  446. if (remoteVideo) {
  447. remoteVideo.updateView();
  448. this._updateLargeVideoIfDisplayed(id);
  449. }
  450. },
  451. /**
  452. * Hides the connection indicator
  453. * @param id
  454. */
  455. hideConnectionIndicator(id) {
  456. const remoteVideo = remoteVideos[id];
  457. if (remoteVideo) {
  458. remoteVideo.removeConnectionIndicator();
  459. }
  460. },
  461. /**
  462. * Hides all the indicators
  463. */
  464. hideStats() {
  465. for (const video in remoteVideos) { // eslint-disable-line guard-for-in
  466. const remoteVideo = remoteVideos[video];
  467. if (remoteVideo) {
  468. remoteVideo.removeConnectionIndicator();
  469. }
  470. }
  471. localVideoThumbnail.removeConnectionIndicator();
  472. },
  473. removeParticipantContainer(id) {
  474. // Unlock large video
  475. if (this.getPinnedId() === id) {
  476. logger.info('Focused video owner has left the conference');
  477. APP.store.dispatch(pinParticipant(null));
  478. }
  479. const remoteVideo = remoteVideos[id];
  480. if (remoteVideo) {
  481. // Remove remote video
  482. logger.info(`Removing remote video: ${id}`);
  483. delete remoteVideos[id];
  484. remoteVideo.remove();
  485. } else {
  486. logger.warn(`No remote video for ${id}`);
  487. }
  488. VideoLayout.resizeThumbnails();
  489. },
  490. onVideoTypeChanged(id, newVideoType) {
  491. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  492. return;
  493. }
  494. logger.info('Peer video type changed: ', id, newVideoType);
  495. let smallVideo;
  496. if (APP.conference.isLocalId(id)) {
  497. if (!localVideoThumbnail) {
  498. logger.warn('Local video not ready yet');
  499. return;
  500. }
  501. smallVideo = localVideoThumbnail;
  502. } else if (remoteVideos[id]) {
  503. smallVideo = remoteVideos[id];
  504. } else {
  505. return;
  506. }
  507. smallVideo.setVideoType(newVideoType);
  508. this._updateLargeVideoIfDisplayed(id, true);
  509. },
  510. /**
  511. * Resizes the video area.
  512. *
  513. * TODO: Remove the "animate" param as it is no longer passed in as true.
  514. *
  515. * @param forceUpdate indicates that hidden thumbnails will be shown
  516. */
  517. resizeVideoArea(
  518. forceUpdate = false,
  519. animate = false) {
  520. // Resize the thumbnails first.
  521. this.resizeThumbnails(forceUpdate);
  522. if (largeVideo) {
  523. largeVideo.updateContainerSize();
  524. largeVideo.resize(animate);
  525. }
  526. },
  527. getSmallVideo(id) {
  528. if (APP.conference.isLocalId(id)) {
  529. return localVideoThumbnail;
  530. }
  531. return remoteVideos[id];
  532. },
  533. changeUserAvatar(id, avatarUrl) {
  534. const smallVideo = VideoLayout.getSmallVideo(id);
  535. if (smallVideo) {
  536. smallVideo.initializeAvatar();
  537. } else {
  538. logger.warn(
  539. `Missed avatar update - no small video yet for ${id}`
  540. );
  541. }
  542. if (this.isCurrentlyOnLarge(id)) {
  543. largeVideo.updateAvatar(avatarUrl);
  544. }
  545. },
  546. isLargeVideoVisible() {
  547. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  548. },
  549. /**
  550. * @return {LargeContainer} the currently displayed container on large
  551. * video.
  552. */
  553. getCurrentlyOnLargeContainer() {
  554. return largeVideo.getCurrentContainer();
  555. },
  556. isCurrentlyOnLarge(id) {
  557. return largeVideo && largeVideo.id === id;
  558. },
  559. /**
  560. * Triggers an update of remote video and large video displays so they may
  561. * pick up any state changes that have occurred elsewhere.
  562. *
  563. * @returns {void}
  564. */
  565. updateAllVideos() {
  566. const displayedUserId = this.getLargeVideoID();
  567. if (displayedUserId) {
  568. this.updateLargeVideo(displayedUserId, true);
  569. }
  570. Object.keys(remoteVideos).forEach(video => {
  571. remoteVideos[video].updateView();
  572. });
  573. },
  574. updateLargeVideo(id, forceUpdate) {
  575. if (!largeVideo) {
  576. return;
  577. }
  578. const currentContainer = largeVideo.getCurrentContainer();
  579. const currentContainerType = largeVideo.getCurrentContainerType();
  580. const currentId = largeVideo.id;
  581. const isOnLarge = this.isCurrentlyOnLarge(id);
  582. const smallVideo = this.getSmallVideo(id);
  583. if (isOnLarge && !forceUpdate
  584. && LargeVideoManager.isVideoContainer(currentContainerType)
  585. && smallVideo) {
  586. const currentStreamId = currentContainer.getStreamID();
  587. const newStreamId
  588. = smallVideo.videoStream
  589. ? smallVideo.videoStream.getId() : null;
  590. // FIXME it might be possible to get rid of 'forceUpdate' argument
  591. if (currentStreamId !== newStreamId) {
  592. logger.debug('Enforcing large video update for stream change');
  593. forceUpdate = true; // eslint-disable-line no-param-reassign
  594. }
  595. }
  596. if ((!isOnLarge || forceUpdate) && smallVideo) {
  597. const videoType = this.getRemoteVideoType(id);
  598. // FIXME video type is not the same thing as container type
  599. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  600. APP.API.notifyOnStageParticipantChanged(id);
  601. }
  602. let oldSmallVideo;
  603. if (currentId) {
  604. oldSmallVideo = this.getSmallVideo(currentId);
  605. }
  606. smallVideo.waitForResolutionChange();
  607. if (oldSmallVideo) {
  608. oldSmallVideo.waitForResolutionChange();
  609. }
  610. largeVideo.updateLargeVideo(
  611. id,
  612. smallVideo.videoStream,
  613. videoType || VIDEO_TYPE.CAMERA
  614. ).then(() => {
  615. // update current small video and the old one
  616. smallVideo.updateView();
  617. oldSmallVideo && oldSmallVideo.updateView();
  618. }, () => {
  619. // use clicked other video during update, nothing to do.
  620. });
  621. } else if (currentId) {
  622. const currentSmallVideo = this.getSmallVideo(currentId);
  623. currentSmallVideo && currentSmallVideo.updateView();
  624. }
  625. },
  626. addLargeVideoContainer(type, container) {
  627. largeVideo && largeVideo.addContainer(type, container);
  628. },
  629. removeLargeVideoContainer(type) {
  630. largeVideo && largeVideo.removeContainer(type);
  631. },
  632. /**
  633. * @returns Promise
  634. */
  635. showLargeVideoContainer(type, show) {
  636. if (!largeVideo) {
  637. return Promise.reject();
  638. }
  639. const isVisible = this.isLargeContainerTypeVisible(type);
  640. if (isVisible === show) {
  641. return Promise.resolve();
  642. }
  643. const currentId = largeVideo.id;
  644. let oldSmallVideo;
  645. if (currentId) {
  646. oldSmallVideo = this.getSmallVideo(currentId);
  647. }
  648. let containerTypeToShow = type;
  649. // if we are hiding a container and there is focusedVideo
  650. // (pinned remote video) use its video type,
  651. // if not then use default type - large video
  652. if (!show) {
  653. const pinnedId = this.getPinnedId();
  654. if (pinnedId) {
  655. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  656. } else {
  657. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  658. }
  659. }
  660. return largeVideo.showContainer(containerTypeToShow)
  661. .then(() => {
  662. if (oldSmallVideo) {
  663. oldSmallVideo && oldSmallVideo.updateView();
  664. }
  665. });
  666. },
  667. isLargeContainerTypeVisible(type) {
  668. return largeVideo && largeVideo.state === type;
  669. },
  670. /**
  671. * Returns the id of the current video shown on large.
  672. * Currently used by tests (torture).
  673. */
  674. getLargeVideoID() {
  675. return largeVideo && largeVideo.id;
  676. },
  677. /**
  678. * Returns the the current video shown on large.
  679. * Currently used by tests (torture).
  680. */
  681. getLargeVideo() {
  682. return largeVideo;
  683. },
  684. /**
  685. * Sets the flipX state of the local video.
  686. * @param {boolean} true for flipped otherwise false;
  687. */
  688. setLocalFlipX(val) {
  689. this.localFlipX = val;
  690. },
  691. getEventEmitter() {
  692. return eventEmitter;
  693. },
  694. /**
  695. * Handles user's features changes.
  696. */
  697. onUserFeaturesChanged(user) {
  698. const video = this.getSmallVideo(user.getId());
  699. if (!video) {
  700. return;
  701. }
  702. this._setRemoteControlProperties(user, video);
  703. },
  704. /**
  705. * Sets the remote control properties (checks whether remote control
  706. * is supported and executes remoteVideo.setRemoteControlSupport).
  707. * @param {JitsiParticipant} user the user that will be checked for remote
  708. * control support.
  709. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  710. * will be set.
  711. */
  712. _setRemoteControlProperties(user, remoteVideo) {
  713. APP.remoteControl.checkUserRemoteControlSupport(user)
  714. .then(result => remoteVideo.setRemoteControlSupport(result))
  715. .catch(error =>
  716. logger.warn('could not get remote control properties', error));
  717. },
  718. /**
  719. * Returns the wrapper jquery selector for the largeVideo
  720. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  721. */
  722. getLargeVideoWrapper() {
  723. return this.getCurrentlyOnLargeContainer().$wrapper;
  724. },
  725. /**
  726. * Returns the number of remove video ids.
  727. *
  728. * @returns {number} The number of remote videos.
  729. */
  730. getRemoteVideosCount() {
  731. return Object.keys(remoteVideos).length;
  732. },
  733. /**
  734. * Sets the remote control active status for a remote participant.
  735. *
  736. * @param {string} participantID - The id of the remote participant.
  737. * @param {boolean} isActive - The new remote control active status.
  738. * @returns {void}
  739. */
  740. setRemoteControlActiveStatus(participantID, isActive) {
  741. remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
  742. },
  743. /**
  744. * Sets the remote control active status for the local participant.
  745. *
  746. * @returns {void}
  747. */
  748. setLocalRemoteControlActiveChanged() {
  749. Object.values(remoteVideos).forEach(
  750. remoteVideo => remoteVideo.updateRemoteVideoMenu()
  751. );
  752. },
  753. /**
  754. * Helper method to invoke when the video layout has changed and elements
  755. * have to be re-arranged and resized.
  756. *
  757. * @returns {void}
  758. */
  759. refreshLayout() {
  760. localVideoThumbnail && localVideoThumbnail.updateDOMLocation();
  761. VideoLayout.resizeVideoArea();
  762. },
  763. /**
  764. * Cleans up any existing largeVideo instance.
  765. *
  766. * @private
  767. * @returns {void}
  768. */
  769. _resetLargeVideo() {
  770. if (largeVideo) {
  771. largeVideo.destroy();
  772. }
  773. largeVideo = null;
  774. },
  775. /**
  776. * Cleans up filmstrip state. While a separate {@code Filmstrip} exists, its
  777. * implementation is mainly for querying and manipulating the DOM while
  778. * state mostly remains in {@code VideoLayout}.
  779. *
  780. * @private
  781. * @returns {void}
  782. */
  783. _resetFilmstrip() {
  784. Object.keys(remoteVideos).forEach(remoteVideoId => {
  785. this.removeParticipantContainer(remoteVideoId);
  786. delete remoteVideos[remoteVideoId];
  787. });
  788. if (localVideoThumbnail) {
  789. localVideoThumbnail.remove();
  790. localVideoThumbnail = null;
  791. }
  792. },
  793. /**
  794. * Triggers an update of large video if the passed in participant is
  795. * currently displayed on large video.
  796. *
  797. * @param {string} participantId - The participant ID that should trigger an
  798. * update of large video if displayed.
  799. * @param {boolean} force - Whether or not the large video update should
  800. * happen no matter what.
  801. * @returns {void}
  802. */
  803. _updateLargeVideoIfDisplayed(participantId, force = false) {
  804. if (this.isCurrentlyOnLarge(participantId)) {
  805. this.updateLargeVideo(participantId, force);
  806. }
  807. }
  808. };
  809. export default VideoLayout;