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 34KB

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