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

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