Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VideoLayout.js 35KB

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