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

VideoLayout.js 36KB

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