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

VideoLayout.js 35KB

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