您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VideoLayout.js 28KB

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