You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoLayout.js 35KB

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