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

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