Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VideoLayout.js 33KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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. getParticipants,
  8. getPinnedParticipant,
  9. pinParticipant
  10. } from '../../../react/features/base/participants';
  11. import Filmstrip from './Filmstrip';
  12. import UIEvents from '../../../service/UI/UIEvents';
  13. import UIUtil from '../util/UIUtil';
  14. import RemoteVideo from './RemoteVideo';
  15. import LargeVideoManager from './LargeVideoManager';
  16. import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
  17. import LocalVideo from './LocalVideo';
  18. const remoteVideos = {};
  19. let localVideoThumbnail = 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 user ID of the remote participant that is current the dominant
  38. * speaker.
  39. *
  40. * @private
  41. * @returns {string|null}
  42. */
  43. function getCurrentRemoteDominantSpeakerID() {
  44. const dominantSpeaker = getParticipants(APP.store.getState)
  45. .find(participant => participant.dominantSpeaker);
  46. if (dominantSpeaker) {
  47. return dominantSpeaker.local ? null : dominantSpeaker.id;
  48. }
  49. return null;
  50. }
  51. /**
  52. * Returns the corresponding resource id to the given peer container
  53. * DOM element.
  54. *
  55. * @return the corresponding resource id to the given peer container
  56. * DOM element
  57. */
  58. function getPeerContainerResourceId(containerElement) {
  59. if (localVideoThumbnail.container === containerElement) {
  60. return localVideoThumbnail.id;
  61. }
  62. const i = containerElement.id.indexOf('participant_');
  63. if (i >= 0) {
  64. return containerElement.id.substring(i + 12);
  65. }
  66. }
  67. const VideoLayout = {
  68. init(emitter) {
  69. eventEmitter = emitter;
  70. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  71. // sets default video type of local video
  72. // FIXME container type is totally different thing from the video type
  73. localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
  74. // if we do not resize the thumbs here, if there is no video device
  75. // the local video thumb maybe one pixel
  76. this.resizeThumbnails(true);
  77. this.handleVideoThumbClicked = this.handleVideoThumbClicked.bind(this);
  78. this.registerListeners();
  79. },
  80. /**
  81. * Cleans up any existing largeVideo instance.
  82. *
  83. * @returns {void}
  84. */
  85. resetLargeVideo() {
  86. if (largeVideo) {
  87. largeVideo.destroy();
  88. }
  89. largeVideo = null;
  90. },
  91. /**
  92. * Registering listeners for UI events in Video layout component.
  93. *
  94. * @returns {void}
  95. */
  96. registerListeners() {
  97. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
  98. onLocalFlipXChanged);
  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 (getCurrentRemoteDominantSpeakerID()) {
  204. newId = getCurrentRemoteDominantSpeakerID();
  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 (getCurrentRemoteDominantSpeakerID()) {
  332. this.updateLargeVideo(getCurrentRemoteDominantSpeakerID());
  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(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, () => {
  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. && !getCurrentRemoteDominantSpeakerID()
  422. && this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE))
  423. || pinnedId === resourceJid
  424. || (!pinnedId && resourceJid
  425. && getCurrentRemoteDominantSpeakerID() === 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. forceUpdate = false,
  484. onComplete = null) {
  485. const { localVideo, remoteVideo }
  486. = Filmstrip.calculateThumbnailSize();
  487. Filmstrip.resizeThumbnails(localVideo, remoteVideo, forceUpdate);
  488. if (onComplete && typeof onComplete === 'function') {
  489. onComplete();
  490. }
  491. return { localVideo,
  492. remoteVideo };
  493. },
  494. /**
  495. * On audio muted event.
  496. */
  497. onAudioMute(id, isMuted) {
  498. if (APP.conference.isLocalId(id)) {
  499. localVideoThumbnail.showAudioIndicator(isMuted);
  500. } else {
  501. const remoteVideo = remoteVideos[id];
  502. if (!remoteVideo) {
  503. return;
  504. }
  505. remoteVideo.showAudioIndicator(isMuted);
  506. remoteVideo.updateRemoteVideoMenu(isMuted);
  507. }
  508. },
  509. /**
  510. * On video muted event.
  511. */
  512. onVideoMute(id, value) {
  513. if (APP.conference.isLocalId(id)) {
  514. localVideoThumbnail.setVideoMutedView(value);
  515. } else {
  516. const remoteVideo = remoteVideos[id];
  517. if (remoteVideo) {
  518. remoteVideo.setVideoMutedView(value);
  519. }
  520. }
  521. if (this.isCurrentlyOnLarge(id)) {
  522. // large video will show avatar instead of muted stream
  523. this.updateLargeVideo(id, true);
  524. }
  525. },
  526. /**
  527. * Display name changed.
  528. */
  529. onDisplayNameChanged(id, displayName, status) {
  530. if (id === 'localVideoContainer'
  531. || APP.conference.isLocalId(id)) {
  532. localVideoThumbnail.setDisplayName(displayName);
  533. } else {
  534. const remoteVideo = remoteVideos[id];
  535. if (remoteVideo) {
  536. remoteVideo.setDisplayName(displayName, status);
  537. }
  538. }
  539. },
  540. /**
  541. * Sets the "raised hand" status for a participant identified by 'id'.
  542. */
  543. setRaisedHandStatus(id, raisedHandStatus) {
  544. const video
  545. = APP.conference.isLocalId(id)
  546. ? localVideoThumbnail : remoteVideos[id];
  547. if (video) {
  548. video.showRaisedHandIndicator(raisedHandStatus);
  549. if (raisedHandStatus) {
  550. video.showDominantSpeakerIndicator(false);
  551. }
  552. }
  553. },
  554. /**
  555. * On dominant speaker changed event.
  556. *
  557. * @param {string} id - The participant ID of the new dominant speaker.
  558. * @returns {void}
  559. */
  560. onDominantSpeakerChanged(id) {
  561. Object.values(remoteVideos).forEach(remoteVideo =>
  562. remoteVideo.showDominantSpeakerIndicator(
  563. id === remoteVideo.getId()));
  564. localVideoThumbnail.showDominantSpeakerIndicator(
  565. APP.conference.isLocalId(id));
  566. if (!remoteVideos[id]) {
  567. return;
  568. }
  569. // Local video will not have container found, but that's ok
  570. // since we don't want to switch to local video.
  571. if (!interfaceConfig.filmStripOnly && !this.getPinnedId()
  572. && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
  573. this.updateLargeVideo(id);
  574. }
  575. },
  576. /**
  577. * Shows/hides warning about remote user's connectivity issues.
  578. *
  579. * @param {string} id the ID of the remote participant(MUC nickname)
  580. */
  581. // eslint-disable-next-line no-unused-vars
  582. onParticipantConnectionStatusChanged(id) {
  583. // Show/hide warning on the large video
  584. if (this.isCurrentlyOnLarge(id)) {
  585. if (largeVideo) {
  586. // We have to trigger full large video update to transition from
  587. // avatar to video on connectivity restored.
  588. this.updateLargeVideo(id, true /* force update */);
  589. }
  590. }
  591. // Show/hide warning on the thumbnail
  592. const remoteVideo = remoteVideos[id];
  593. if (remoteVideo) {
  594. // Updating only connection status indicator is not enough, because
  595. // when we the connection is restored while the avatar was displayed
  596. // (due to 'muted while disconnected' condition) we may want to show
  597. // the video stream again and in order to do that the display mode
  598. // must be updated.
  599. // remoteVideo.updateConnectionStatusIndicator(isActive);
  600. remoteVideo.updateView();
  601. }
  602. },
  603. /**
  604. * On last N change event.
  605. *
  606. * @param endpointsLeavingLastN the list currently leaving last N
  607. * endpoints
  608. * @param endpointsEnteringLastN the list currently entering last N
  609. * endpoints
  610. */
  611. onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
  612. if (endpointsLeavingLastN) {
  613. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  614. }
  615. if (endpointsEnteringLastN) {
  616. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  617. }
  618. },
  619. /**
  620. * Updates remote video by id if it exists.
  621. * @param {string} id of the remote video
  622. * @private
  623. */
  624. _updateRemoteVideo(id) {
  625. const remoteVideo = remoteVideos[id];
  626. if (remoteVideo) {
  627. remoteVideo.updateView();
  628. if (remoteVideo.isCurrentlyOnLargeVideo()) {
  629. this.updateLargeVideo(id);
  630. }
  631. }
  632. },
  633. /**
  634. * Hides the connection indicator
  635. * @param id
  636. */
  637. hideConnectionIndicator(id) {
  638. const remoteVideo = remoteVideos[id];
  639. if (remoteVideo) {
  640. remoteVideo.removeConnectionIndicator();
  641. }
  642. },
  643. /**
  644. * Hides all the indicators
  645. */
  646. hideStats() {
  647. for (const video in remoteVideos) { // eslint-disable-line guard-for-in
  648. const remoteVideo = remoteVideos[video];
  649. if (remoteVideo) {
  650. remoteVideo.removeConnectionIndicator();
  651. }
  652. }
  653. localVideoThumbnail.removeConnectionIndicator();
  654. },
  655. removeParticipantContainer(id) {
  656. // Unlock large video
  657. if (this.getPinnedId() === id) {
  658. logger.info('Focused video owner has left the conference');
  659. this.pinParticipant(null);
  660. }
  661. const remoteVideo = remoteVideos[id];
  662. if (remoteVideo) {
  663. // Remove remote video
  664. logger.info(`Removing remote video: ${id}`);
  665. delete remoteVideos[id];
  666. remoteVideo.remove();
  667. } else {
  668. logger.warn(`No remote video for ${id}`);
  669. }
  670. VideoLayout.resizeThumbnails();
  671. },
  672. onVideoTypeChanged(id, newVideoType) {
  673. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  674. return;
  675. }
  676. logger.info('Peer video type changed: ', id, newVideoType);
  677. let smallVideo;
  678. if (APP.conference.isLocalId(id)) {
  679. if (!localVideoThumbnail) {
  680. logger.warn('Local video not ready yet');
  681. return;
  682. }
  683. smallVideo = localVideoThumbnail;
  684. } else if (remoteVideos[id]) {
  685. smallVideo = remoteVideos[id];
  686. } else {
  687. return;
  688. }
  689. smallVideo.setVideoType(newVideoType);
  690. if (this.isCurrentlyOnLarge(id)) {
  691. this.updateLargeVideo(id, true);
  692. }
  693. },
  694. /**
  695. * Resizes the video area.
  696. *
  697. * TODO: Remove the "animate" param as it is no longer passed in as true.
  698. *
  699. * @param forceUpdate indicates that hidden thumbnails will be shown
  700. */
  701. resizeVideoArea(
  702. forceUpdate = false,
  703. animate = false) {
  704. if (largeVideo) {
  705. largeVideo.updateContainerSize();
  706. largeVideo.resize(animate);
  707. }
  708. // Calculate available width and height.
  709. const availableHeight = window.innerHeight;
  710. const availableWidth = UIUtil.getAvailableVideoWidth();
  711. if (availableWidth < 0 || availableHeight < 0) {
  712. return;
  713. }
  714. // Resize the thumbnails first.
  715. this.resizeThumbnails(forceUpdate);
  716. },
  717. getSmallVideo(id) {
  718. if (APP.conference.isLocalId(id)) {
  719. return localVideoThumbnail;
  720. }
  721. return remoteVideos[id];
  722. },
  723. changeUserAvatar(id, avatarUrl) {
  724. const smallVideo = VideoLayout.getSmallVideo(id);
  725. if (smallVideo) {
  726. smallVideo.avatarChanged(avatarUrl);
  727. } else {
  728. logger.warn(
  729. `Missed avatar update - no small video yet for ${id}`
  730. );
  731. }
  732. if (this.isCurrentlyOnLarge(id)) {
  733. largeVideo.updateAvatar(avatarUrl);
  734. }
  735. },
  736. /**
  737. * Indicates that the video has been interrupted.
  738. */
  739. onVideoInterrupted() {
  740. if (largeVideo) {
  741. largeVideo.onVideoInterrupted();
  742. }
  743. },
  744. /**
  745. * Indicates that the video has been restored.
  746. */
  747. onVideoRestored() {
  748. if (largeVideo) {
  749. largeVideo.onVideoRestored();
  750. }
  751. },
  752. isLargeVideoVisible() {
  753. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  754. },
  755. /**
  756. * @return {LargeContainer} the currently displayed container on large
  757. * video.
  758. */
  759. getCurrentlyOnLargeContainer() {
  760. return largeVideo.getCurrentContainer();
  761. },
  762. isCurrentlyOnLarge(id) {
  763. return largeVideo && largeVideo.id === id;
  764. },
  765. /**
  766. * Triggers an update of remote video and large video displays so they may
  767. * pick up any state changes that have occurred elsewhere.
  768. *
  769. * @returns {void}
  770. */
  771. updateAllVideos() {
  772. const displayedUserId = this.getLargeVideoID();
  773. if (displayedUserId) {
  774. this.updateLargeVideo(displayedUserId, true);
  775. }
  776. Object.keys(remoteVideos).forEach(video => {
  777. remoteVideos[video].updateView();
  778. });
  779. },
  780. updateLargeVideo(id, forceUpdate) {
  781. if (!largeVideo) {
  782. return;
  783. }
  784. const currentContainer = largeVideo.getCurrentContainer();
  785. const currentContainerType = largeVideo.getCurrentContainerType();
  786. const currentId = largeVideo.id;
  787. const isOnLarge = this.isCurrentlyOnLarge(id);
  788. const smallVideo = this.getSmallVideo(id);
  789. if (isOnLarge && !forceUpdate
  790. && LargeVideoManager.isVideoContainer(currentContainerType)
  791. && smallVideo) {
  792. const currentStreamId = currentContainer.getStreamID();
  793. const newStreamId
  794. = smallVideo.videoStream
  795. ? smallVideo.videoStream.getId() : null;
  796. // FIXME it might be possible to get rid of 'forceUpdate' argument
  797. if (currentStreamId !== newStreamId) {
  798. logger.debug('Enforcing large video update for stream change');
  799. forceUpdate = true; // eslint-disable-line no-param-reassign
  800. }
  801. }
  802. if (!isOnLarge || forceUpdate) {
  803. const videoType = this.getRemoteVideoType(id);
  804. // FIXME video type is not the same thing as container type
  805. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  806. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  807. }
  808. let oldSmallVideo;
  809. if (currentId) {
  810. oldSmallVideo = this.getSmallVideo(currentId);
  811. }
  812. smallVideo.waitForResolutionChange();
  813. if (oldSmallVideo) {
  814. oldSmallVideo.waitForResolutionChange();
  815. }
  816. largeVideo.updateLargeVideo(
  817. id,
  818. smallVideo.videoStream,
  819. videoType
  820. ).then(() => {
  821. // update current small video and the old one
  822. smallVideo.updateView();
  823. oldSmallVideo && oldSmallVideo.updateView();
  824. }, () => {
  825. // use clicked other video during update, nothing to do.
  826. });
  827. } else if (currentId) {
  828. const currentSmallVideo = this.getSmallVideo(currentId);
  829. currentSmallVideo.updateView();
  830. }
  831. },
  832. addLargeVideoContainer(type, container) {
  833. largeVideo && largeVideo.addContainer(type, container);
  834. },
  835. removeLargeVideoContainer(type) {
  836. largeVideo && largeVideo.removeContainer(type);
  837. },
  838. /**
  839. * @returns Promise
  840. */
  841. showLargeVideoContainer(type, show) {
  842. if (!largeVideo) {
  843. return Promise.reject();
  844. }
  845. const isVisible = this.isLargeContainerTypeVisible(type);
  846. if (isVisible === show) {
  847. return Promise.resolve();
  848. }
  849. const currentId = largeVideo.id;
  850. let oldSmallVideo;
  851. if (currentId) {
  852. oldSmallVideo = this.getSmallVideo(currentId);
  853. }
  854. let containerTypeToShow = type;
  855. // if we are hiding a container and there is focusedVideo
  856. // (pinned remote video) use its video type,
  857. // if not then use default type - large video
  858. if (!show) {
  859. const pinnedId = this.getPinnedId();
  860. if (pinnedId) {
  861. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  862. } else {
  863. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  864. }
  865. }
  866. return largeVideo.showContainer(containerTypeToShow)
  867. .then(() => {
  868. if (oldSmallVideo) {
  869. oldSmallVideo && oldSmallVideo.updateView();
  870. }
  871. });
  872. },
  873. isLargeContainerTypeVisible(type) {
  874. return largeVideo && largeVideo.state === type;
  875. },
  876. /**
  877. * Returns the id of the current video shown on large.
  878. * Currently used by tests (torture).
  879. */
  880. getLargeVideoID() {
  881. return largeVideo && largeVideo.id;
  882. },
  883. /**
  884. * Returns the the current video shown on large.
  885. * Currently used by tests (torture).
  886. */
  887. getLargeVideo() {
  888. return largeVideo;
  889. },
  890. /**
  891. * Sets the flipX state of the local video.
  892. * @param {boolean} true for flipped otherwise false;
  893. */
  894. setLocalFlipX(val) {
  895. this.localFlipX = val;
  896. },
  897. getEventEmitter() {
  898. return eventEmitter;
  899. },
  900. /**
  901. * Handles user's features changes.
  902. */
  903. onUserFeaturesChanged(user) {
  904. const video = this.getSmallVideo(user.getId());
  905. if (!video) {
  906. return;
  907. }
  908. this._setRemoteControlProperties(user, video);
  909. },
  910. /**
  911. * Sets the remote control properties (checks whether remote control
  912. * is supported and executes remoteVideo.setRemoteControlSupport).
  913. * @param {JitsiParticipant} user the user that will be checked for remote
  914. * control support.
  915. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  916. * will be set.
  917. */
  918. _setRemoteControlProperties(user, remoteVideo) {
  919. APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
  920. remoteVideo.setRemoteControlSupport(result));
  921. },
  922. /**
  923. * Returns the wrapper jquery selector for the largeVideo
  924. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  925. */
  926. getLargeVideoWrapper() {
  927. return this.getCurrentlyOnLargeContainer().$wrapper;
  928. },
  929. /**
  930. * Returns the number of remove video ids.
  931. *
  932. * @returns {number} The number of remote videos.
  933. */
  934. getRemoteVideosCount() {
  935. return Object.keys(remoteVideos).length;
  936. },
  937. /**
  938. * Sets the remote control active status for a remote participant.
  939. *
  940. * @param {string} participantID - The id of the remote participant.
  941. * @param {boolean} isActive - The new remote control active status.
  942. * @returns {void}
  943. */
  944. setRemoteControlActiveStatus(participantID, isActive) {
  945. remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
  946. },
  947. /**
  948. * Sets the remote control active status for the local participant.
  949. *
  950. * @returns {void}
  951. */
  952. setLocalRemoteControlActiveChanged() {
  953. Object.values(remoteVideos).forEach(
  954. remoteVideo => remoteVideo.updateRemoteVideoMenu()
  955. );
  956. }
  957. };
  958. export default VideoLayout;