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

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