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

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