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.

VideoLayout.js 33KB

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