Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

VideoLayout.js 32KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. /* global config, APP, $, interfaceConfig */
  2. /* jshint -W101 */
  3. import AudioLevels from "../audio_levels/AudioLevels";
  4. import Avatar from "../avatar/Avatar";
  5. import BottomToolbar from "../toolbars/BottomToolbar";
  6. import UIEvents from "../../../service/UI/UIEvents";
  7. import UIUtil from "../util/UIUtil";
  8. import RemoteVideo from "./RemoteVideo";
  9. import LargeVideoManager, {VideoContainerType} from "./LargeVideo";
  10. import {PreziContainerType} from '../prezi/Prezi';
  11. import LocalVideo from "./LocalVideo";
  12. const RTCUIUtil = JitsiMeetJS.util.RTCUIHelper;
  13. var remoteVideos = {};
  14. var remoteVideoTypes = {};
  15. var localVideoThumbnail = null;
  16. var currentDominantSpeaker = null;
  17. var lastNCount = config.channelLastN;
  18. var localLastNCount = config.channelLastN;
  19. var localLastNSet = [];
  20. var lastNEndpointsCache = [];
  21. var lastNPickupId = null;
  22. var eventEmitter = null;
  23. /**
  24. * Currently focused video jid
  25. * @type {String}
  26. */
  27. var focusedVideoResourceJid = null;
  28. const thumbAspectRatio = 16.0 / 9.0;
  29. /**
  30. * On contact list item clicked.
  31. */
  32. function onContactClicked (id) {
  33. if (APP.conference.isLocalId(id)) {
  34. $("#localVideoContainer").click();
  35. return;
  36. }
  37. let remoteVideo = remoteVideos[id];
  38. if (remoteVideo && remoteVideo.hasVideo()) {
  39. // It is not always the case that a videoThumb exists (if there is
  40. // no actual video).
  41. if (remoteVideo.hasVideoStarted()) {
  42. // We have a video src, great! Let's update the large video
  43. // now.
  44. VideoLayout.handleVideoThumbClicked(false, id);
  45. } else {
  46. // If we don't have a video src for jid, there's absolutely
  47. // no point in calling handleVideoThumbClicked; Quite
  48. // simply, it won't work because it needs an src to attach
  49. // to the large video.
  50. //
  51. // Instead, we trigger the pinned endpoint changed event to
  52. // let the bridge adjust its lastN set for myjid and store
  53. // the pinned user in the lastNPickupId variable to be
  54. // picked up later by the lastN changed event handler.
  55. lastNPickupId = id;
  56. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
  57. }
  58. }
  59. }
  60. /**
  61. * Returns the corresponding resource id to the given peer container
  62. * DOM element.
  63. *
  64. * @return the corresponding resource id to the given peer container
  65. * DOM element
  66. */
  67. function getPeerContainerResourceId (containerElement) {
  68. if (localVideoThumbnail.container === containerElement) {
  69. return localVideoThumbnail.id;
  70. }
  71. let i = containerElement.id.indexOf('participant_');
  72. if (i >= 0) {
  73. return containerElement.id.substring(i + 12);
  74. }
  75. }
  76. let largeVideo;
  77. var VideoLayout = {
  78. init (emitter) {
  79. eventEmitter = emitter;
  80. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  81. emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
  82. },
  83. initLargeVideo (isSideBarVisible) {
  84. largeVideo = new LargeVideoManager();
  85. largeVideo.updateContainerSize(isSideBarVisible);
  86. AudioLevels.init();
  87. },
  88. setAudioLevel(id, lvl) {
  89. if (!largeVideo) {
  90. return;
  91. }
  92. AudioLevels.updateAudioLevel(
  93. id, lvl, largeVideo.id
  94. );
  95. },
  96. isInLastN (resource) {
  97. return lastNCount < 0 || // lastN is disabled
  98. // lastNEndpoints cache not built yet
  99. (lastNCount > 0 && !lastNEndpointsCache.length) ||
  100. (lastNEndpointsCache &&
  101. lastNEndpointsCache.indexOf(resource) !== -1);
  102. },
  103. changeLocalAudio (stream) {
  104. let localAudio = document.getElementById('localAudio');
  105. localAudio = stream.attach(localAudio);
  106. // Now when Temasys plugin is converting also <audio> elements to
  107. // plugin's <object>s, in current layout it will capture click events
  108. // before it reaches the local video object. We hide it here in order
  109. // to prevent that.
  110. //if (RTCBrowserType.isIExplorer()) {
  111. // The issue is not present on Safari. Also if we hide it in Safari
  112. // then the local audio track will have 'enabled' flag set to false
  113. // which will result in audio mute issues
  114. // $(localAudio).hide();
  115. localAudio.width = 1;
  116. localAudio.height = 1;
  117. //}
  118. },
  119. changeLocalVideo (stream) {
  120. // Set default display name.
  121. localVideoThumbnail.setDisplayName();
  122. localVideoThumbnail.createConnectionIndicator();
  123. let localId = APP.conference.localId;
  124. this.onVideoTypeChanged(localId, stream.videoType);
  125. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  126. AudioLevels.updateAudioLevelCanvas(
  127. null, thumbWidth, thumbHeight);
  128. if (!stream.isMuted()) {
  129. localVideoThumbnail.changeVideo(stream);
  130. }
  131. /* force update if we're currently being displayed */
  132. if (this.isCurrentlyOnLarge(localId)) {
  133. this.updateLargeVideo(localId, true);
  134. }
  135. },
  136. /**
  137. * Get's the localID of the conference and set it to the local video
  138. * (small one). This needs to be called as early as possible, when muc is
  139. * actually joined. Otherwise events can come with information like email
  140. * and setting them assume the id is already set.
  141. */
  142. mucJoined () {
  143. let id = APP.conference.localId;
  144. localVideoThumbnail.joined(id);
  145. if (largeVideo && !largeVideo.id) {
  146. this.updateLargeVideo(id, true);
  147. }
  148. },
  149. /**
  150. * Adds or removes icons for not available camera and microphone.
  151. * @param resourceJid the jid of user
  152. * @param devices available devices
  153. */
  154. setDeviceAvailabilityIcons (id, devices) {
  155. if (APP.conference.isLocalId(id)) {
  156. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  157. return;
  158. }
  159. let video = remoteVideos[id];
  160. if (!video) {
  161. return;
  162. }
  163. video.setDeviceAvailabilityIcons(devices);
  164. },
  165. /**
  166. * Checks if removed video is currently displayed and tries to display
  167. * another one instead.
  168. */
  169. updateRemovedVideo (id) {
  170. if (!this.isCurrentlyOnLarge(id)) {
  171. return;
  172. }
  173. let newId;
  174. // We'll show user's avatar if he is the dominant speaker or if
  175. // his video thumbnail is pinned
  176. if (remoteVideos[id] && (id === focusedVideoResourceJid
  177. || id === currentDominantSpeaker)) {
  178. newId = id;
  179. } else {
  180. // Otherwise select last visible video
  181. newId = this.electLastVisibleVideo();
  182. }
  183. this.updateLargeVideo(newId);
  184. },
  185. electLastVisibleVideo () {
  186. // pick the last visible video in the row
  187. // if nobody else is left, this picks the local video
  188. let thumbs = BottomToolbar.getThumbs(true).filter('[id!="mixedstream"]');
  189. let lastVisible = thumbs.filter(':visible:last');
  190. if (lastVisible.length) {
  191. let id = getPeerContainerResourceId(lastVisible[0]);
  192. if (remoteVideos[id]) {
  193. console.info("electLastVisibleVideo: " + id);
  194. return id;
  195. }
  196. // The RemoteVideo was removed (but the DOM elements may still
  197. // exist).
  198. }
  199. console.info("Last visible video no longer exists");
  200. thumbs = BottomToolbar.getThumbs();
  201. if (thumbs.length) {
  202. let id = getPeerContainerResourceId(thumbs[0]);
  203. if (remoteVideos[id]) {
  204. console.info("electLastVisibleVideo: " + id);
  205. return id;
  206. }
  207. // The RemoteVideo was removed (but the DOM elements may
  208. // still exist).
  209. }
  210. // Go with local video
  211. console.info("Fallback to local video...");
  212. let id = APP.conference.localId;
  213. console.info("electLastVisibleVideo: " + id);
  214. return id;
  215. },
  216. onRemoteStreamAdded (stream) {
  217. let id = stream.getParticipantId();
  218. remoteVideos[id].addRemoteStreamElement(stream);
  219. // if track is muted make sure we reflect that
  220. if(stream.isMuted())
  221. {
  222. if(stream.getType() === "audio")
  223. this.onAudioMute(stream.getParticipantId(), true);
  224. else
  225. this.onVideoMute(stream.getParticipantId(), true);
  226. }
  227. },
  228. /**
  229. * Return the type of the remote video.
  230. * @param id the id for the remote video
  231. * @returns the video type video or screen.
  232. */
  233. getRemoteVideoType (id) {
  234. return remoteVideoTypes[id];
  235. },
  236. handleVideoThumbClicked (noPinnedEndpointChangedEvent,
  237. resourceJid) {
  238. if(focusedVideoResourceJid) {
  239. var oldSmallVideo
  240. = VideoLayout.getSmallVideo(focusedVideoResourceJid);
  241. if (oldSmallVideo && !interfaceConfig.filmStripOnly)
  242. oldSmallVideo.focus(false);
  243. }
  244. var smallVideo = VideoLayout.getSmallVideo(resourceJid);
  245. // Unlock current focused.
  246. if (focusedVideoResourceJid === resourceJid)
  247. {
  248. focusedVideoResourceJid = null;
  249. // Enable the currently set dominant speaker.
  250. if (currentDominantSpeaker) {
  251. if(smallVideo && smallVideo.hasVideo()) {
  252. this.updateLargeVideo(currentDominantSpeaker);
  253. }
  254. }
  255. if (!noPinnedEndpointChangedEvent) {
  256. eventEmitter.emit(UIEvents.PINNED_ENDPOINT);
  257. }
  258. return;
  259. }
  260. // Lock new video
  261. focusedVideoResourceJid = resourceJid;
  262. // Update focused/pinned interface.
  263. if (resourceJid) {
  264. if (smallVideo && !interfaceConfig.filmStripOnly)
  265. smallVideo.focus(true);
  266. if (!noPinnedEndpointChangedEvent) {
  267. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, resourceJid);
  268. }
  269. }
  270. this.updateLargeVideo(resourceJid);
  271. },
  272. /**
  273. * Checks if container for participant identified by given id exists
  274. * in the document and creates it eventually.
  275. *
  276. * @return Returns <tt>true</tt> if the peer container exists,
  277. * <tt>false</tt> - otherwise
  278. */
  279. addParticipantContainer (id) {
  280. let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
  281. remoteVideos[id] = remoteVideo;
  282. let videoType = remoteVideoTypes[id];
  283. if (videoType) {
  284. remoteVideo.setVideoType(videoType);
  285. }
  286. // In case this is not currently in the last n we don't show it.
  287. if (localLastNCount && localLastNCount > 0 &&
  288. BottomToolbar.getThumbs().length >= localLastNCount + 2) {
  289. remoteVideo.showPeerContainer('hide');
  290. } else {
  291. VideoLayout.resizeThumbnails(false, true);
  292. }
  293. },
  294. inputDisplayNameHandler (name) {
  295. localVideoThumbnail.inputDisplayNameHandler(name);
  296. },
  297. videoactive (videoelem, resourceJid) {
  298. console.info(resourceJid + " video is now active", videoelem);
  299. $(videoelem).show();
  300. VideoLayout.resizeThumbnails();
  301. // Update the large video to the last added video only if there's no
  302. // current dominant, focused speaker or prezi playing or update it to
  303. // the current dominant speaker.
  304. if ((!focusedVideoResourceJid &&
  305. !currentDominantSpeaker &&
  306. !this.isLargeContainerTypeVisible(PreziContainerType)) ||
  307. focusedVideoResourceJid === resourceJid ||
  308. (resourceJid &&
  309. currentDominantSpeaker === resourceJid)) {
  310. this.updateLargeVideo(resourceJid, true);
  311. }
  312. },
  313. /**
  314. * Shows the presence status message for the given video.
  315. */
  316. setPresenceStatus (id, statusMsg) {
  317. remoteVideos[id].setPresenceStatus(statusMsg);
  318. },
  319. /**
  320. * Shows a visual indicator for the moderator of the conference.
  321. * On local or remote participants.
  322. */
  323. showModeratorIndicator () {
  324. let isModerator = APP.conference.isModerator;
  325. if (isModerator) {
  326. localVideoThumbnail.createModeratorIndicatorElement();
  327. }
  328. APP.conference.listMembers().forEach(function (member) {
  329. let id = member.getId();
  330. if (member.isModerator()) {
  331. remoteVideos[id].removeRemoteVideoMenu();
  332. remoteVideos[id].createModeratorIndicatorElement();
  333. } else if (isModerator) {
  334. // We are moderator, but user is not - add menu
  335. if ($(`#remote_popupmenu_${id}`).length <= 0) {
  336. remoteVideos[id].addRemoteVideoMenu();
  337. }
  338. }
  339. });
  340. },
  341. /*
  342. * Shows or hides the audio muted indicator over the local thumbnail video.
  343. * @param {boolean} isMuted
  344. */
  345. showLocalAudioIndicator (isMuted) {
  346. localVideoThumbnail.showAudioIndicator(isMuted);
  347. },
  348. /**
  349. * Resizes the large video container.
  350. */
  351. resizeLargeVideoContainer (isSideBarVisible, forceUpdate) {
  352. let animate = false;
  353. if (largeVideo) {
  354. largeVideo.updateContainerSize(isSideBarVisible);
  355. largeVideo.resize(animate);
  356. }
  357. this.resizeVideoSpace(animate, isSideBarVisible);
  358. this.resizeThumbnails(false, forceUpdate);
  359. },
  360. /**
  361. * Resizes thumbnails.
  362. */
  363. resizeThumbnails (animate = false, forceUpdate = false) {
  364. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  365. $('.userAvatar').css('left', (thumbWidth - thumbHeight) / 2);
  366. BottomToolbar.resizeThumbnails(thumbWidth, thumbHeight,
  367. animate, forceUpdate)
  368. .then(function () {
  369. BottomToolbar.resizeToolbar(thumbWidth, thumbHeight);
  370. AudioLevels.updateCanvasSize(thumbWidth, thumbHeight);
  371. });
  372. },
  373. /**
  374. * Calculates the thumbnail size.
  375. *
  376. */
  377. calculateThumbnailSize () {
  378. let videoSpaceWidth = BottomToolbar.getFilmStripWidth();
  379. // Calculate the available height, which is the inner window height
  380. // minus 39px for the header minus 2px for the delimiter lines on the
  381. // top and bottom of the large video, minus the 36px space inside the
  382. // remoteVideos container used for highlighting shadow.
  383. let availableHeight = 100;
  384. let numvids = BottomToolbar.getThumbs().length;
  385. if (localLastNCount && localLastNCount > 0) {
  386. numvids = Math.min(localLastNCount + 1, numvids);
  387. }
  388. // Remove the 3px borders arround videos and border around the remote
  389. // videos area and the 4 pixels between the local video and the others
  390. //TODO: Find out where the 4 pixels come from and remove them
  391. let availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
  392. let availableWidth = availableWinWidth / numvids;
  393. let maxHeight = Math.min(160, availableHeight);
  394. availableHeight
  395. = Math.min( maxHeight,
  396. availableWidth / thumbAspectRatio,
  397. window.innerHeight - 18);
  398. if (availableHeight < availableWidth / thumbAspectRatio) {
  399. availableWidth = Math.floor(availableHeight * thumbAspectRatio);
  400. }
  401. return {
  402. thumbWidth: availableWidth,
  403. thumbHeight: availableHeight
  404. };
  405. },
  406. /**
  407. * On audio muted event.
  408. */
  409. onAudioMute (id, isMuted) {
  410. if (APP.conference.isLocalId(id)) {
  411. localVideoThumbnail.showAudioIndicator(isMuted);
  412. } else {
  413. remoteVideos[id].showAudioIndicator(isMuted);
  414. if (APP.conference.isModerator) {
  415. remoteVideos[id].updateRemoteVideoMenu(isMuted);
  416. }
  417. }
  418. },
  419. /**
  420. * On video muted event.
  421. */
  422. onVideoMute (id, value) {
  423. if (APP.conference.isLocalId(id)) {
  424. localVideoThumbnail.setMutedView(value);
  425. } else {
  426. var remoteVideo = remoteVideos[id];
  427. remoteVideo.setMutedView(value);
  428. }
  429. if(this.isCurrentlyOnLarge(id))
  430. largeVideo.showAvatar(value);
  431. },
  432. /**
  433. * Display name changed.
  434. */
  435. onDisplayNameChanged (id, displayName, status) {
  436. if (id === 'localVideoContainer' ||
  437. APP.conference.isLocalId(id)) {
  438. localVideoThumbnail.setDisplayName(displayName);
  439. } else {
  440. remoteVideos[id].setDisplayName(displayName, status);
  441. }
  442. },
  443. /**
  444. * On dominant speaker changed event.
  445. */
  446. onDominantSpeakerChanged (id) {
  447. if (id === currentDominantSpeaker) {
  448. return;
  449. }
  450. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  451. // We ignore local user events, but just unmark remote user as dominant
  452. // while we are talking
  453. if (APP.conference.isLocalId(id)) {
  454. if(oldSpeakerRemoteVideo)
  455. {
  456. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  457. localVideoThumbnail.updateDominantSpeakerIndicator(true);
  458. currentDominantSpeaker = null;
  459. }
  460. return;
  461. }
  462. let remoteVideo = remoteVideos[id];
  463. if (!remoteVideo) {
  464. return;
  465. }
  466. // Update the current dominant speaker.
  467. remoteVideo.updateDominantSpeakerIndicator(true);
  468. localVideoThumbnail.updateDominantSpeakerIndicator(false);
  469. // let's remove the indications from the remote video if any
  470. if (oldSpeakerRemoteVideo) {
  471. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  472. }
  473. currentDominantSpeaker = id;
  474. // Local video will not have container found, but that's ok
  475. // since we don't want to switch to local video.
  476. // Update the large video if the video source is already available,
  477. // otherwise wait for the "videoactive.jingle" event.
  478. if (!focusedVideoResourceJid && remoteVideo.hasVideoStarted()) {
  479. this.updateLargeVideo(id);
  480. }
  481. },
  482. /**
  483. * On last N change event.
  484. *
  485. * @param lastNEndpoints the list of last N endpoints
  486. * @param endpointsEnteringLastN the list currently entering last N
  487. * endpoints
  488. */
  489. onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
  490. if (lastNCount !== lastNEndpoints.length)
  491. lastNCount = lastNEndpoints.length;
  492. lastNEndpointsCache = lastNEndpoints;
  493. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  494. //
  495. // If LastN drops to, say, 2, because of adaptivity, then E should see
  496. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  497. // so E sees them. C is only in E's local LastN set.
  498. //
  499. // If F starts talking and LastN = 3, then E should see thumbnails for
  500. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  501. // enters E's local LastN ejecting C.
  502. // Increase the local LastN set size, if necessary.
  503. if (lastNCount > localLastNCount) {
  504. localLastNCount = lastNCount;
  505. }
  506. // Update the local LastN set preserving the order in which the
  507. // endpoints appeared in the LastN/local LastN set.
  508. var nextLocalLastNSet = lastNEndpoints.slice(0);
  509. for (var i = 0; i < localLastNSet.length; i++) {
  510. if (nextLocalLastNSet.length >= localLastNCount) {
  511. break;
  512. }
  513. var resourceJid = localLastNSet[i];
  514. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  515. nextLocalLastNSet.push(resourceJid);
  516. }
  517. }
  518. localLastNSet = nextLocalLastNSet;
  519. var updateLargeVideo = false;
  520. // Handle LastN/local LastN changes.
  521. BottomToolbar.getThumbs().each(( index, element ) => {
  522. var resourceJid = getPeerContainerResourceId(element);
  523. var smallVideo = remoteVideos[resourceJid];
  524. // We do not want to process any logic for our own(local) video
  525. // because the local participant is never in the lastN set.
  526. // The code of this function might detect that the local participant
  527. // has been dropped out of the lastN set and will update the large
  528. // video
  529. // Detected from avatar tests, where lastN event override
  530. // local video pinning
  531. if(APP.conference.isLocalId(resourceJid))
  532. return;
  533. var isReceived = true;
  534. if (resourceJid &&
  535. lastNEndpoints.indexOf(resourceJid) < 0 &&
  536. localLastNSet.indexOf(resourceJid) < 0) {
  537. console.log("Remove from last N", resourceJid);
  538. if (smallVideo)
  539. smallVideo.showPeerContainer('hide');
  540. else if (!APP.conference.isLocalId(resourceJid))
  541. console.error("No remote video for: " + resourceJid);
  542. isReceived = false;
  543. } else if (resourceJid &&
  544. smallVideo.isVisible() &&
  545. lastNEndpoints.indexOf(resourceJid) < 0 &&
  546. localLastNSet.indexOf(resourceJid) >= 0) {
  547. if (smallVideo)
  548. smallVideo.showPeerContainer('avatar');
  549. else if (!APP.conference.isLocalId(resourceJid))
  550. console.error("No remote video for: " + resourceJid);
  551. isReceived = false;
  552. }
  553. if (!isReceived) {
  554. // resourceJid has dropped out of the server side lastN set, so
  555. // it is no longer being received. If resourceJid was being
  556. // displayed in the large video we have to switch to another
  557. // user.
  558. if (!updateLargeVideo &&
  559. this.isCurrentlyOnLarge(resourceJid)) {
  560. updateLargeVideo = true;
  561. }
  562. }
  563. });
  564. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  565. endpointsEnteringLastN = lastNEndpoints;
  566. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  567. endpointsEnteringLastN.forEach(function (resourceJid) {
  568. var remoteVideo = remoteVideos[resourceJid];
  569. remoteVideo.showPeerContainer('show');
  570. if (!remoteVideo.isVisible()) {
  571. console.log("Add to last N", resourceJid);
  572. remoteVideo.addRemoteStreamElement(remoteVideo.videoStream);
  573. if (lastNPickupId == resourceJid) {
  574. // Clean up the lastN pickup id.
  575. lastNPickupId = null;
  576. // Don't fire the events again, they've already
  577. // been fired in the contact list click handler.
  578. VideoLayout.handleVideoThumbClicked(
  579. false,
  580. resourceJid);
  581. updateLargeVideo = false;
  582. }
  583. remoteVideo.waitForPlayback(
  584. remoteVideo.selectVideoElement()[0],
  585. remoteVideo.videoStream);
  586. }
  587. });
  588. }
  589. // The endpoint that was being shown in the large video has dropped out
  590. // of the lastN set and there was no lastN pickup jid. We need to update
  591. // the large video now.
  592. if (updateLargeVideo) {
  593. var resource;
  594. // Find out which endpoint to show in the large video.
  595. for (i = 0; i < lastNEndpoints.length; i++) {
  596. resource = lastNEndpoints[i];
  597. if (!resource || APP.conference.isLocalId(resource))
  598. continue;
  599. // videoSrcToSsrc needs to be update for this call to succeed.
  600. this.updateLargeVideo(resource);
  601. break;
  602. }
  603. }
  604. },
  605. /**
  606. * Updates local stats
  607. * @param percent
  608. * @param object
  609. */
  610. updateLocalConnectionStats (percent, object) {
  611. let resolutions = object.resolution;
  612. object.resolution = resolutions[APP.conference.localId];
  613. localVideoThumbnail.updateStatsIndicator(percent, object);
  614. Object.keys(resolutions).forEach(function (id) {
  615. if (APP.conference.isLocalId(id)) {
  616. return;
  617. }
  618. let resolution = resolutions[id];
  619. let remoteVideo = remoteVideos[id];
  620. if (resolution && remoteVideo) {
  621. remoteVideo.updateResolution(resolution);
  622. }
  623. });
  624. },
  625. /**
  626. * Updates remote stats.
  627. * @param id the id associated with the stats
  628. * @param percent the connection quality percent
  629. * @param object the stats data
  630. */
  631. updateConnectionStats (id, percent, object) {
  632. if (remoteVideos[id]) {
  633. remoteVideos[id].updateStatsIndicator(percent, object);
  634. }
  635. },
  636. /**
  637. * Hides the connection indicator
  638. * @param id
  639. */
  640. hideConnectionIndicator (id) {
  641. remoteVideos[id].hideConnectionIndicator();
  642. },
  643. /**
  644. * Hides all the indicators
  645. */
  646. hideStats () {
  647. for(var video in remoteVideos) {
  648. remoteVideos[video].hideIndicator();
  649. }
  650. localVideoThumbnail.hideIndicator();
  651. },
  652. removeParticipantContainer (id) {
  653. // Unlock large video
  654. if (focusedVideoResourceJid === id) {
  655. console.info("Focused video owner has left the conference");
  656. focusedVideoResourceJid = null;
  657. }
  658. if (currentDominantSpeaker === id) {
  659. console.info("Dominant speaker has left the conference");
  660. currentDominantSpeaker = null;
  661. }
  662. var remoteVideo = remoteVideos[id];
  663. if (remoteVideo) {
  664. // Remove remote video
  665. console.info("Removing remote video: " + id);
  666. delete remoteVideos[id];
  667. remoteVideo.remove();
  668. } else {
  669. console.warn("No remote video for " + id);
  670. }
  671. VideoLayout.resizeThumbnails();
  672. },
  673. onVideoTypeChanged (id, newVideoType) {
  674. if (remoteVideoTypes[id] === newVideoType) {
  675. return;
  676. }
  677. console.info("Peer video type changed: ", id, newVideoType);
  678. remoteVideoTypes[id] = newVideoType;
  679. var smallVideo;
  680. if (APP.conference.isLocalId(id)) {
  681. if (!localVideoThumbnail) {
  682. console.warn("Local video not ready yet");
  683. return;
  684. }
  685. smallVideo = localVideoThumbnail;
  686. } else if (remoteVideos[id]) {
  687. smallVideo = remoteVideos[id];
  688. } else {
  689. return;
  690. }
  691. smallVideo.setVideoType(newVideoType);
  692. if (this.isCurrentlyOnLarge(id)) {
  693. this.updateLargeVideo(id, true);
  694. }
  695. },
  696. showMore (jid) {
  697. if (jid === 'local') {
  698. localVideoThumbnail.connectionIndicator.showMore();
  699. } else {
  700. var remoteVideo = remoteVideos[Strophe.getResourceFromJid(jid)];
  701. if (remoteVideo) {
  702. remoteVideo.connectionIndicator.showMore();
  703. } else {
  704. console.info("Error - no remote video for jid: " + jid);
  705. }
  706. }
  707. },
  708. addRemoteVideoContainer (id) {
  709. return RemoteVideo.createContainer(id);
  710. },
  711. /**
  712. * Resizes the video area.
  713. *
  714. * @param isSideBarVisible indicates if the side bar is currently visible
  715. * @param callback a function to be called when the video space is
  716. * resized.
  717. */
  718. resizeVideoArea (isSideBarVisible, callback) {
  719. let animate = true;
  720. if (largeVideo) {
  721. largeVideo.updateContainerSize(isSideBarVisible);
  722. largeVideo.resize(animate);
  723. this.resizeVideoSpace(animate, isSideBarVisible, callback);
  724. }
  725. VideoLayout.resizeThumbnails(animate);
  726. },
  727. /**
  728. * Resizes the #videospace html element
  729. * @param animate boolean property that indicates whether the resize should
  730. * be animated or not.
  731. * @param isChatVisible boolean property that indicates whether the chat
  732. * area is displayed or not.
  733. * If that parameter is null the method will check the chat panel
  734. * visibility.
  735. * @param completeFunction a function to be called when the video space
  736. * is resized.
  737. */
  738. resizeVideoSpace (animate, isChatVisible, completeFunction) {
  739. let availableHeight = window.innerHeight;
  740. let availableWidth = UIUtil.getAvailableVideoWidth(isChatVisible);
  741. if (availableWidth < 0 || availableHeight < 0) {
  742. return;
  743. }
  744. $('#videospace').animate({
  745. right: window.innerWidth - availableWidth,
  746. width: availableWidth,
  747. height: availableHeight
  748. }, {
  749. queue: false,
  750. duration: animate ? 500 : 1,
  751. complete: completeFunction
  752. });
  753. },
  754. getSmallVideo (id) {
  755. if (APP.conference.isLocalId(id)) {
  756. return localVideoThumbnail;
  757. } else {
  758. return remoteVideos[id];
  759. }
  760. },
  761. changeUserAvatar (id, avatarUrl) {
  762. var smallVideo = VideoLayout.getSmallVideo(id);
  763. if (smallVideo) {
  764. smallVideo.avatarChanged(avatarUrl);
  765. } else {
  766. console.warn(
  767. "Missed avatar update - no small video yet for " + id
  768. );
  769. }
  770. if (this.isCurrentlyOnLarge(id)) {
  771. largeVideo.updateAvatar(avatarUrl);
  772. }
  773. },
  774. /**
  775. * Indicates that the video has been interrupted.
  776. */
  777. onVideoInterrupted () {
  778. this.enableVideoProblemFilter(true);
  779. let reconnectingKey = "connection.RECONNECTING";
  780. $('#videoConnectionMessage')
  781. .attr("data-i18n", reconnectingKey)
  782. .text(APP.translation.translateString(reconnectingKey))
  783. .css({display: "block"});
  784. },
  785. /**
  786. * Indicates that the video has been restored.
  787. */
  788. onVideoRestored () {
  789. this.enableVideoProblemFilter(false);
  790. $('#videoConnectionMessage').css({display: "none"});
  791. },
  792. enableVideoProblemFilter (enable) {
  793. if (!largeVideo) {
  794. return;
  795. }
  796. largeVideo.enableVideoProblemFilter(enable);
  797. },
  798. isLargeVideoVisible () {
  799. return this.isLargeContainerTypeVisible(VideoContainerType);
  800. },
  801. isCurrentlyOnLarge (id) {
  802. return largeVideo && largeVideo.id === id;
  803. },
  804. updateLargeVideo (id, forceUpdate) {
  805. if (!largeVideo) {
  806. return;
  807. }
  808. let isOnLarge = this.isCurrentlyOnLarge(id);
  809. let currentId = largeVideo.id;
  810. if (!isOnLarge || forceUpdate) {
  811. if (id !== currentId) {
  812. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  813. }
  814. if (currentId) {
  815. var oldSmallVideo = this.getSmallVideo(currentId);
  816. }
  817. let smallVideo = this.getSmallVideo(id);
  818. let videoType = this.getRemoteVideoType(id);
  819. largeVideo.updateLargeVideo(
  820. id,
  821. smallVideo.videoStream,
  822. videoType
  823. ).then(function() {
  824. // update current small video and the old one
  825. smallVideo.updateView();
  826. oldSmallVideo && oldSmallVideo.updateView();
  827. }, function () {
  828. // use clicked other video during update, nothing to do.
  829. });
  830. } else if (currentId) {
  831. let currentSmallVideo = this.getSmallVideo(currentId);
  832. currentSmallVideo.updateView();
  833. }
  834. },
  835. addLargeVideoContainer (type, container) {
  836. largeVideo && largeVideo.addContainer(type, container);
  837. },
  838. removeLargeVideoContainer (type) {
  839. largeVideo && largeVideo.removeContainer(type);
  840. },
  841. /**
  842. * @returns Promise
  843. */
  844. showLargeVideoContainer (type, show) {
  845. if (!largeVideo) {
  846. return Promise.reject();
  847. }
  848. let isVisible = this.isLargeContainerTypeVisible(type);
  849. if (isVisible === show) {
  850. return Promise.resolve();
  851. }
  852. // if !show then use default type - large video
  853. return largeVideo.showContainer(show ? type : VideoContainerType);
  854. },
  855. isLargeContainerTypeVisible (type) {
  856. return largeVideo && largeVideo.state === type;
  857. },
  858. /**
  859. * Returns the id of the current video shown on large.
  860. * Currently used by tests (troture).
  861. */
  862. getLargeVideoID () {
  863. return largeVideo.id;
  864. }
  865. };
  866. export default VideoLayout;