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

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