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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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
  488. .connectionIndicator.updateConnectionStatusIndicator(status);
  489. },
  490. /**
  491. * Resizes thumbnails.
  492. */
  493. resizeThumbnails ( animate = false,
  494. forceUpdate = false,
  495. onComplete = null) {
  496. const { localVideo, remoteVideo }
  497. = Filmstrip.calculateThumbnailSize();
  498. Filmstrip.resizeThumbnails(localVideo, remoteVideo,
  499. animate, forceUpdate)
  500. .then(function () {
  501. if (onComplete && typeof onComplete === "function")
  502. onComplete();
  503. });
  504. return { localVideo, remoteVideo };
  505. },
  506. /**
  507. * On audio muted event.
  508. */
  509. onAudioMute (id, isMuted) {
  510. if (APP.conference.isLocalId(id)) {
  511. localVideoThumbnail.showAudioIndicator(isMuted);
  512. } else {
  513. let remoteVideo = remoteVideos[id];
  514. if (!remoteVideo)
  515. return;
  516. remoteVideo.showAudioIndicator(isMuted);
  517. if (APP.conference.isModerator) {
  518. remoteVideo.updateRemoteVideoMenu(isMuted);
  519. }
  520. }
  521. },
  522. /**
  523. * On video muted event.
  524. */
  525. onVideoMute (id, value) {
  526. if (APP.conference.isLocalId(id)) {
  527. localVideoThumbnail.setVideoMutedView(value);
  528. } else {
  529. let remoteVideo = remoteVideos[id];
  530. if (remoteVideo)
  531. remoteVideo.setVideoMutedView(value);
  532. }
  533. if (this.isCurrentlyOnLarge(id)) {
  534. // large video will show avatar instead of muted stream
  535. this.updateLargeVideo(id, true);
  536. }
  537. },
  538. /**
  539. * Display name changed.
  540. */
  541. onDisplayNameChanged (id, displayName, status) {
  542. if (id === 'localVideoContainer' ||
  543. APP.conference.isLocalId(id)) {
  544. localVideoThumbnail.setDisplayName(displayName);
  545. } else {
  546. let remoteVideo = remoteVideos[id];
  547. if (remoteVideo)
  548. remoteVideo.setDisplayName(displayName, status);
  549. }
  550. },
  551. /**
  552. * Sets the "raised hand" status for a participant identified by 'id'.
  553. */
  554. setRaisedHandStatus(id, raisedHandStatus) {
  555. var video
  556. = APP.conference.isLocalId(id)
  557. ? localVideoThumbnail : remoteVideos[id];
  558. if (video) {
  559. video.showRaisedHandIndicator(raisedHandStatus);
  560. if (raisedHandStatus) {
  561. video.showDominantSpeakerIndicator(false);
  562. }
  563. }
  564. },
  565. /**
  566. * On dominant speaker changed event.
  567. */
  568. onDominantSpeakerChanged (id) {
  569. if (id === currentDominantSpeaker) {
  570. return;
  571. }
  572. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  573. // We ignore local user events, but just unmark remote user as dominant
  574. // while we are talking
  575. if (APP.conference.isLocalId(id)) {
  576. if(oldSpeakerRemoteVideo)
  577. {
  578. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  579. currentDominantSpeaker = null;
  580. }
  581. localVideoThumbnail.showDominantSpeakerIndicator(true);
  582. return;
  583. }
  584. let remoteVideo = remoteVideos[id];
  585. if (!remoteVideo) {
  586. return;
  587. }
  588. // Update the current dominant speaker.
  589. remoteVideo.showDominantSpeakerIndicator(true);
  590. localVideoThumbnail.showDominantSpeakerIndicator(false);
  591. // let's remove the indications from the remote video if any
  592. if (oldSpeakerRemoteVideo) {
  593. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  594. }
  595. currentDominantSpeaker = id;
  596. // Local video will not have container found, but that's ok
  597. // since we don't want to switch to local video.
  598. // Update the large video if the video source is already available,
  599. // otherwise wait for the "videoactive.jingle" event.
  600. // FIXME: there is no "videoactive.jingle" event.
  601. if (!interfaceConfig.filmStripOnly && !pinnedId
  602. && remoteVideo.hasVideoStarted()
  603. && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
  604. this.updateLargeVideo(id);
  605. }
  606. },
  607. /**
  608. * Shows/hides warning about remote user's connectivity issues.
  609. *
  610. * @param {string} id the ID of the remote participant(MUC nickname)
  611. */
  612. // eslint-disable-next-line no-unused-vars
  613. onParticipantConnectionStatusChanged (id) {
  614. // Show/hide warning on the large video
  615. if (this.isCurrentlyOnLarge(id)) {
  616. if (largeVideo) {
  617. // We have to trigger full large video update to transition from
  618. // avatar to video on connectivity restored.
  619. this.updateLargeVideo(id, true /* force update */);
  620. }
  621. }
  622. // Show/hide warning on the thumbnail
  623. let remoteVideo = remoteVideos[id];
  624. if (remoteVideo) {
  625. // Updating only connection status indicator is not enough, because
  626. // when we the connection is restored while the avatar was displayed
  627. // (due to 'muted while disconnected' condition) we may want to show
  628. // the video stream again and in order to do that the display mode
  629. // must be updated.
  630. //remoteVideo.updateConnectionStatusIndicator(isActive);
  631. remoteVideo.updateView();
  632. }
  633. },
  634. /**
  635. * On last N change event.
  636. *
  637. * @param endpointsLeavingLastN the list currently leaving last N
  638. * endpoints
  639. * @param endpointsEnteringLastN the list currently entering last N
  640. * endpoints
  641. */
  642. onLastNEndpointsChanged (endpointsLeavingLastN, endpointsEnteringLastN) {
  643. if (endpointsLeavingLastN) {
  644. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  645. }
  646. if (endpointsEnteringLastN) {
  647. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  648. }
  649. },
  650. /**
  651. * Updates remote video by id if it exists.
  652. * @param {string} id of the remote video
  653. * @private
  654. */
  655. _updateRemoteVideo(id) {
  656. const remoteVideo = remoteVideos[id];
  657. if (remoteVideo) {
  658. remoteVideo.updateView();
  659. if (remoteVideo.isCurrentlyOnLargeVideo()) {
  660. this.updateLargeVideo(id);
  661. }
  662. }
  663. },
  664. /**
  665. * Updates local stats
  666. * @param percent
  667. * @param object
  668. */
  669. updateLocalConnectionStats (percent, object) {
  670. const { framerate, resolution } = object;
  671. // FIXME overwrites 'lib-jitsi-meet' internal object
  672. // Why library internal objects are passed as event's args ?
  673. object.resolution = resolution[APP.conference.getMyUserId()];
  674. object.framerate = framerate[APP.conference.getMyUserId()];
  675. localVideoThumbnail.updateStatsIndicator(percent, object);
  676. Object.keys(resolution).forEach(function (id) {
  677. if (APP.conference.isLocalId(id)) {
  678. return;
  679. }
  680. let resolutionValue = resolution[id];
  681. let remoteVideo = remoteVideos[id];
  682. if (resolutionValue && remoteVideo) {
  683. remoteVideo.updateResolution(resolutionValue);
  684. }
  685. });
  686. Object.keys(framerate).forEach(function (id) {
  687. if (APP.conference.isLocalId(id)) {
  688. return;
  689. }
  690. const framerateValue = framerate[id];
  691. const remoteVideo = remoteVideos[id];
  692. if (framerateValue && remoteVideo) {
  693. remoteVideo.updateFramerate(framerateValue);
  694. }
  695. });
  696. },
  697. /**
  698. * Updates remote stats.
  699. * @param id the id associated with the stats
  700. * @param percent the connection quality percent
  701. * @param object the stats data
  702. */
  703. updateConnectionStats (id, percent, object) {
  704. let remoteVideo = remoteVideos[id];
  705. if (remoteVideo) {
  706. remoteVideo.updateStatsIndicator(percent, object);
  707. }
  708. },
  709. /**
  710. * Hides the connection indicator
  711. * @param id
  712. */
  713. hideConnectionIndicator (id) {
  714. let remoteVideo = remoteVideos[id];
  715. if (remoteVideo)
  716. remoteVideo.hideConnectionIndicator();
  717. },
  718. /**
  719. * Hides all the indicators
  720. */
  721. hideStats () {
  722. for (var video in remoteVideos) {
  723. let remoteVideo = remoteVideos[video];
  724. if (remoteVideo)
  725. remoteVideo.hideIndicator();
  726. }
  727. localVideoThumbnail.hideIndicator();
  728. },
  729. removeParticipantContainer (id) {
  730. // Unlock large video
  731. if (pinnedId === id) {
  732. logger.info("Focused video owner has left the conference");
  733. pinnedId = null;
  734. }
  735. if (currentDominantSpeaker === id) {
  736. logger.info("Dominant speaker has left the conference");
  737. currentDominantSpeaker = null;
  738. }
  739. var remoteVideo = remoteVideos[id];
  740. if (remoteVideo) {
  741. // Remove remote video
  742. logger.info("Removing remote video: " + id);
  743. delete remoteVideos[id];
  744. remoteVideo.remove();
  745. } else {
  746. logger.warn("No remote video for " + id);
  747. }
  748. VideoLayout.resizeThumbnails();
  749. },
  750. onVideoTypeChanged (id, newVideoType) {
  751. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  752. return;
  753. }
  754. logger.info("Peer video type changed: ", id, newVideoType);
  755. var smallVideo;
  756. if (APP.conference.isLocalId(id)) {
  757. if (!localVideoThumbnail) {
  758. logger.warn("Local video not ready yet");
  759. return;
  760. }
  761. smallVideo = localVideoThumbnail;
  762. } else if (remoteVideos[id]) {
  763. smallVideo = remoteVideos[id];
  764. } else {
  765. return;
  766. }
  767. smallVideo.setVideoType(newVideoType);
  768. if (this.isCurrentlyOnLarge(id)) {
  769. this.updateLargeVideo(id, true);
  770. }
  771. },
  772. showMore (id) {
  773. if (id === 'local') {
  774. localVideoThumbnail.connectionIndicator.showMore();
  775. } else {
  776. let remoteVideo = remoteVideos[id];
  777. if (remoteVideo) {
  778. remoteVideo.connectionIndicator.showMore();
  779. } else {
  780. logger.info("Error - no remote video for id: " + id);
  781. }
  782. }
  783. },
  784. /**
  785. * Resizes the video area.
  786. *
  787. * @param forceUpdate indicates that hidden thumbnails will be shown
  788. * @param completeFunction a function to be called when the video area is
  789. * resized.
  790. */
  791. resizeVideoArea (forceUpdate = false,
  792. animate = false,
  793. completeFunction = null) {
  794. if (largeVideo) {
  795. largeVideo.updateContainerSize();
  796. largeVideo.resize(animate);
  797. }
  798. // Calculate available width and height.
  799. let availableHeight = window.innerHeight;
  800. let availableWidth = UIUtil.getAvailableVideoWidth();
  801. if (availableWidth < 0 || availableHeight < 0) {
  802. return;
  803. }
  804. // Resize the thumbnails first.
  805. this.resizeThumbnails(false, forceUpdate);
  806. // Resize the video area element.
  807. $('#videospace').animate({
  808. right: window.innerWidth - availableWidth,
  809. width: availableWidth,
  810. height: availableHeight
  811. }, {
  812. queue: false,
  813. duration: animate ? 500 : 1,
  814. complete: completeFunction
  815. });
  816. },
  817. getSmallVideo (id) {
  818. if (APP.conference.isLocalId(id)) {
  819. return localVideoThumbnail;
  820. } else {
  821. return remoteVideos[id];
  822. }
  823. },
  824. changeUserAvatar (id, avatarUrl) {
  825. var smallVideo = VideoLayout.getSmallVideo(id);
  826. if (smallVideo) {
  827. smallVideo.avatarChanged(avatarUrl);
  828. } else {
  829. logger.warn(
  830. "Missed avatar update - no small video yet for " + id
  831. );
  832. }
  833. if (this.isCurrentlyOnLarge(id)) {
  834. largeVideo.updateAvatar(avatarUrl);
  835. }
  836. },
  837. /**
  838. * Indicates that the video has been interrupted.
  839. */
  840. onVideoInterrupted () {
  841. if (largeVideo) {
  842. largeVideo.onVideoInterrupted();
  843. }
  844. },
  845. /**
  846. * Indicates that the video has been restored.
  847. */
  848. onVideoRestored () {
  849. if (largeVideo) {
  850. largeVideo.onVideoRestored();
  851. }
  852. },
  853. isLargeVideoVisible () {
  854. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  855. },
  856. /**
  857. * @return {LargeContainer} the currently displayed container on large
  858. * video.
  859. */
  860. getCurrentlyOnLargeContainer () {
  861. return largeVideo.getContainer(largeVideo.state);
  862. },
  863. isCurrentlyOnLarge (id) {
  864. return largeVideo && largeVideo.id === id;
  865. },
  866. /**
  867. * Triggers an update of remote video and large video displays so they may
  868. * pick up any state changes that have occurred elsewhere.
  869. *
  870. * @returns {void}
  871. */
  872. updateAllVideos() {
  873. const displayedUserId = this.getLargeVideoID();
  874. if (displayedUserId) {
  875. this.updateLargeVideo(displayedUserId, true);
  876. }
  877. Object.keys(remoteVideos).forEach(video => {
  878. remoteVideos[video].updateView();
  879. });
  880. },
  881. updateLargeVideo (id, forceUpdate) {
  882. if (!largeVideo) {
  883. return;
  884. }
  885. let isOnLarge = this.isCurrentlyOnLarge(id);
  886. let currentId = largeVideo.id;
  887. if (!isOnLarge || forceUpdate) {
  888. let videoType = this.getRemoteVideoType(id);
  889. // FIXME video type is not the same thing as container type
  890. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  891. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  892. }
  893. let smallVideo = this.getSmallVideo(id);
  894. let oldSmallVideo;
  895. if (currentId) {
  896. oldSmallVideo = this.getSmallVideo(currentId);
  897. }
  898. smallVideo.waitForResolutionChange();
  899. if (oldSmallVideo)
  900. oldSmallVideo.waitForResolutionChange();
  901. largeVideo.updateLargeVideo(
  902. id,
  903. smallVideo.videoStream,
  904. videoType
  905. ).then(function() {
  906. // update current small video and the old one
  907. smallVideo.updateView();
  908. oldSmallVideo && oldSmallVideo.updateView();
  909. }, function () {
  910. // use clicked other video during update, nothing to do.
  911. });
  912. } else if (currentId) {
  913. let currentSmallVideo = this.getSmallVideo(currentId);
  914. currentSmallVideo.updateView();
  915. }
  916. },
  917. addLargeVideoContainer (type, container) {
  918. largeVideo && largeVideo.addContainer(type, container);
  919. },
  920. removeLargeVideoContainer (type) {
  921. largeVideo && largeVideo.removeContainer(type);
  922. },
  923. /**
  924. * @returns Promise
  925. */
  926. showLargeVideoContainer (type, show) {
  927. if (!largeVideo) {
  928. return Promise.reject();
  929. }
  930. let isVisible = this.isLargeContainerTypeVisible(type);
  931. if (isVisible === show) {
  932. return Promise.resolve();
  933. }
  934. let currentId = largeVideo.id;
  935. if(currentId) {
  936. var oldSmallVideo = this.getSmallVideo(currentId);
  937. }
  938. let containerTypeToShow = type;
  939. // if we are hiding a container and there is focusedVideo
  940. // (pinned remote video) use its video type,
  941. // if not then use default type - large video
  942. if (!show) {
  943. if(pinnedId)
  944. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  945. else
  946. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  947. }
  948. return largeVideo.showContainer(containerTypeToShow)
  949. .then(() => {
  950. if(oldSmallVideo)
  951. oldSmallVideo && oldSmallVideo.updateView();
  952. });
  953. },
  954. isLargeContainerTypeVisible (type) {
  955. return largeVideo && largeVideo.state === type;
  956. },
  957. /**
  958. * Returns the id of the current video shown on large.
  959. * Currently used by tests (torture).
  960. */
  961. getLargeVideoID () {
  962. return largeVideo.id;
  963. },
  964. /**
  965. * Returns the the current video shown on large.
  966. * Currently used by tests (torture).
  967. */
  968. getLargeVideo () {
  969. return largeVideo;
  970. },
  971. /**
  972. * Sets the flipX state of the local video.
  973. * @param {boolean} true for flipped otherwise false;
  974. */
  975. setLocalFlipX (val) {
  976. this.localFlipX = val;
  977. },
  978. getEventEmitter() {return eventEmitter;},
  979. /**
  980. * Handles user's features changes.
  981. */
  982. onUserFeaturesChanged (user) {
  983. let video = this.getSmallVideo(user.getId());
  984. if (!video) {
  985. return;
  986. }
  987. this._setRemoteControlProperties(user, video);
  988. },
  989. /**
  990. * Sets the remote control properties (checks whether remote control
  991. * is supported and executes remoteVideo.setRemoteControlSupport).
  992. * @param {JitsiParticipant} user the user that will be checked for remote
  993. * control support.
  994. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  995. * will be set.
  996. */
  997. _setRemoteControlProperties (user, remoteVideo) {
  998. APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
  999. remoteVideo.setRemoteControlSupport(result));
  1000. },
  1001. /**
  1002. * Returns the wrapper jquery selector for the largeVideo
  1003. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  1004. */
  1005. getLargeVideoWrapper() {
  1006. return this.getCurrentlyOnLargeContainer().$wrapper;
  1007. },
  1008. /**
  1009. * Returns the number of remove video ids.
  1010. *
  1011. * @returns {number} The number of remote videos.
  1012. */
  1013. getRemoteVideosCount() {
  1014. return Object.keys(remoteVideos).length;
  1015. }
  1016. };
  1017. export default VideoLayout;