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

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