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

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