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

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