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

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