您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VideoLayout.js 35KB

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