Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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