Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

VideoLayout.js 35KB

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