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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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. /* Update if we're currently being displayed */
  167. if (this.isCurrentlyOnLarge(localId)) {
  168. this.updateLargeVideo(localId);
  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. // Make sure track's muted state is reflected
  282. if (stream.getType() === "audio") {
  283. this.onAudioMute(stream.getParticipantId(), stream.isMuted());
  284. } else {
  285. this.onVideoMute(stream.getParticipantId(), stream.isMuted());
  286. }
  287. },
  288. onRemoteStreamRemoved (stream) {
  289. let id = stream.getParticipantId();
  290. let remoteVideo = remoteVideos[id];
  291. // Remote stream may be removed after participant left the conference.
  292. if (remoteVideo) {
  293. remoteVideo.removeRemoteStreamElement(stream);
  294. }
  295. this.updateMutedForNoTracks(id, stream.getType());
  296. },
  297. /**
  298. * FIXME get rid of this method once muted indicator are reactified (by
  299. * making sure that user with no tracks is displayed as muted )
  300. *
  301. * If participant has no tracks will make the UI display muted status.
  302. * @param {string} participantId
  303. * @param {string} mediaType 'audio' or 'video'
  304. */
  305. updateMutedForNoTracks(participantId, mediaType) {
  306. const participant = APP.conference.getParticipantById(participantId);
  307. if (participant
  308. && !participant.getTracksByMediaType(mediaType).length) {
  309. if (mediaType === 'audio') {
  310. APP.UI.setAudioMuted(participantId, true);
  311. } else if (mediaType === 'video') {
  312. APP.UI.setVideoMuted(participantId, true);
  313. } else {
  314. logger.error(`Unsupported media type: ${mediaType}`);
  315. }
  316. }
  317. },
  318. /**
  319. * Return the type of the remote video.
  320. * @param id the id for the remote video
  321. * @returns {String} the video type video or screen.
  322. */
  323. getRemoteVideoType (id) {
  324. let smallVideo = VideoLayout.getSmallVideo(id);
  325. return smallVideo ? smallVideo.getVideoType() : null;
  326. },
  327. isPinned (id) {
  328. return (pinnedId) ? (id === pinnedId) : false;
  329. },
  330. getPinnedId () {
  331. return pinnedId;
  332. },
  333. /**
  334. * Handles the click on a video thumbnail.
  335. *
  336. * @param id the identifier of the video thumbnail
  337. */
  338. handleVideoThumbClicked (id) {
  339. var smallVideo = VideoLayout.getSmallVideo(id);
  340. if(pinnedId) {
  341. var oldSmallVideo = VideoLayout.getSmallVideo(pinnedId);
  342. if (oldSmallVideo && !interfaceConfig.filmStripOnly) {
  343. oldSmallVideo.focus(false);
  344. // as no pinned event will be sent for local video
  345. // and we will unpin old one, lets signal it
  346. // otherwise we will just send the new pinned one
  347. if (smallVideo.isLocal)
  348. eventEmitter.emit(
  349. UIEvents.PINNED_ENDPOINT, oldSmallVideo, false);
  350. }
  351. }
  352. // Unpin if currently pinned.
  353. if (pinnedId === id)
  354. {
  355. pinnedId = null;
  356. // Enable the currently set dominant speaker.
  357. if (currentDominantSpeaker) {
  358. if(smallVideo && smallVideo.hasVideo()) {
  359. this.updateLargeVideo(currentDominantSpeaker);
  360. }
  361. } else {
  362. // if there is no currentDominantSpeaker, it can also be
  363. // that local participant is the dominant speaker
  364. // we should act as a participant has left and was on large
  365. // and we should choose somebody (electLastVisibleVideo)
  366. this.updateLargeVideo(this.electLastVisibleVideo());
  367. }
  368. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, smallVideo, false);
  369. return;
  370. }
  371. // Lock new video
  372. pinnedId = id;
  373. // Update focused/pinned interface.
  374. if (id) {
  375. if (smallVideo && !interfaceConfig.filmStripOnly)
  376. smallVideo.focus(true);
  377. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, smallVideo, true);
  378. }
  379. this.updateLargeVideo(id);
  380. },
  381. /**
  382. * Creates or adds a participant container for the given id and smallVideo.
  383. *
  384. * @param {JitsiParticipant} user the participant to add
  385. * @param {SmallVideo} smallVideo optional small video instance to add as a
  386. * remote video, if undefined <tt>RemoteVideo</tt> will be created
  387. */
  388. addParticipantContainer (user, smallVideo) {
  389. let id = user.getId();
  390. let remoteVideo;
  391. if(smallVideo)
  392. remoteVideo = smallVideo;
  393. else
  394. remoteVideo = new RemoteVideo(user, VideoLayout, eventEmitter);
  395. this._setRemoteControlProperties(user, remoteVideo);
  396. this.addRemoteVideoContainer(id, remoteVideo);
  397. this.updateMutedForNoTracks(id, 'audio');
  398. this.updateMutedForNoTracks(id, 'video');
  399. const remoteVideosCount = Object.keys(remoteVideos).length;
  400. if (remoteVideosCount === 1) {
  401. window.setTimeout(() => {
  402. const updatedRemoteVideosCount
  403. = Object.keys(remoteVideos).length;
  404. if (updatedRemoteVideosCount === 1 && remoteVideos[id]) {
  405. this._maybePlaceParticipantOnLargeVideo(id);
  406. }
  407. }, 3000);
  408. }
  409. },
  410. /**
  411. * Adds remote video container for the given id and <tt>SmallVideo</tt>.
  412. *
  413. * @param {string} the id of the video to add
  414. * @param {SmallVideo} smallVideo the small video instance to add as a
  415. * remote video
  416. */
  417. addRemoteVideoContainer (id, remoteVideo) {
  418. remoteVideos[id] = remoteVideo;
  419. if (!remoteVideo.getVideoType()) {
  420. // make video type the default one (camera)
  421. // FIXME container type is not a video type
  422. remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
  423. }
  424. VideoLayout.resizeThumbnails(false, true);
  425. // Initialize the view
  426. remoteVideo.updateView();
  427. },
  428. // FIXME: what does this do???
  429. remoteVideoActive(videoElement, resourceJid) {
  430. logger.info(resourceJid + " video is now active", videoElement);
  431. VideoLayout.resizeThumbnails(
  432. false, false, () => {
  433. if (videoElement) {
  434. $(videoElement).show();
  435. }
  436. });
  437. this._maybePlaceParticipantOnLargeVideo(resourceJid);
  438. },
  439. /**
  440. * Update the large video to the last added video only if there's no current
  441. * dominant, focused speaker or update it to the current dominant speaker.
  442. *
  443. * @params {string} resourceJid - The id of the user to maybe display on
  444. * large video.
  445. * @returns {void}
  446. */
  447. _maybePlaceParticipantOnLargeVideo(resourceJid) {
  448. if ((!pinnedId &&
  449. !currentDominantSpeaker &&
  450. this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE)) ||
  451. pinnedId === resourceJid ||
  452. (!pinnedId && resourceJid &&
  453. currentDominantSpeaker === resourceJid) ||
  454. /* Playback started while we're on the stage - may need to update
  455. video source with the new stream */
  456. this.isCurrentlyOnLarge(resourceJid)) {
  457. this.updateLargeVideo(resourceJid, true);
  458. }
  459. },
  460. /**
  461. * Shows a visual indicator for the moderator of the conference.
  462. * On local or remote participants.
  463. */
  464. showModeratorIndicator () {
  465. let isModerator = APP.conference.isModerator;
  466. if (isModerator) {
  467. localVideoThumbnail.addModeratorIndicator();
  468. } else {
  469. localVideoThumbnail.removeModeratorIndicator();
  470. }
  471. APP.conference.listMembers().forEach(function (member) {
  472. let id = member.getId();
  473. let remoteVideo = remoteVideos[id];
  474. if (!remoteVideo)
  475. return;
  476. if (member.isModerator()) {
  477. remoteVideo.addModeratorIndicator();
  478. }
  479. if (isModerator) {
  480. // We are moderator, but user is not - add menu
  481. if(!remoteVideo.hasRemoteVideoMenu) {
  482. remoteVideo.addRemoteVideoMenu();
  483. }
  484. }
  485. });
  486. },
  487. /*
  488. * Shows or hides the audio muted indicator over the local thumbnail video.
  489. * @param {boolean} isMuted
  490. */
  491. showLocalAudioIndicator (isMuted) {
  492. localVideoThumbnail.showAudioIndicator(isMuted);
  493. },
  494. /**
  495. * Shows/hides the indication about local connection being interrupted.
  496. *
  497. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  498. * currently in the interrupted state or <tt>false</tt> if the connection
  499. * is fine.
  500. */
  501. showLocalConnectionInterrupted (isInterrupted) {
  502. // Currently local video thumbnail displays only "active" or
  503. // "interrupted" despite the fact that ConnectionIndicator supports more
  504. // states.
  505. const status
  506. = isInterrupted
  507. ? ParticipantConnectionStatus.INTERRUPTED
  508. : ParticipantConnectionStatus.ACTIVE;
  509. localVideoThumbnail.updateConnectionStatus(status);
  510. },
  511. /**
  512. * Resizes thumbnails.
  513. */
  514. resizeThumbnails ( animate = false,
  515. forceUpdate = false,
  516. onComplete = null) {
  517. const { localVideo, remoteVideo }
  518. = Filmstrip.calculateThumbnailSize();
  519. Filmstrip.resizeThumbnails(localVideo, remoteVideo,
  520. animate, forceUpdate)
  521. .then(function () {
  522. if (onComplete && typeof onComplete === "function")
  523. onComplete();
  524. });
  525. return { localVideo, remoteVideo };
  526. },
  527. /**
  528. * On audio muted event.
  529. */
  530. onAudioMute (id, isMuted) {
  531. if (APP.conference.isLocalId(id)) {
  532. localVideoThumbnail.showAudioIndicator(isMuted);
  533. } else {
  534. let remoteVideo = remoteVideos[id];
  535. if (!remoteVideo)
  536. return;
  537. remoteVideo.showAudioIndicator(isMuted);
  538. if (APP.conference.isModerator) {
  539. remoteVideo.updateRemoteVideoMenu(isMuted);
  540. }
  541. }
  542. },
  543. /**
  544. * On video muted event.
  545. */
  546. onVideoMute (id, value) {
  547. if (APP.conference.isLocalId(id)) {
  548. localVideoThumbnail.setVideoMutedView(value);
  549. } else {
  550. let remoteVideo = remoteVideos[id];
  551. if (remoteVideo)
  552. remoteVideo.setVideoMutedView(value);
  553. }
  554. if (this.isCurrentlyOnLarge(id)) {
  555. // large video will show avatar instead of muted stream
  556. this.updateLargeVideo(id, true);
  557. }
  558. },
  559. /**
  560. * Display name changed.
  561. */
  562. onDisplayNameChanged (id, displayName, status) {
  563. if (id === 'localVideoContainer' ||
  564. APP.conference.isLocalId(id)) {
  565. localVideoThumbnail.setDisplayName(displayName);
  566. } else {
  567. let remoteVideo = remoteVideos[id];
  568. if (remoteVideo)
  569. remoteVideo.setDisplayName(displayName, status);
  570. }
  571. },
  572. /**
  573. * Sets the "raised hand" status for a participant identified by 'id'.
  574. */
  575. setRaisedHandStatus(id, raisedHandStatus) {
  576. var video
  577. = APP.conference.isLocalId(id)
  578. ? localVideoThumbnail : remoteVideos[id];
  579. if (video) {
  580. video.showRaisedHandIndicator(raisedHandStatus);
  581. if (raisedHandStatus) {
  582. video.showDominantSpeakerIndicator(false);
  583. }
  584. }
  585. },
  586. /**
  587. * On dominant speaker changed event.
  588. */
  589. onDominantSpeakerChanged (id) {
  590. if (id === currentDominantSpeaker) {
  591. return;
  592. }
  593. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  594. // We ignore local user events, but just unmark remote user as dominant
  595. // while we are talking
  596. if (APP.conference.isLocalId(id)) {
  597. if(oldSpeakerRemoteVideo)
  598. {
  599. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  600. currentDominantSpeaker = null;
  601. }
  602. localVideoThumbnail.showDominantSpeakerIndicator(true);
  603. return;
  604. }
  605. let remoteVideo = remoteVideos[id];
  606. if (!remoteVideo) {
  607. return;
  608. }
  609. // Update the current dominant speaker.
  610. remoteVideo.showDominantSpeakerIndicator(true);
  611. localVideoThumbnail.showDominantSpeakerIndicator(false);
  612. // let's remove the indications from the remote video if any
  613. if (oldSpeakerRemoteVideo) {
  614. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  615. }
  616. currentDominantSpeaker = id;
  617. // Local video will not have container found, but that's ok
  618. // since we don't want to switch to local video.
  619. // Update the large video if the video source is already available,
  620. // otherwise wait for the "videoactive.jingle" event.
  621. // FIXME: there is no "videoactive.jingle" event.
  622. if (!interfaceConfig.filmStripOnly && !pinnedId
  623. && remoteVideo.hasVideoStarted()
  624. && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
  625. this.updateLargeVideo(id);
  626. }
  627. },
  628. /**
  629. * Shows/hides warning about remote user's connectivity issues.
  630. *
  631. * @param {string} id the ID of the remote participant(MUC nickname)
  632. */
  633. // eslint-disable-next-line no-unused-vars
  634. onParticipantConnectionStatusChanged (id) {
  635. // Show/hide warning on the large video
  636. if (this.isCurrentlyOnLarge(id)) {
  637. if (largeVideo) {
  638. // We have to trigger full large video update to transition from
  639. // avatar to video on connectivity restored.
  640. this.updateLargeVideo(id, true /* force update */);
  641. }
  642. }
  643. // Show/hide warning on the thumbnail
  644. let remoteVideo = remoteVideos[id];
  645. if (remoteVideo) {
  646. // Updating only connection status indicator is not enough, because
  647. // when we the connection is restored while the avatar was displayed
  648. // (due to 'muted while disconnected' condition) we may want to show
  649. // the video stream again and in order to do that the display mode
  650. // must be updated.
  651. //remoteVideo.updateConnectionStatusIndicator(isActive);
  652. remoteVideo.updateView();
  653. }
  654. },
  655. /**
  656. * On last N change event.
  657. *
  658. * @param endpointsLeavingLastN the list currently leaving last N
  659. * endpoints
  660. * @param endpointsEnteringLastN the list currently entering last N
  661. * endpoints
  662. */
  663. onLastNEndpointsChanged (endpointsLeavingLastN, endpointsEnteringLastN) {
  664. if (endpointsLeavingLastN) {
  665. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  666. }
  667. if (endpointsEnteringLastN) {
  668. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  669. }
  670. },
  671. /**
  672. * Updates remote video by id if it exists.
  673. * @param {string} id of the remote video
  674. * @private
  675. */
  676. _updateRemoteVideo(id) {
  677. const remoteVideo = remoteVideos[id];
  678. if (remoteVideo) {
  679. remoteVideo.updateView();
  680. if (remoteVideo.isCurrentlyOnLargeVideo()) {
  681. this.updateLargeVideo(id);
  682. }
  683. }
  684. },
  685. /**
  686. * Updates local stats
  687. * @param percent
  688. * @param object
  689. */
  690. updateLocalConnectionStats (percent, object) {
  691. const { framerate, resolution } = object;
  692. // FIXME overwrites 'lib-jitsi-meet' internal object
  693. // Why library internal objects are passed as event's args ?
  694. object.resolution = resolution[APP.conference.getMyUserId()];
  695. object.framerate = framerate[APP.conference.getMyUserId()];
  696. localVideoThumbnail.updateConnectionStats(percent, object);
  697. Object.keys(resolution).forEach(function (id) {
  698. if (APP.conference.isLocalId(id)) {
  699. return;
  700. }
  701. let resolutionValue = resolution[id];
  702. let remoteVideo = remoteVideos[id];
  703. if (resolutionValue && remoteVideo) {
  704. remoteVideo.updateResolution(resolutionValue);
  705. }
  706. });
  707. Object.keys(framerate).forEach(function (id) {
  708. if (APP.conference.isLocalId(id)) {
  709. return;
  710. }
  711. const framerateValue = framerate[id];
  712. const remoteVideo = remoteVideos[id];
  713. if (framerateValue && remoteVideo) {
  714. remoteVideo.updateFramerate(framerateValue);
  715. }
  716. });
  717. },
  718. /**
  719. * Updates remote stats.
  720. * @param id the id associated with the stats
  721. * @param percent the connection quality percent
  722. * @param object the stats data
  723. */
  724. updateConnectionStats (id, percent, object) {
  725. let remoteVideo = remoteVideos[id];
  726. if (remoteVideo) {
  727. remoteVideo.updateConnectionStats(percent, object);
  728. }
  729. },
  730. /**
  731. * Hides the connection indicator
  732. * @param id
  733. */
  734. hideConnectionIndicator (id) {
  735. let remoteVideo = remoteVideos[id];
  736. if (remoteVideo)
  737. remoteVideo.removeConnectionIndicator();
  738. },
  739. /**
  740. * Hides all the indicators
  741. */
  742. hideStats () {
  743. for (var video in remoteVideos) {
  744. let remoteVideo = remoteVideos[video];
  745. if (remoteVideo)
  746. remoteVideo.hideIndicator();
  747. }
  748. localVideoThumbnail.hideIndicator();
  749. },
  750. removeParticipantContainer (id) {
  751. // Unlock large video
  752. if (pinnedId === id) {
  753. logger.info("Focused video owner has left the conference");
  754. pinnedId = null;
  755. }
  756. if (currentDominantSpeaker === id) {
  757. logger.info("Dominant speaker has left the conference");
  758. currentDominantSpeaker = null;
  759. }
  760. var remoteVideo = remoteVideos[id];
  761. if (remoteVideo) {
  762. // Remove remote video
  763. logger.info("Removing remote video: " + id);
  764. delete remoteVideos[id];
  765. remoteVideo.remove();
  766. } else {
  767. logger.warn("No remote video for " + id);
  768. }
  769. VideoLayout.resizeThumbnails();
  770. },
  771. onVideoTypeChanged (id, newVideoType) {
  772. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  773. return;
  774. }
  775. logger.info("Peer video type changed: ", id, newVideoType);
  776. var smallVideo;
  777. if (APP.conference.isLocalId(id)) {
  778. if (!localVideoThumbnail) {
  779. logger.warn("Local video not ready yet");
  780. return;
  781. }
  782. smallVideo = localVideoThumbnail;
  783. } else if (remoteVideos[id]) {
  784. smallVideo = remoteVideos[id];
  785. } else {
  786. return;
  787. }
  788. smallVideo.setVideoType(newVideoType);
  789. if (this.isCurrentlyOnLarge(id)) {
  790. this.updateLargeVideo(id, true);
  791. }
  792. },
  793. /**
  794. * Resizes the video area.
  795. *
  796. * @param forceUpdate indicates that hidden thumbnails will be shown
  797. * @param completeFunction a function to be called when the video area is
  798. * resized.
  799. */
  800. resizeVideoArea (forceUpdate = false,
  801. animate = false,
  802. completeFunction = null) {
  803. if (largeVideo) {
  804. largeVideo.updateContainerSize();
  805. largeVideo.resize(animate);
  806. }
  807. // Calculate available width and height.
  808. let availableHeight = window.innerHeight;
  809. let availableWidth = UIUtil.getAvailableVideoWidth();
  810. if (availableWidth < 0 || availableHeight < 0) {
  811. return;
  812. }
  813. // Resize the thumbnails first.
  814. this.resizeThumbnails(false, forceUpdate);
  815. // Resize the video area element.
  816. $('#videospace').animate({
  817. right: window.innerWidth - availableWidth,
  818. width: availableWidth,
  819. height: availableHeight
  820. }, {
  821. queue: false,
  822. duration: animate ? 500 : 1,
  823. complete: completeFunction
  824. });
  825. },
  826. getSmallVideo (id) {
  827. if (APP.conference.isLocalId(id)) {
  828. return localVideoThumbnail;
  829. } else {
  830. return remoteVideos[id];
  831. }
  832. },
  833. changeUserAvatar (id, avatarUrl) {
  834. var smallVideo = VideoLayout.getSmallVideo(id);
  835. if (smallVideo) {
  836. smallVideo.avatarChanged(avatarUrl);
  837. } else {
  838. logger.warn(
  839. "Missed avatar update - no small video yet for " + id
  840. );
  841. }
  842. if (this.isCurrentlyOnLarge(id)) {
  843. largeVideo.updateAvatar(avatarUrl);
  844. }
  845. },
  846. /**
  847. * Indicates that the video has been interrupted.
  848. */
  849. onVideoInterrupted () {
  850. if (largeVideo) {
  851. largeVideo.onVideoInterrupted();
  852. }
  853. },
  854. /**
  855. * Indicates that the video has been restored.
  856. */
  857. onVideoRestored () {
  858. if (largeVideo) {
  859. largeVideo.onVideoRestored();
  860. }
  861. },
  862. isLargeVideoVisible () {
  863. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  864. },
  865. /**
  866. * @return {LargeContainer} the currently displayed container on large
  867. * video.
  868. */
  869. getCurrentlyOnLargeContainer () {
  870. return largeVideo.getCurrentContainer();
  871. },
  872. isCurrentlyOnLarge (id) {
  873. return largeVideo && largeVideo.id === id;
  874. },
  875. /**
  876. * Triggers an update of remote video and large video displays so they may
  877. * pick up any state changes that have occurred elsewhere.
  878. *
  879. * @returns {void}
  880. */
  881. updateAllVideos() {
  882. const displayedUserId = this.getLargeVideoID();
  883. if (displayedUserId) {
  884. this.updateLargeVideo(displayedUserId, true);
  885. }
  886. Object.keys(remoteVideos).forEach(video => {
  887. remoteVideos[video].updateView();
  888. });
  889. },
  890. updateLargeVideo (id, forceUpdate) {
  891. if (!largeVideo) {
  892. return;
  893. }
  894. const currentContainer = largeVideo.getCurrentContainer();
  895. const currentContainerType = largeVideo.getCurrentContainerType();
  896. const currentId = largeVideo.id;
  897. const isOnLarge = this.isCurrentlyOnLarge(id);
  898. const smallVideo = this.getSmallVideo(id);
  899. if (isOnLarge && !forceUpdate
  900. && LargeVideoManager.isVideoContainer(currentContainerType)
  901. && smallVideo) {
  902. const currentStreamId = currentContainer.getStreamID();
  903. const newStreamId
  904. = smallVideo.videoStream
  905. ? smallVideo.videoStream.getId() : null;
  906. // FIXME it might be possible to get rid of 'forceUpdate' argument
  907. if (currentStreamId !== newStreamId) {
  908. logger.debug('Enforcing large video update for stream change');
  909. forceUpdate = true;
  910. }
  911. }
  912. if (!isOnLarge || forceUpdate) {
  913. let videoType = this.getRemoteVideoType(id);
  914. // FIXME video type is not the same thing as container type
  915. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  916. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  917. }
  918. let oldSmallVideo;
  919. if (currentId) {
  920. oldSmallVideo = this.getSmallVideo(currentId);
  921. }
  922. smallVideo.waitForResolutionChange();
  923. if (oldSmallVideo)
  924. oldSmallVideo.waitForResolutionChange();
  925. largeVideo.updateLargeVideo(
  926. id,
  927. smallVideo.videoStream,
  928. videoType
  929. ).then(function() {
  930. // update current small video and the old one
  931. smallVideo.updateView();
  932. oldSmallVideo && oldSmallVideo.updateView();
  933. }, function () {
  934. // use clicked other video during update, nothing to do.
  935. });
  936. } else if (currentId) {
  937. let currentSmallVideo = this.getSmallVideo(currentId);
  938. currentSmallVideo.updateView();
  939. }
  940. },
  941. addLargeVideoContainer (type, container) {
  942. largeVideo && largeVideo.addContainer(type, container);
  943. },
  944. removeLargeVideoContainer (type) {
  945. largeVideo && largeVideo.removeContainer(type);
  946. },
  947. /**
  948. * @returns Promise
  949. */
  950. showLargeVideoContainer (type, show) {
  951. if (!largeVideo) {
  952. return Promise.reject();
  953. }
  954. let isVisible = this.isLargeContainerTypeVisible(type);
  955. if (isVisible === show) {
  956. return Promise.resolve();
  957. }
  958. let currentId = largeVideo.id;
  959. if(currentId) {
  960. var oldSmallVideo = this.getSmallVideo(currentId);
  961. }
  962. let containerTypeToShow = type;
  963. // if we are hiding a container and there is focusedVideo
  964. // (pinned remote video) use its video type,
  965. // if not then use default type - large video
  966. if (!show) {
  967. if(pinnedId)
  968. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  969. else
  970. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  971. }
  972. return largeVideo.showContainer(containerTypeToShow)
  973. .then(() => {
  974. if(oldSmallVideo)
  975. oldSmallVideo && oldSmallVideo.updateView();
  976. });
  977. },
  978. isLargeContainerTypeVisible (type) {
  979. return largeVideo && largeVideo.state === type;
  980. },
  981. /**
  982. * Returns the id of the current video shown on large.
  983. * Currently used by tests (torture).
  984. */
  985. getLargeVideoID () {
  986. return largeVideo.id;
  987. },
  988. /**
  989. * Returns the the current video shown on large.
  990. * Currently used by tests (torture).
  991. */
  992. getLargeVideo () {
  993. return largeVideo;
  994. },
  995. /**
  996. * Sets the flipX state of the local video.
  997. * @param {boolean} true for flipped otherwise false;
  998. */
  999. setLocalFlipX (val) {
  1000. this.localFlipX = val;
  1001. },
  1002. getEventEmitter() {return eventEmitter;},
  1003. /**
  1004. * Handles user's features changes.
  1005. */
  1006. onUserFeaturesChanged (user) {
  1007. let video = this.getSmallVideo(user.getId());
  1008. if (!video) {
  1009. return;
  1010. }
  1011. this._setRemoteControlProperties(user, video);
  1012. },
  1013. /**
  1014. * Sets the remote control properties (checks whether remote control
  1015. * is supported and executes remoteVideo.setRemoteControlSupport).
  1016. * @param {JitsiParticipant} user the user that will be checked for remote
  1017. * control support.
  1018. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  1019. * will be set.
  1020. */
  1021. _setRemoteControlProperties (user, remoteVideo) {
  1022. APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
  1023. remoteVideo.setRemoteControlSupport(result));
  1024. },
  1025. /**
  1026. * Returns the wrapper jquery selector for the largeVideo
  1027. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  1028. */
  1029. getLargeVideoWrapper() {
  1030. return this.getCurrentlyOnLargeContainer().$wrapper;
  1031. },
  1032. /**
  1033. * Returns the number of remove video ids.
  1034. *
  1035. * @returns {number} The number of remote videos.
  1036. */
  1037. getRemoteVideosCount() {
  1038. return Object.keys(remoteVideos).length;
  1039. }
  1040. };
  1041. export default VideoLayout;